Skip to content

Commit

Permalink
fix: update hsn_code on change of item_group
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninad1306 committed Oct 25, 2024
1 parent 4e79581 commit 8d4c14a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
60 changes: 43 additions & 17 deletions india_compliance/gst_india/client_scripts/item.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
frappe.ui.form.on('Item', {
onload: function(frm) {
india_compliance.set_hsn_code_query(frm.get_field("gst_hsn_code"));
},
frappe.ui.form.on("Item", {
onload: function (frm) {
india_compliance.set_hsn_code_query(frm.get_field("gst_hsn_code"));
},

gst_hsn_code: function(frm) {
if ((!frm.doc.taxes || !frm.doc.taxes.length) && frm.doc.gst_hsn_code) {
frappe.db.get_doc("GST HSN Code", frm.doc.gst_hsn_code).then(hsn_doc => {
$.each(hsn_doc.taxes || [], function(_, tax) {
let a = frappe.model.add_child(frm.doc, 'Item Tax', 'taxes');
a.item_tax_template = tax.item_tax_template;
a.tax_category = tax.tax_category;
a.valid_from = tax.valid_from;
frm.refresh_field('taxes');
});
});
}
},
item_group: async function (frm) {
if (frm.doc.item_group) {
const { message } = await frappe.db.get_value(
"Item Group",
frm.doc.item_group,
"gst_hsn_code"
);

if (message.gst_hsn_code && message.gst_hsn_code !== frm.doc.gst_hsn_code) {
frm.set_value("gst_hsn_code", message.gst_hsn_code);
}
}
},

before_save: async function (frm) {
if (!frm.doc.gst_hsn_code && frm.doc.item_group) {
const { message } = await frappe.db.get_value(
"Item Group",
frm.doc.item_group,
"gst_hsn_code"
);

frm.set_value("gst_hsn_code", message.gst_hsn_code);
}
},

gst_hsn_code: function (frm) {
if ((!frm.doc.taxes || !frm.doc.taxes.length) && frm.doc.gst_hsn_code) {
frappe.db.get_doc("GST HSN Code", frm.doc.gst_hsn_code).then(hsn_doc => {
$.each(hsn_doc.taxes || [], function (_, tax) {
let a = frappe.model.add_child(frm.doc, "Item Tax", "taxes");
a.item_tax_template = tax.item_tax_template;
a.tax_category = tax.tax_category;
a.valid_from = tax.valid_from;
frm.refresh_field("taxes");
});
});
}
},
});
14 changes: 9 additions & 5 deletions india_compliance/public/js/quick_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class GSTQuickEntryForm extends frappe.ui.form.QuickEntryForm {
fieldtype: "Section Break",
description: this.api_enabled
? __(
`When you enter a GSTIN, the permanent address linked to it is
`When you enter a GSTIN, the permanent address linked to it is
autofilled.<br>
Change the {0} to autofill other addresses.`,
[frappe.meta.get_label("Address", "pincode")]
)
[frappe.meta.get_label("Address", "pincode")]
)
: "",
collapsible: 0,
},
Expand Down Expand Up @@ -338,15 +338,19 @@ class ItemQuickEntryForm extends frappe.ui.form.QuickEntryForm {
}

set_hsn_from_item_group() {
let item_group_field = this.dialog.fields_dict.item_group;
const item_group_field = this.dialog.fields_dict.item_group;
const hsn_code_field = this.dialog.fields_dict.gst_hsn_code;

item_group_field.df.onchange = async () => {
const { message } = await frappe.db.get_value(
"Item Group",
item_group_field.value,
"gst_hsn_code"
);
this.dialog.set_value("gst_hsn_code", message.gst_hsn_code);

if (message.gst_hsn_code && message.gst_hsn_code !== hsn_code_field.value) {
this.dialog.set_value("gst_hsn_code", message.gst_hsn_code);
}
};
}
}
Expand Down

0 comments on commit 8d4c14a

Please sign in to comment.