Skip to content

Commit

Permalink
fix: Only Validate Taxes if e-Waybill Applicable (#2803)
Browse files Browse the repository at this point in the history
* fix: better naming

* fix: only validate taxes if e-waybill applicable

* refactor: remove redundent function declaration

(cherry picked from commit ad75fb4)
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Dec 5, 2024
1 parent 1b3f9e2 commit a679251
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
5 changes: 0 additions & 5 deletions india_compliance/gst_india/client_scripts/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ frappe.ui.form.on(DOCTYPE, {
"supplier_address",
...get_field_and_label(frm, "party_field")
);

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

refresh(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ 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 @@ -42,28 +42,21 @@ frappe.ui.form.on(DOCTYPE, {
...filters,
supplied_items: get_supplied_items(doc),
},
}

};
else if (row.link_doctype == "Subcontracting Receipt")
return {
query: "india_compliance.gst_india.overrides.subcontracting_transaction.get_subcontracting_receipt_references",
filters: {
...filters,
received_items: get_received_items(doc),
}
}

},
};
});
},
onload(frm) {
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
8 changes: 4 additions & 4 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"fieldtype": "Section Break",
"insert_after": "total",
"hide_border": 1,
"depends_on": "eval: doc.purchase_order && india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
"depends_on": "eval: doc.purchase_order && india_compliance.is_e_waybill_applicable_for_subcontracting(doc)",
},
],
"Subcontracting Receipt": [
Expand All @@ -66,7 +66,7 @@
"fieldtype": "Section Break",
"insert_after": "total",
"hide_border": 1,
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
"depends_on": "eval: india_compliance.is_e_waybill_applicable_for_subcontracting(doc)",
},
{
"fieldname": "section_break_ref_doc",
Expand Down Expand Up @@ -182,14 +182,14 @@
"label": "Taxes",
"fieldtype": "Section Break",
"insert_after": "get_stock_and_rate",
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
"depends_on": "eval: india_compliance.is_e_waybill_applicable_for_subcontracting(doc)",
},
{
"label": "E-Waybill Info",
"fieldname": "tab_break_ewaybill",
"fieldtype": "Tab Break",
"insert_after": "address_display",
"depends_on": "eval: india_compliance.is_e_waybill_generatable_for_subcontracting(doc)",
"depends_on": "eval: india_compliance.is_e_waybill_applicable_for_subcontracting(doc)",
},
{
"label": "e-Waybill Address",
Expand Down
18 changes: 11 additions & 7 deletions india_compliance/gst_india/overrides/subcontracting_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,24 @@ def validate(doc, method=None):


def before_save(doc, method=None):
if ignore_gst_validations(doc):
if not is_e_waybill_applicable(doc):
doc.taxes_and_charges = ""
doc.taxes = []
return

validate_doc_references(doc)
for row in doc.taxes:
if row.charge_type == "Actual":
frappe.throw(
_(
"Tax Row #{0}: Charge Type cannot be {1}. Try setting it to 'On Net Total' or 'On Item Quantity'."
).format(row.idx, bold(row.charge_type))
)


def before_submit(doc, method=None):
def validate_doc_references(doc, method=None):
if ignore_gst_validations(doc):
return

validate_doc_references(doc)


def validate_doc_references(doc):
is_return_material_transfer = (
doc.doctype == "Stock Entry"
and doc.purpose == "Material Transfer"
Expand Down
9 changes: 7 additions & 2 deletions india_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,22 @@
"Stock Entry": {
"onload": "india_compliance.gst_india.overrides.subcontracting_transaction.onload",
"validate": "india_compliance.gst_india.overrides.subcontracting_transaction.validate",
"before_submit": "india_compliance.gst_india.overrides.subcontracting_transaction.before_submit",
"before_save": "india_compliance.gst_india.overrides.subcontracting_transaction.before_save",
"before_submit": "india_compliance.gst_india.overrides.subcontracting_transaction.validate_doc_references",
"after_mapping": "india_compliance.gst_india.overrides.subcontracting_transaction.after_mapping_stock_entry",
},
"Subcontracting Order": {
"validate": "india_compliance.gst_india.overrides.subcontracting_transaction.validate",
"before_save": "india_compliance.gst_india.overrides.subcontracting_transaction.before_save",
"after_mapping": "india_compliance.gst_india.overrides.subcontracting_transaction.after_mapping_subcontracting_order",
},
"Subcontracting Receipt": {
"onload": "india_compliance.gst_india.overrides.subcontracting_transaction.onload",
"validate": "india_compliance.gst_india.overrides.subcontracting_transaction.validate",
"before_save": "india_compliance.gst_india.overrides.subcontracting_transaction.before_save",
"before_save": [
"india_compliance.gst_india.overrides.subcontracting_transaction.before_save",
"india_compliance.gst_india.overrides.subcontracting_transaction.validate_doc_references",
],
"before_mapping": "india_compliance.gst_india.overrides.subcontracting_transaction.before_mapping_subcontracting_receipt",
},
"Supplier": {
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ Object.assign(india_compliance, {
return alert;
},

is_e_waybill_generatable_for_subcontracting(doc) {
is_e_waybill_applicable_for_subcontracting(doc) {
if (
!(
gst_settings.enable_api &&
Expand Down

0 comments on commit a679251

Please sign in to comment.