From 0a35effe49f8125ef250dfc877dea4201b47ad5b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Aug 2014 12:39:40 +0530 Subject: [PATCH] Precision issue in tax calculation --- .../purchase_invoice/purchase_invoice.py | 21 +++++++++---------- erpnext/controllers/accounts_controller.py | 2 +- erpnext/public/js/transaction.js | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 68a21d9117..af7c85a83f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -273,10 +273,10 @@ class PurchaseInvoice(BuyingController): def make_gl_entries(self): auto_accounting_for_stock = \ cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) - + stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed") expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") - + gl_entries = [] # parent's gl entry @@ -329,32 +329,31 @@ class PurchaseInvoice(BuyingController): "cost_center": item.cost_center }) ) - + if auto_accounting_for_stock and item.item_code in stock_items and item.item_tax_amount: # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt negative_expense_booked_in_pi = None if item.purchase_receipt: negative_expense_booked_in_pi = frappe.db.sql("""select name from `tabGL Entry` - where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", + where voucher_type='Purchase Receipt' and voucher_no=%s and account=%s""", (item.purchase_receipt, expenses_included_in_valuation)) - + if not negative_expense_booked_in_pi: gl_entries.append( self.get_gl_dict({ "account": stock_received_but_not_billed, "against": self.credit_to, - "debit": flt(item.item_tax_amount), + "debit": flt(item.item_tax_amount, self.precision("item_tax_amount", item)), "remarks": self.remarks or "Accounting Entry for Stock" }) ) - - negative_expense_to_be_booked += flt(item.item_tax_amount) + negative_expense_to_be_booked += flt(item.item_tax_amount, self.precision("item_tax_amount", item)) if negative_expense_to_be_booked and valuation_tax: # credit valuation tax amount in "Expenses Included In Valuation" # this will balance out valuation amount included in cost of goods sold - + total_valuation_amount = sum(valuation_tax.values()) amount_including_divisional_loss = negative_expense_to_be_booked i = 1 @@ -364,7 +363,7 @@ class PurchaseInvoice(BuyingController): else: applicable_amount = negative_expense_to_be_booked * (amount / total_valuation_amount) amount_including_divisional_loss -= applicable_amount - + gl_entries.append( self.get_gl_dict({ "account": expenses_included_in_valuation, @@ -374,7 +373,7 @@ class PurchaseInvoice(BuyingController): "remarks": self.remarks or "Accounting Entry for Stock" }) ) - + i += 1 # writeoff account includes petty difference in the invoice amount diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 3df62e7934..59a49afb22 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -209,7 +209,7 @@ class AccountsController(TransactionBase): def calculate_taxes(self): # maintain actual tax rate based on idx - actual_tax_dict = dict([[tax.idx, tax.rate] for tax in self.tax_doclist + actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.precision("tax_amount", tax))] for tax in self.tax_doclist if tax.charge_type == "Actual"]) for n, item in enumerate(self.item_doclist): diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index dd11fab6f9..801ea57d21 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -647,7 +647,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ // maintain actual tax rate based on idx $.each(this.frm.tax_doclist, function(i, tax) { if (tax.charge_type == "Actual") { - actual_tax_dict[tax.idx] = flt(tax.rate); + actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax)); } });