Skip to content

Commit

Permalink
[FIX] mrp: edit to-consume qty on confirmed MO
Browse files Browse the repository at this point in the history
When adding a new raw SM to a confirmed and locked MO, it should still
be possible for the user to define the to-consume quantity (else, he
would have to unlock the MO and only then to edit the new line)

OPW-3253204

closes odoo#136009

X-original-commit: b78c468
Signed-off-by: William Henrotin (whe) <[email protected]>
Signed-off-by: Djamel Touati (otd) <[email protected]>
  • Loading branch information
adwid authored and DjamelTouati committed Sep 22, 2023
1 parent d2e771b commit 4d429a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
35 changes: 35 additions & 0 deletions addons/mrp/tests/test_procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,38 @@ def test_update_merged_mo_component_qty(self):
# comp2 (2 + 4 extra) = 6
# comp3 (2 + 2 extra) = 4
self.assertEqual(mo.picking_ids[0].move_ids.mapped('product_uom_qty'), [5, 6, 4], 'Comp qty do not match expected')

def test_pbm_and_additionnal_components(self):
"""
2-steps manufacturring.
When adding a new component to a confirmed MO, it should add an SM in
the PBM picking. Also, it should be possible to define the to-consume
qty of the new line even if the MO is locked
"""
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
warehouse.manufacture_steps = 'pbm'

mo_form = Form(self.env['mrp.production'])
mo_form.bom_id = self.bom_4
mo = mo_form.save()
mo.action_confirm()

if not mo.is_locked:
mo.action_toggle_is_locked()

with Form(mo) as mo_form:
with mo_form.move_raw_ids.new() as raw_line:
raw_line.product_id = self.product_2
raw_line.product_uom_qty = 2.0

move_vals = mo._get_move_raw_values(self.product_3, 0, self.product_3.uom_id)
mo.move_raw_ids = [(0, 0, move_vals)]
mo.move_raw_ids[-1].product_uom_qty = 3.0

expected_vals = [
{'product_id': self.product_1.id, 'product_uom_qty': 1.0},
{'product_id': self.product_2.id, 'product_uom_qty': 2.0},
{'product_id': self.product_3.id, 'product_uom_qty': 3.0},
]
self.assertRecordValues(mo.move_raw_ids, expected_vals)
self.assertRecordValues(mo.picking_ids.move_ids, expected_vals)
4 changes: 2 additions & 2 deletions addons/mrp/views/mrp_production_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@
<field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]" column_invisible="True"/>
<field name="state" column_invisible="True" force_save="1"/>
<field name="should_consume_qty" column_invisible="True"/>
<field name="product_uom_qty" force_save="1" string="To Consume" column_invisible="not parent.show_produce_all" readonly="parent.state != 'draft' and ((parent.state not in ('confirmed', 'progress', 'to_close') and not parent.is_planned) or parent.is_locked)"/>
<field name="product_uom_qty" widget="mrp_should_consume" force_save="1" string="To Consume" column_invisible="parent.show_produce_all" readonly="parent.state != 'draft' and ((parent.state not in ('confirmed', 'progress', 'to_close') and not parent.is_planned) or parent.is_locked)"/>
<field name="product_uom_qty" force_save="1" string="To Consume" column_invisible="not parent.show_produce_all" readonly="parent.state != 'draft' and ((parent.state not in ('confirmed', 'progress', 'to_close') and not parent.is_planned) or (parent.is_locked and state != 'draft'))"/>
<field name="product_uom_qty" widget="mrp_should_consume" force_save="1" string="To Consume" column_invisible="parent.show_produce_all" readonly="parent.state != 'draft' and ((parent.state not in ('confirmed', 'progress', 'to_close') and not parent.is_planned) or (parent.is_locked and state != 'draft'))"/>
<field name="product_uom" readonly="state != 'draft' and id" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom"/>
<field name="product_type" column_invisible="True"/>
<field name="product_qty" readonly="1" column_invisible="True"/>
Expand Down

0 comments on commit 4d429a1

Please sign in to comment.