From fb0b24af78fad7ef3acbd47105f01c9c0f69a2d2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 20 Jan 2016 14:46:26 +0530 Subject: [PATCH] Rounding based on smallest circulating currency fraction value --- erpnext/controllers/taxes_and_totals.py | 11 ++++++++--- erpnext/patches.txt | 1 + erpnext/public/js/controllers/taxes_and_totals.js | 9 +++++++-- erpnext/public/js/pos/pos.js | 8 +++----- .../doctype/material_request/test_material_request.py | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 6a0b3c025f..f4fb8a9c4f 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals 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 @@ class calculate_taxes_and_totals(object): 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 e919e92262..3cfc83b481 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -20,6 +20,7 @@ execute:frappe.reload_doc('stock', 'doctype', 'purchase_receipt') # 2014-01-29 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 3ccc648aaa..a2ee1b75b9 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -392,10 +392,15 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({ // 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 e848bc439b..db60025183 100644 --- a/erpnext/public/js/pos/pos.js +++ b/erpnext/public/js/pos/pos.js @@ -416,9 +416,6 @@ erpnext.pos.PointOfSale = Class.extend({ 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 @@ erpnext.pos.PointOfSale = Class.extend({ 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 0905b399c6..37d985edb0 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 @@ class TestMaterialRequest(unittest.TestCase): 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 @@ class TestMaterialRequest(unittest.TestCase): 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 @@ class TestMaterialRequest(unittest.TestCase): 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)