From 76ca410f821f91e2317f68e7a86e25e2dff33873 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 5 Mar 2013 17:20:15 +0100 Subject: [PATCH] [FIX] _find_partner refactoring for res_partner and using it in creation of stock account moves bzr revid: jco@openerp.com-20130305162015-lndgz2f0z4xtd62z --- addons/account/account_invoice.py | 23 ++++++++++++----------- addons/account_voucher/invoice.py | 2 +- addons/stock/stock.py | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 2a4b410de2f..55bb2aa6f4f 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -305,16 +305,7 @@ 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): @@ -980,7 +971,7 @@ class account_invoice(osv.osv): date = inv.date_invoice or time.strftime('%Y-%m-%d') - part = self._find_partner(inv) + part = self.pool.get("res.partner")._find_partner(inv.partner_id) line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, part.id, date, context=ctx)),iml) @@ -1752,6 +1743,16 @@ class res_partner(osv.osv): 'invoice_ids': fields.one2many('account.invoice.line', 'partner_id', 'Invoices', readonly=True), } + def _find_partner(self, part): + ''' + 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' + if part.parent_id and not part.is_company: + part = part.parent_id + return part + def copy(self, cr, uid, id, default=None, context=None): default = default or {} default.update({'invoice_ids' : []}) diff --git a/addons/account_voucher/invoice.py b/addons/account_voucher/invoice.py index bd43694260b..8a529a36492 100644 --- a/addons/account_voucher/invoice.py +++ b/addons/account_voucher/invoice.py @@ -41,7 +41,7 @@ class invoice(osv.osv): 'target': 'new', 'domain': '[]', 'context': { - 'default_partner_id': self._find_partner(inv).id, + 'default_partner_id': self.pool.get('res.partner')._find_partner(inv.partner_id).id, 'default_amount': inv.type in ('out_refund', 'in_refund') and -inv.residual or inv.residual, 'default_reference': inv.name, 'close_after_process': True, diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 7198c89e286..0bf1bd485bf 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2396,7 +2396,7 @@ class stock_move(osv.osv): processing of the given stock move. """ # prepare default values considering that the destination accounts have the reference_currency_id as their main currency - partner_id = (move.picking_id.partner_id and move.picking_id.partner_id.id and move.picking_id.partner_id.id) or False + partner_id = (move.picking_id.partner_id and move.picking_id.partner_id.id and self.pool.get('res.partner')._find_partner(move.picking_id.partner_id).id) or False debit_line_vals = { 'name': move.name, 'product_id': move.product_id and move.product_id.id or False,