mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_request:
- fixes the computation of the allocated product quantity when a stock move has multiple requests.
This commit is contained in:
@@ -50,16 +50,21 @@ class StockMoveLine(models.Model):
|
||||
|
||||
# We do sudo because potentially the user that completes the move
|
||||
# may not have permissions for stock.request.
|
||||
to_allocate_qty = ml.qty_done
|
||||
for allocation in ml.move_id.allocation_ids:
|
||||
to_allocate_qty = qty_done
|
||||
for allocation in ml.move_id.allocation_ids.sudo():
|
||||
allocated_qty = 0.0
|
||||
if allocation.open_product_qty:
|
||||
allocated_qty = min(allocation.open_product_qty, qty_done)
|
||||
allocated_qty = min(allocation.open_product_qty, to_allocate_qty)
|
||||
allocation.allocated_product_qty += allocated_qty
|
||||
to_allocate_qty -= allocated_qty
|
||||
request = allocation.stock_request_id
|
||||
message_data = self._prepare_message_data(ml, request, allocated_qty)
|
||||
message = self._stock_request_confirm_done_message_content(message_data)
|
||||
request.message_post(body=message, subtype="mail.mt_comment")
|
||||
request.check_done()
|
||||
if allocated_qty:
|
||||
request = allocation.stock_request_id
|
||||
message_data = self._prepare_message_data(
|
||||
ml, request, allocated_qty
|
||||
)
|
||||
message = self._stock_request_confirm_done_message_content(
|
||||
message_data
|
||||
)
|
||||
request.message_post(body=message, subtype="mail.mt_comment")
|
||||
request.check_done()
|
||||
return res
|
||||
|
||||
@@ -688,11 +688,15 @@ class TestStockRequestBase(TestStockRequest):
|
||||
)
|
||||
stock_request_2.product_uom_qty = 6.0
|
||||
self.product.route_ids = [(6, 0, self.route.ids)]
|
||||
stock_request_1.with_user(self.stock_request_manager).action_confirm()
|
||||
stock_request_2.with_user(self.stock_request_manager).action_confirm()
|
||||
self.assertEqual(len(stock_request_1.picking_ids), 1)
|
||||
self.assertEqual(stock_request_1.picking_ids, stock_request_2.picking_ids)
|
||||
self.assertEqual(stock_request_1.move_ids, stock_request_2.move_ids)
|
||||
stock_request_1.action_confirm()
|
||||
stock_request_2.action_confirm()
|
||||
self.assertEqual(len(stock_request_1.sudo().picking_ids), 1)
|
||||
self.assertEqual(
|
||||
stock_request_1.sudo().picking_ids, stock_request_2.sudo().picking_ids
|
||||
)
|
||||
self.assertEqual(
|
||||
stock_request_1.sudo().move_ids, stock_request_2.sudo().move_ids
|
||||
)
|
||||
self.env["stock.quant"].create(
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
@@ -700,12 +704,28 @@ class TestStockRequestBase(TestStockRequest):
|
||||
"quantity": 10.0,
|
||||
}
|
||||
)
|
||||
picking = stock_request_1.picking_ids[0]
|
||||
picking.with_user(self.stock_request_manager).action_confirm()
|
||||
picking.with_user(self.stock_request_manager).action_assign()
|
||||
picking = stock_request_1.sudo().picking_ids[0]
|
||||
picking.action_confirm()
|
||||
picking.action_assign()
|
||||
self.assertEqual(stock_request_1.qty_in_progress, 4)
|
||||
self.assertEqual(stock_request_1.qty_done, 0)
|
||||
self.assertEqual(stock_request_1.qty_cancelled, 0)
|
||||
self.assertEqual(stock_request_2.qty_in_progress, 6)
|
||||
self.assertEqual(stock_request_2.qty_done, 0)
|
||||
self.assertEqual(stock_request_2.qty_cancelled, 0)
|
||||
packout1 = picking.move_line_ids[0]
|
||||
packout1.qty_done = 10
|
||||
picking.with_user(self.stock_request_manager).action_done()
|
||||
packout1.qty_done = 4
|
||||
self.env["stock.backorder.confirmation"].create(
|
||||
{"pick_ids": [(4, picking.id)]}
|
||||
).process_cancel_backorder()
|
||||
self.assertEqual(stock_request_1.qty_in_progress, 0)
|
||||
self.assertEqual(stock_request_1.qty_done, 4)
|
||||
self.assertEqual(stock_request_1.qty_cancelled, 0)
|
||||
self.assertEqual(stock_request_1.state, "done")
|
||||
self.assertEqual(stock_request_2.qty_in_progress, 0)
|
||||
self.assertEqual(stock_request_2.qty_done, 0)
|
||||
self.assertEqual(stock_request_2.qty_cancelled, 6)
|
||||
self.assertEqual(stock_request_2.state, "done")
|
||||
|
||||
def test_cancel_request(self):
|
||||
expected_date = fields.Datetime.now()
|
||||
|
||||
Reference in New Issue
Block a user