Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cur_frm.cscript['Get Alternative Items']= function(doc){
- var dialog = new frappe.ui.Dialog({
- title:__('Alternative Items'),
- fields: [
- {fieldtype:'HTML', fieldname:'alt_item_name', label:__(''), reqd:false,
- description: __("")},
- {fieldtype:'Button', fieldname:'get_item_details', label:__('Ok') }
- ]
- })
- var fd = dialog.fields_dict;
- $(fd.get_item_details.input).closest('div').css("padding-top","15px")
- frappe.call({
- method:"erpnext.selling.custom_methods.get_alternative_item_details",
- args:{"doc":cur_frm.doc},
- callback:function(r){
- var me = this;
- var result_set =r.message
- alter_dic={}
- $.each(result_set,function(i,d){
- if (d.length!=0){
- me.table = $("<br><div><b>Alternative Items for "+i+"</b></div></br><div style='width:100%;height:200px;overflow:scroll'><form><table class='table table-bordered' id='mytable'>\
- <thead><tr><th></th><th>Item</th><th>Stock Level</th></tr></thead>\
- <tbody></tbody>\
- </table></form></div>").appendTo($(fd.alt_item_name.wrapper))
- $.each(d,function(key,val){
- var row = $("<tr>").appendTo(me.table.find("tbody"));
- $("<td>").html('<input type="radio" name="sp" id="'+i+'">')
- .attr("item", val["item_code"])
- .attr("qty", val["actual_qty"])
- .appendTo(row)
- $("<td>").html('<p>'+val["item_code"]+'</p>').appendTo(row);
- $("<td>").html('<p>'+val["actual_qty"]+'</p>').appendTo(row);
- })
- }
- else{
- $('<div><b>Alternative Items for '+i+'</b></div></br><div><h5>There is no Stock available of any Equivalent Item</h5></div>').appendTo($(fd.alt_item_name.wrapper))
- }
- })
- dialog.show();
- $("input[name='sp']").change(function () {
- alter_dic[$(this).attr('id')]={"item_code":$(this).closest('td').attr("item"),"qty":$(this).closest('td').attr("qty")}
- })
- $(fd.get_item_details.input).click(function(){
- frappe.call({
- method: "erpnext.selling.custom_methods.set_alternative_item_details",
- args: { "alter_dic":alter_dic,"doc":cur_frm.doc},
- callback: function(r){
- dialog.hide()
- refresh_field('delivery_note_details')
- }
- })
- })
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement