Skip to content

Commit

Permalink
Merge branch 'develop' into invoice_restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit authored Oct 16, 2024
2 parents 7566d29 + 4bb9af2 commit c1fb3c4
Show file tree
Hide file tree
Showing 62 changed files with 477 additions and 710 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
BRANCH_TO_CLONE: ${{ env.BRANCH }}

- name: Run Tests
run: cd ~/frappe-bench/ && bench --site test_site run-tests --app ${{ env.APP_NAME }} --coverage
run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app ${{ env.APP_NAME }} --with-coverage
env:
TYPE: server

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.tests import IntegrationTestCase


class TestAccountsSettings(FrappeTestCase):
class TestAccountsSettings(IntegrationTestCase):
def test_validate_change_in_enable_audit_trail_and_validate_delete_linked_ledger_entries(
self,
):
Expand Down
13 changes: 11 additions & 2 deletions india_compliance/audit_trail/overrides/test_property_setter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import re

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.tests import IntegrationTestCase


class TestPropertySetter(FrappeTestCase):
class TestPropertySetter(IntegrationTestCase):
def test_validate_property_setter_where_audit_trail_enabled_and_doc_is_protected(
self,
):
frappe.db.set_single_value("Accounts Settings", "enable_audit_trail", 1)
frappe.db.delete(
"Property Setter",
{
"doctype_or_field": "DocType",
"doc_type": "Purchase Invoice",
"property": "track_changes",
},
)

doc = frappe.get_doc(
{
"doctype": "Property Setter",
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/audit_trail/overrides/test_version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import re

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.tests import IntegrationTestCase

from india_compliance.gst_india.utils.tests import create_sales_invoice


class TestVersion(FrappeTestCase):
class TestVersion(IntegrationTestCase):
def test_validate_version_where_audit_trail_enabled(self):
# enable audit trail
frappe.db.set_single_value("Accounts Settings", "enable_audit_trail", 1)
Expand Down
14 changes: 13 additions & 1 deletion india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ 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() {
refresh(frm) {
frm.get_field("bill_to_address_display")
.$wrapper.find(".ql-editor")
.css("white-space", "normal");
frm.get_field("bill_from_address_display")
.$wrapper.find(".ql-editor")
.css("white-space", "normal");

if (!gst_settings.enable_e_waybill || !gst_settings.enable_e_waybill_for_sc)
return;

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) {
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",
"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

0 comments on commit c1fb3c4

Please sign in to comment.