[FIX] account: invoice onchange partner accounts properties
Since revision7eab8e26d3the `_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.80861660c6) 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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user