From ad1650854eead5af703d535cb03d5bdf56088cde Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Sun, 7 Apr 2013 23:23:33 +0200 Subject: [PATCH] [FIX] account: recursively find proper partner to link to journal items, as discussed in bugs 1160365 and 1151947 lp bug: https://launchpad.net/bugs/1160365 fixed lp bug: https://launchpad.net/bugs/1151947 fixed bzr revid: odo@openerp.com-20130407212333-34jahthhppcz2wju --- addons/account/account_invoice.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index eb362455cd9..4611e0ab240 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1260,9 +1260,7 @@ class account_invoice(osv.osv): ref = invoice.reference else: ref = self._convert_ref(cr, uid, invoice.number) - partner = invoice.partner_id - if partner.parent_id and not partner.is_company: - partner = partner.parent_id + partner = self.pool['res.partner']._find_accounting_partner(invoice.partner_id) # Pay attention to the sign for both debit/credit AND amount_currency l1 = { 'debit': direction * pay_amount>0 and direction * pay_amount, @@ -1733,15 +1731,17 @@ class res_partner(osv.osv): 'invoice_ids': fields.one2many('account.invoice.line', 'partner_id', 'Invoices', readonly=True), } - def _find_accounting_partner(self, part): + def _find_accounting_partner(self, partner): ''' Find the partner for which the accounting entries will be created ''' + # FIXME: after 7.0, to replace by function field partner.commercial_id + #if the chosen partner is not a company and has a parent company, use the parent for the journal entries #because you want to invoice 'Agrolait, accounting department' but the journal items are for 'Agrolait' - if part.parent_id and not part.is_company: - part = part.parent_id - return part + while not partner.is_company and partner.parent_id: + partner = partner.parent_id + return partner def copy(self, cr, uid, id, default=None, context=None): default = default or {}