From 7e92e4967af8a25df2d193604ddd494ec07b1f77 Mon Sep 17 00:00:00 2001 From: Sugesh393 Date: Tue, 11 Mar 2025 11:52:42 +0530 Subject: [PATCH] fix: add patch to update base_outstanding and base_paid_amount --- erpnext/patches.txt | 1 + ...date_payment_schedule_fields_in_invoices.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 erpnext/patches/v15_0/update_payment_schedule_fields_in_invoices.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d83bfc6d1f3..a4af11761bb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -408,3 +408,4 @@ erpnext.patches.v15_0.rename_sla_fields erpnext.stock.doctype.stock_ledger_entry.patches.ensure_sle_indexes erpnext.patches.v15_0.update_query_report erpnext.patches.v15_0.set_purchase_receipt_row_item_to_capitalization_stock_item +erpnext.patches.v15_0.update_payment_schedule_fields_in_invoices diff --git a/erpnext/patches/v15_0/update_payment_schedule_fields_in_invoices.py b/erpnext/patches/v15_0/update_payment_schedule_fields_in_invoices.py new file mode 100644 index 00000000000..74d8ac38f72 --- /dev/null +++ b/erpnext/patches/v15_0/update_payment_schedule_fields_in_invoices.py @@ -0,0 +1,18 @@ +import frappe +from frappe.query_builder import DocType + + +def execute(): + invoice_types = ["Sales Invoice", "Purchase Invoice"] + for invoice_type in invoice_types: + invoice = DocType(invoice_type) + invoice_details = frappe.qb.from_(invoice).select(invoice.conversion_rate, invoice.name) + update_payment_schedule(invoice_details) + + +def update_payment_schedule(invoice_details): + ps = DocType("Payment Schedule") + + frappe.qb.update(ps).join(invoice_details).on(ps.parent == invoice_details.name).set( + ps.base_paid_amount, ps.paid_amount * invoice_details.conversion_rate + ).set(ps.base_outstanding, ps.outstanding * invoice_details.conversion_rate).run()