brotherton-erpnext/erpnext/patches/v11_0/update_total_qty_field.py
Suraj Shetty bfc195dd8b Changes to support refactor in frappe pg-poc branch (#15287)
* Remove quotes from sql to make it compatible with postgres as well

* Fix queries
- Replace mysql specifc queries with standard ones

* Make repo URL chages to test pg-poc

* Add root passowrd to test site config

* Fix quotes issue

* Remove debug flag from a pricing rule query

* Remove python 3.6 version from travis.yml

* Fix improper query issue

* Fix incorrect query

* Fix a query

- This fix need to be changed when we will  start supporting postgres
since date_format is not supported by postgres

* Get price list map as dict

* Convert price_list_currency_map to dict
2018-09-21 10:20:52 +05:30

35 lines
1.1 KiB
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:
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")))
if when_then:
frappe.db.sql('''
UPDATE
`tab%s` dt SET dt.total_qty = CASE %s ELSE 0.0 END
''' % (doctype, " ".join(when_then)))