Merge pull request #44138 from frappe/mergify/copy/develop/pr-43651

fix: bulk update invoice remarks during site upgrade (copy #43651)
This commit is contained in:
ruthra kumar
2024-11-14 13:15:10 +05:30
committed by GitHub

View File

@@ -8,44 +8,142 @@ def execute():
def update_sales_invoice_remarks(): def update_sales_invoice_remarks():
si_list = frappe.db.get_all( """
"Sales Invoice", Update remarks in Sales Invoice.
filters={ Some sites may have very large volume of sales invoices.
"docstatus": 1, In such cases, updating documents one by one won't be successful, especially during site migration step.
"remarks": "No Remarks", Refer to the bug report: https://github.com/frappe/erpnext/issues/43634
"po_no": ["!=", ""], In this case, a bulk update must be done.
},
fields=["name", "po_no"],
)
for doc in si_list: Step 1: Update remarks in GL Entries
remarks = _("Against Customer Order {0}").format(doc.po_no) Step 2: Update remarks in Payment Ledger Entries
update_remarks("Sales Invoice", doc.name, remarks) Step 3: Update remarks in Sales Invoice - Should be last step
"""
### Step 1: Update remarks in GL Entries
update_sales_invoice_gle_remarks()
### Step 2: Update remarks in Payment Ledger Entries
update_sales_invoice_ple_remarks()
### Step 3: Update remarks in Sales Invoice
update_query = """
UPDATE `tabSales Invoice`
SET remarks = concat('Against Customer Order ', po_no)
WHERE po_no <> '' AND docstatus = %(docstatus)s and remarks = %(remarks)s
"""
# Data for update query
values = {"remarks": "No Remarks", "docstatus": 1}
# Execute query
frappe.db.sql(update_query, values=values, as_dict=0)
def update_purchase_invoice_remarks(): def update_purchase_invoice_remarks():
pi_list = frappe.db.get_all( """
"Purchase Invoice", Update remarks in Purchase Invoice.
filters={ Some sites may have very large volume of purchase invoices.
"docstatus": 1, In such cases, updating documents one by one wont be successful, especially during site migration step.
"remarks": "No Remarks", Refer to the bug report: https://github.com/frappe/erpnext/issues/43634
"bill_no": ["!=", ""], In this case, a bulk update must be done.
},
fields=["name", "bill_no"],
)
for doc in pi_list: Step 1: Update remarks in GL Entries
remarks = _("Against Supplier Invoice {0}").format(doc.bill_no) Step 2: Update remarks in Payment Ledger Entries
update_remarks("Purchase Invoice", doc.name, remarks) Step 3: Update remarks in Purchase Invoice - Should be last step
"""
### Step 1: Update remarks in GL Entries
update_purchase_invoice_gle_remarks()
### Step 2: Update remarks in Payment Ledger Entries
update_purchase_invoice_ple_remarks()
### Step 3: Update remarks in Purchase Invoice
update_query = """
UPDATE `tabPurchase Invoice`
SET remarks = concat('Against Supplier Invoice ', bill_no)
WHERE bill_no <> '' AND docstatus = %(docstatus)s and remarks = %(remarks)s
"""
# Data for update query
values = {"remarks": "No Remarks", "docstatus": 1}
# Execute query
frappe.db.sql(update_query, values=values, as_dict=0)
def update_remarks(doctype, docname, remarks): def update_sales_invoice_gle_remarks():
filters = { ## Update query to update GL Entry - Updates all entries which are for Sales Invoice with No Remarks
"voucher_type": doctype, update_query = """
"remarks": "No Remarks", UPDATE
"voucher_no": docname, `tabGL Entry` as gle
} INNER JOIN `tabSales Invoice` as si
ON gle.voucher_type = 'Sales Invoice' AND gle.voucher_no = si.name AND gle.remarks = %(remarks)s
SET
gle.remarks = concat('Against Customer Order ', si.po_no)
WHERE si.po_no <> '' AND si.docstatus = %(docstatus)s and si.remarks = %(remarks)s
"""
frappe.db.set_value(doctype, docname, "remarks", remarks) # Data for update query
frappe.db.set_value("GL Entry", filters, "remarks", remarks) values = {"remarks": "No Remarks", "docstatus": 1}
frappe.db.set_value("Payment Ledger Entry", filters, "remarks", remarks)
# Execute query
frappe.db.sql(update_query, values=values, as_dict=0)
def update_sales_invoice_ple_remarks():
## Update query to update Payment Ledger Entry - Updates all entries which are for Sales Invoice with No Remarks
update_query = """
UPDATE
`tabPayment Ledger Entry` as ple
INNER JOIN `tabSales Invoice` as si
ON ple.voucher_type = 'Sales Invoice' AND ple.voucher_no = si.name AND ple.remarks = %(remarks)s
SET
ple.remarks = concat('Against Customer Order ', si.po_no)
WHERE si.po_no <> '' AND si.docstatus = %(docstatus)s and si.remarks = %(remarks)s
"""
### Data for update query
values = {"remarks": "No Remarks", "docstatus": 1}
### Execute query
frappe.db.sql(update_query, values=values, as_dict=0)
def update_purchase_invoice_gle_remarks():
### Query to update GL Entry - Updates all entries which are for Purchase Invoice with No Remarks
update_query = """
UPDATE
`tabGL Entry` as gle
INNER JOIN `tabPurchase Invoice` as pi
ON gle.voucher_type = 'Purchase Invoice' AND gle.voucher_no = pi.name AND gle.remarks = %(remarks)s
SET
gle.remarks = concat('Against Supplier Invoice ', pi.bill_no)
WHERE pi.bill_no <> '' AND pi.docstatus = %(docstatus)s and pi.remarks = %(remarks)s
"""
### Data for update query
values = {"remarks": "No Remarks", "docstatus": 1}
### Execute query
frappe.db.sql(update_query, values=values, as_dict=0)
def update_purchase_invoice_ple_remarks():
### Query to update Payment Ledger Entry - Updates all entries which are for Purchase Invoice with No Remarks
update_query = """
UPDATE
`tabPayment Ledger Entry` as ple
INNER JOIN `tabPurchase Invoice` as pi
ON ple.voucher_type = 'Purchase Invoice' AND ple.voucher_no = pi.name AND ple.remarks = %(remarks)s
SET
ple.remarks = concat('Against Supplier Invoice ', pi.bill_no)
WHERE pi.bill_no <> '' AND pi.docstatus = %(docstatus)s and pi.remarks = %(remarks)s
"""
### Data for update query
values = {"remarks": "No Remarks", "docstatus": 1}
### Execute query
frappe.db.sql(update_query, values=values, as_dict=0)