Skip to content

Commit 9c9f347

Browse files
committed
[FIX] mrp: apply source location of unbuild order on SM
When unbuilding a product, the selected source location is not applied on the SM. To reproduce the issue: 1. In Settings, enable "Storage Locations" 2. Create two storable products P_compo, P_finished 3. Update the qty of P_compo: 1 in WH/Stock 4. Create a BoM: - Product: P_finished - Components: 1 x P_compo 5. Process a manufacturing order MO with 1 x P_finished 6. Transfer the P_finished from WH/Stock to WH/Stock/Shelf 1 7. Create an unbuild order UO: - Manufacturing Order: MO - Source Location: WH/Stock/Shelf 1 - Destination Location: WH/Stock/Shelf 2 8. Confirm UO 9. Open the associated product moves Error: The SML of P_finished is incorrect, its source location is WH/Stock instead of WH/Stock/Shelf 1 (as a result, the quants are incorrect too). The issue only happens with P_finished. The destination of the components is correctly defined: https://github.com/odoo/odoo/blob/90a87d6ecd420c61ea8db8a6c571db477ee7220e/addons/mrp/models/mrp_unbuild.py#L229 (i.e., we use the destination location of the unbuild order) OPW-2869454 closes odoo#94350 X-original-commit: 45ec587 Signed-off-by: Tiffany Chang <[email protected]> Signed-off-by: Adrien Widart <[email protected]>
1 parent 6d9bf97 commit 9c9f347

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

addons/mrp/models/mrp_unbuild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _generate_consume_moves(self):
208208
finished_moves = unbuild.mo_id.move_finished_ids.filtered(lambda move: move.state == 'done')
209209
factor = unbuild.product_qty / unbuild.mo_id.product_uom_id._compute_quantity(unbuild.mo_id.product_qty, unbuild.product_uom_id)
210210
for finished_move in finished_moves:
211-
moves += unbuild._generate_move_from_existing_move(finished_move, factor, finished_move.location_dest_id, finished_move.location_id)
211+
moves += unbuild._generate_move_from_existing_move(finished_move, factor, unbuild.location_id, finished_move.location_id)
212212
else:
213213
factor = unbuild.product_uom_id._compute_quantity(unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
214214
moves += unbuild._generate_move_from_bom_line(self.product_id, self.product_uom_id, unbuild.product_qty)

addons/mrp/tests/test_unbuild.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,54 @@ def test_unbuild_similar_tracked_components(self):
687687
uo.action_unbuild()
688688

689689
self.assertEqual(uo.produce_line_ids.filtered(lambda sm: sm.product_id == compo).lot_ids, lot01 + lot02)
690+
691+
def test_unbuild_and_multilocations(self):
692+
"""
693+
Basic flow: produce p_final, transfer it to a sub-location and then
694+
unbuild it. The test ensures that the source/destination locations of an
695+
unbuild order are applied on the stock moves
696+
"""
697+
grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
698+
self.env.user.write({'groups_id': [(4, grp_multi_loc.id, 0)]})
699+
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
700+
prod_location = self.env['stock.location'].search([('usage', '=', 'production'), ('company_id', '=', self.env.user.id)])
701+
subloc01, subloc02, = self.stock_location.child_ids[:2]
702+
703+
mo, _, p_final, p1, p2 = self.generate_mo(qty_final=1, qty_base_1=1, qty_base_2=1)
704+
705+
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1)
706+
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 1)
707+
mo.action_assign()
708+
709+
mo_form = Form(mo)
710+
mo_form.qty_producing = 1.0
711+
mo = mo_form.save()
712+
mo.button_mark_done()
713+
714+
# Transfer the finished product from WH/Stock to `subloc01`
715+
internal_form = Form(self.env['stock.picking'])
716+
internal_form.picking_type_id = warehouse.int_type_id
717+
internal_form.location_id = self.stock_location
718+
internal_form.location_dest_id = subloc01
719+
with internal_form.move_ids_without_package.new() as move:
720+
move.product_id = p_final
721+
move.product_uom_qty = 1.0
722+
internal_transfer = internal_form.save()
723+
internal_transfer.action_confirm()
724+
internal_transfer.action_assign()
725+
internal_transfer.move_line_ids.qty_done = 1.0
726+
internal_transfer.button_validate()
727+
728+
unbuild_order_form = Form(self.env['mrp.unbuild'])
729+
unbuild_order_form.mo_id = mo
730+
unbuild_order_form.location_id = subloc01
731+
unbuild_order_form.location_dest_id = subloc02
732+
unbuild_order = unbuild_order_form.save()
733+
unbuild_order.action_unbuild()
734+
735+
self.assertRecordValues(unbuild_order.produce_line_ids, [
736+
# pylint: disable=bad-whitespace
737+
{'product_id': p_final.id, 'location_id': subloc01.id, 'location_dest_id': prod_location.id},
738+
{'product_id': p2.id, 'location_id': prod_location.id, 'location_dest_id': subloc02.id},
739+
{'product_id': p1.id, 'location_id': prod_location.id, 'location_dest_id': subloc02.id},
740+
])

0 commit comments

Comments
 (0)