Skip to content

Commit 8cfca49

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#93903 Signed-off-by: Tiffany Chang <[email protected]>
1 parent a4a83b5 commit 8cfca49

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

addons/mrp/models/mrp_unbuild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _generate_consume_moves(self):
201201
for product in finished_moves.product_id:
202202
product_moves = finished_moves.filtered(lambda m: m.product_id == product)
203203
qty = sum(product_moves.mapped('product_uom_qty'))
204-
moves += unbuild._generate_move_from_existing_move_with_qty(product_moves[0], factor * qty, product_moves[0].location_dest_id, product_moves[0].location_id)
204+
moves += unbuild._generate_move_from_existing_move_with_qty(product_moves[0], factor * qty, self.location_id, product_moves[0].location_id)
205205
else:
206206
factor = unbuild.product_uom_id._compute_quantity(unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
207207
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,55 @@ def test_unbuild_from_partially_done_mo(self):
706706
{'product_id': p2.id, 'quantity_done': 2.0},
707707
{'product_id': p1.id, 'quantity_done': 2.0},
708708
])
709+
710+
def test_unbuild_and_multilocations(self):
711+
"""
712+
Basic flow: produce p_final, transfer it to a sub-location and then
713+
unbuild it. The test ensures that the source/destination locations of an
714+
unbuild order are applied on the stock moves
715+
"""
716+
grp_multi_loc = self.env.ref('stock.group_stock_multi_locations')
717+
self.env.user.write({'groups_id': [(4, grp_multi_loc.id, 0)]})
718+
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
719+
prod_location = self.env['stock.location'].search([('usage', '=', 'production'), ('company_id', '=', self.env.user.id)])
720+
subloc01, subloc02, = self.stock_location.child_ids
721+
722+
mo, _, p_final, p1, p2 = self.generate_mo(qty_final=1, qty_base_1=1, qty_base_2=1)
723+
724+
self.env['stock.quant']._update_available_quantity(p1, self.stock_location, 1)
725+
self.env['stock.quant']._update_available_quantity(p2, self.stock_location, 1)
726+
mo.action_assign()
727+
728+
produce_form = Form(self.env['mrp.product.produce'].with_context({'active_id': mo.id, 'active_ids': mo.ids}))
729+
produce_form.qty_producing = 1.0
730+
produce_wizard = produce_form.save()
731+
produce_wizard.do_produce()
732+
mo.button_mark_done()
733+
734+
# Transfer the finished product from WH/Stock to `subloc01`
735+
internal_form = Form(self.env['stock.picking'])
736+
internal_form.picking_type_id = warehouse.int_type_id
737+
internal_form.location_id = self.stock_location
738+
internal_form.location_dest_id = subloc01
739+
with internal_form.move_ids_without_package.new() as move:
740+
move.product_id = p_final
741+
move.product_uom_qty = 1.0
742+
internal_transfer = internal_form.save()
743+
internal_transfer.action_confirm()
744+
internal_transfer.action_assign()
745+
internal_transfer.move_line_ids.qty_done = 1.0
746+
internal_transfer.button_validate()
747+
748+
unbuild_order_form = Form(self.env['mrp.unbuild'])
749+
unbuild_order_form.mo_id = mo
750+
unbuild_order_form.location_id = subloc01
751+
unbuild_order_form.location_dest_id = subloc02
752+
unbuild_order = unbuild_order_form.save()
753+
unbuild_order.action_unbuild()
754+
755+
self.assertRecordValues(unbuild_order.produce_line_ids, [
756+
# pylint: disable=bad-whitespace
757+
{'product_id': p_final.id, 'location_id': subloc01.id, 'location_dest_id': prod_location.id},
758+
{'product_id': p2.id, 'location_id': prod_location.id, 'location_dest_id': subloc02.id},
759+
{'product_id': p1.id, 'location_id': prod_location.id, 'location_dest_id': subloc02.id},
760+
])

0 commit comments

Comments
 (0)