diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 2a4b410de2f..17135ed1f76 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_accounting_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_accounting_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..c0584ddbd52 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_accounting_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..1e85d2f29e5 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 self.pool.get('res.partner')._find_accounting_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,