-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update hsn_code on change of item_group
- Loading branch information
Showing
2 changed files
with
52 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters