feat: HSN Code wise Item Tax (#19478)

* feat: HSN Code wise Item Tax

* feat: enqueued task of updating all items
This commit is contained in:
Anurag Mishra 2019-11-29 17:33:10 +05:30 committed by Nabin Hait
parent 0de066c3b1
commit 10017c14f3
4 changed files with 95 additions and 100 deletions

View File

@ -3,6 +3,26 @@
frappe.ui.form.on('GST HSN Code', { frappe.ui.form.on('GST HSN Code', {
refresh: function(frm) { refresh: function(frm) {
if(! frm.doc.__islocal && frm.doc.taxes.length){
frm.add_custom_button(__('Update Taxes for Items'), function(){
frappe.confirm(
'Are you sure? It will overwrite taxes for all items with HSN Code <b>'+frm.doc.name+'</b>.',
function(){
frappe.call({
args:{
taxes: frm.doc.taxes,
hsn_code: frm.doc.name
},
method: 'erpnext.regional.doctype.gst_hsn_code.gst_hsn_code.update_taxes_in_item_master',
callback: function(r) {
if(r.message){
frappe.show_alert(__('Item taxes updated'));
}
}
});
}
);
});
}
} }
}); });

View File

@ -1,104 +1,46 @@
{ {
"allow_copy": 0, "autoname": "field:hsn_code",
"allow_guest_to_view": 0, "creation": "2017-06-21 10:48:56.422086",
"allow_import": 0, "doctype": "DocType",
"allow_rename": 0, "editable_grid": 1,
"autoname": "field:hsn_code", "engine": "InnoDB",
"beta": 0, "field_order": [
"creation": "2017-06-21 10:48:56.422086", "hsn_code",
"custom": 0, "description",
"docstatus": 0, "taxes"
"doctype": "DocType", ],
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0, "fieldname": "hsn_code",
"allow_on_submit": 0, "fieldtype": "Data",
"bold": 0, "in_list_view": 1,
"collapsible": 0, "label": "HSN Code",
"columns": 0, "reqd": 1,
"fieldname": "hsn_code", "unique": 1
"fieldtype": "Data", },
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "HSN Code",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "fieldname": "description",
"allow_on_submit": 0, "fieldtype": "Small Text",
"bold": 0, "in_list_view": 1,
"collapsible": 0, "label": "Description"
"columns": 0, },
"fieldname": "description", {
"fieldtype": "Small Text", "fieldname": "taxes",
"hidden": 0, "fieldtype": "Table",
"ignore_user_permissions": 0, "label": "Taxes",
"ignore_xss_filter": 0, "options": "Item Tax"
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Description",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"has_web_view": 0, "modified": "2019-11-01 11:18:59.556931",
"hide_heading": 0, "modified_by": "Administrator",
"hide_toolbar": 0, "module": "Regional",
"idx": 0, "name": "GST HSN Code",
"image_view": 0, "owner": "Administrator",
"in_create": 0, "permissions": [],
"is_submittable": 0, "quick_entry": 1,
"issingle": 0, "search_fields": "hsn_code, description",
"istable": 0, "sort_field": "modified",
"max_attachments": 0, "sort_order": "DESC",
"modified": "2017-09-29 14:38:52.220743", "title_field": "hsn_code",
"modified_by": "Administrator", "track_changes": 1
"module": "Regional",
"name": "GST HSN Code",
"name_case": "",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"search_fields": "hsn_code, description",
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "hsn_code",
"track_changes": 1,
"track_seen": 0
} }

View File

@ -8,3 +8,22 @@ from frappe.model.document import Document
class GSTHSNCode(Document): class GSTHSNCode(Document):
pass pass
@frappe.whitelist()
def update_taxes_in_item_master(taxes, hsn_code):
items = frappe.get_list("Item", filters={
'gst_hsn_code': hsn_code
})
taxes = frappe.parse_json(taxes)
frappe.enqueue(update_item_document, items=items, taxes=taxes)
return 1
def update_item_document(items, taxes):
for item in items:
item_to_be_updated=frappe.get_doc("Item", item.name)
item_to_be_updated.taxes = []
for tax in taxes:
tax = frappe._dict(tax)
item_to_be_updated.append("taxes", {'item_tax_template': tax.item_tax_template, 'tax_category': tax.tax_category})
item_to_be_updated.save()

View File

@ -136,6 +136,20 @@ frappe.ui.form.on("Item", {
frm.toggle_reqd('customer', frm.doc.is_customer_provided_item ? 1:0); frm.toggle_reqd('customer', frm.doc.is_customer_provided_item ? 1:0);
}, },
gst_hsn_code: function(frm){
if(!frm.doc.taxes){
frappe.db.get_doc("GST HSN Code", frm.doc.gst_hsn_code).then(hsn_doc=>{
frm.doc.taxes = [];
$.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;
frm.refresh_field('taxes');
});
});
}
},
is_fixed_asset: function(frm) { is_fixed_asset: function(frm) {
// set serial no to false & toggles its visibility // set serial no to false & toggles its visibility
frm.set_value('has_serial_no', 0); frm.set_value('has_serial_no', 0);