[IMP] repair: add link from lot to repair orders

Add links to repair orders in which the tracked lot was consumed

Task-2467686
This commit is contained in:
Quentin Wolfs
2021-08-12 06:34:04 +00:00
parent 4e39893706
commit e68ec01b1b
4 changed files with 62 additions and 0 deletions
+1
View File
@@ -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',
+1
View File
@@ -3,4 +3,5 @@
from . import repair
from . import stock_traceability
from . import stock_production_lot
from . import account_move
@@ -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
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock_production_lot_view_form" model="ir.ui.view">
<field name="name">stock.production.lot.view.form</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_button_box')]/button" position="before">
<button class="oe_stat_button" name="action_view_ro" type="object" icon="fa-wrench" help="Repair Orders"
attrs="{'invisible': ['|', ('repair_order_count', '=', 0), ('display_complete', '=', False)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="repair_order_count" widget="statinfo" nolabel="1" class="mr4"/>
</span>
<span class="o_stat_text">Repairs</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>