Skip to content

Commit

Permalink
[FIX] stock_request_purchase: Define the correct quantity of allocati…
Browse files Browse the repository at this point in the history
…ons to be created from purchase order lines

Example use case:
- Create stock request for a product with quantity 10
- Confirm purchase order
- Change purchase order line to quantity 12
- "In progress" quantity of the stock request must be 10 (not 22=10+12)

TT51567
  • Loading branch information
victoralmau committed Nov 5, 2024
1 parent 8b97bdc commit 4ede3a7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stock_request_purchase/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def _prepare_stock_moves(self, picking):
0,
{
"stock_request_id": request.id,
"requested_product_uom_qty": request.product_qty,
"requested_product_uom_qty": re["product_uom_qty"]
/ len(self.stock_request_ids),
},
)
for request in self.stock_request_ids
Expand Down
48 changes: 48 additions & 0 deletions stock_request_purchase/tests/test_stock_request_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,54 @@ def test_create_request_cancel_purchase(self):
stock_request.action_cancel()
self.assertEqual(stock_request.purchase_ids.state, "cancel")

def test_update_purchase_order_line_qty(self):
expected_date = fields.Datetime.now()
vals = {
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.warehouse.lot_stock_id.id,
"expected_date": expected_date,
"stock_request_ids": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 10.0,
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.warehouse.lot_stock_id.id,
"expected_date": expected_date,
},
),
],
}
order = (
self.env["stock.request.order"]
.with_user(self.stock_request_user)
.create(vals)
)
order.action_confirm()
self.assertEqual(order.state, "open")
self.assertEqual(len(order.purchase_ids), 1)
request = order.stock_request_ids
purchase = order.purchase_ids.sudo()
purchase_line = purchase.order_line
self.assertEqual(purchase_line.product_qty, 10)
purchase.button_confirm()
self.assertEqual(len(request.allocation_ids), 1)
self.assertEqual(request.qty_in_progress, 10)
purchase_line.write({"product_qty": 12})
self.assertEqual(len(request.allocation_ids), 2)
self.assertEqual(request.qty_in_progress, 12)
picking = purchase.picking_ids
picking.move_line_ids.qty_done = 12
picking.button_validate()
self.assertEqual(request.qty_in_progress, 0)
self.assertEqual(request.qty_done, 12)
self.assertEqual(request.state, "done")

def test_unlink_purchase_order_line(self):
"""
Test that when a purchase order line is unlinked,
Expand Down

0 comments on commit 4ede3a7

Please sign in to comment.