[FIX] purchase: mark order as invoiced when fully invoiced only

Make sure the purchase order is marked as invoiced only when fully invoiced.
If the invoices are generated on delivery order (invoice_method picking), make
sure all products are delivered before setting it as invoiced.
opw 614256
This commit is contained in:
Martin Trigaux 2015-04-23 17:36:07 +02:00
parent 81a3f56651
commit 316be12a3c
1 changed files with 8 additions and 2 deletions

View File

@ -1328,10 +1328,16 @@ class account_invoice(osv.Model):
for order in purchase_order_obj.browse(cr, uid, po_ids, context=context):
# Signal purchase order workflow that an invoice has been validated.
invoiced = []
shipped = True
# for invoice method manual or order, don't care about shipping state
# for invoices based on incoming shippment, beware of partial deliveries
if (order.invoice_method == 'picking' and
not all(picking.invoice_state in ['invoiced'] for picking in order.picking_ids)):
shipped = False
for po_line in order.order_line:
if any(line.invoice_id.state not in ['draft', 'cancel'] for line in po_line.invoice_lines):
if all(line.invoice_id.state not in ['draft', 'cancel'] for line in po_line.invoice_lines):
invoiced.append(po_line.id)
if invoiced:
if invoiced and shipped:
self.pool['purchase.order.line'].write(cr, uid, invoiced, {'invoiced': True})
wf_service.trg_write(uid, 'purchase.order', order.id, cr)
return res