From d6822ddd7c8b82b7f7053e146710433fabada29a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 13 Mar 2015 18:23:10 +0530 Subject: [PATCH] manipulate grand total for inclusive tax --- erpnext/controllers/accounts_controller.py | 14 ++++++++++++++ erpnext/public/js/transaction.js | 1 + erpnext/selling/sales_common.js | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index fcc350a3ee..e9c6c84184 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -185,6 +185,7 @@ class AccountsController(TransactionBase): self.calculate_net_total() self.calculate_taxes() + self.manipulate_grand_total_for_inclusive_tax() self.calculate_totals() self._cleanup() @@ -353,6 +354,19 @@ class AccountsController(TransactionBase): self.precision(base_field, item)) item.set(base_field, value_in_company_currency) + def manipulate_grand_total_for_inclusive_tax(self): + # if fully inclusive taxes and diff + if (self.meta.get_field("net_total_export") and self.tax_doclist + and all(cint(t.included_in_print_rate) for t in self.tax_doclist)): + + last_tax = self.tax_doclist[-1] + + diff = self.net_total_export - flt(last_tax.total / self.conversion_rate, + self.precision("grand_total_export")) + + if diff: + last_tax.total = last_tax.total + flt(diff * self.conversion_rate, self.precision("total", last_tax)) + def calculate_total_advance(self, parenttype, advance_parentfield): if self.doctype == parenttype and self.docstatus < 2: sum_of_allocated_amount = sum([flt(adv.allocated_amount, self.precision("allocated_amount", adv)) diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index ebdb136dd4..ba0fa408d8 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -632,6 +632,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({ this.determine_exclusive_rate && this.determine_exclusive_rate(); this.calculate_net_total(); this.calculate_taxes(); + this.manipulate_grand_total_for_inclusive_tax && this.manipulate_grand_total_for_inclusive_tax(); this.calculate_totals(); this._cleanup(); diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 1c5df6e304..6fdfeae876 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -458,6 +458,26 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }); }, + manipulate_grand_total_for_inclusive_tax: function() { + // if fully inclusive taxes and diff + if (this.frm.tax_doclist.length) { + var all_inclusive = frappe.utils.all(this.frm.tax_doclist.map(function(d) { + return cint(d.included_in_print_rate); + })); + + if (all_inclusive) { + var last_tax = this.frm.tax_doclist.slice(-1)[0]; + + var diff = this.frm.doc.net_total_export + - flt(last_tax.total / this.frm.doc.conversion_rate, precision("grand_total_export")); + + if (diff) { + last_tax.total += flt(diff * this.frm.doc.conversion_rate, precision("total", last_tax)); + } + } + } + }, + _cleanup: function() { this._super(); this.frm.doc.in_words = this.frm.doc.in_words_export = "";