[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
This commit is contained in:
Olivier Dony 2013-04-07 23:23:33 +02:00
parent eb3ffc52ed
commit ad1650854e
1 changed files with 7 additions and 7 deletions

View File

@ -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 {}