From aedd0251b2ddfd0460ec1eb0502f443ca3430aca Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 25 May 2016 14:32:49 +0200 Subject: [PATCH] [FIX] account: invoice onchange partner accounts properties Since revision 7eab8e26d3d46c53f4be924d6a34e80a66e74960 the `_onchange_partner_id` of `account.invoice` failed if the SUPERUSER created an invoice for another company than his own, and if the partner had not a specific receivable or payable account (meaning the default accounts are used, the accounts coming from the properties of this company without any partner specified) because ``` prop.search([ ('name', '=', 'property_account_receivable_id'), ('company_id', '=', company_id) ])` ``` can return multiple records, if several partners have their own receivable accounts set, and, since the above revision, `get_by_record` specify `ensure_one`, meaning you cannot pass multiple records to this method. This domain was built a the time (2009, rev. 80861660c6fd598c29b3cf6bb044490f2b1feec9) to handle the multi-company property, which can now be handle with a simple `force_company` passed in the context. It was not the case at the time. This revision could be applied in former releases, but this is not a necessity. This is a necessity in saas-10, because of the above revision. opw-678536 --- addons/account/models/account_invoice.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index d9f76a86cff..40dccf363d5 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -451,30 +451,16 @@ class AccountInvoice(models.Model): payment_term_id = False fiscal_position = False bank_id = False - p = self.partner_id company_id = self.company_id.id + p = self.partner_id if not company_id else self.partner_id.with_context(force_company=company_id) type = self.type if p: - partner_id = p.id rec_account = p.property_account_receivable_id pay_account = p.property_account_payable_id - if company_id: - if p.property_account_receivable_id.company_id and \ - p.property_account_receivable_id.company_id.id != company_id and \ - p.property_account_payable_id.company_id and \ - p.property_account_payable_id.company_id.id != company_id: - prop = self.env['ir.property'] - rec_dom = [('name', '=', 'property_account_receivable_id'), ('company_id', '=', company_id)] - pay_dom = [('name', '=', 'property_account_payable_id'), ('company_id', '=', company_id)] - res_dom = [('res_id', '=', 'res.partner,%s' % partner_id)] - rec_prop = prop.search(rec_dom + res_dom) or prop.search(rec_dom) - pay_prop = prop.search(pay_dom + res_dom) or prop.search(pay_dom) - rec_account = rec_prop.get_by_record() - pay_account = pay_prop.get_by_record() - if not rec_account and not pay_account: - action = self.env.ref('account.action_account_config') - msg = _('Cannot find a chart of accounts for this company, You should configure it. \nPlease go to Account Configuration.') - raise RedirectWarning(msg, action.id, _('Go to the configuration panel')) + if not rec_account and not pay_account: + action = self.env.ref('account.action_account_config') + msg = _('Cannot find a chart of accounts for this company, You should configure it. \nPlease go to Account Configuration.') + raise RedirectWarning(msg, action.id, _('Go to the configuration panel')) if type in ('out_invoice', 'out_refund'): account_id = rec_account.id