From 28caa8fccc5993bc7b623a043ef75ed4c5e93c9c Mon Sep 17 00:00:00 2001 From: momegahed Date: Mon, 30 May 2022 12:34:26 +0000 Subject: [PATCH] [FIX] sale_project_account: Analytic account is overridden Steps to reproduce: 1- install sales ,accounting, project, timesheets 2- create a new service product p1 that triggers a project and a task 3- create a new sales order so with p1 and validate 1 hour in the task 4- create an invoice from so, an anayltic account is added 5- edit any field of product_id, account_id, partner_id, date 6- the analytic default rule is applied (in this case none) so the anayltic account is removed Bug: the `compute_analytic_account_id` method forces the analytic default rule even if the field is already set before the changes Fix: apply analytic default rule only if the analytic acount is not set and if it is not a project generated move OPW-2833912 closes odoo/odoo#94034 X-original-commit: 7f69d623265a53be854eca474876bde2a0b14df6 Signed-off-by: Laurent Stukkens (ltu) --- addons/sale_project/models/__init__.py | 1 + addons/sale_project/models/account_move.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 addons/sale_project/models/account_move.py diff --git a/addons/sale_project/models/__init__.py b/addons/sale_project/models/__init__.py index 2ca122c0b24..b627bbd3dd6 100644 --- a/addons/sale_project/models/__init__.py +++ b/addons/sale_project/models/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from . import account_move from . import product from . import project from . import project_milestone diff --git a/addons/sale_project/models/account_move.py b/addons/sale_project/models/account_move.py new file mode 100644 index 00000000000..5179cde0281 --- /dev/null +++ b/addons/sale_project/models/account_move.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +from odoo import models + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + def _compute_analytic_account_id(self): + # when a project creates an aml, it adds an analytic account to it. the following filter is to save this + # analytic account from being overridden by analytic default rules and lack thereof + project_amls = self.filtered(lambda aml: aml.analytic_account_id and any(aml.sale_line_ids.project_id)) + super(AccountMoveLine, self - project_amls)._compute_analytic_account_id()