brotherton-erpnext/erpnext/patches/v11_0/update_total_qty_field.py
Shreya Shah e329038aaa Total Quantity in Sales and Purchase DocTypes (#14114)
* Add  field to all sales and purchase doctypes

* Add patch to update existing records

* Modify taxes_and_totals.py
2018-05-28 11:49:08 +05:30

28 lines
885 B
Python

import frappe
def execute():
frappe.reload_doc('buying', 'doctype', 'purchase_order')
frappe.reload_doc('buying', 'doctype', 'supplier_quotation')
frappe.reload_doc('selling', 'doctype', 'sales_order')
frappe.reload_doc('selling', 'doctype', 'quotation')
frappe.reload_doc('stock', 'doctype', 'delivery_note')
frappe.reload_doc('stock', 'doctype', 'purchase_receipt')
frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
doctypes = ["Sales Order", "Sales Invoice", "Delivery Note",\
"Purchase Order", "Purchase Invoice", "Purchase Receipt", "Quotation", "Supplier Quotation"]
for doctype in doctypes:
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))