diff --git a/project_stock/models/stock_move.py b/project_stock/models/stock_move.py index c5cc1094dd..bb77c57783 100644 --- a/project_stock/models/stock_move.py +++ b/project_stock/models/stock_move.py @@ -60,6 +60,9 @@ def _prepare_analytic_line_from_task(self): vals["ref"] = task.name if "product_id" in analytic_line_fields: vals["product_id"] = product.id + # Prevent incoherence when hr_timesheet addon is installed. + if "project_id" in analytic_line_fields: + vals["project_id"] = False # tags + distributions if task.stock_analytic_tag_ids: vals["tag_ids"] = [(6, 0, task.stock_analytic_tag_ids.ids)] diff --git a/project_stock/tests/test_project_stock.py b/project_stock/tests/test_project_stock.py index f8c9757568..6427176a50 100644 --- a/project_stock/tests/test_project_stock.py +++ b/project_stock/tests/test_project_stock.py @@ -68,6 +68,9 @@ def _test_task_analytic_lines_from_task(self, amount): self.analytic_account, stock_analytic_lines.mapped("account_id"), ) + # Prevent incoherence when hr_timesheet addon is installed. + if "project_id" in self.task.stock_analytic_line_ids._fields: + self.assertFalse(self.task.stock_analytic_line_ids.project_id) def test_project_task_without_analytic_account(self): self.task = self.env["project.task"].browse(self.task.id)