Skip to content

Commit

Permalink
[ADD] fieldservise_account_analytic: analytic plans
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarRetes committed Nov 27, 2024
1 parent 097a3bc commit d81de59
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions fieldservice_account_analytic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions fieldservice_account_analytic/data/analytic_plan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<odoo noupdate="1">
<record id="fsm_order_analytic_plan" model="account.analytic.plan">
<field name="name">FSM Orders</field>
</record>
<record id="fsm_location_analytic_plan" model="account.analytic.plan">
<field name="name">FSM Locations</field>
</record>
<record id="fsm_route_analytic_plan" model="account.analytic.plan">
<field name="name">FSM Routes</field>
</record>
</odoo>
7 changes: 7 additions & 0 deletions fieldservice_account_analytic/models/analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions fieldservice_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit d81de59

Please sign in to comment.