diff options
| author | Rémy Voet (ryv) <ryv@odoo.com> | 2020-01-22 08:17:09 +0000 |
|---|---|---|
| committer | Rémy Voet (ryv) <ryv@odoo.com> | 2020-01-24 10:47:52 +0000 |
| commit | bd2bbb27fe83ab082fe04374de0fb45c5750488f (patch) | |
| tree | 8a4d6658d73e907af49b6f2a83c2d50a818f1e46 /addons | |
| parent | 8458cc18674b267e64f95aa311a210ed5be41c51 (diff) | |
[IMP] mrp: add unbuild button on MO
In this commit:
- On done MO's form, add an Unbuild button, it would open a
wizard with the form view of an unbuild, and some pre-filled fields
such as MO, product, BOM, quantity and total quantity finished which
can be edited.
- In the unbuild order, improve the on_change of mo_id:
if the selected product is tracked by serial number,
set quantity to 1 by default and readonly
- Also clean the testcase of unbuild order.
task-2144636
closes odoo/odoo#43719
Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Co-authored-by: Ankita Raval <anr@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/mrp/models/mrp_production.py | 12 | ||||
| -rw-r--r-- | addons/mrp/models/mrp_unbuild.py | 6 | ||||
| -rw-r--r-- | addons/mrp/tests/test_unbuild.py | 18 | ||||
| -rw-r--r-- | addons/mrp/views/mrp_production_views.xml | 1 | ||||
| -rw-r--r-- | addons/mrp/views/mrp_unbuild_views.xml | 4 |
5 files changed, 20 insertions, 21 deletions
diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index df6f3272b8d..70250d72e63 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1143,3 +1143,15 @@ class MrpProduction(models.Model): return self.env.ref('mrp.exception_on_mo').render(values=values) self.env['stock.picking']._log_activity(_render_note_exception_quantity_mo, documents) + + def button_unbuild(self): + self.ensure_one() + return { + 'name': _('Unbuild'), + 'view_mode': 'form', + 'res_model': 'mrp.unbuild', + 'view_id': self.env.ref('mrp.mrp_unbuild_form_view').id, + 'type': 'ir.actions.act_window', + 'context': {'default_mo_id': self.id, 'create': False, 'edit': False}, + 'target': 'new', + } diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index dbeeeb84fe7..9d57f1b71b9 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -106,8 +106,12 @@ class MrpUnbuild(models.Model): def _onchange_mo_id(self): if self.mo_id: self.product_id = self.mo_id.product_id.id - self.product_qty = self.mo_id.product_qty + self.bom_id = self.mo_id.bom_id self.product_uom_id = self.mo_id.product_uom_id + if self.has_tracking == 'serial': + self.product_qty = 1 + else: + self.product_qty = self.mo_id.product_qty @api.onchange('product_id') def _onchange_product_id(self): diff --git a/addons/mrp/tests/test_unbuild.py b/addons/mrp/tests/test_unbuild.py index bf5c6e25f47..79aabcd0978 100644 --- a/addons/mrp/tests/test_unbuild.py +++ b/addons/mrp/tests/test_unbuild.py @@ -50,7 +50,6 @@ class TestUnbuild(TestMrpCommon): x.product_id = p_final x.bom_id = bom x.product_qty = 3 - x.product_uom_id = self.uom_unit x.save().action_unbuild() @@ -62,7 +61,6 @@ class TestUnbuild(TestMrpCommon): x.product_id = p_final x.bom_id = bom x.product_qty = 2 - x.product_uom_id = self.uom_unit x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location), 0, 'You should have 0 finalproduct in stock') @@ -73,7 +71,6 @@ class TestUnbuild(TestMrpCommon): x.product_id = p_final x.bom_id = bom x.product_qty = 5 - x.product_uom_id = self.uom_unit x.save().action_unbuild() # Check quantity in stock after last unbuild. @@ -128,14 +125,12 @@ class TestUnbuild(TestMrpCommon): x.product_id = p_final x.bom_id = bom x.product_qty = 3 - x.product_uom_id = self.uom_unit unbuild_order = x.save() x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom x.product_qty = 3 - x.product_uom_id = self.uom_unit x.lot_id = lot x.save().action_unbuild() @@ -148,7 +143,6 @@ class TestUnbuild(TestMrpCommon): x.bom_id = bom x.product_qty = 2 x.lot_id = lot - x.product_uom_id = self.uom_unit x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot), 0, 'You should have 0 finalproduct in stock') @@ -160,7 +154,6 @@ class TestUnbuild(TestMrpCommon): x.bom_id = bom x.product_qty = 5 x.lot_id = lot - x.product_uom_id = self.uom_unit x.save().action_unbuild() self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final, self.stock_location, lot_id=lot, allow_negative=True), -5, 'You should have negative quantity for final product in stock') @@ -213,7 +206,6 @@ class TestUnbuild(TestMrpCommon): x.product_id = p_final x.bom_id = bom x.product_qty = 3 - x.product_uom_id = self.uom_unit unbuild_order = x.save() # This should fail since we do not provide the MO that we wanted to unbuild. (without MO we do not know which consumed lot we have to restore) @@ -232,7 +224,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 2 x.save().action_unbuild() @@ -244,7 +235,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 5 x.save().action_unbuild() @@ -307,14 +297,12 @@ class TestUnbuild(TestMrpCommon): with self.assertRaises(AssertionError): x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.product_qty = 3 x.save() with self.assertRaises(AssertionError): x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.product_qty = 3 x.save() @@ -323,7 +311,6 @@ class TestUnbuild(TestMrpCommon): with self.assertRaises(AssertionError): x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 3 x.save() @@ -333,7 +320,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 3 x.lot_id = lot_final @@ -346,7 +332,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 2 x.lot_id = lot_final @@ -359,7 +344,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 5 x.lot_id = lot_final @@ -417,7 +401,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = p_final x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 5 x.save().action_unbuild() @@ -580,7 +563,6 @@ class TestUnbuild(TestMrpCommon): x = Form(self.env['mrp.unbuild']) x.product_id = finshed_product x.bom_id = bom - x.product_uom_id = self.uom_unit x.mo_id = mo x.product_qty = 1 x.location_id = self.stock_location diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 3c1766a5dd7..2aa12daf471 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -66,6 +66,7 @@ <button name="action_cancel" type="object" string="Cancel" attrs="{'invisible': ['|', '|', '|', ('id', '=', False), ('is_locked', '=', False), ('state', 'in', ('done','cancel')), ('confirm_cancel', '=', False)]}" confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?"/> + <button name="button_unbuild" type="object" string="Unbuild" attrs="{'invisible': [('state', '!=', 'done')]}"/> </header> <sheet> <field name="reservation_state" invisible="1"/> diff --git a/addons/mrp/views/mrp_unbuild_views.xml b/addons/mrp/views/mrp_unbuild_views.xml index 4b9590da780..ab4df3167cd 100644 --- a/addons/mrp/views/mrp_unbuild_views.xml +++ b/addons/mrp/views/mrp_unbuild_views.xml @@ -114,8 +114,8 @@ <field name="bom_id" attrs="{'readonly':[('mo_id','!=',False)]}" force_save="1"/> <label for="product_qty"/> <div class="o_row"> - <field name="product_qty"/> - <field name="product_uom_id" options="{'no_open':True,'no_create':True}" groups="uom.group_uom"/> + <field name="product_qty" attrs="{'readonly': [('has_tracking', '=', 'serial')]}"/> + <field name="product_uom_id" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom" attrs="{'readonly': [('mo_id', '!=', False)]}" force_save="1"/> </div> </group> <group> |
