jcloude/press/patches/v0_0_1/patch_invoice.py
2025-12-23 19:17:16 +08:00

37 lines
672 B
Python

# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# For license information, please see license.txt
import frappe
def execute():
frappe.reload_doc("press", "doctype", "invoice")
frappe.reload_doc("press", "doctype", "invoice_item")
# invoice site usage -> invoice item
frappe.db.sql(
"""
update
`tabInvoice Item` i,
`tabInvoice Site Usage` u
set
i.document_type = 'Site',
i.document_name = u.site,
i.plan = u.plan
where
u.parent = i.parent
and u.idx = i.idx
"""
)
# compute applied_credits
frappe.db.sql(
"""
update
tabInvoice
set
applied_credits = -1 * (starting_balance - ending_balance)
"""
)