[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>
This commit is contained in:
co-authored by
Ankita Raval
parent
8458cc1867
commit
bd2bbb27fe
@@ -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',
|
||||
}
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user