From 2e31e097fa427377b4a24ffd64680196ddb1a2e4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 19 Aug 2013 19:58:23 +0530 Subject: [PATCH] [fix] [minor] _round function - implement round halfs to nearest even number --- controllers/buying_controller.py | 6 +++--- controllers/selling_controller.py | 6 +++--- hr/doctype/salary_slip/salary_slip.py | 8 ++++---- .../february_2013/gle_floating_point_issue_revisited.py | 2 +- stock/doctype/packing_slip/packing_slip.js | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 938db8c993..63244c5fce 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes from webnotes import _, msgprint -from webnotes.utils import flt +from webnotes.utils import flt, _round from buying.utils import get_item_details from setup.utils import get_company_currency @@ -129,10 +129,10 @@ class BuyingController(StockController): self.precision("total_tax")) if self.meta.get_field("rounded_total"): - self.doc.rounded_total = round(self.doc.grand_total) + self.doc.rounded_total = _round(self.doc.grand_total) if self.meta.get_field("rounded_total_import"): - self.doc.rounded_total_import = round(self.doc.grand_total_import) + self.doc.rounded_total_import = _round(self.doc.grand_total_import) def calculate_outstanding_amount(self): if self.doc.doctype == "Purchase Invoice" and self.doc.docstatus < 2: diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index 8d80652a26..620fcff066 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cint, flt, comma_or +from webnotes.utils import cint, flt, comma_or, _round from setup.utils import get_company_currency from selling.utils import get_item_details from webnotes import msgprint, _ @@ -218,8 +218,8 @@ class SellingController(StockController): self.doc.other_charges_total_export = flt(self.doc.grand_total_export - self.doc.net_total_export, self.precision("other_charges_total_export")) - self.doc.rounded_total = round(self.doc.grand_total) - self.doc.rounded_total_export = round(self.doc.grand_total_export) + self.doc.rounded_total = _round(self.doc.grand_total) + self.doc.rounded_total_export = _round(self.doc.grand_total_export) def calculate_outstanding_amount(self): # NOTE: diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py index 4ca1734b53..36d7ceba84 100644 --- a/hr/doctype/salary_slip/salary_slip.py +++ b/hr/doctype/salary_slip/salary_slip.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cint, cstr, flt, getdate, nowdate +from webnotes.utils import add_days, cint, cstr, flt, getdate, nowdate, _round from webnotes.model.doc import make_autoname from webnotes.model.bean import getlist from webnotes.model.code import get_obj @@ -164,7 +164,7 @@ class DocType(TransactionBase): self.doc.gross_pay = flt(self.doc.arrear_amount) + flt(self.doc.leave_encashment_amount) for d in self.doclist.get({"parentfield": "earning_details"}): if cint(d.e_depends_on_lwp) == 1: - d.e_modified_amount = round(flt(d.e_amount) * flt(self.doc.payment_days) + d.e_modified_amount = _round(flt(d.e_amount) * flt(self.doc.payment_days) / cint(self.doc.total_days_in_month), 2) elif not self.doc.payment_days: d.e_modified_amount = 0 @@ -176,7 +176,7 @@ class DocType(TransactionBase): self.doc.total_deduction = 0 for d in getlist(self.doclist, 'deduction_details'): if cint(d.d_depends_on_lwp) == 1: - d.d_modified_amount = round(flt(d.d_amount) * flt(self.doc.payment_days) + d.d_modified_amount = _round(flt(d.d_amount) * flt(self.doc.payment_days) / cint(self.doc.total_days_in_month), 2) elif not self.doc.payment_days: d.d_modified_amount = 0 @@ -189,7 +189,7 @@ class DocType(TransactionBase): self.calculate_earning_total() self.calculate_ded_total() self.doc.net_pay = flt(self.doc.gross_pay) - flt(self.doc.total_deduction) - self.doc.rounded_total = round(self.doc.net_pay) + self.doc.rounded_total = _round(self.doc.net_pay) def on_submit(self): if(self.doc.email_check == 1): diff --git a/patches/february_2013/gle_floating_point_issue_revisited.py b/patches/february_2013/gle_floating_point_issue_revisited.py index a979dadf71..6d026ebcfd 100644 --- a/patches/february_2013/gle_floating_point_issue_revisited.py +++ b/patches/february_2013/gle_floating_point_issue_revisited.py @@ -13,7 +13,7 @@ def execute(): where account = %s and voucher_type = 'Sales Invoice' and voucher_no = %s and ifnull(is_cancelled, 'No') = 'No' limit 1""", (r.debit_to, r.name), as_dict=1) if gle: - diff = round((flt(r.grand_total) - flt(gle[0]['debit'])), 2) + diff = flt((flt(r.grand_total) - flt(gle[0]['debit'])), 2) if abs(diff) == 0.01: # print r.name, r.grand_total, gle[0]['debit'], diff diff --git a/stock/doctype/packing_slip/packing_slip.js b/stock/doctype/packing_slip/packing_slip.js index f3634f6a2d..eba20c5579 100644 --- a/stock/doctype/packing_slip/packing_slip.js +++ b/stock/doctype/packing_slip/packing_slip.js @@ -103,7 +103,7 @@ cur_frm.cscript.calc_net_total_pkg = function(doc, ps_detail) { net_weight_pkg += flt(item.net_weight) * flt(item.qty); } - doc.net_weight_pkg = roundNumber(net_weight_pkg, 2); + doc.net_weight_pkg = _round(net_weight_pkg, 2); if(!flt(doc.gross_weight_pkg)) { doc.gross_weight_pkg = doc.net_weight_pkg }