From 73c53b40719947f37f8ae057dd73051679545a46 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Fri, 30 Nov 2012 17:35:28 +0100 Subject: [PATCH] [FIX] account_voucher: pay invoice propose the good partner (parent if not a company) bzr revid: qdp-launchpad@openerp.com-20121130163528-zjjncja58hhnyflh --- addons/account/account_invoice.py | 18 +++++++++++++----- addons/account_voucher/invoice.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 8d13ec9dc8f..b1620e4a0ff 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -294,6 +294,18 @@ class account_invoice(osv.osv): ('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number must be unique per Company!'), ] + def _find_partner(self, inv): + ''' + Find the partner for which the accounting entries will be created + ''' + #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' + part = inv.partner_id + if part.parent_id and not part.is_company: + part = part.parent_id + return part + + def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False): journal_obj = self.pool.get('account.journal') if context is None: @@ -959,11 +971,7 @@ class account_invoice(osv.osv): date = inv.date_invoice or time.strftime('%Y-%m-%d') - #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' - part = inv.partner_id - if part.parent_id and not part.is_company: - part = part.parent_id + part = self._find_partner(inv) line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part.id, date, context=ctx)),iml) diff --git a/addons/account_voucher/invoice.py b/addons/account_voucher/invoice.py index 91ba438756e..426027f984c 100644 --- a/addons/account_voucher/invoice.py +++ b/addons/account_voucher/invoice.py @@ -40,7 +40,7 @@ class invoice(osv.osv): 'target': 'new', 'domain': '[]', 'context': { - 'default_partner_id': inv.partner_id.id, + 'default_partner_id': self._find_partner(inv), 'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual, 'default_number':inv.name, 'close_after_process': True,