mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 04:39:11 +00:00
feat: Item Taxes based on net rate
This commit is contained in:
@@ -12,7 +12,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
if (in_list(["Sales Order", "Quotation"], item.parenttype) && item.blanket_order_rate) {
|
||||
effective_item_rate = item.blanket_order_rate;
|
||||
}
|
||||
if(item.margin_type == "Percentage"){
|
||||
if(item.margin_type == "Percentage") {
|
||||
item.rate_with_margin = flt(effective_item_rate)
|
||||
+ flt(effective_item_rate) * ( flt(item.margin_rate_or_amount) / 100);
|
||||
} else {
|
||||
@@ -73,15 +73,18 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
},
|
||||
|
||||
_calculate_taxes_and_totals: function() {
|
||||
this.validate_conversion_rate();
|
||||
this.calculate_item_values();
|
||||
this.initialize_taxes();
|
||||
this.determine_exclusive_rate();
|
||||
this.calculate_net_total();
|
||||
this.calculate_taxes();
|
||||
this.manipulate_grand_total_for_inclusive_tax();
|
||||
this.calculate_totals();
|
||||
this._cleanup();
|
||||
frappe.run_serially([
|
||||
() => this.validate_conversion_rate(),
|
||||
() => this.calculate_item_values(),
|
||||
() => this.update_item_tax_map(),
|
||||
() => this.initialize_taxes(),
|
||||
() => this.determine_exclusive_rate(),
|
||||
() => this.calculate_net_total(),
|
||||
() => this.calculate_taxes(),
|
||||
() => this.manipulate_grand_total_for_inclusive_tax(),
|
||||
() => this.calculate_totals(),
|
||||
() => this._cleanup()
|
||||
]);
|
||||
},
|
||||
|
||||
validate_conversion_rate: function() {
|
||||
@@ -263,6 +266,68 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
|
||||
},
|
||||
|
||||
update_item_tax_map: function() {
|
||||
let me = this;
|
||||
let item_codes = [];
|
||||
let item_rates = {};
|
||||
$.each(this.frm.doc.items || [], function(i, item) {
|
||||
if(item.item_code) {
|
||||
// Use combination of name and item code in case same item is added multiple times
|
||||
item_codes.push([item.item_code, item.name]);
|
||||
item_rates[item.name] = item.net_rate;
|
||||
}
|
||||
});
|
||||
|
||||
if(item_codes.length) {
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_tax_info",
|
||||
args: {
|
||||
company: me.frm.doc.company,
|
||||
tax_category: cstr(me.frm.doc.tax_category),
|
||||
item_codes: item_codes,
|
||||
item_rates: item_rates
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
$.each(me.frm.doc.items || [], function(i, item) {
|
||||
if(item.name && r.message.hasOwnProperty(item.name)) {
|
||||
item.item_tax_template = r.message[item.name].item_tax_template;
|
||||
item.item_tax_rate = r.message[item.name].item_tax_rate;
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
}
|
||||
else {
|
||||
item.item_tax_template = "";
|
||||
item.item_tax_rate = "{}";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.frm.refresh_fields();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
add_taxes_from_item_tax_template: function(item_tax_map) {
|
||||
let me = this;
|
||||
|
||||
if(item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
||||
if(typeof (item_tax_map) == "string") {
|
||||
item_tax_map = JSON.parse(item_tax_map);
|
||||
}
|
||||
|
||||
$.each(item_tax_map, function(tax, rate) {
|
||||
let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax);
|
||||
if(!found) {
|
||||
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
||||
child.charge_type = "On Net Total";
|
||||
child.account_head = tax;
|
||||
child.rate = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
calculate_taxes: function() {
|
||||
var me = this;
|
||||
this.frm.doc.rounding_adjustment = 0;
|
||||
@@ -406,6 +471,11 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
let tax_detail = tax.item_wise_tax_detail;
|
||||
let key = item.item_code || item.item_name;
|
||||
|
||||
if(typeof (tax_detail) == "string") {
|
||||
tax.item_wise_tax_detail = JSON.parse(tax.item_wise_tax_detail);
|
||||
tax_detail = tax.item_wise_tax_detail;
|
||||
}
|
||||
|
||||
let item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
|
||||
if (tax_detail && tax_detail[key])
|
||||
item_wise_tax_amount += tax_detail[key][1];
|
||||
|
||||
@@ -6,6 +6,7 @@ frappe.provide('erpnext.accounts.dimensions');
|
||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup: function() {
|
||||
this._super();
|
||||
let me = this;
|
||||
frappe.flags.hide_serial_batch_dialog = true;
|
||||
frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
@@ -43,8 +44,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
cur_frm.cscript.calculate_stock_uom_rate(frm, cdt, cdn);
|
||||
});
|
||||
|
||||
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
});
|
||||
@@ -121,7 +120,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
});
|
||||
|
||||
var me = this;
|
||||
if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
|
||||
this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
|
||||
return me.set_query_for_batch(doc, cdt, cdn);
|
||||
@@ -556,6 +554,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
name: me.frm.doc.name,
|
||||
project: item.project || me.frm.doc.project,
|
||||
qty: item.qty || 1,
|
||||
net_rate: item.rate,
|
||||
stock_qty: item.stock_qty,
|
||||
conversion_factor: item.conversion_factor,
|
||||
weight_per_unit: item.weight_per_unit,
|
||||
@@ -712,26 +711,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
});
|
||||
},
|
||||
|
||||
add_taxes_from_item_tax_template: function(item_tax_map) {
|
||||
let me = this;
|
||||
|
||||
if(item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
|
||||
if(typeof (item_tax_map) == "string") {
|
||||
item_tax_map = JSON.parse(item_tax_map);
|
||||
}
|
||||
|
||||
$.each(item_tax_map, function(tax, rate) {
|
||||
let found = (me.frm.doc.taxes || []).find(d => d.account_head === tax);
|
||||
if(!found) {
|
||||
let child = frappe.model.add_child(me.frm.doc, "taxes");
|
||||
child.charge_type = "On Net Total";
|
||||
child.account_head = tax;
|
||||
child.rate = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
serial_no: function(doc, cdt, cdn) {
|
||||
var me = this;
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
@@ -835,9 +814,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
frappe.run_serially([
|
||||
() => me.frm.script_manager.trigger("currency"),
|
||||
() => me.update_item_tax_map(),
|
||||
() => me.apply_default_taxes(),
|
||||
() => me.apply_pricing_rule()
|
||||
() => me.apply_pricing_rule(),
|
||||
() => me.calculate_taxes_and_totals()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1816,7 +1795,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
item.item_tax_rate = r.message;
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
me.calculate_taxes_and_totals();
|
||||
}
|
||||
}
|
||||
@@ -1827,43 +1805,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
|
||||
update_item_tax_map: function() {
|
||||
var me = this;
|
||||
var item_codes = [];
|
||||
$.each(this.frm.doc.items || [], function(i, item) {
|
||||
if(item.item_code) {
|
||||
item_codes.push(item.item_code);
|
||||
}
|
||||
});
|
||||
|
||||
if(item_codes.length) {
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_tax_info",
|
||||
args: {
|
||||
company: me.frm.doc.company,
|
||||
tax_category: cstr(me.frm.doc.tax_category),
|
||||
item_codes: item_codes
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
$.each(me.frm.doc.items || [], function(i, item) {
|
||||
if(item.item_code && r.message.hasOwnProperty(item.item_code)) {
|
||||
if (!item.item_tax_template) {
|
||||
item.item_tax_template = r.message[item.item_code].item_tax_template;
|
||||
item.item_tax_rate = r.message[item.item_code].item_tax_rate;
|
||||
}
|
||||
me.add_taxes_from_item_tax_template(item.item_tax_rate);
|
||||
} else {
|
||||
item.item_tax_template = "";
|
||||
item.item_tax_rate = "{}";
|
||||
}
|
||||
});
|
||||
me.calculate_taxes_and_totals();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
is_recurring: function() {
|
||||
// set default values for recurring documents
|
||||
|
||||
Reference in New Issue
Block a user