mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
discount calculation and in print view
This commit is contained in:
@@ -14,7 +14,7 @@ from erpnext.controllers.stock_controller import StockController
|
|||||||
|
|
||||||
class BuyingController(StockController):
|
class BuyingController(StockController):
|
||||||
def __setup__(self):
|
def __setup__(self):
|
||||||
if hasattr(self, "items"):
|
if hasattr(self, "taxes"):
|
||||||
self.print_templates = {
|
self.print_templates = {
|
||||||
"taxes": "templates/print_formats/includes/taxes.html"
|
"taxes": "templates/print_formats/includes/taxes.html"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from erpnext.controllers.stock_controller import StockController
|
|||||||
|
|
||||||
class SellingController(StockController):
|
class SellingController(StockController):
|
||||||
def __setup__(self):
|
def __setup__(self):
|
||||||
if hasattr(self, "items"):
|
if hasattr(self, "taxes"):
|
||||||
self.print_templates = {
|
self.print_templates = {
|
||||||
"taxes": "templates/print_formats/includes/taxes.html"
|
"taxes": "templates/print_formats/includes/taxes.html"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,8 +76,9 @@ class calculate_taxes_and_totals(object):
|
|||||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||||
"tax_fraction_for_current_item", "grand_total_fraction_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:
|
if tax.charge_type != "Actual" and \
|
||||||
tax_fields.append("tax_amount")
|
not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"):
|
||||||
|
tax_fields.append("tax_amount")
|
||||||
|
|
||||||
for fieldname in tax_fields:
|
for fieldname in tax_fields:
|
||||||
tax.set(fieldname, 0.0)
|
tax.set(fieldname, 0.0)
|
||||||
@@ -215,8 +216,9 @@ class calculate_taxes_and_totals(object):
|
|||||||
current_tax_amount += actual_tax_dict[tax.idx]
|
current_tax_amount += actual_tax_dict[tax.idx]
|
||||||
|
|
||||||
# accumulate tax amount into tax.tax_amount
|
# accumulate tax amount into tax.tax_amount
|
||||||
if tax.charge_type != "Actual" and not self.discount_amount_applied:
|
if tax.charge_type != "Actual" and \
|
||||||
tax.tax_amount += current_tax_amount
|
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
|
# store tax_amount for current item as it will be used for
|
||||||
# charge type = 'On Previous Row Amount'
|
# charge type = 'On Previous Row Amount'
|
||||||
@@ -250,8 +252,9 @@ class calculate_taxes_and_totals(object):
|
|||||||
self.round_off_totals(tax)
|
self.round_off_totals(tax)
|
||||||
|
|
||||||
# adjust Discount Amount loss in last tax iteration
|
# adjust Discount Amount loss in last tax iteration
|
||||||
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied:
|
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
|
||||||
self.adjust_discount_amount_loss(tax)
|
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):
|
def get_current_tax_amount(self, item, tax, item_tax_map):
|
||||||
tax_rate = self._get_tax_rate(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 = 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"))
|
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):
|
def adjust_discount_amount_loss(self, tax):
|
||||||
discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
|
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
|
self.doc.base_discount_amount = 0
|
||||||
|
|
||||||
def get_total_for_discount_amount(self):
|
def get_total_for_discount_amount(self):
|
||||||
if self.doc.apply_discount_on == "Print Total":
|
if self.doc.apply_discount_on == "Net Total":
|
||||||
return self.net_total
|
return self.doc.net_total
|
||||||
else:
|
else:
|
||||||
actual_taxes_dict = {}
|
actual_taxes_dict = {}
|
||||||
|
|
||||||
|
|||||||
@@ -93,11 +93,11 @@ cur_frm.pformat.in_words = function(doc) { return ''; }
|
|||||||
|
|
||||||
cur_frm.pformat.taxes= function(doc){
|
cur_frm.pformat.taxes= function(doc){
|
||||||
//function to make row of table
|
//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>';
|
var bstart = '<b>'; var bend = '</b>';
|
||||||
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
|
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>'
|
+ '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '')
|
||||||
+ '</tr>';
|
+ format_currency(val, doc.currency) + '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert_rate(val) {
|
function convert_rate(val) {
|
||||||
@@ -125,6 +125,10 @@ cur_frm.pformat.taxes= function(doc){
|
|||||||
out += make_row('Net Total', doc.print_total, 1);
|
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
|
// add rows
|
||||||
if(cl.length){
|
if(cl.length){
|
||||||
for(var i=0;i<cl.length;i++) {
|
for(var i=0;i<cl.length;i++) {
|
||||||
@@ -133,9 +137,9 @@ cur_frm.pformat.taxes= function(doc){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discount Amount
|
// Discount Amount on grand total
|
||||||
if(!print_hide('discount_amount') && doc.discount_amount)
|
if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount)
|
||||||
out += make_row('Discount Amount', doc.discount_amount, 0);
|
out += make_row('Discount Amount', doc.discount_amount, 0, 1);
|
||||||
|
|
||||||
// grand total
|
// grand total
|
||||||
if(!print_hide('grand_total'))
|
if(!print_hide('grand_total'))
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
|||||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
|
||||||
|
|
||||||
if (cstr(tax.charge_type) != "Actual" && !me.discount_amount_applied)
|
if (cstr(tax.charge_type) != "Actual" &&
|
||||||
tax_fields.push("tax_amount");
|
!(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 });
|
$.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
|
// accumulate tax amount into tax.tax_amount
|
||||||
if (tax.charge_type != "Actual" && !me.discount_amount_applied)
|
if (tax.charge_type != "Actual" &&
|
||||||
tax.tax_amount += current_tax_amount;
|
!(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
|
// store tax_amount for current item as it will be used for
|
||||||
// charge type = 'On Previous Row Amount'
|
// charge type = 'On Previous Row Amount'
|
||||||
@@ -254,7 +256,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
|||||||
me.round_off_totals(tax);
|
me.round_off_totals(tax);
|
||||||
|
|
||||||
// adjust Discount Amount loss in last tax iteration
|
// 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);
|
me.adjust_discount_amount_loss(tax);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -428,8 +430,8 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
|
|||||||
get_total_for_discount_amount: function() {
|
get_total_for_discount_amount: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
if(this.apply_discount_amount == "Print Total") {
|
if(this.frm.doc.apply_discount_on == "Net Total") {
|
||||||
return this.net_total
|
return this.frm.doc.net_total
|
||||||
} else {
|
} else {
|
||||||
var total_actual_tax = 0.0;
|
var total_actual_tax = 0.0;
|
||||||
var actual_taxes_dict = {};
|
var actual_taxes_dict = {};
|
||||||
|
|||||||
@@ -325,6 +325,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "base_net_total",
|
"fieldname": "base_net_total",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"hidden": 0,
|
||||||
"label": "Net Total (Company Currency)",
|
"label": "Net Total (Company Currency)",
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
"oldfieldname": "net_total",
|
"oldfieldname": "net_total",
|
||||||
@@ -353,9 +354,11 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "net_total",
|
"fieldname": "net_total",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"hidden": 0,
|
||||||
"label": "Net Total",
|
"label": "Net Total",
|
||||||
"options": "currency",
|
"options": "currency",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -408,6 +411,7 @@
|
|||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Sales Taxes and Charges",
|
"options": "Sales Taxes and Charges",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
|
"print_hide": 0,
|
||||||
"read_only": 0
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -454,16 +458,18 @@
|
|||||||
"fieldname": "apply_discount_on",
|
"fieldname": "apply_discount_on",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Apply Discount On",
|
"label": "Apply Discount On",
|
||||||
"options": "\nGrand Total\nPrint Total",
|
"options": "\nGrand Total\nNet Total",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"precision": ""
|
"precision": "",
|
||||||
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "discount_amount",
|
"fieldname": "discount_amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Discount Amount",
|
"label": "Discount Amount",
|
||||||
"options": "currency",
|
"options": "currency",
|
||||||
"permlevel": 0
|
"permlevel": 0,
|
||||||
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "base_discount_amount",
|
"fieldname": "base_discount_amount",
|
||||||
@@ -838,7 +844,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"max_attachments": 1,
|
"max_attachments": 1,
|
||||||
"modified": "2015-02-20 05:16:20.664025",
|
"modified": "2015-02-23 00:55:17.519474",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Quotation",
|
"name": "Quotation",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"autoname": "hash",
|
"autoname": "QUOD/.#####",
|
||||||
"creation": "2013-03-07 11:42:57",
|
"creation": "2013-03-07 11:42:57",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@@ -190,9 +190,11 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "net_rate",
|
"fieldname": "net_rate",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
|
"hidden": 0,
|
||||||
"label": "Net Rate",
|
"label": "Net Rate",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"precision": "",
|
"precision": "",
|
||||||
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -249,6 +251,7 @@
|
|||||||
"label": "Net Rate (Company Currency)",
|
"label": "Net Rate (Company Currency)",
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"precision": "",
|
"precision": "",
|
||||||
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -385,7 +388,7 @@
|
|||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2015-02-19 15:08:25.451407",
|
"modified": "2015-02-23 00:48:08.477241",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Quotation Item",
|
"name": "Quotation Item",
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
apply_discount_on: function() {
|
||||||
|
this.calculate_taxes_and_totals();
|
||||||
|
},
|
||||||
|
|
||||||
discount_amount: function() {
|
discount_amount: function() {
|
||||||
this.calculate_taxes_and_totals();
|
this.calculate_taxes_and_totals();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -442,17 +442,6 @@
|
|||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"width": "150px"
|
"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,
|
"allow_on_submit": 1,
|
||||||
"fieldname": "page_break",
|
"fieldname": "page_break",
|
||||||
@@ -467,7 +456,7 @@
|
|||||||
],
|
],
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"modified": "2015-02-19 01:06:59.675246",
|
"modified": "2015-02-23 00:06:50.441413",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Delivery Note Item",
|
"name": "Delivery Note Item",
|
||||||
|
|||||||
@@ -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="row">
|
||||||
<div class="col-xs-6"></div>
|
<div class="col-xs-6"></div>
|
||||||
<div class="col-xs-6">
|
<div class="col-xs-6">
|
||||||
|
{%- if doc.apply_discount_on == "Net Total" -%}
|
||||||
|
{{ render_discount_amount(doc) }}
|
||||||
|
{%- endif -%}
|
||||||
{%- for charge in data -%}
|
{%- for charge in data -%}
|
||||||
{%- if not charge.included_in_print_rate -%}
|
{%- if not charge.included_in_print_rate -%}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -13,5 +28,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
{%- if doc.apply_discount_on == "Grand Total" -%}
|
||||||
|
{{ render_discount_amount(doc) }}
|
||||||
|
{%- endif -%}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user