All the calculations in taxes_and_totals file
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 52a22c3..07d6841 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -8,6 +8,7 @@
calculate_taxes_and_totals: function(update_paid_amount) {
this.discount_amount_applied = false;
this._calculate_taxes_and_totals();
+
if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
this.apply_discount_amount();
@@ -37,6 +38,22 @@
this.show_item_wise_taxes();
},
+ calculate_item_values: function() {
+ var me = this;
+
+ if (!this.discount_amount_applied) {
+ $.each(this.frm.doc["items"] || [], function(i, item) {
+ frappe.model.round_floats_in(item);
+ item.amount = flt(item.rate * item.qty, precision("amount", item));
+ item.item_tax_amount = 0.0;
+
+ $.each(["price_list_rate", "rate", "amount"], function(i, f) {
+ item["base_" + f] = flt(item[f] * me.frm.doc.conversion_rate, precision("base_" + f, item));
+ })
+ });
+ }
+ },
+
initialize_taxes: function() {
var me = this;
@@ -57,6 +74,76 @@
});
},
+ determine_exclusive_rate: function() {
+ if(!in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) return;
+
+ var me = this;
+ $.each(me.frm.doc["items"] || [], function(n, item) {
+ var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
+ var cumulated_tax_fraction = 0.0;
+
+ $.each(me.frm.doc["taxes"] || [], function(i, tax) {
+ tax.tax_fraction_for_current_item = me.get_current_tax_fraction(tax, item_tax_map);
+
+ if(i==0) {
+ tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item;
+ } else {
+ tax.grand_total_fraction_for_current_item =
+ me.frm.doc["taxes"][i-1].grand_total_fraction_for_current_item +
+ tax.tax_fraction_for_current_item;
+ }
+
+ cumulated_tax_fraction += tax.tax_fraction_for_current_item;
+ });
+
+ if(cumulated_tax_fraction && !me.discount_amount_applied) {
+ item.base_amount = flt(
+ (item.amount * me.frm.doc.conversion_rate) / (1 + cumulated_tax_fraction),
+ precision("base_amount", item));
+
+ item.base_rate = flt(item.base_amount / item.qty, precision("base_rate", item));
+
+ if(item.discount_percentage == 100) {
+ item.base_price_list_rate = item.base_rate;
+ item.base_rate = 0.0;
+ } else {
+ item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
+ precision("base_price_list_rate", item));
+ }
+ }
+ });
+ },
+
+ get_current_tax_fraction: function(tax, item_tax_map) {
+ // Get tax fraction for calculating tax exclusive amount
+ // from tax inclusive amount
+ var current_tax_fraction = 0.0;
+
+ if(cint(tax.included_in_print_rate)) {
+ var tax_rate = this._get_tax_rate(tax, item_tax_map);
+
+ if(tax.charge_type == "On Net Total") {
+ current_tax_fraction = (tax_rate / 100.0);
+
+ } else if(tax.charge_type == "On Previous Row Amount") {
+ current_tax_fraction = (tax_rate / 100.0) *
+ this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_fraction_for_current_item;
+
+ } else if(tax.charge_type == "On Previous Row Total") {
+ current_tax_fraction = (tax_rate / 100.0) *
+ this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
+ }
+ }
+
+ return current_tax_fraction;
+ },
+
+ _get_tax_rate: function(tax, item_tax_map) {
+ return (keys(item_tax_map).indexOf(tax.account_head) != -1) ?
+ flt(item_tax_map[tax.account_head], precision("rate", tax)) :
+ tax.rate;
+ },
+
calculate_taxes: function() {
var me = this;
var actual_tax_dict = {};
@@ -129,18 +216,8 @@
});
},
- round_off_totals: function(tax) {
- tax.total = flt(tax.total, precision("total", tax));
- tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
- tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
- precision("tax_amount", tax));
- },
-
- adjust_discount_amount_loss: function(tax) {
- var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
- tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
- discount_amount_loss, precision("tax_amount", tax));
- tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
+ _load_item_tax_rate: function(item_tax_rate) {
+ return item_tax_rate ? JSON.parse(item_tax_rate) : {};
},
get_current_tax_amount: function(item, tax, item_tax_map) {
@@ -173,6 +250,21 @@
return current_tax_amount;
},
+ round_off_totals: function(tax) {
+ tax.total = flt(tax.total, precision("total", tax));
+ tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
+ tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
+ precision("tax_amount", tax));
+ },
+
+ adjust_discount_amount_loss: function(tax) {
+ var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
+ tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
+ discount_amount_loss, precision("tax_amount", tax));
+ tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
+ },
+
+
_cleanup: function() {
this.frm.doc.in_words = this.frm.doc.in_words_import = this.frm.doc.in_words_export = "";
@@ -203,41 +295,6 @@
}
},
-
- calculate_total_advance: function(update_paid_amount) {
- this.frm.doc.total_advance = flt(frappe.utils.sum(
- $.map(this.frm.doc["advances"] || [], function(adv) { return adv.allocated_amount })
- ), precision("total_advance"));
-
- this.calculate_outstanding_amount(update_paid_amount);
- },
-
- calculate_item_values: function() {
- var me = this;
-
- if (!this.discount_amount_applied) {
- $.each(this.frm.doc["items"] || [], function(i, item) {
- frappe.model.round_floats_in(item);
- item.amount = flt(item.rate * item.qty, precision("amount", item));
- item.item_tax_amount = 0.0;
-
- $.each(["price_list_rate", "rate", "amount"], function(i, f) {
- item["base_" + f] = flt(item[f] * me.frm.doc.conversion_rate, precision("base_" + f, item));
- })
- });
- }
- },
-
- _load_item_tax_rate: function(item_tax_rate) {
- return item_tax_rate ? JSON.parse(item_tax_rate) : {};
- },
-
- _get_tax_rate: function(tax, item_tax_map) {
- return (keys(item_tax_map).indexOf(tax.account_head) != -1) ?
- flt(item_tax_map[tax.account_head], precision("rate", tax)) :
- tax.rate;
- },
-
apply_discount_amount: function() {
var me = this;
var distributed_amount = 0.0;
@@ -286,69 +343,11 @@
return grand_total_for_discount_amount;
},
+ calculate_total_advance: function(update_paid_amount) {
+ this.frm.doc.total_advance = flt(frappe.utils.sum(
+ $.map(this.frm.doc["advances"] || [], function(adv) { return adv.allocated_amount })
+ ), precision("total_advance"));
- determine_exclusive_rate: function() {
- if(!in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"])) return;
-
- var me = this;
- $.each(me.frm.doc["items"] || [], function(n, item) {
- var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
- var cumulated_tax_fraction = 0.0;
-
- $.each(me.frm.doc["taxes"] || [], function(i, tax) {
- tax.tax_fraction_for_current_item = me.get_current_tax_fraction(tax, item_tax_map);
-
- if(i==0) {
- tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item;
- } else {
- tax.grand_total_fraction_for_current_item =
- me.frm.doc["taxes"][i-1].grand_total_fraction_for_current_item +
- tax.tax_fraction_for_current_item;
- }
-
- cumulated_tax_fraction += tax.tax_fraction_for_current_item;
- });
-
- if(cumulated_tax_fraction && !me.discount_amount_applied) {
- item.base_amount = flt(
- (item.amount * me.frm.doc.conversion_rate) / (1 + cumulated_tax_fraction),
- precision("base_amount", item));
-
- item.base_rate = flt(item.base_amount / item.qty, precision("base_rate", item));
-
- if(item.discount_percentage == 100) {
- item.base_price_list_rate = item.base_rate;
- item.base_rate = 0.0;
- } else {
- item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
- precision("base_price_list_rate", item));
- }
- }
- });
- },
-
- get_current_tax_fraction: function(tax, item_tax_map) {
- // Get tax fraction for calculating tax exclusive amount
- // from tax inclusive amount
- var current_tax_fraction = 0.0;
-
- if(cint(tax.included_in_print_rate)) {
- var tax_rate = this._get_tax_rate(tax, item_tax_map);
-
- if(tax.charge_type == "On Net Total") {
- current_tax_fraction = (tax_rate / 100.0);
-
- } else if(tax.charge_type == "On Previous Row Amount") {
- current_tax_fraction = (tax_rate / 100.0) *
- this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_fraction_for_current_item;
-
- } else if(tax.charge_type == "On Previous Row Total") {
- current_tax_fraction = (tax_rate / 100.0) *
- this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_fraction_for_current_item;
- }
- }
-
- return current_tax_fraction;
- },
-
+ this.calculate_outstanding_amount(update_paid_amount);
+ }
})
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
index c906c48..73eb9a6 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
@@ -177,6 +177,15 @@
"width": "100px"
},
{
+ "fieldname": "net_amount",
+ "fieldtype": "Currency",
+ "label": "Net Amount",
+ "options": "currency",
+ "permlevel": 0,
+ "precision": "",
+ "read_only": 1
+ },
+ {
"fieldname": "col_break3",
"fieldtype": "Column Break",
"permlevel": 0
@@ -211,6 +220,15 @@
"width": "100px"
},
{
+ "fieldname": "base_net_amount",
+ "fieldtype": "Currency",
+ "label": "Net Amount (Company Currency)",
+ "options": "Company:company:default_currency",
+ "permlevel": 0,
+ "precision": "",
+ "read_only": 1
+ },
+ {
"fieldname": "pricing_rule",
"fieldtype": "Link",
"label": "Pricing Rule",
@@ -415,7 +433,7 @@
],
"idx": 1,
"istable": 1,
- "modified": "2015-01-01 14:29:59.458236",
+ "modified": "2015-01-22 13:52:44.959126",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order Item",