SHARE
TWEET

Untitled

a guest Sep 9th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let alter_dic = {};
  2.  
  3. let dialog = new frappe.ui.Dialog({
  4.     title: __('Alternative Items'),
  5.     fields: [
  6.     {
  7.         fieldtype: 'HTML',
  8.         fieldname: 'alt_item_name',
  9.         label: __(''),
  10.         reqd: false,
  11.         description: __(""),
  12.         options: rendered_template // HTML code
  13.     },
  14.     {
  15.         fieldtype: 'Column Break',
  16.         fieldname: 'c_break'
  17.     },
  18.     {
  19.         fieldtype: 'HTML',
  20.         fieldname: 'competitor_prices'
  21.     },
  22.     {
  23.         fieldtype: 'HTML',
  24.         fieldname: 'supplier_prices'
  25.     }
  26.     ],
  27.     primary_action_label: __("Ok"),
  28.     primary_action: function () {
  29.             // console.log('test')
  30.             $.each(doc.items, function (i, d) {
  31.  
  32.                 if (alter_dic[d.item_code]) {
  33.  
  34.                     if (d.same_as_item_code_above) {
  35.  
  36.                         d.same_as_item_code_above = 0;
  37.                     }
  38.  
  39.                     let original_item = d.item_code;
  40.                     let alter_item = alter_dic[d.item_code];
  41.                     d.item_code = alter_item["item_code"];
  42.                     d.item_name = alter_item["item_name"];
  43.                     d.manufacturer_pn = alter_item["manufacturer_pn"];
  44.                     d.description = alter_item["description"];
  45.                     d.stock_uom = alter_item["stock_uom"];
  46.                     d.sales_item_name = d.item_code;
  47.  
  48.                     if (alter_dic[original_item]["qty"] < d.qty) {
  49.                         d.actual_qty = alter_item["qty"]
  50.                     }
  51.  
  52.                     // d.rate = alter_item['rate'];
  53.                     d.price_list_rate = alter_item['rate'];
  54.  
  55.                     frm.script_manager.trigger("qty", d.doctype, d.name);
  56.                     frm.script_manager.trigger("item_code", d.doctype, d.name);
  57.                     frm.script_manager.trigger("price_list_rate", d.doctype, d.name);
  58.                     frm.script_manager.trigger("rate", d.doctype, d.name);
  59.                     frm.script_manager.trigger("warehouse", d.doctype, d.name);
  60.                 }
  61.             });
  62.  
  63.             dialog.hide();
  64.             refresh_field('items');
  65.             // cur_frm.save();
  66.  
  67.         }
  68.     });
  69.  
  70. dialog.show();
  71. dialog.$wrapper.find('.modal-dialog').css("width", "70%");
  72. dialog.$wrapper.find('.modal-dialog').css("height", "70%");
  73.  
  74. // I need to add the code below in setTimeout
  75. $("input[name='sp']").change(function () {
  76.  
  77.     alter_dic[$(this).attr('id')] = {
  78.         "item_code": $(this).closest('td').attr("item"),
  79.         "qty": $(this).closest('td').attr("qty"),
  80.         "item_name": $(this).closest('td').attr("item_name"),
  81.         "manufacturer_pn": $(this).closest('td').attr("manufacturer_pn"),
  82.         "description": $(this).closest('td').attr("description"),
  83.         "warehouse": $(this).closest('td').attr("warehouse"),
  84.         "stock_uom": $(this).closest('td').attr("stock_uom"),
  85.         "rate": $(this).closest('td').attr("rate"),
  86.         "price_list_rate": $(this).closest('td').attr("price_list_rate")
  87.     };
  88.  
  89.     console.log(alter_dic)
  90. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top