From 71e3188383e8f0f10059e2b0b7e7002f09484e6f Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Mon, 14 Apr 2025 16:13:29 +0200 Subject: [PATCH] [FIX]account_budget_forecast:odoo cant copy multiple times on the same record One2many fields that all point to analic_id, so pass them to copy=False --- account_budget_forecast/__manifest__.py | 2 +- .../models/account_analytic_account.py | 14 +++++++------- account_budget_forecast/models/sale_order.py | 11 ++++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/account_budget_forecast/__manifest__.py b/account_budget_forecast/__manifest__.py index 894f1d3..2120b28 100644 --- a/account_budget_forecast/__manifest__.py +++ b/account_budget_forecast/__manifest__.py @@ -3,7 +3,7 @@ { "name": "account_budget_forecast", - "version": "14.0.1.3.0", + "version": "14.0.1.4.0", "author": "Elabore", "maintainer": "False", "website": "False", diff --git a/account_budget_forecast/models/account_analytic_account.py b/account_budget_forecast/models/account_analytic_account.py index 84a8ace..d47c488 100644 --- a/account_budget_forecast/models/account_analytic_account.py +++ b/account_budget_forecast/models/account_analytic_account.py @@ -12,43 +12,43 @@ class AccountAnalyticAccount(models.Model): "budget.forecast", "analytic_id", domain=[("budget_category", "=", "manpower")], - copy=True, + copy=False, ) budget_forecast_material_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "material")], - copy=True, + copy=False, ) budget_forecast_equipment_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "equipment")], - copy=True, + copy=False, ) budget_forecast_subcontractors_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "subcontractors")], - copy=True, + copy=False, ) budget_forecast_delivery_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "delivery")], - copy=True, + copy=False, ) budget_forecast_miscellaneous_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "miscellaneous")], - copy=True, + copy=False, ) budget_forecast_unplanned_ids = fields.One2many( "budget.forecast", "analytic_id", domain=[("budget_category", "=", "unplanned")], - copy=True, + copy=False, ) project_section_budget_ids = fields.One2many( "budget.forecast", diff --git a/account_budget_forecast/models/sale_order.py b/account_budget_forecast/models/sale_order.py index 883f1b2..b343a67 100644 --- a/account_budget_forecast/models/sale_order.py +++ b/account_budget_forecast/models/sale_order.py @@ -2,6 +2,8 @@ from odoo import models, fields, _, api from odoo.exceptions import Warning +import logging +_logger = logging.getLogger(__name__) class SaleOrder(models.Model): @@ -49,9 +51,12 @@ class SaleOrder(models.Model): name = self.analytic_account_id.name.replace(self.name, record.name) else: name = "%s: %s" % (self.analytic_account_id.name, record.name) - record.analytic_account_id = self.analytic_account_id.copy( - default=dict(name=name) - ) + try: + copied_account = self.analytic_account_id.copy(default={"name": name}) + if copied_account: + record.analytic_account_id = copied_account + except Exception as e: + _logger.error("Failed to copy analytic account for sale order %s: %s", self.name, e) return record