From 82c1443254b5a8e2b293e6434a34d87dd1ea9800 Mon Sep 17 00:00:00 2001 From: Jigar Vaghela Date: Fri, 7 Oct 2022 10:50:09 +0000 Subject: [PATCH] [IMP] mrp,mrp_*,repair: MRP back to basics 6 mrp === - no time has been recorded on operations then give warning with apply button - do not allow to mass edit UOM in any manufacturing state - set value of lot/serial from MO and set read only on unbuild from MO - remove "archive operation" icon repair ====== Currently it is not possible to select a return on a repair order unless save it first. so after this commit user can able to select it without save it. only show picking related to selected product closes odoo/odoo#106571 Task: 2845380 X-original-commit: dd60647ce41547ecd00bbde45ddf564a7ada91c7 Related: odoo/enterprise#34403 Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_production.py | 13 ++++++++++--- addons/mrp/models/mrp_unbuild.py | 16 ++-------------- addons/mrp/tests/test_traceability.py | 1 - addons/mrp/tests/test_unbuild.py | 11 ----------- addons/mrp/views/mrp_production_views.xml | 8 ++++---- addons/mrp/views/mrp_routing_views.xml | 2 +- addons/mrp/views/mrp_unbuild_views.xml | 4 ++-- addons/repair/models/repair.py | 4 +++- addons/repair/views/repair_views.xml | 2 +- 9 files changed, 23 insertions(+), 38 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index e424be4fd14..540a74f55ad 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1791,8 +1791,11 @@ class MrpProduction(models.Model): 'state': 'done', 'product_uom_qty': 0.0, }) - + diff_per_production = {} for production in self: + diff_per_production[production] = 1 + if production.qty_produced != production.product_qty: + diff_per_production[production] = production.qty_produced/production.product_qty production.write({ 'date_finished': fields.Datetime.now(), 'product_qty': production.qty_produced, @@ -1801,8 +1804,11 @@ class MrpProduction(models.Model): 'state': 'done', }) - for workorder in self.workorder_ids.filtered(lambda w: w.state not in ('done', 'cancel')): - workorder.duration_expected = workorder._get_duration_expected() + for workorder in self.workorder_ids: + if workorder.state not in ('done', 'cancel'): + workorder.duration_expected = workorder._get_duration_expected() + if workorder.duration == 0.0: + workorder.duration = workorder.duration_expected * diff_per_production[workorder.production_id] if not backorders: if self.env.context.get('from_workorder'): @@ -1968,6 +1974,7 @@ class MrpProduction(models.Model): 'view_id': self.env.ref('mrp.mrp_unbuild_form_view_simplified').id, 'type': 'ir.actions.act_window', 'context': {'default_product_id': self.product_id.id, + 'default_lot_id': self.lot_producing_id.id, 'default_mo_id': self.id, 'default_company_id': self.company_id.id, 'default_location_id': self.location_dest_id.id, diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 31f38afc2f7..12747d5a732 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -53,8 +53,7 @@ class MrpUnbuild(models.Model): mo_bom_id = fields.Many2one('mrp.bom', 'Bill of Material used on the Production Order', related='mo_id.bom_id') lot_id = fields.Many2one( 'stock.lot', 'Lot/Serial Number', - domain="[('product_id', '=', product_id), ('company_id', '=', company_id)]", check_company=True, - states={'done': [('readonly', True)]}) + domain="[('product_id', '=', product_id), ('company_id', '=', company_id)]", check_company=True) has_tracking=fields.Selection(related='product_id.tracking', readonly=True) location_id = fields.Many2one( 'stock.location', 'Source Location', @@ -102,23 +101,12 @@ class MrpUnbuild(models.Model): self.product_id = self.mo_id.product_id.id self.bom_id = self.mo_id.bom_id self.product_uom_id = self.mo_id.product_uom_id + self.lot_id = self.mo_id.lot_producing_id if self.has_tracking == 'serial': self.product_qty = 1 else: self.product_qty = self.mo_id.product_qty - if self.lot_id and self.lot_id not in self.mo_id.move_finished_ids.move_line_ids.lot_id: - return {'warning': { - 'title': _("Warning"), - 'message': _("The selected serial number does not correspond to the one used in the manufacturing order, please select another one.") - }} - @api.onchange('lot_id') - def _onchange_lot_id(self): - if self.mo_id and self.lot_id and self.lot_id not in self.mo_id.move_finished_ids.move_line_ids.lot_id: - return {'warning': { - 'title': _("Warning"), - 'message': _("The selected serial number does not correspond to the one used in the manufacturing order, please select another one.") - }} @api.onchange('product_id') def _onchange_product_id(self): diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py index ecaeaadfd1c..14eb9d00043 100644 --- a/addons/mrp/tests/test_traceability.py +++ b/addons/mrp/tests/test_traceability.py @@ -349,7 +349,6 @@ class TestTraceability(TestMrpCommon): unbuild_form = Form(self.env['mrp.unbuild']) unbuild_form.mo_id = mo - unbuild_form.lot_id = lot unbuild_form.save().action_unbuild() mo_form = Form(self.env['mrp.production']) diff --git a/addons/mrp/tests/test_unbuild.py b/addons/mrp/tests/test_unbuild.py index cc30780ac35..a8e6aa19047 100644 --- a/addons/mrp/tests/test_unbuild.py +++ b/addons/mrp/tests/test_unbuild.py @@ -305,13 +305,6 @@ class TestUnbuild(TestMrpCommon): self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot_final), 5, 'You should have consumed 3 final product in stock') - with self.assertRaises(AssertionError): - x.product_id = p_final - x.bom_id = bom - x.mo_id = mo - x.product_qty = 3 - x.save() - self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot_final), 5, 'You should have consumed 3 final product in stock') x = Form(self.env['mrp.unbuild']) @@ -319,7 +312,6 @@ class TestUnbuild(TestMrpCommon): x.bom_id = bom x.mo_id = mo x.product_qty = 3 - x.lot_id = lot_final x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot_final), 2, 'You should have consumed 3 final product in stock') @@ -331,7 +323,6 @@ class TestUnbuild(TestMrpCommon): x.bom_id = bom x.mo_id = mo x.product_qty = 2 - x.lot_id = lot_final x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot_final), 0, 'You should have 0 finalproduct in stock') @@ -343,7 +334,6 @@ class TestUnbuild(TestMrpCommon): x.bom_id = bom x.mo_id = mo x.product_qty = 5 - x.lot_id = lot_final x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot_final, allow_negative=True), -5, 'You should have negative quantity for final product in stock') @@ -814,7 +804,6 @@ class TestUnbuild(TestMrpCommon): #unbuild order unbuild_form = Form(self.env['mrp.unbuild']) unbuild_form.mo_id = mo - unbuild_form.lot_id = product_1_sn unbuild_form.save().action_unbuild() #mo2 diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 7886f7e3dea..cb146f0582f 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -17,7 +17,7 @@ - + @@ -34,7 +34,7 @@ decoration-danger="reservation_state != 'assigned' and components_availability_state == 'late'"/> - + @@ -348,11 +348,11 @@ {'column_invisible': [('parent.product_id', '!=', False)]} -