| 1 | from odoo import fields, models |
| 2 | |
| 3 | |
| 4 | class StockLocation(models.Model): |
| 5 | _inherit = 'stock.location' |
| 6 | |
| 7 | equipment_count = fields.Integer('Equipment Count', compute='_compute_equipment_count') |
| 8 | |
| 9 | def _compute_equipment_count(self): |
| 10 | equipment_data = self.env['maintenance.equipment']._read_group([('location_id', 'in', self.ids)], ['location_id'], ['__count']) |
| 11 | mapped_data = {location.id: count for location, count in equipment_data} |
| 12 | for location in self: |
| 13 | location.equipment_count = mapped_data.get(location.id, 0) |
| 14 | |
| 15 | def action_view_equipments_records(self): |
| 16 | action = self.env["ir.actions.actions"]._for_xml_id("maintenance.hr_equipment_action") |
| 17 | action['domain'] = [('location_id', '=', self.id)] |
| 18 | return action |