mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
Patch for total quantity (#14458)
* Add path to patches.txt * Modify patch
This commit is contained in:
@@ -546,4 +546,5 @@ erpnext.patches.v11_0.update_backflush_subcontract_rm_based_on_bom
|
|||||||
erpnext.patches.v10_0.update_status_in_purchase_receipt
|
erpnext.patches.v10_0.update_status_in_purchase_receipt
|
||||||
erpnext.patches.v11_0.inter_state_field_for_gst
|
erpnext.patches.v11_0.inter_state_field_for_gst
|
||||||
erpnext.patches.v11_0.rename_members_with_naming_series #04-06-2018
|
erpnext.patches.v11_0.rename_members_with_naming_series #04-06-2018
|
||||||
erpnext.patches.v11_0.set_update_field_and_value_in_workflow_state
|
erpnext.patches.v11_0.set_update_field_and_value_in_workflow_state
|
||||||
|
erpnext.patches.v11_0.update_total_qty_field
|
||||||
|
|||||||
@@ -9,19 +9,26 @@ def execute():
|
|||||||
frappe.reload_doc('stock', 'doctype', 'purchase_receipt')
|
frappe.reload_doc('stock', 'doctype', 'purchase_receipt')
|
||||||
frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
|
frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
|
||||||
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
|
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
|
||||||
|
|
||||||
doctypes = ["Sales Order", "Sales Invoice", "Delivery Note",\
|
doctypes = ["Sales Order", "Sales Invoice", "Delivery Note",\
|
||||||
"Purchase Order", "Purchase Invoice", "Purchase Receipt", "Quotation", "Supplier Quotation"]
|
"Purchase Order", "Purchase Invoice", "Purchase Receipt", "Quotation", "Supplier Quotation"]
|
||||||
|
|
||||||
for doctype in doctypes:
|
for doctype in doctypes:
|
||||||
|
total_qty = frappe.db.sql('''
|
||||||
|
SELECT
|
||||||
|
parent, SUM(qty) as qty
|
||||||
|
FROM
|
||||||
|
`tab%s Item`
|
||||||
|
GROUP BY parent
|
||||||
|
''' % (doctype), as_dict = True)
|
||||||
|
|
||||||
|
when_then = []
|
||||||
|
for d in total_qty:
|
||||||
|
when_then.append("""
|
||||||
|
when dt.name = '{0}' then {1}
|
||||||
|
""".format(frappe.db.escape(d.get("parent")), d.get("qty")))
|
||||||
|
|
||||||
frappe.db.sql('''
|
frappe.db.sql('''
|
||||||
UPDATE
|
UPDATE
|
||||||
`tab%s` dt SET dt.total_qty =
|
`tab%s` dt SET dt.total_qty = CASE %s END
|
||||||
(
|
''' % (doctype, " ".join(when_then)))
|
||||||
SELECT SUM(dt_item.qty)
|
|
||||||
FROM
|
|
||||||
`tab%s Item` dt_item
|
|
||||||
WHERE
|
|
||||||
dt_item.parent=dt.name
|
|
||||||
)
|
|
||||||
''' % (doctype, doctype))
|
|
||||||
Reference in New Issue
Block a user