fix: keep PO billed qty in sync when allocating amount to receipts

The amount-capped allocation branch reduced the remaining PO-invoiced
amount but left the invoiced qty untouched. A later receipt entering the
qty-proportional branch then divided by the stale qty and was under-billed:
PO 10 x 500, PO-level PI for 5 (2500), PR1 qty 3 with 500 billed directly
consumes 1000 (pool 2500 -> 1500, qty stuck at 5), PR2 qty 3 got
1500 * 3/5 = 900 instead of its full 1500. Scale the remaining qty by the
consumed fraction so both stay proportional.

Follow-up to #58021.
This commit is contained in:
Mihir Kandoi
2026-08-11 18:39:52 +05:30
parent abb23fffdc
commit 7803998fce

View File

@@ -72,14 +72,15 @@ def update_billed_amount_based_on_po(po_details: list, update_modified: bool = T
)
else:
pending_to_bill = flt(pr_item.amount) - billed_amt_against_pr
if pending_to_bill <= billed_amt_against_po:
billed_amt_against_pr += pending_to_bill
billed_amt_against_po -= pending_to_bill
else:
billed_amt_against_pr += billed_amt_against_po
billed_amt_against_po = 0
consumed_amt_against_po = min(pending_to_bill, billed_amt_against_po)
billed_amt_against_pr += consumed_amt_against_po
po_billed_amt_details[pr_item.purchase_order_item]["billed_amt"] = billed_amt_against_po
po_billed_amt_details[pr_item.purchase_order_item]["billed_amt"] = (
billed_amt_against_po - consumed_amt_against_po
)
po_billed_amt_details[pr_item.purchase_order_item]["billed_qty"] = billed_qty_against_po * (
1 - consumed_amt_against_po / billed_amt_against_po
)
if pr_item.billed_amt != billed_amt_against_pr:
# update existing doc if possible