diff --git a/addons/repair/__manifest__.py b/addons/repair/__manifest__.py index ad74d6c34fb..c69466d64ca 100644 --- a/addons/repair/__manifest__.py +++ b/addons/repair/__manifest__.py @@ -29,6 +29,7 @@ The following topics are covered by this module: 'wizard/stock_warn_insufficient_qty_views.xml', 'views/stock_move_views.xml', 'views/repair_views.xml', + 'views/stock_production_lot_views.xml', 'report/repair_reports.xml', 'report/repair_templates_repair_order.xml', 'data/ir_sequence_data.xml', diff --git a/addons/repair/models/__init__.py b/addons/repair/models/__init__.py index 1997e59df6e..975c1b98256 100644 --- a/addons/repair/models/__init__.py +++ b/addons/repair/models/__init__.py @@ -3,4 +3,5 @@ from . import repair from . import stock_traceability +from . import stock_production_lot from . import account_move diff --git a/addons/repair/models/stock_production_lot.py b/addons/repair/models/stock_production_lot.py new file mode 100644 index 00000000000..f830bbac4b5 --- /dev/null +++ b/addons/repair/models/stock_production_lot.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from collections import defaultdict +from odoo import api, fields, models, _ + +class ProductionLot(models.Model): + _inherit = 'stock.production.lot' + + repair_order_ids = fields.Many2many('repair.order', string="Repair Orders", compute="_compute_repair_order_ids") + repair_order_count = fields.Integer('Repair order count', compute="_compute_repair_order_ids") + + @api.depends('name') + def _compute_repair_order_ids(self): + repair_orders = defaultdict(lambda: self.env['repair.order']) + for repair_line in self.env['repair.line'].search([('lot_id', 'in', self.ids), ('state', '=', 'done')]): + repair_orders[repair_line.lot_id.id] |= repair_line.repair_id + for lot in self: + lot.repair_order_ids = repair_orders[lot.id] + lot.repair_order_count = len(lot.repair_order_ids) + + def action_view_ro(self): + self.ensure_one() + + action = { + 'res_model': 'repair.order', + 'type': 'ir.actions.act_window' + } + if len(self.repair_order_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': self.repair_order_ids[0].id + }) + else: + action.update({ + 'name': _("Repair orders of %s", self.name), + 'domain': [('id', 'in', self.repair_order_ids.ids)], + 'view_mode': 'tree,form' + }) + return action diff --git a/addons/repair/views/stock_production_lot_views.xml b/addons/repair/views/stock_production_lot_views.xml new file mode 100644 index 00000000000..f68bfd22410 --- /dev/null +++ b/addons/repair/views/stock_production_lot_views.xml @@ -0,0 +1,21 @@ + + + + stock.production.lot.view.form + stock.production.lot + + + + + + + +