Skip to content

Commit

Permalink
[ADD] fieldservice_account_analytic: Smart buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarRetes committed Nov 29, 2024
1 parent 32878ce commit 40d4df5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
17 changes: 16 additions & 1 deletion fieldservice_account_analytic/models/fsm_location.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import _, api, fields, models


class FSMLocation(models.Model):
Expand Down Expand Up @@ -70,3 +70,18 @@ def create(self, vals_list):
)
record.analytic_account_id = analytic_account
return record

def action_view_analytic_account(self):
self.ensure_one()
analytic_account = self.env["account.analytic.account"].search(
[("fsm_order_id", "=", self.id)], limit=1
)

if analytic_account:
return {
"type": "ir.actions.act_window",
"res_model": "account.analytic.account",
"view_mode": "form",
"res_id": analytic_account.id,
"name": _("Analytic Account for Location %s") % self.name,
}
17 changes: 16 additions & 1 deletion fieldservice_account_analytic/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import _, api, fields, models


class FSMOrder(models.Model):
Expand Down Expand Up @@ -56,3 +56,18 @@ def create(self, vals_list):
)
record.analytic_account_id = analytic_account
return record

def action_view_analytic_account(self):
self.ensure_one()
analytic_account = self.env["account.analytic.account"].search(
[("fsm_order_id", "=", self.id)], limit=1
)

if analytic_account:
return {
"type": "ir.actions.act_window",
"res_model": "account.analytic.account",
"view_mode": "form",
"res_id": analytic_account.id,
"name": _("Analytic Account for Order %s") % self.name,
}
15 changes: 15 additions & 0 deletions fieldservice_account_analytic/views/fsm_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
<field name="model">fsm.location</field>
<field name="inherit_id" ref="fieldservice.fsm_location_form_view" />
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button
name="action_view_analytic_account"
type="object"
class="oe_stat_button"
icon="fa-bar-chart"
invisible="not analytic_account_id"
>
<field
name="analytic_account_id"
widget="statinfo"
string="Analytic Account"
/>
</button>
</xpath>
<page id="others-page" position="before">
<page name="accounting" string="Accounting">
<group>
Expand Down
15 changes: 15 additions & 0 deletions fieldservice_account_analytic/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
<field name="model">fsm.order</field>
<field name="inherit_id" ref="fieldservice.fsm_order_form" />
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button
name="action_view_analytic_account"
type="object"
class="oe_stat_button"
icon="fa-bar-chart"
invisible="not analytic_account_id"
>
<field
name="analytic_account_id"
widget="statinfo"
string="Analytic Account"
/>
</button>
</xpath>
<notebook position="inside">
<page name="accounting" string="Accounting">
<group name="bill_to">
Expand Down

0 comments on commit 40d4df5

Please sign in to comment.