Skip to content
Snippets Groups Projects
Commit dd627b96 authored by Samuel Degueldre's avatar Samuel Degueldre Committed by fw-bot
Browse files

[FIX] account_analytic_default: fix ocr not using default analytic account


PURPOSE:

Default analytic account should be used wherever possible. This wasn't
the case because the module didn't implement a default_get and only
filled the fields on product_id change, which isn't set by the OCR

task-2067097
opw-2068110

closes odoo/odoo#37389

X-original-commit: 2c450015
Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 3371bfab
Branches
Tags
No related merge requests found
......@@ -63,6 +63,28 @@ class AccountAnalyticDefault(models.Model):
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
@api.model
def default_get(self, fields_list):
defaults = super(AccountInvoiceLine, self).default_get(fields_list)
if set(['account_analytic_id', 'analytic_tag_ids']) & set(fields_list):
rec = self.env['account.analytic.default'].account_get(
self.product_id.id,
self.invoice_id.commercial_partner_id.id,
self.invoice_id.user_id.id or self.env.uid,
fields.Date.today(),
company_id=self.company_id.id
)
if rec:
if 'account_analytic_id' in fields_list:
defaults.update({
'account_analytic_id': rec.analytic_id.id,
})
if 'analytic_tag_ids' in fields_list:
defaults.update({
'analytic_tag_ids': rec.analytic_tag_ids.ids,
})
return defaults
@api.onchange('product_id')
def _onchange_product_id(self):
res = super(AccountInvoiceLine, self)._onchange_product_id()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment