From a701934ac79a32cb534ff768190c1a444b2f8544 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 15 Apr 2014 10:12:11 +0200 Subject: [PATCH] [FIX] purchase: invoiced based on invoiced bool of purchase order line, instead of rate invoiced bool of purchase order line is set to true on invoice validation, not on invoice creation bzr revid: dle@openerp.com-20140415081211-jz6if0vzgq3inzzw --- addons/purchase/purchase.py | 17 ++++++++++------- addons/purchase/stock.py | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 344da2e70a6..a9d8e773b19 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -134,10 +134,7 @@ class purchase_order(osv.osv): def _invoiced(self, cursor, user, ids, name, arg, context=None): res = {} for purchase in self.browse(cursor, user, ids, context=context): - invoiced = False - if purchase.invoiced_rate == 100.00: - invoiced = True - res[purchase.id] = invoiced + res[purchase.id] = all(line.invoiced for line in purchase.order_line) return res def _get_journal(self, cr, uid, context=None): @@ -544,7 +541,7 @@ class purchase_order(osv.osv): inv_line_id = inv_line_obj.create(cr, uid, inv_line_data, context=context) inv_lines.append(inv_line_id) - po_line.write({'invoiced': True, 'invoice_lines': [(4, inv_line_id)]}, context=context) + po_line.write({'invoice_lines': [(4, inv_line_id)]}, context=context) # get invoice data and create invoice inv_data = { @@ -1290,9 +1287,15 @@ class account_invoice(osv.Model): user_id = uid po_ids = purchase_order_obj.search(cr, user_id, [('invoice_ids', 'in', ids)], context=context) wf_service = netsvc.LocalService("workflow") - for po_id in po_ids: + for order in purchase_order_obj.browse(cr, uid, po_ids, context=context): # Signal purchase order workflow that an invoice has been validated. - wf_service.trg_write(uid, 'purchase.order', po_id, cr) + invoiced = [] + for po_line in order.order_line: + if any(line.invoice_id.state not in ['draft', 'cancel'] for line in po_line.invoice_lines): + invoiced.append(po_line.id) + if invoiced: + self.pool['purchase.order.line'].write(cr, uid, invoiced, {'invoiced': True}) + wf_service.trg_write(uid, 'purchase.order', order.id, cr) return res # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index e4a3252eef2..d0055d80c7f 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -111,7 +111,6 @@ class stock_picking(osv.osv): invoice_line_obj = self.pool.get('account.invoice.line') purchase_line_obj = self.pool.get('purchase.order.line') purchase_line_obj.write(cursor, user, [move_line.purchase_line_id.id], { - 'invoiced': True, 'invoice_lines': [(4, invoice_line_id)], }) return super(stock_picking, self)._invoice_line_hook(cursor, user, move_line, invoice_line_id)