discount calculation and in print view

This commit is contained in:
Nabin Hait
2015-02-23 01:06:00 +05:30
parent 2b019ed430
commit de9c8a9028
10 changed files with 1241 additions and 1212 deletions

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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 = {}

View File

@@ -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 = '<b>'; var bend = '</b>';
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
+ '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
+ '</tr>';
+ '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '')
+ format_currency(val, doc.currency) + '</td></tr>';
}
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<cl.length;i++) {
@@ -133,9 +137,9 @@ cur_frm.pformat.taxes= function(doc){
}
}
// Discount Amount
if(!print_hide('discount_amount') && doc.discount_amount)
out += make_row('Discount Amount', doc.discount_amount, 0);
// Discount Amount on grand total
if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount)
out += make_row('Discount Amount', doc.discount_amount, 0, 1);
// grand total
if(!print_hide('grand_total'))

View File

@@ -88,8 +88,9 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
if (cstr(tax.charge_type) != "Actual" && !me.discount_amount_applied)
tax_fields.push("tax_amount");
if (cstr(tax.charge_type) != "Actual" &&
!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
tax_fields.push("tax_amount");
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
@@ -217,8 +218,9 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
}
// accumulate tax amount into tax.tax_amount
if (tax.charge_type != "Actual" && !me.discount_amount_applied)
tax.tax_amount += current_tax_amount;
if (tax.charge_type != "Actual" &&
!(me.discount_amount_applied && me.frm.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'
@@ -254,7 +256,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
me.round_off_totals(tax);
// adjust Discount Amount loss in last tax iteration
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied)
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
me.adjust_discount_amount_loss(tax);
}
});
@@ -428,8 +430,8 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
get_total_for_discount_amount: function() {
var me = this;
if(this.apply_discount_amount == "Print Total") {
return this.net_total
if(this.frm.doc.apply_discount_on == "Net Total") {
return this.frm.doc.net_total
} else {
var total_actual_tax = 0.0;
var actual_taxes_dict = {};

View File

@@ -325,6 +325,7 @@
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Total (Company Currency)",
"no_copy": 0,
"oldfieldname": "net_total",
@@ -353,9 +354,11 @@
{
"fieldname": "net_total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Total",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
@@ -408,6 +411,7 @@
"oldfieldtype": "Table",
"options": "Sales Taxes and Charges",
"permlevel": 0,
"print_hide": 0,
"read_only": 0
},
{
@@ -454,16 +458,18 @@
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nPrint Total",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": ""
"precision": "",
"print_hide": 1
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0
"permlevel": 0,
"print_hide": 1
},
{
"fieldname": "base_discount_amount",
@@ -838,7 +844,7 @@
"idx": 1,
"is_submittable": 1,
"max_attachments": 1,
"modified": "2015-02-20 05:16:20.664025",
"modified": "2015-02-23 00:55:17.519474",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation",

View File

@@ -1,5 +1,5 @@
{
"autoname": "hash",
"autoname": "QUOD/.#####",
"creation": "2013-03-07 11:42:57",
"docstatus": 0,
"doctype": "DocType",
@@ -190,9 +190,11 @@
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Rate",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
@@ -249,6 +251,7 @@
"label": "Net Rate (Company Currency)",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
@@ -385,7 +388,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 15:08:25.451407",
"modified": "2015-02-23 00:48:08.477241",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation Item",

View File

@@ -154,6 +154,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
},
apply_discount_on: function() {
this.calculate_taxes_and_totals();
},
discount_amount: function() {
this.calculate_taxes_and_totals();
},

View File

@@ -442,17 +442,6 @@
"read_only": 1,
"width": "150px"
},
{
"fieldname": "buying_amount",
"fieldtype": "Currency",
"hidden": 1,
"label": "Buying Amount",
"no_copy": 1,
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"allow_on_submit": 1,
"fieldname": "page_break",
@@ -467,7 +456,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:06:59.675246",
"modified": "2015-02-23 00:06:50.441413",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",

View File

@@ -1,6 +1,21 @@
{%- macro render_discount_amount(doc) -%}
{%- if doc.discount_amount -%}
<div class="row">
<div class="col-xs-5 text-right">
<label>{{ "Discount Amount" }}</label></div>
<div class="col-xs-7 text-right">
- {{ doc.get_formatted("discount_amount", doc) }}
</div>
</div>
{%- endif -%}
{%- endmacro -%}
<div class="row">
<div class="col-xs-6"></div>
<div class="col-xs-6">
{%- if doc.apply_discount_on == "Net Total" -%}
{{ render_discount_amount(doc) }}
{%- endif -%}
{%- for charge in data -%}
{%- if not charge.included_in_print_rate -%}
<div class="row">
@@ -13,5 +28,8 @@
</div>
{%- endif -%}
{%- endfor -%}
{%- if doc.apply_discount_on == "Grand Total" -%}
{{ render_discount_amount(doc) }}
{%- endif -%}
</div>
</div>