mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 06:31:48 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
Reference in New Issue
Block a user