Skip to content

Commit

Permalink
[IMP] maintenance_equipment_contract: Access requests from contract i…
Browse files Browse the repository at this point in the history
…n order to verify that all has been processed
  • Loading branch information
etobella committed Oct 11, 2023
1 parent 9e24778 commit 31e7641
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
19 changes: 18 additions & 1 deletion maintenance_equipment_contract/models/contract_contract.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# Copyright 2019 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class ContractContract(models.Model):

_inherit = "contract.contract"

equipment_ids = fields.Many2many("maintenance.equipment", string="Equipments")
equipment_count = fields.Integer(compute="_compute_equipment_count")

@api.depends("equipment_ids")
def _compute_equipment_count(self):
for record in self:
record.equipment_count = len(record.equipment_ids)

Check warning on line 17 in maintenance_equipment_contract/models/contract_contract.py

View check run for this annotation

Codecov / codecov/patch

maintenance_equipment_contract/models/contract_contract.py#L17

Added line #L17 was not covered by tests

def action_show_maintenance_requests(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(

Check warning on line 21 in maintenance_equipment_contract/models/contract_contract.py

View check run for this annotation

Codecov / codecov/patch

maintenance_equipment_contract/models/contract_contract.py#L20-L21

Added lines #L20 - L21 were not covered by tests
"maintenance.hr_equipment_request_action"
)
action["domain"] = self._action_show_maintenance_requests_domain()
return action

Check warning on line 25 in maintenance_equipment_contract/models/contract_contract.py

View check run for this annotation

Codecov / codecov/patch

maintenance_equipment_contract/models/contract_contract.py#L24-L25

Added lines #L24 - L25 were not covered by tests

def _action_show_maintenance_requests_domain(self):
return [("equipment_id", "in", self.equipment_ids.ids)]

Check warning on line 28 in maintenance_equipment_contract/models/contract_contract.py

View check run for this annotation

Codecov / codecov/patch

maintenance_equipment_contract/models/contract_contract.py#L28

Added line #L28 was not covered by tests
3 changes: 3 additions & 0 deletions maintenance_equipment_contract/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
* Jaime Arroyo <jaime.arroyo@creublanca.es>
* `Dixmit <https://www.dixmit.com>`_:

* Enric Tobella
11 changes: 11 additions & 0 deletions maintenance_equipment_contract/views/contract_contract.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
<field name="model">contract.contract</field>
<field name="inherit_id" ref="contract.contract_contract_form_view" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
type="object"
name="action_show_maintenance_requests"
class="oe_stat_button"
icon="fa-wrench"
string="Maintenances"
attrs="{'invisible': [('equipment_count', '=', 0)]}"
/>
</div>
<field name="tag_ids" position="before">
<field
name="equipment_ids"
widget="many2many_tags"
options="{'no_create_edit': True}"
/>
<field name="equipment_count" invisible="1" />
</field>
</field>
</record>
Expand Down

0 comments on commit 31e7641

Please sign in to comment.