Fixed Label Printing

This commit is contained in:
CAnetzberger committed 2022-02-28 09:51:26 +01:00
1 parent 476d52ba45
commit 0a8cb76ad1
4 files changed
+11 -17

No files matched your search

+7
View File
@@ -18,12 +18,19 @@ def print_label(values):
for label in values["labels"]: for label in values["labels"]:
doc = frappe.new_doc('Label') doc = frappe.new_doc('Label')
if "item_code" in values:
doc.item_code = values["item_code"] doc.item_code = values["item_code"]
if "item_name" in values:
doc.item_name = values["item_name"] doc.item_name = values["item_name"]
if "delivery_date" in values:
doc.delivery_date = values["delivery_date"] doc.delivery_date = values["delivery_date"]
if "customer" in values:
doc.customer = values["customer"] doc.customer = values["customer"]
if "batch" in values:
doc.batch = values["batch"] doc.batch = values["batch"]
if "qty" in label:
doc.qty = label["item_qty"] doc.qty = label["item_qty"]
if "information" in label:
doc.information = label["information"] doc.information = label["information"]
newdoc = doc.insert() newdoc = doc.insert()
+1 -1
View File
@@ -1,2 +1,2 @@
!function(){"use strict";function e(e,a){var t;return frappe.call({method:"frappe.client.get",async:!1,args:{doctype:e,name:a},callback:function(e){e.message&&(t=e.message)}}),t}$(document).ready(function(){$(".dropdown-notifications").after('<li id="labels-toolbar" class="nav-item"><a class="nav-link label-printing-icon text-muted"><i class="fa fa-tag fa-lg" aria-hidden="true"></i></a></li>'),$("#labels-toolbar").click(function(a){!function(a){var t=a.view.cur_frm,l={doctype:"",docname:"",item_code:"",item_name:"",delivery_date:"",customer:"",batch:"",information:"",total_amount:0,labels:[{item_qty:0,label_qty:0,information:""}]};null!==t&&("Work Order"!==t.doctype&&"Item"!==t.doctype||t.docname&&(l.doctype=t.doctype,l.docname=t.docname));var i=new frappe.ui.Dialog({title:__("Print Labels"),fields:[{label:__("Reference Doctype"),options:["Work Order","Item","Label"],fieldname:"doctype",fieldtype:"Select",default:l.doctype},{label:__("Get data"),fieldname:"get_data",fieldtype:"Button",click:function(){n()}},{fieldtype:"Column Break"},{label:__("Reference Docname"),fieldname:"docname",fieldtype:"Data",options:"doctype",default:l.docname},{fieldtype:"Section Break",label:__("Information")},{label:__("Item Code"),fieldname:"item_code",fieldtype:"Data"},{label:__("Item Name"),fieldname:"item_name",fieldtype:"Data"},{label:__("Delivery Date"),fieldname:"delivery_date",fieldtype:"Date"},{fieldtype:"Column Break"},{label:__("Customer"),fieldname:"customer",fieldtype:"Data"},{label:__("Batch"),fieldname:"batch",fieldtype:"Data"},{fieldtype:"Section Break",label:__("Labels")},{fieldname:"labels",fieldtype:"Table",cannot_add_rows:!1,in_place_edit:!0,data:l.labels,get_data:function(){return l.labels},fields:[{fieldtype:"Int",fieldname:"item_qty",in_list_view:1,label:__("Item Qty")},{label:__("Label Qty"),fieldname:"label_qty",in_list_view:1,fieldtype:"Int"},{fieldtype:"Data",fieldname:"information",in_list_view:1,label:__("Information")}]}],primary_action_label:"Print",primary_action:function(e){l=e,frappe.call({method:"label_printing.api.print_label",args:{values:l},callback:function(e){200===e.message&&frappe.show_alert("Label printing successful",5)}}),i.hide()}});function n(){if((l=i.get_values()).doctype&&l.docname){var a=e(l.doctype,l.docname);if("Work Order"===l.doctype){var t=e("Item",a.production_item);if(frappe.call({method:"label_printing.api.get_associated_stockentry",async:!1,args:{workorder:l.docname},callback:function(e){e.message&&(l.batch=e.message.items[e.message.items.length-1].batch_no)}}),l.item_code=t.item_code,l.item_name=t.item_name,l.delivery_date=a.expected_delivery_date,l.labels[0].item_qty=a.qty,l.labels[0].label_qty=1,t.associated_company){var n=e("Customer",t.associated_company);n.short_name?l.customer=n.short_name:l.customer=t.associated_company}l.total_amount=a.qty,l.labels[0].qty_per_label=a.qty,i.fields_dict.labels.refresh()}else if("Item"===l.doctype){var o=e("Item",a.item_code);if(l.item_code=a.item_code,l.item_name=a.item_name,o.associated_company){var c=e("Customer",a.associated_company);c.short_name?l.customer=c.short_name:l.customer=a.associated_company}}i.set_values(l)}}n(),i.show(),i.fields_dict.doctype.$input.on("change",function(){i.fields_dict.docname.refresh()})}(a)})})}(); !function(){"use strict";function e(e,a){var t;return frappe.call({method:"frappe.client.get",async:!1,args:{doctype:e,name:a},callback:function(e){e.message&&(t=e.message)}}),t}$(document).ready(function(){$(".dropdown-notifications").after('<li id="labels-toolbar" class="nav-item"><a class="nav-link label-printing-icon text-muted"><i class="fa fa-tag fa-lg" aria-hidden="true"></i></a></li>'),$("#labels-toolbar").click(function(a){!function(a){var t=a.view.cur_frm,l={labels:[{item_qty:0,label_qty:1}]};null!==t&&("Work Order"!==t.doctype&&"Item"!==t.doctype||t.docname&&(l.doctype=t.doctype,l.docname=t.docname));var i=new frappe.ui.Dialog({title:__("Print Labels"),fields:[{label:__("Reference Doctype"),options:["Work Order","Item","Label"],fieldname:"doctype",fieldtype:"Select",default:l.doctype},{label:__("Get data"),fieldname:"get_data",fieldtype:"Button",click:function(){n()}},{fieldtype:"Column Break"},{label:__("Reference Docname"),fieldname:"docname",fieldtype:"Data",options:"doctype",default:l.docname},{fieldtype:"Section Break",label:__("Information")},{label:__("Item Code"),fieldname:"item_code",fieldtype:"Data"},{label:__("Item Name"),fieldname:"item_name",fieldtype:"Data"},{label:__("Delivery Date"),fieldname:"delivery_date",fieldtype:"Date"},{fieldtype:"Column Break"},{label:__("Customer"),fieldname:"customer",fieldtype:"Data"},{label:__("Batch"),fieldname:"batch",fieldtype:"Data"},{fieldtype:"Section Break",label:__("Labels")},{fieldname:"labels",fieldtype:"Table",cannot_add_rows:!1,in_place_edit:!0,data:l.labels,get_data:function(){return l.labels},fields:[{fieldtype:"Int",fieldname:"item_qty",in_list_view:1,label:__("Item Qty")},{label:__("Label Qty"),fieldname:"label_qty",in_list_view:1,fieldtype:"Int"},{fieldtype:"Data",fieldname:"information",in_list_view:1,label:__("Information")}]}],primary_action_label:"Print",primary_action:function(e){frappe.call({method:"label_printing.api.print_label",args:{values:e},callback:function(e){200===e.message&&frappe.show_alert("Label printing successful",5)}}),i.hide()}});function n(){if((l=i.get_values()).doctype&&l.docname){var a=e(l.doctype,l.docname);if("Work Order"===l.doctype){var t=e("Item",a.production_item);if(frappe.call({method:"label_printing.api.get_associated_stockentry",async:!1,args:{workorder:l.docname},callback:function(e){e.message&&(l.batch=e.message.items[e.message.items.length-1].batch_no)}}),l.item_code=t.item_code,l.item_name=t.item_name,l.delivery_date=a.expected_delivery_date,l.labels[0].item_qty=a.qty,l.labels[0].label_qty=1,t.associated_company){var n=e("Customer",t.associated_company);n.short_name?l.customer=n.short_name:l.customer=t.associated_company}l.total_amount=a.qty,l.labels[0].qty_per_label=a.qty,i.fields_dict.labels.refresh()}else if("Item"===l.doctype){var o=e("Item",a.item_code);if(l.item_code=a.item_code,l.item_name=a.item_name,o.associated_company){var c=e("Customer",a.associated_company);c.short_name?l.customer=c.short_name:l.customer=a.associated_company}}i.set_values(l)}}n(),i.show(),i.fields_dict.doctype.$input.on("change",function(){i.fields_dict.docname.refresh()})}(a)})})}();
//# sourceMappingURL=label_printing.min.js.map //# sourceMappingURL=label_printing.min.js.map
@@ -1 +1 @@
{"version":3,"file":"label_printing.min.js","sources":["../../../../apps/label_printing/label_printing/public/js/label_printing_desk.js"],"sourcesContent":["$(document).ready(function () {\n $(\".dropdown-notifications\").after('<li id=\"labels-toolbar\" class=\"nav-item\"><a class=\"nav-link label-printing-icon text-muted\"><i class=\"fa fa-tag fa-lg\" aria-hidden=\"true\"></i></a></li>');\n $(\"#labels-toolbar\").click(function (page) {\n setupLabelsDialog(page);\n });\n\n});\n\n\n\nfunction setupLabelsDialog(page) {\n let cur_frm = page.view.cur_frm\n\n let fields = {\n doctype: '',\n docname: '',\n item_code: '',\n item_name: '',\n delivery_date: '',\n customer: '',\n batch: '',\n information: '',\n total_amount: 0,\n labels: [{\n item_qty: 0,\n label_qty: 0,\n information: ''\n }]\n };\n\n\n if (cur_frm !== null) {\n if (cur_frm.doctype === \"Work Order\" || cur_frm.doctype === \"Item\") {\n if (cur_frm.docname) {\n fields.doctype = cur_frm.doctype\n fields.docname = cur_frm.docname\n }\n }\n }\n\n let d = new frappe.ui.Dialog({\n title: __(\"Print Labels\"),\n fields: [{\n label: __(\"Reference Doctype\"),\n options: ['Work Order', 'Item', 'Label'],\n fieldname: 'doctype',\n fieldtype: 'Select',\n default: fields.doctype,\n },\n {\n label: __(\"Get data\"),\n fieldname: 'get_data',\n fieldtype: 'Button',\n click: () => {\n handleDataFetch()\n }\n },\n {\n fieldtype: 'Column Break'\n },\n {\n label: __(\"Reference Docname\"),\n fieldname: 'docname',\n fieldtype: 'Data',\n options: 'doctype',\n default: fields.docname,\n },\n {\n fieldtype: 'Section Break',\n label: __('Information')\n },\n {\n label: __(\"Item Code\"),\n fieldname: 'item_code',\n fieldtype: 'Data'\n },\n {\n label: __(\"Item Name\"),\n fieldname: 'item_name',\n fieldtype: 'Data'\n },\n {\n label: __(\"Delivery Date\"),\n fieldname: 'delivery_date',\n fieldtype: 'Date'\n },\n {\n fieldtype: 'Column Break'\n },\n {\n label: __(\"Customer\"),\n fieldname: 'customer',\n fieldtype: 'Data'\n },\n {\n label: __(\"Batch\"),\n fieldname: 'batch',\n fieldtype: 'Data'\n },\n {\n fieldtype: 'Section Break',\n label: __('Labels')\n },\n {\n fieldname: \"labels\",\n fieldtype: \"Table\",\n cannot_add_rows: false,\n in_place_edit: true,\n data: fields.labels,\n get_data: () => {\n return fields.labels;\n },\n fields: [{\n fieldtype: 'Int',\n fieldname: \"item_qty\",\n in_list_view: 1,\n label: __('Item Qty')\n },\n {\n label: __(\"Label Qty\"),\n fieldname: 'label_qty',\n in_list_view: 1,\n fieldtype: 'Int'\n },\n {\n fieldtype: 'Data',\n fieldname: \"information\",\n in_list_view: 1,\n label: __('Information')\n },\n ]\n },\n ],\n primary_action_label: 'Print',\n primary_action(values) {\n fields = values\n\n frappe.call({\n method: \"label_printing.api.print_label\",\n args: {\n values: fields\n },\n callback: function (r) {\n if (r.message === 200) {\n frappe.show_alert(\"Label printing successful\", 5);\n }\n },\n });\n\n d.hide();\n }\n });\n handleDataFetch();\n d.show();\n\n\n // handle dpctype change\n d.fields_dict.doctype.$input.on('change', function () {\n d.fields_dict.docname.refresh();\n });\n\n function handleDataFetch() {\n fields = d.get_values()\n if (fields.doctype && fields.docname) {\n let doc = get_doc(fields.doctype, fields.docname)\n if (fields.doctype === \"Work Order\") {\n let item = get_doc(\"Item\", doc.production_item)\n let se = 1\n frappe.call({\n method: \"label_printing.api.get_associated_stockentry\",\n async: false,\n args: { workorder: fields.docname },\n callback(r) {\n if (r.message) {\n fields.batch = r.message.items[r.message.items.length - 1].batch_no\n }\n }\n })\n fields.item_code = item.item_code\n fields.item_name = item.item_name\n fields.delivery_date = doc.expected_delivery_date\n fields.labels[0].item_qty = doc.qty\n fields.labels[0].label_qty = 1\n\n if (item.associated_company) {\n let customer = get_doc(\"Customer\", item.associated_company)\n if (customer.short_name) {\n fields.customer = customer.short_name\n } else {\n fields.customer = item.associated_company\n }\n }\n\n fields.total_amount = doc.qty\n fields.labels[0].qty_per_labeLine truncated {"version":3,"file":"label_printing.min.js","sources":["../../../../apps/label_printing/label_printing/public/js/label_printing_desk.js"],"sourcesContent":["$(document).ready(function () {\n $(\".dropdown-notifications\").after('<li id=\"labels-toolbar\" class=\"nav-item\"><a class=\"nav-link label-printing-icon text-muted\"><i class=\"fa fa-tag fa-lg\" aria-hidden=\"true\"></i></a></li>');\n $(\"#labels-toolbar\").click(function (page) {\n setupLabelsDialog(page);\n });\n\n});\n\n\n\nfunction setupLabelsDialog(page) {\n let cur_frm = page.view.cur_frm\n\n let fields = {\n labels: [{\n item_qty: 0,\n label_qty: 1\n }]\n };\n\n\n if (cur_frm !== null) {\n if (cur_frm.doctype === \"Work Order\" || cur_frm.doctype === \"Item\") {\n if (cur_frm.docname) {\n fields.doctype = cur_frm.doctype\n fields.docname = cur_frm.docname\n }\n }\n }\n\n let d = new frappe.ui.Dialog({\n title: __(\"Print Labels\"),\n fields: [{\n label: __(\"Reference Doctype\"),\n options: ['Work Order', 'Item', 'Label'],\n fieldname: 'doctype',\n fieldtype: 'Select',\n default: fields.doctype,\n },\n {\n label: __(\"Get data\"),\n fieldname: 'get_data',\n fieldtype: 'Button',\n click: () => {\n handleDataFetch()\n }\n },\n {\n fieldtype: 'Column Break'\n },\n {\n label: __(\"Reference Docname\"),\n fieldname: 'docname',\n fieldtype: 'Data',\n options: 'doctype',\n default: fields.docname,\n },\n {\n fieldtype: 'Section Break',\n label: __('Information')\n },\n {\n label: __(\"Item Code\"),\n fieldname: 'item_code',\n fieldtype: 'Data'\n },\n {\n label: __(\"Item Name\"),\n fieldname: 'item_name',\n fieldtype: 'Data'\n },\n {\n label: __(\"Delivery Date\"),\n fieldname: 'delivery_date',\n fieldtype: 'Date'\n },\n {\n fieldtype: 'Column Break'\n },\n {\n label: __(\"Customer\"),\n fieldname: 'customer',\n fieldtype: 'Data'\n },\n {\n label: __(\"Batch\"),\n fieldname: 'batch',\n fieldtype: 'Data'\n },\n {\n fieldtype: 'Section Break',\n label: __('Labels')\n },\n {\n fieldname: \"labels\",\n fieldtype: \"Table\",\n cannot_add_rows: false,\n in_place_edit: true,\n data: fields.labels,\n get_data: () => {\n return fields.labels;\n },\n fields: [{\n fieldtype: 'Int',\n fieldname: \"item_qty\",\n in_list_view: 1,\n label: __('Item Qty')\n },\n {\n label: __(\"Label Qty\"),\n fieldname: 'label_qty',\n in_list_view: 1,\n fieldtype: 'Int'\n },\n {\n fieldtype: 'Data',\n fieldname: \"information\",\n in_list_view: 1,\n label: __('Information')\n },\n ]\n },\n ],\n primary_action_label: 'Print',\n primary_action(values) {\n frappe.call({\n method: \"label_printing.api.print_label\",\n args: {\n values: values\n },\n callback: function (r) {\n if (r.message === 200) {\n frappe.show_alert(\"Label printing successful\", 5);\n }\n },\n });\n d.hide();\n }\n });\n handleDataFetch();\n d.show();\n\n\n // handle dpctype change\n d.fields_dict.doctype.$input.on('change', function () {\n d.fields_dict.docname.refresh();\n });\n\n function handleDataFetch() {\n fields = d.get_values()\n if (fields.doctype && fields.docname) {\n let doc = get_doc(fields.doctype, fields.docname)\n if (fields.doctype === \"Work Order\") {\n let item = get_doc(\"Item\", doc.production_item)\n let se = 1\n frappe.call({\n method: \"label_printing.api.get_associated_stockentry\",\n async: false,\n args: { workorder: fields.docname },\n callback(r) {\n if (r.message) {\n fields.batch = r.message.items[r.message.items.length - 1].batch_no\n }\n }\n })\n fields.item_code = item.item_code\n fields.item_name = item.item_name\n fields.delivery_date = doc.expected_delivery_date\n fields.labels[0].item_qty = doc.qty\n fields.labels[0].label_qty = 1\n\n if (item.associated_company) {\n let customer = get_doc(\"Customer\", item.associated_company)\n if (customer.short_name) {\n fields.customer = customer.short_name\n } else {\n fields.customer = item.associated_company\n }\n }\n\n fields.total_amount = doc.qty\n fields.labels[0].qty_per_label = doc.qty\n d.fields_dict.labels.refresh();\n\n } else if (fields.doctype === \"Item\") {\n let item = get_doc(\"Item\", doc.item_code)\n\n fields.item_code = doc.item_code\n fields.item_name = dLine truncated
@@ -12,19 +12,9 @@ function setupLabelsDialog(page) {
let cur_frm = page.view.cur_frm let cur_frm = page.view.cur_frm
let fields = { let fields = {
doctype: '',
docname: '',
item_code: '',
item_name: '',
delivery_date: '',
customer: '',
batch: '',
information: '',
total_amount: 0,
labels: [{ labels: [{
item_qty: 0, item_qty: 0,
label_qty: 1, label_qty: 1
information: ''
}] }]
}; };
@@ -133,12 +123,10 @@ function setupLabelsDialog(page) {
], ],
primary_action_label: 'Print', primary_action_label: 'Print',
primary_action(values) { primary_action(values) {
fields = values
frappe.call({ frappe.call({
method: "label_printing.api.print_label", method: "label_printing.api.print_label",
args: { args: {
values: fields values: values
}, },
callback: function (r) { callback: function (r) {
if (r.message === 200) { if (r.message === 200) {
@@ -146,7 +134,6 @@ function setupLabelsDialog(page) {
} }
}, },
}); });
d.hide(); d.hide();
} }
}); });