Merge pull request #4655 from nabinhait/rounding_issue
Rounding based on smallest circulating currency fraction value
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 6a0b3c0..f4fb8a9 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -5,7 +5,7 @@
import json
import frappe
from frappe import _, scrub
-from frappe.utils import cint, flt, rounded
+from frappe.utils import cint, flt, round_based_on_smallest_currency_fraction
from erpnext.setup.utils import get_company_currency
from erpnext.controllers.accounts_controller import validate_conversion_rate, \
validate_taxes_and_charges, validate_inclusive_tax
@@ -319,9 +319,14 @@
self.doc.round_floats_in(self.doc, ["grand_total", "base_grand_total"])
if self.doc.meta.get_field("rounded_total"):
- self.doc.rounded_total = rounded(self.doc.grand_total)
+ self.doc.rounded_total = round_based_on_smallest_currency_fraction(self.doc.grand_total,
+ self.doc.currency, self.doc.precision("rounded_total"))
if self.doc.meta.get_field("base_rounded_total"):
- self.doc.base_rounded_total = rounded(self.doc.base_grand_total)
+ company_currency = get_company_currency(self.doc.company)
+
+ self.doc.base_rounded_total = \
+ round_based_on_smallest_currency_fraction(self.doc.base_grand_total,
+ company_currency, self.doc.precision("base_rounded_total"))
def _cleanup(self):
for tax in self.doc.get("taxes"):
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e919e92..3cfc83b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -20,6 +20,7 @@
execute:frappe.reload_doc('accounts', 'doctype', 'pos_setting') # 2014-01-29
execute:frappe.reload_doc('selling', 'doctype', 'customer') # 2014-01-29
execute:frappe.reload_doc('buying', 'doctype', 'supplier') # 2014-01-29
+execute:frappe.reload_doctype('Item')
erpnext.patches.v4_0.map_charge_to_taxes_and_charges
execute:frappe.reload_doc('support', 'doctype', 'newsletter') # 2014-01-31
execute:frappe.reload_doc('hr', 'doctype', 'employee') # 2014-02-03
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 3ccc648..a2ee1b7 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -392,10 +392,15 @@
// rounded totals
if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
- this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
+ this.frm.doc.rounded_total = round_based_on_smallest_currency_fraction(this.frm.doc.grand_total,
+ this.frm.doc.currency, precision("rounded_total"));
}
if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
- this.frm.doc.base_rounded_total = Math.round(this.frm.doc.base_grand_total);
+ var company_currency = this.get_company_currency();
+
+ this.frm.doc.base_rounded_total =
+ round_based_on_smallest_currency_fraction(this.frm.doc.base_grand_total,
+ company_currency, precision("base_rounded_total"));
}
},
diff --git a/erpnext/public/js/pos/pos.js b/erpnext/public/js/pos/pos.js
index e848bc4..db60025 100644
--- a/erpnext/public/js/pos/pos.js
+++ b/erpnext/public/js/pos/pos.js
@@ -416,9 +416,6 @@
var default_mode = me.frm.doc.mode_of_payment ? me.frm.doc.mode_of_payment :
me.modes_of_payment.indexOf(__("Cash"))!==-1 ? __("Cash") : undefined;
- var smallest_currency_fraction_value = flt(frappe.model.get_value(":Currency",
- me.frm.doc.currency, "smallest_currency_fraction_value"))
-
// show payment wizard
var dialog = new frappe.ui.Dialog({
width: 400,
@@ -439,8 +436,9 @@
precision("paid_amount"));
if (actual_change > 0) {
- var rounded_change = actual_change - remainder(actual_change,
- smallest_currency_fraction_value, precision("paid_amount"));
+ var rounded_change =
+ round_based_on_smallest_currency_fraction(actual_change,
+ me.frm.doc.currency, precision("paid_amount"));
} else {
var rounded_change = 0;
}
diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py
index 0905b39..37d985e 100644
--- a/erpnext/stock/doctype/material_request/test_material_request.py
+++ b/erpnext/stock/doctype/material_request/test_material_request.py
@@ -106,6 +106,7 @@
mr.submit()
# check if per complete is None
+ mr.load_from_db()
self.assertEquals(mr.per_ordered, 0)
self.assertEquals(mr.get("items")[0].ordered_qty, 0)
self.assertEquals(mr.get("items")[1].ordered_qty, 0)
@@ -173,6 +174,7 @@
mr.submit()
# check if per complete is None
+ mr.load_from_db()
self.assertEquals(mr.per_ordered, 0)
self.assertEquals(mr.get("items")[0].ordered_qty, 0)
self.assertEquals(mr.get("items")[1].ordered_qty, 0)
@@ -262,6 +264,7 @@
mr.submit()
# check if per complete is None
+ mr.load_from_db()
self.assertEquals(mr.per_ordered, 0)
self.assertEquals(mr.get("items")[0].ordered_qty, 0)
self.assertEquals(mr.get("items")[1].ordered_qty, 0)