Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions addons/mrp/models/stock_scrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,5 @@ def do_replenish(self, values=False):
if self.production_id and self.production_id.procurement_group_id:
values.update({
'group_id': self.production_id.procurement_group_id,
'move_dest_ids': self.production_id.procurement_group_id.stock_move_ids.filtered(
lambda m: m.location_id == self.location_id
and m.product_id == self.product_id
and m.state not in ('assigned', 'done', 'cancel'))
})
super().do_replenish(values)
43 changes: 43 additions & 0 deletions addons/mrp/tests/test_replenish.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,49 @@ def test_replenish_from_scrap(self):
replenish_picking.button_validate()
self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned'])

def test_scrap_replenishment_reassigns_required_qty_to_component(self):
""" Test that when validating the scrap replenishment transfer, the required quantity
is re-assigned to the component for the final manufacturing product. """
warehouse = self.env.ref('stock.warehouse0')
warehouse.manufacture_steps = 'pbm'
basic_mo, _, _, product_to_scrap, other_product = self.generate_mo(qty_final=1, qty_base_1=10, qty_base_2=10)
for product in (product_to_scrap, other_product):
self.env['stock.quant'].create({
'product_id': product.id,
'location_id': warehouse.lot_stock_id.id,
'quantity': 20
})
self.assertEqual(basic_mo.move_raw_ids.location_id, warehouse.pbm_loc_id)
basic_mo.action_confirm()
self.assertEqual(len(basic_mo.picking_ids), 1)
basic_mo.picking_ids.action_assign()
basic_mo.picking_ids.button_validate()
self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned'])

# Scrap the product and trigger replenishment
scrap_form = Form.from_action(self.env, basic_mo.button_scrap())
scrap_form.product_id = product_to_scrap
scrap_form.scrap_qty = 5
scrap_form.should_replenish = True
self.assertEqual(scrap_form.location_id, warehouse.pbm_loc_id)
scrap_form.save().action_validate()

# Assert that the component quantity is reduced
self.assertNotEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned'])
move_to_scrap = basic_mo.move_raw_ids.filtered(lambda m: m.product_id == product_to_scrap)
move_other = basic_mo.move_raw_ids.filtered(lambda m: m.product_id == other_product)
self.assertEqual(move_to_scrap.quantity, 5, "Scrapped component should have qty 5")
self.assertEqual(move_other.quantity, 10, "Other component should remain qty 10")
self.assertEqual(len(basic_mo.picking_ids), 2)

replenish_picking = basic_mo.picking_ids.filtered(lambda x: x.state == 'assigned')
replenish_picking.button_validate()

# Assert that the component quantity is re-assigned
self.assertEqual(basic_mo.move_raw_ids.mapped('state'), ['assigned', 'assigned'])
self.assertEqual(move_to_scrap.quantity, 10, "Scrapped component should return to qty 10")
self.assertEqual(move_other.quantity, 10, "Other component should still be qty 10")

def test_global_visibility_days_affect_lead_time_manufacture_rule(self):
""" Ensure global visibility days will only be captured one time in an orderpoint's
lead_days/json_lead_days.
Expand Down