mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-17 16:38:41 +00:00
When a Purchase Invoice is raised directly from a Purchase Order (po_detail set, pr_detail null), update_billed_amount_based_on_po distributes the billed amount across the PO's Purchase Receipts in FIFO order. The proportional branch, taken when the invoiced qty exceeds a single receipt's qty, computed each receipt's share but never deducted the consumed amount/qty from the running po_billed_amt_details total. As a result every subsequent receipt was billed against the same amount again, so the receipts together showed more billed amount than was actually invoiced. A receipt with no invoice truly against it could reach 100% billed and become Completed, dropping out of pending-invoice reports. Deduct the consumed billed_amt and billed_qty in the proportional branch, mirroring the existing else branch, so each receipt only consumes what is left. Add a regression test covering a PO invoice spanning two receipts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>