Try ERPNext Buy Support Partners Foundation

Based on GST HSN number how to auto populate the item tax template in item

Hello,
I have create one GST HSN number also in that create item tax template .base on the GST HSN number i want to autopopulate the item tax template in the item …
when i create item in that select the GTS HSN number based on that autopopulate the item tax template which are created in the time of GST HSN
so for that i have create one custom script but it will not working for me can any one help me where i am wrong.

frappe.ui.form.on(“Item”, “hsn_code”, function(frm, cdt, cdn) {
frappe.model.with_doc(“GST HSN Code”, frm.doc.hsn_code, function() {
var tabletransfer= frappe.model.get_doc(“GST HSN Code”, frm.doc.hsn_code)
$.each(tabletransfer.taxes, function(index, row){
var d = frm.add_child(“taxes”);
d.item_tax_template = row.item_tax_template;
d.tax_category = row.tax_category;
frm.refresh_field(“taxes”);
});
});
});

this is my custom script

this is my gst hsn code and below are the item tax template.so when i create new item and in that this hsn gst code is used then this item tax tamplate is autopopulate in that item


my custom script is not working can u please help where i am getting wrong

This feature is already available in version 12. Which version are you using?

The related code is here: https://github.com/frappe/erpnext/blob/version-12/erpnext/stock/doctype/item/item.js#L139-L151

I am using version 12. i used this code but nothing happen …
i am create one custom script for the same but script also not working can u please help where i a, wrong…

frappe.ui.form.on("Item", {
    gst_hsn_code: function(frm) {
        if(!frm.doc.taxes || !frm.doc.taxes.length){
            frappe.db.get_doc("GST HSN Code",frm.doc.gst_hsn_code).then(hsn_doc => {
                $.each(hsn_doc.taxes || [],function(i,tax){
                    let a = frappe.model.add_child(cur_frm.doc,'Item Tax','taxes');
                    console.log("aaaa",a)
                    a.item_tax_template = tax.item_tax_template;
                    console.log("item_tax_temlate",a.item_tax_template)
                    a.tax_category = tax.tax_category;
                    console.log("tax_category",a.tax_category)
                    a.valid_from = tax.valid_from;
                    console.log("valid_from", a.valid_from)
                    frm.refresh_field('taxes');
                });
            });
        }
    }
});

I used this code but not able to autopopulate the item tax template in item based on the gst hsn number

But it should work by default, I have just checked, it is working fine in my account.

In my case it is not working …
i am use version
ERPNext: v12.1.4
Frappe Framework: v12.0.14

i did not update the code …i use old code base.
even i put the same code in item.js file but after that also there is no effect …need help…i try this using custom script but am not able to do this .can u please tell me where i am wrong
this is my custom script

frappe.ui.form.on(“Item”, {
gst_hsn_code: function(frm) {
if(!frm.doc.taxes || !frm.doc.taxes.length){
frappe.db.get_doc(“GST HSN Code”,frm.doc.gst_hsn_code).then(hsn_doc => {
$.each(hsn_doc.taxes || [],function(i,tax){
let a = frappe.model.add_child(cur_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’);
});
});
}
}
});

still i am facing same issue …

It should work. Is there any error in browser console?

No error in console bt the script is not working

What about console.log? Are they printed in console?

no nothing is in console when i add the deubgger then it will show when select the hsn in item

gst_hsn_code()
where this function is called

issue is resolve …