Skip to content

Commit

Permalink
[IMP] #115 Worker Agreement Smart Button
Browse files Browse the repository at this point in the history
  • Loading branch information
osi-scampbell authored and max3903 committed May 7, 2019
1 parent 1f1d5d9 commit 9d3a892
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fieldservice_agreement/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
'views/fsm_order_view.xml',
'views/fsm_equipment_view.xml',
'views/agreement_view.xml',
'views/fsm_person.xml'
],
'installable': True,
'development_status': 'Beta',
'maintainers': [
'max3903',
'bodedra',
'smangukiya',
'osi-scampbell'
],
}
1 change: 1 addition & 0 deletions fieldservice_agreement/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
agreement,
fsm_equipment,
fsm_order,
fsm_person
)
31 changes: 31 additions & 0 deletions fieldservice_agreement/models/fsm_person.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class FSMPerson(models.Model):
_inherit = 'fsm.person'

agreement_count = fields.Integer(string='Agreements',
compute='_compute_agreements')

def _compute_agreements(self):
self.agreement_count = self.env['agreement'].search_count([
('partner_id', '=', self.name)])

@api.multi
def action_view_agreements(self):
for person in self:
action = self.env.ref('agreement_legal.\
agreement_operations_agreement').read()[0]
agreements = self.env['agreement'].search(
[('partner_id', '=', person.partner_id.id)])
if len(agreements) == 1:
action['views'] = [
(self.env.ref('agreement_legal.\
partner_agreement_form_view').id, 'form')]
action['res_id'] = agreements.id
else:
action['domain'] = [('id', 'in', agreements.ids)]
return action
22 changes: 22 additions & 0 deletions fieldservice_agreement/views/fsm_person.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="fsm_person_form" model="ir.ui.view">
<field name="name">fsm.person.form</field>
<field name="model">fsm.person</field>
<field name="inherit_id" ref="fieldservice.fsm_person_form"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button type="object"
name="action_view_agreements"
class="oe_stat_button"
icon="fa-folder"
groups="base.group_user">
<field name="agreement_count" widget="statinfo"
string="Agreements"/>
</button>
</div>
</field>
</record>

</odoo>

0 comments on commit 9d3a892

Please sign in to comment.