Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Common Taxes for BOE and Subcontracting #2515

Merged
merged 13 commits into from
Oct 10, 2024
5 changes: 5 additions & 0 deletions india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ frappe.ui.form.on(DOCTYPE, {
__("Bill To (same as Supplier Address)"),
__("Bill To")
);

frm.get_docfield("taxes", "charge_type").options = [
"On Net Total",
"On Item Quantity",
];
},

refresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ frappe.ui.form.on("Subcontracting Order", {
frm.taxes_controller = new india_compliance.taxes_controller(frm, {
total_taxable_value: "total",
});

frm.get_docfield("taxes", "charge_type").options = [
"On Net Total",
"On Item Quantity",
];
},

taxes_and_charges(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ frappe.ui.form.on(DOCTYPE, {
frm.taxes_controller = new india_compliance.taxes_controller(frm, {
total_taxable_value: "total",
});

frm.get_docfield("taxes", "charge_type").options = [
"On Net Total",
"On Item Quantity",
];
},

refresh() {
Expand Down
230 changes: 1 addition & 229 deletions india_compliance/gst_india/doctype/bill_of_entry/bill_of_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,10 @@ frappe.ui.form.on("Bill of Entry Item", {
},
});

frappe.ui.form.on("Bill of Entry Taxes", {
rate(frm, cdt, cdn) {
frm.taxes_controller.update_tax_rate(cdt, cdn);
},

tax_amount(frm, cdt, cdn) {
frm.taxes_controller.update_tax_amount(cdt, cdn);
},

async account_head(frm, cdt, cdn) {
await frm.taxes_controller.set_item_wise_tax_rates(null, cdn);
frm.taxes_controller.update_tax_amount(cdt, cdn);
},

async charge_type(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (!row.charge_type || row.charge_type === "Actual") {
row.rate = 0;
row.item_wise_tax_rates = "{}";
frm.refresh_field("taxes");
} else {
await frm.taxes_controller.set_item_wise_tax_rates(null, cdn);
frm.taxes_controller.update_tax_amount(cdt, cdn);
}
},

taxes_remove(frm) {
Ninad1306 marked this conversation as resolved.
Show resolved Hide resolved
frm.bill_of_entry_controller.update_total_taxes();
},
});

class BillOfEntryController {
constructor(frm) {
this.frm = frm;
this.frm.taxes_controller = new TaxesController(frm);
this.frm.taxes_controller = new india_compliance.taxes_controller(frm);
this.setup();
}

Expand Down Expand Up @@ -191,207 +160,10 @@ class BillOfEntryController {
);
}

update_total_taxes() {
const total_taxes = this.frm.doc.taxes.reduce(
(total, row) => total + row.tax_amount,
0
);
this.frm.set_value("total_taxes", total_taxes);
}

update_total_amount_payable() {
this.frm.set_value(
"total_amount_payable",
this.frm.doc.total_customs_duty + this.frm.doc.total_taxes
);
}
}

class TaxesController {
constructor(frm) {
this.frm = frm;
this.setup();
}

setup() {
this.fetch_round_off_accounts();
this.set_item_tax_template_query();
this.set_account_head_query();
}

fetch_round_off_accounts() {
if (this.frm.doc.docstatus !== 0 || !this.frm.doc.company) return;

frappe.call({
method: "erpnext.controllers.taxes_and_totals.get_round_off_applicable_accounts",
args: {
company: this.frm.doc.company,
account_list: [],
},
callback(r) {
if (r.message) {
frappe.flags.round_off_applicable_accounts = r.message;
}
},
});
}

set_item_tax_template_query() {
this.frm.set_query("item_tax_template", "items", () => {
return {
filters: {
company: this.frm.doc.company,
},
};
});
}

set_account_head_query() {
this.frm.set_query("account_head", "taxes", () => {
return {
filters: {
company: this.frm.doc.company,
is_group: 0,
},
};
});
}

async set_item_wise_tax_rates(item_name, tax_name) {
/**
* This method is used to set item wise tax rates from the server
* and update the item_wise_tax_rates field in the taxes table.
*
* @param {string} item_name - Item row name for which the tax rates are to be fetched.
* @param {string} tax_name - Tax row name for which the tax rates are to be fetched.
*/

if (!this.frm.taxes || !this.frm.taxes.length) return;

await this.frm.call("set_item_wise_tax_rates", {
item_name: item_name,
tax_name: tax_name,
});
}

update_item_wise_tax_rates(tax_row) {
/**
* This method is used to update the item_wise_tax_rates field in the taxes table when
* - Item tax template is removed from the item row.
* - Tax rate is changed in the tax row.
*
* It will update item rate with default tax rate.
*
* @param {object} tax_row - Tax row object.
*/

let taxes;
if (tax_row) taxes = [tax_row];
else taxes = this.frm.doc.taxes;

taxes.forEach(tax => {
const item_wise_tax_rates = JSON.parse(tax.item_wise_tax_rates || "{}");
this.frm.doc.items.forEach(item => {
if (item.item_tax_template) return;
item_wise_tax_rates[item.name] = tax.rate;
});
tax.item_wise_tax_rates = JSON.stringify(item_wise_tax_rates);
});
}

async update_tax_rate(cdt, cdn) {
const row = locals[cdt][cdn];
if (!row.charge_type || row.charge_type === "Actual") row.rate = 0;
else {
this.update_item_wise_tax_rates(row);
await this.update_tax_amount(cdt, cdn);
}
}

async update_tax_amount(cdt, cdn) {
/**
* This method is used to update the tax amount in the tax row
* - Update for all tax rows when cdt is null.
* - Update for a single tax row when cdt and cdn are passed.
*
* @param {string} cdt - DocType of the tax row.
* @param {string} cdn - Name of the tax row.
*/

let taxes;
if (cdt) taxes = [locals[cdt][cdn]];
else taxes = this.frm.doc.taxes;

taxes.forEach(async row => {
if (!row.charge_type || row.charge_type === "Actual") return;

let tax_amount = 0;

if (row.charge_type === "On Net Total") {
tax_amount = this.get_tax_on_net_total(row);
}

if (row.charge_type == "On Item Quantity") {
tax_amount = this.get_tax_on_item_quantity(row);
}

// update if tax amount is changed manually
if (tax_amount !== row.tax_amount) {
row.tax_amount = tax_amount;
}

if (
frappe.flags.round_off_applicable_accounts?.includes(row.account_head)
) {
row.tax_amount = Math.round(row.tax_amount);
}
});

this.update_total_amount();
this.frm.bill_of_entry_controller.update_total_taxes();
}

update_total_amount() {
this.frm.doc.taxes.reduce((total, row) => {
const total_amount = total + row.tax_amount;
row.total = total_amount;

return total_amount;
}, this.frm.doc.total_taxable_value);

this.frm.refresh_field("taxes");
}

get_tax_on_net_total(tax_row) {
/**
* This method is used to calculate the tax amount on net total
* based on the item wise tax rates.
*
* @param {object} tax_row - Tax row object.
*/

const item_wise_tax_rates = JSON.parse(tax_row.item_wise_tax_rates || "{}");
return this.frm.doc.items.reduce((total, item) => {
return (
total +
(item.taxable_value *
(item_wise_tax_rates[item.name] || tax_row.rate)) /
100
);
}, 0);
}

get_tax_on_item_quantity(tax_row) {
/**
* This method is used to calculate the tax amount on item quntity (cess non advol)
* based on the item wise tax rates and item quantity.
*
* @param {object} tax_row - Tax row object.
*/

const item_wise_tax_rates = JSON.parse(tax_row.item_wise_tax_rates || "{}");
return this.frm.doc.items.reduce((total, item) => {
return total + item.qty * (item_wise_tax_rates[item.name] || tax_row.rate);
}, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
{
"fieldname": "taxes",
"fieldtype": "Table",
"options": "Bill of Entry Taxes",
"options": "India Compliance Taxes and Charges",
Ninad1306 marked this conversation as resolved.
Show resolved Hide resolved
"reqd": 1
},
{
Expand Down Expand Up @@ -297,7 +297,7 @@
"link_fieldname": "link_name"
}
],
"modified": "2024-03-29 11:36:17.991037",
"modified": "2024-08-12 15:48:43.769450",
"modified_by": "Administrator",
"module": "GST India",
"name": "Bill of Entry",
Expand Down
Loading
Loading