From de9c8a90287a99cf46fb07a1fd4a96a662753d44 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 23 Feb 2015 01:06:00 +0530 Subject: [PATCH] discount calculation and in print view --- erpnext/controllers/buying_controller.py | 2 +- erpnext/controllers/selling_controller.py | 2 +- erpnext/controllers/taxes_and_totals.py | 21 +- erpnext/public/js/controllers/accounts.js | 16 +- .../public/js/controllers/taxes_and_totals.js | 16 +- .../selling/doctype/quotation/quotation.json | 1706 +++++++++-------- .../quotation_item/quotation_item.json | 655 +++---- erpnext/selling/sales_common.js | 4 + .../delivery_note_item.json | 13 +- .../print_formats/includes/taxes.html | 18 + 10 files changed, 1241 insertions(+), 1212 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 5e27b3a69a9..4e4e507cae6 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -14,7 +14,7 @@ from erpnext.controllers.stock_controller import StockController class BuyingController(StockController): def __setup__(self): - if hasattr(self, "items"): + if hasattr(self, "taxes"): self.print_templates = { "taxes": "templates/print_formats/includes/taxes.html" } diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index e6ec2af3859..9cee5832b41 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -12,7 +12,7 @@ from erpnext.controllers.stock_controller import StockController class SellingController(StockController): def __setup__(self): - if hasattr(self, "items"): + if hasattr(self, "taxes"): self.print_templates = { "taxes": "templates/print_formats/includes/taxes.html" } diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 640bcea4a54..1b1527b7eb0 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -76,8 +76,9 @@ class calculate_taxes_and_totals(object): "tax_amount_for_current_item", "grand_total_for_current_item", "tax_fraction_for_current_item", "grand_total_fraction_for_current_item"] - if tax.charge_type != "Actual" and not self.discount_amount_applied: - tax_fields.append("tax_amount") + if tax.charge_type != "Actual" and \ + not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"): + tax_fields.append("tax_amount") for fieldname in tax_fields: tax.set(fieldname, 0.0) @@ -215,8 +216,9 @@ class calculate_taxes_and_totals(object): current_tax_amount += actual_tax_dict[tax.idx] # accumulate tax amount into tax.tax_amount - if tax.charge_type != "Actual" and not self.discount_amount_applied: - tax.tax_amount += current_tax_amount + if tax.charge_type != "Actual" and \ + not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"): + tax.tax_amount += current_tax_amount # store tax_amount for current item as it will be used for # charge type = 'On Previous Row Amount' @@ -250,8 +252,9 @@ class calculate_taxes_and_totals(object): self.round_off_totals(tax) # adjust Discount Amount loss in last tax iteration - if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied: - self.adjust_discount_amount_loss(tax) + if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \ + and self.doc.apply_discount_on == "Grand Total": + self.adjust_discount_amount_loss(tax) def get_current_tax_amount(self, item, tax, item_tax_map): tax_rate = self._get_tax_rate(tax, item_tax_map) @@ -291,7 +294,7 @@ class calculate_taxes_and_totals(object): tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount")) tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, tax.precision("tax_amount")) - self._set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]); + self._set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]) def adjust_discount_amount_loss(self, tax): discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total @@ -360,8 +363,8 @@ class calculate_taxes_and_totals(object): self.doc.base_discount_amount = 0 def get_total_for_discount_amount(self): - if self.doc.apply_discount_on == "Print Total": - return self.net_total + if self.doc.apply_discount_on == "Net Total": + return self.doc.net_total else: actual_taxes_dict = {} diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index 652350ac801..21ad71fc5d0 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -93,11 +93,11 @@ cur_frm.pformat.in_words = function(doc) { return ''; } cur_frm.pformat.taxes= function(doc){ //function to make row of table - var make_row = function(title, val, bold){ + var make_row = function(title, val, bold, is_negative) { var bstart = ''; var bend = ''; return '' + (bold?bstart:'') + title + (bold?bend:'') + '' - + '' + format_currency(val, doc.currency) + '' - + ''; + + '' + (is_negative ? '- ' : '') + + format_currency(val, doc.currency) + ''; } function convert_rate(val) { @@ -125,6 +125,10 @@ cur_frm.pformat.taxes= function(doc){ out += make_row('Net Total', doc.print_total, 1); } + // Discount Amount on net total + if(!print_hide('discount_amount') && doc.apply_discount_on == "Net Total" && doc.discount_amount) + out += make_row('Discount Amount', doc.discount_amount, 0, 1); + // add rows if(cl.length){ for(var i=0;i +
+
+
+ - {{ doc.get_formatted("discount_amount", doc) }} +
+ + {%- endif -%} +{%- endmacro -%} +
+ {%- if doc.apply_discount_on == "Net Total" -%} + {{ render_discount_amount(doc) }} + {%- endif -%} {%- for charge in data -%} {%- if not charge.included_in_print_rate -%}
@@ -13,5 +28,8 @@
{%- endif -%} {%- endfor -%} + {%- if doc.apply_discount_on == "Grand Total" -%} + {{ render_discount_amount(doc) }} + {%- endif -%}