fix(stock): repair existing underbilled purchase receipts

The qty-sync fix corrects allocation going forward, but receipts billed
before it can keep understated billed_amt, per_billed, and status. The
earlier repair patch only selects over-billed PO items, so it never picks
these up.

Recompute every candidate PO item (multiple submitted receipts, PO-level
invoicing, no invoice-created receipts). update_billed_amount_based_on_po
only writes rows whose recomputed value differs, so already-correct items
are untouched and the patch stays idempotent. This also converges receipts
left with direct-only billed_amt by last-event-wins overwrites.
This commit is contained in:
Mihir Kandoi
2026-08-11 19:21:38 +05:30
parent 4108be4637
commit e99ae3796c
2 changed files with 26 additions and 0 deletions

View File

@@ -511,3 +511,4 @@ erpnext.patches.v16_0.set_stock_uom_in_job_card
erpnext.patches.v16_0.set_work_order_requested_and_picked_qty
erpnext.patches.v16_0.rename_italy_customer_name_fields
erpnext.patches.v16_0.recalculate_purchase_receipt_billing_status
erpnext.patches.v16_0.recalculate_mixed_purchase_receipt_billing_status

View File

@@ -0,0 +1,25 @@
import frappe
from erpnext.patches.v16_0.recalculate_purchase_receipt_billing_status import (
exclude_purchase_order_items_with_invoice_created_receipts,
get_candidate_purchase_order_items,
)
from erpnext.stock.doctype.purchase_receipt.services.billing_status import (
update_billed_amount_based_on_po,
update_billing_percentage,
)
def execute():
purchase_order_items = get_candidate_purchase_order_items()
if purchase_order_items:
purchase_order_items = exclude_purchase_order_items_with_invoice_created_receipts(
purchase_order_items
)
if not purchase_order_items:
return
updated_purchase_receipts = update_billed_amount_based_on_po(purchase_order_items)
for purchase_receipt in set(updated_purchase_receipts):
update_billing_percentage(frappe.get_doc("Purchase Receipt", purchase_receipt))