frappe.ui.form.on("Sales Order", "refresh", function(frm, doctype, name) {
cur_frm.add_custom_button(__('Get Individual Items'), function() {
var d = new frappe.ui.Dialog({
title: __("Get Item from Quote"),
fields: [
{
"label": __("Quotation"),
"fieldname": "quotation",
"fieldtype": "Link",
"options": "Quotation",
"reqd": 1
},
{
"fieldname":"sb1",
"fieldtype":"Section Break",
},
{
"label": __("html"),
"fieldname": "my_html",
"fieldtype": "HTML",
"options" : "Items from quote<br>",
},
],
primary_action_label: "Get Items",
primary_action: function(){
//msgprint("hi");
args = d.get_values();
if(!args) return;
console.log(args.quotation);
quotation_name = args.quotation;
all_items = []
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Quotation Item",
fields: ["item_code", "item_name", "qty", "rate","name"],
filters: { 'parent': quotation_name },
},
callback: function(res){
if (res && res.message){
all_items = res.message;
html = "Items from quote<br>"
console.log( res.message);
for (var i = 0; i<res.message.length; i=i+1) {
console.log( res.message[i].item_code);
html +="<p><input type='checkbox' class='select' id='_select' name='"
+res.message[i].item_code
+"' value='"
+res.message[i].item_code
+"'> "
+res.message[i].item_code
+ "</p>"
}
html += "<br><input type='button'name='Add items' value='Add items' <br>"
$("#item_select").append("sam");
var wrapper = d.fields_dict.my_html.$wrapper;
wrapper.empty();
wrapper.html(html);
}
}
});
}
});
d.show();
var test_list = [];
$(".frappe-control input:checkbox:checked").each ( function() {
test_list.push($(this).attr("name"));
});
test_list.forEach(function(element) {
console.log(element);
var row = frappe.model.add_child(cur_frm.doc, "Sales Order Item", "items");
row.item_code = element;
row.item_name = element;
row.rate = 0;
//add child
});
refresh_field("items");
});
});
cur_frm.add_custom_button(__('Get Individual Items'), function() {
var d = new frappe.ui.Dialog({
title: __("Get Item from Quote"),
fields: [
{
"label": __("Quotation"),
"fieldname": "quotation",
"fieldtype": "Link",
"options": "Quotation",
"reqd": 1
},
{
"fieldname":"sb1",
"fieldtype":"Section Break",
},
{
"label": __("html"),
"fieldname": "my_html",
"fieldtype": "HTML",
"options" : "Items from quote<br>",
},
],
primary_action_label: "Get Items",
primary_action: function(){
//msgprint("hi");
args = d.get_values();
if(!args) return;
console.log(args.quotation);
quotation_name = args.quotation;
all_items = []
frappe.call({
method: "frappe.client.get_list",
args: {
doctype: "Quotation Item",
fields: ["item_code", "item_name", "qty", "rate","name"],
filters: { 'parent': quotation_name },
},
callback: function(res){
if (res && res.message){
all_items = res.message;
html = "Items from quote<br>"
console.log( res.message);
for (var i = 0; i<res.message.length; i=i+1) {
console.log( res.message[i].item_code);
html +="<p><input type='checkbox' class='select' id='_select' name='"
+res.message[i].item_code
+"' value='"
+res.message[i].item_code
+"'> "
+res.message[i].item_code
+ "</p>"
}
html += "<br><input type='button'name='Add items' value='Add items' <br>"
$("#item_select").append("sam");
var wrapper = d.fields_dict.my_html.$wrapper;
wrapper.empty();
wrapper.html(html);
}
}
});
}
});
d.show();
var test_list = [];
$(".frappe-control input:checkbox:checked").each ( function() {
test_list.push($(this).attr("name"));
});
test_list.forEach(function(element) {
console.log(element);
var row = frappe.model.add_child(cur_frm.doc, "Sales Order Item", "items");
row.item_code = element;
row.item_name = element;
row.rate = 0;
//add child
});
refresh_field("items");
});
});
No comments:
Post a Comment