Skip to content
Permalink
Browse files

[FIX] mrp: tracked products follow putaway strat.

Before this commit, when a product goes from manufacturing order to
location having putaway strategy, if this product is tracked, the
putaway strategy don't apply.

opw-1948514

closes #31808

Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
  • Loading branch information...
svs-odoo committed Mar 12, 2019
1 parent ee5f1e2 commit 776cab07d017292d67ea8b5ccfcc16e1162720e7
Showing with 116 additions and 2 deletions.
  1. +2 −1 addons/mrp/models/mrp_workorder.py
  2. +112 −0 addons/mrp/tests/test_stock.py
  3. +2 −1 addons/mrp/wizard/mrp_product_produce.py
@@ -362,6 +362,7 @@ def record_production(self):
move_line.product_uom_qty += self.qty_producing
move_line.qty_done += self.qty_producing
else:
location_dest_id = production_move.location_dest_id.get_putaway_strategy(self.product_id).id or production_move.location_dest_id.id
move_line.create({'move_id': production_move.id,
'product_id': production_move.product_id.id,
'lot_id': self.final_lot_id.id,
@@ -370,7 +371,7 @@ def record_production(self):
'qty_done': self.qty_producing,
'workorder_id': self.id,
'location_id': production_move.location_id.id,
'location_dest_id': production_move.location_dest_id.id,
'location_dest_id': location_dest_id,
})
else:
production_move.quantity_done += self.qty_producing
@@ -6,6 +6,52 @@


class TestWarehouse(common.TestMrpCommon):
def setUp(self):
super(TestWarehouse, self).setUp()

self.stock_location = self.env.ref('stock.stock_location_stock')
self.depot_location = self.env['stock.location'].create({
'name': 'Depot',
'usage': 'internal',
'location_id': self.stock_location.id,
})
putaway = self.env['product.putaway'].create({
'name': 'putaway stock->depot',
'fixed_location_ids': [(0, 0, {
'category_id': self.env.ref('product.product_category_all').id,
'fixed_location_id': self.depot_location.id,
})]
})
self.stock_location.write({
'putaway_strategy_id': putaway.id,
})

self.laptop = self.env.ref("product.product_product_25")
graphics_card = self.env.ref("product.product_product_24")
unit = self.env.ref("product.product_uom_unit")
mrp_routing = self.env.ref("mrp.mrp_routing_0")

bom_laptop = self.env['mrp.bom'].create({
'product_tmpl_id': self.laptop.product_tmpl_id.id,
'product_qty': 1,
'product_uom_id': unit.id,
'bom_line_ids': [(0, 0, {
'product_id': graphics_card.id,
'product_qty': 1,
'product_uom_id': unit.id
})],
'routing_id': mrp_routing.id
})

# Return a new Manufacturing Order for laptop
def new_mo_laptop():
return self.env['mrp.production'].create({
'product_id': self.laptop.id,
'product_qty': 1,
'product_uom_id': unit.id,
'bom_id': bom_laptop.id
})
self.new_mo_laptop = new_mo_laptop

def test_manufacturing_route(self):
warehouse_1_stock_manager = self.warehouse_1.sudo(self.user_stock_manager)
@@ -100,3 +146,69 @@ def test_manufacturing_scrap(self):

# scrap_move = production_3.move_raw_ids.filtered(lambda x: x.product_id == self.product_2 and x.scrapped)
# self.assertTrue(scrap_move, "There are no any scrap move created for production order.")

def test_putaway_after_manufacturing_1(self):
""" This test checks a manufactured product without tracking will go to
location defined in putaway strategy.
"""
mo_laptop = self.new_mo_laptop()

mo_laptop.button_plan()
workorder = mo_laptop.workorder_ids[0]

workorder.button_start()
workorder.record_production()
mo_laptop.button_mark_done()

# We check if the laptop go in the depot and not in the stock
move = mo_laptop.move_finished_ids
location_dest = move.move_line_ids.location_dest_id
self.assertEqual(location_dest.id, self.depot_location.id)
self.assertNotEqual(location_dest.id, self.stock_location.id)

def test_putaway_after_manufacturing_2(self):
""" This test checks a tracked manufactured product will go to location
defined in putaway strategy.
"""
self.laptop.tracking = 'serial'
mo_laptop = self.new_mo_laptop()

mo_laptop.button_plan()
workorder = mo_laptop.workorder_ids[0]

workorder.button_start()
serial = self.env['stock.production.lot'].create({'product_id': self.laptop.id})
workorder.final_lot_id = serial
workorder.record_production()
mo_laptop.button_mark_done()

# We check if the laptop go in the depot and not in the stock
move = mo_laptop.move_finished_ids
location_dest = move.move_line_ids.location_dest_id
self.assertEqual(location_dest.id, self.depot_location.id)
self.assertNotEqual(location_dest.id, self.stock_location.id)

def test_putaway_after_manufacturing_3(self):
""" This test checks a tracked manufactured product will go to location
defined in putaway strategy when the production is recorded with
product.produce wizard.
"""
self.laptop.tracking = 'serial'
mo_laptop = self.new_mo_laptop()
serial = self.env['stock.production.lot'].create({'product_id': self.laptop.id})

product_produce = self.env['mrp.product.produce'].with_context({
'active_id': mo_laptop.id,
'active_ids': [mo_laptop.id],
}).create({
'product_qty': 1.0,
'lot_id': serial.id,
})
product_produce.do_produce()
mo_laptop.button_mark_done()

# We check if the laptop go in the depot and not in the stock
move = mo_laptop.move_finished_ids
location_dest = move.move_line_ids.location_dest_id
self.assertEqual(location_dest.id, self.depot_location.id)
self.assertNotEqual(location_dest.id, self.stock_location.id)
@@ -133,6 +133,7 @@ def check_finished_move_lots(self):
existing_move_line.product_uom_qty += self.product_qty
existing_move_line.qty_done += self.product_qty
else:
location_dest_id = produce_move.location_dest_id.get_putaway_strategy(self.product_id).id or produce_move.location_dest_id.id
vals = {
'move_id': produce_move.id,
'product_id': produce_move.product_id.id,
@@ -142,7 +143,7 @@ def check_finished_move_lots(self):
'qty_done': self.product_qty,
'lot_id': self.lot_id.id,
'location_id': produce_move.location_id.id,
'location_dest_id': produce_move.location_dest_id.id,
'location_dest_id': location_dest_id,
}
self.env['stock.move.line'].create(vals)

0 comments on commit 776cab0

Please sign in to comment.
You can’t perform that action at this time.