diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index c43493cd55..42eaf4db59 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -207,10 +207,10 @@ class StatusUpdater(Document): # update percent complete in the parent table if args.get('target_parent_field'): frappe.db.sql("""update `tab%(target_parent_dt)s` - set %(target_parent_field)s = (select sum(if(%(target_ref_field)s > + set %(target_parent_field)s = round((select sum(if(%(target_ref_field)s > ifnull(%(target_field)s, 0), %(target_field)s, %(target_ref_field)s))/sum(%(target_ref_field)s)*100 - from `tab%(target_dt)s` where parent="%(name)s") %(set_modified)s + from `tab%(target_dt)s` where parent="%(name)s"), 2) %(set_modified)s where name='%(name)s'""" % args) # update field diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 51356e5ed9..1d95904b79 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -211,3 +211,4 @@ erpnext.patches.v6_2.remove_newsletter_duplicates erpnext.patches.v6_2.fix_missing_default_taxes_and_lead erpnext.patches.v5_8.tax_rule erpnext.patches.v6_3.convert_applicable_territory +erpnext.patches.v6_4.round_status_updater_percentages diff --git a/erpnext/patches/v6_4/__init__.py b/erpnext/patches/v6_4/__init__.py new file mode 100644 index 0000000000..baffc48825 --- /dev/null +++ b/erpnext/patches/v6_4/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/erpnext/patches/v6_4/round_status_updater_percentages.py b/erpnext/patches/v6_4/round_status_updater_percentages.py new file mode 100644 index 0000000000..900e906b7b --- /dev/null +++ b/erpnext/patches/v6_4/round_status_updater_percentages.py @@ -0,0 +1,14 @@ +from __future__ import unicode_literals +import frappe + +def execute(): + for doctype, fieldname in ( + ("Sales Order", "per_billed"), + ("Sales Order", "per_delivered"), + ("Delivery Note", "per_installed"), + ("Purchase Order", "per_billed"), + ("Purchase Order", "per_received"), + ("Material Request", "per_ordered"), + ): + frappe.db.sql("""update `tab{doctype}` set `{fieldname}`=round(`{fieldname}`, 2)""".format( + doctype=doctype, fieldname=fieldname))