diff --git a/fieldservice_account_analytic/__manifest__.py b/fieldservice_account_analytic/__manifest__.py index 9dc1531467..0268402faa 100644 --- a/fieldservice_account_analytic/__manifest__.py +++ b/fieldservice_account_analytic/__manifest__.py @@ -16,6 +16,7 @@ ], "data": [ "data/ir_rule.xml", + "data/analytic_plan.xml", "security/ir.model.access.csv", "report/fsm_order_report_template.xml", "views/fsm_location.xml", diff --git a/fieldservice_account_analytic/data/analytic_plan.xml b/fieldservice_account_analytic/data/analytic_plan.xml new file mode 100644 index 0000000000..7823ce6664 --- /dev/null +++ b/fieldservice_account_analytic/data/analytic_plan.xml @@ -0,0 +1,11 @@ + + + FSM Orders + + + FSM Locations + + + FSM Routes + + diff --git a/fieldservice_account_analytic/models/analytic_account.py b/fieldservice_account_analytic/models/analytic_account.py index da454ac2ce..66294ef094 100644 --- a/fieldservice_account_analytic/models/analytic_account.py +++ b/fieldservice_account_analytic/models/analytic_account.py @@ -27,3 +27,10 @@ def create(self, vals_list): @api.onchange("product_id") def onchange_product_id(self): self.name = self.product_id.name if self.product_id else False + + +class AnalyticAccount(models.Model): + _inherit = "account.analytic.account" + + fsm_order_id = fields.One2many("fsm.order", "analytic_account_id", copy=False) + # route_id = fields.One2many("tms.route", "analytic_account_id", copy=False) diff --git a/fieldservice_account_analytic/models/fsm_order.py b/fieldservice_account_analytic/models/fsm_order.py index dbcab41ef3..9ed6894df6 100644 --- a/fieldservice_account_analytic/models/fsm_order.py +++ b/fieldservice_account_analytic/models/fsm_order.py @@ -21,6 +21,8 @@ class FSMOrder(models.Model): tracking=True, ) + analytic_account_id = fields.Many2one("account.analytic.account", copy=False) + def _compute_total_cost(self): """To be overridden as needed from other modules""" for order in self: @@ -38,3 +40,18 @@ def write(self, vals): if "customer_id" not in vals and not order.customer_id: order.customer_id = order.location_id.customer_id.id return res + + @api.model + def create(self, vals): + record = super().create(vals) + analytic_account = self.env["account.analytic.account"].create( + { + "name": vals.get("name"), + "plan_id": self.env.ref( + "fieldservice_account_analytic.fsm_order_analytic_plan" + ).id, + "fsm_order_id": record, + } + ) + record.analytic_account_id = analytic_account + return record