From 638ca9122e950b4b91f80748f4edf888dbbc07bd Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 5 Jan 2012 17:08:45 +0100 Subject: [PATCH] Modularize the selection of the partner to invoice when invoicing from the picking. With this modification, all the parameters of the invoice are correct even when the goods are delivered to a third party company i.e. when the partner who receives the goods (picking.address_id.partner_id) is not to partner who ordered the goods (picking.sale_id.partner_id). bzr revid: alexis@via.ecp.fr-20120105160845-c6wk08k7v7i64zyl --- addons/sale/stock.py | 7 ++++++- addons/stock/stock.py | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/sale/stock.py b/addons/sale/stock.py index 653b147..6188678 100644 --- a/addons/sale/stock.py +++ b/addons/sale/stock.py @@ -48,6 +48,11 @@ class stock_picking(osv.osv): else: return super(stock_picking, self).get_currency_id(cursor, user, picking) + def _get_partner_to_invoice(self, cr, uid, picking, context=None): + if picking.sale_id: + return picking.sale_id.partner_id + return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context) + def _get_payment_term(self, cursor, user, picking): if picking.sale_id and picking.sale_id.payment_term: return picking.sale_id.payment_term.id @@ -195,4 +200,4 @@ class stock_picking(osv.osv): }) return result -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ce34480..c1a334a 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -874,6 +874,13 @@ class stock_picking(osv.osv): def get_currency_id(self, cr, uid, picking): return False + def _get_partner_to_invoice(self, cr, uid, picking, context=None): + """ Gets the partner that will be invoiced + Note that this function is inherited in the sale module + @return: partner object + """ + return picking.address_id and picking.address_id.partner_id + def _get_payment_term(self, cr, uid, picking): """ Gets payment term from partner. @return: Payment term @@ -1030,7 +1037,7 @@ class stock_picking(osv.osv): for picking in self.browse(cr, uid, ids, context=context): if picking.invoice_state != '2binvoiced': continue - partner = picking.address_id and picking.address_id.partner_id + partner = self._get_partner_to_invoice(cr, uid, picking, context=context) if not partner: raise osv.except_osv(_('Error, no partner !'), _('Please put a partner on the picking list if you want to generate invoice.')) -- 1.7.10.4