[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
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "account_budget_forecast",
|
"name": "account_budget_forecast",
|
||||||
"version": "14.0.1.3.0",
|
"version": "14.0.1.4.0",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"maintainer": "False",
|
"maintainer": "False",
|
||||||
"website": "False",
|
"website": "False",
|
||||||
|
@@ -12,43 +12,43 @@ class AccountAnalyticAccount(models.Model):
|
|||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "manpower")],
|
domain=[("budget_category", "=", "manpower")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_material_ids = fields.One2many(
|
budget_forecast_material_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "material")],
|
domain=[("budget_category", "=", "material")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_equipment_ids = fields.One2many(
|
budget_forecast_equipment_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "equipment")],
|
domain=[("budget_category", "=", "equipment")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_subcontractors_ids = fields.One2many(
|
budget_forecast_subcontractors_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "subcontractors")],
|
domain=[("budget_category", "=", "subcontractors")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_delivery_ids = fields.One2many(
|
budget_forecast_delivery_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "delivery")],
|
domain=[("budget_category", "=", "delivery")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_miscellaneous_ids = fields.One2many(
|
budget_forecast_miscellaneous_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "miscellaneous")],
|
domain=[("budget_category", "=", "miscellaneous")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
budget_forecast_unplanned_ids = fields.One2many(
|
budget_forecast_unplanned_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
"analytic_id",
|
"analytic_id",
|
||||||
domain=[("budget_category", "=", "unplanned")],
|
domain=[("budget_category", "=", "unplanned")],
|
||||||
copy=True,
|
copy=False,
|
||||||
)
|
)
|
||||||
project_section_budget_ids = fields.One2many(
|
project_section_budget_ids = fields.One2many(
|
||||||
"budget.forecast",
|
"budget.forecast",
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from odoo import models, fields, _, api
|
from odoo import models, fields, _, api
|
||||||
from odoo.exceptions import Warning
|
from odoo.exceptions import Warning
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
@@ -49,9 +51,12 @@ class SaleOrder(models.Model):
|
|||||||
name = self.analytic_account_id.name.replace(self.name, record.name)
|
name = self.analytic_account_id.name.replace(self.name, record.name)
|
||||||
else:
|
else:
|
||||||
name = "%s: %s" % (self.analytic_account_id.name, record.name)
|
name = "%s: %s" % (self.analytic_account_id.name, record.name)
|
||||||
record.analytic_account_id = self.analytic_account_id.copy(
|
try:
|
||||||
default=dict(name=name)
|
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
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user