Patch for total quantity (#14458)
* Add path to patches.txt * Modify patch
This commit is contained in:
parent
0ca76323af
commit
157815ff0c
@ -547,3 +547,4 @@ erpnext.patches.v10_0.update_status_in_purchase_receipt
|
||||
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.set_update_field_and_value_in_workflow_state
|
||||
erpnext.patches.v11_0.update_total_qty_field
|
||||
|
@ -14,14 +14,21 @@ def execute():
|
||||
"Purchase Order", "Purchase Invoice", "Purchase Receipt", "Quotation", "Supplier Quotation"]
|
||||
|
||||
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('''
|
||||
UPDATE
|
||||
`tab%s` dt SET dt.total_qty =
|
||||
(
|
||||
SELECT SUM(dt_item.qty)
|
||||
FROM
|
||||
`tab%s Item` dt_item
|
||||
WHERE
|
||||
dt_item.parent=dt.name
|
||||
)
|
||||
''' % (doctype, doctype))
|
||||
`tab%s` dt SET dt.total_qty = CASE %s END
|
||||
''' % (doctype, " ".join(when_then)))
|
Loading…
x
Reference in New Issue
Block a user