Barcode Generation
This commit is contained in:
@@ -24,6 +24,7 @@ def print_label(values):
|
||||
doc.customer = values["customer"]
|
||||
doc.batch = values["batch"]
|
||||
doc.qty = label["item_qty"]
|
||||
doc.information = label["information"]
|
||||
newdoc = doc.insert()
|
||||
|
||||
print_label_by_server("Label", newdoc.name, label["label_qty"], printer_setting[0],"Label", doc=None, no_letterhead=0, file_path=None)
|
||||
@@ -69,5 +70,4 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_associated_stockentry(workorder):
|
||||
return frappe.get_last_doc('Stock Entry', filters = {"work_order": "PRO-01530"})
|
||||
|
||||
return frappe.get_last_doc('Stock Entry', filters = {"work_order": workorder})
|
||||
@@ -178,3 +178,10 @@ user_data_fields = [
|
||||
# auth_hooks = [
|
||||
# "label_printing.auth.validate"
|
||||
# ]
|
||||
|
||||
jenv = {
|
||||
"methods": [
|
||||
"generateBarcode:label_printing.utils.barcode.generateBarcode",
|
||||
"get_code128_glyphs:label_printing.utils.barcode.generateBarcodeGlyphs"
|
||||
]
|
||||
}
|
||||
@@ -13,7 +13,8 @@
|
||||
"column_break_4",
|
||||
"delivery_date",
|
||||
"customer",
|
||||
"batch"
|
||||
"batch",
|
||||
"information"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -54,11 +55,16 @@
|
||||
"fieldname": "qty",
|
||||
"fieldtype": "Int",
|
||||
"label": "Quantity"
|
||||
},
|
||||
{
|
||||
"fieldname": "information",
|
||||
"fieldtype": "Data",
|
||||
"label": "Information"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-tag",
|
||||
"links": [],
|
||||
"modified": "2022-01-19 12:08:40.613669",
|
||||
"modified": "2022-02-17 09:25:53.912471",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Label Printing",
|
||||
"name": "Label",
|
||||
|
||||
@@ -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}]};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"],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"}]}],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={doctype:"",docname:"",item_code:"",item_name:"",delivery_date:"",customer:"",batch:"",information:"",total_amount:0,labels:[{item_qty:0,label_qty:0}]};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"],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)})})}();
|
||||
//# sourceMappingURL=label_printing.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -41,7 +41,7 @@ function setupLabelsDialog(page) {
|
||||
title: __("Print Labels"),
|
||||
fields: [{
|
||||
label: __("Reference Doctype"),
|
||||
options: ['Work Order', 'Item'],
|
||||
options: ['Work Order', 'Item', 'Label'],
|
||||
fieldname: 'doctype',
|
||||
fieldtype: 'Select',
|
||||
default: fields.doctype,
|
||||
@@ -121,6 +121,12 @@ function setupLabelsDialog(page) {
|
||||
in_list_view: 1,
|
||||
fieldtype: 'Int'
|
||||
},
|
||||
{
|
||||
fieldtype: 'Data',
|
||||
fieldname: "information",
|
||||
in_list_view: 1,
|
||||
label: __('Information')
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
@@ -203,7 +209,6 @@ function setupLabelsDialog(page) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d.set_values(fields)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
/Volumes/development/frappe/frappe-bench/apps/label_printing/node_modules
|
||||
/home/frappe/frappe-bench/apps/label_printing/node_modules
|
||||
136
label_printing/utils/barcode.py
Normal file
136
label_printing/utils/barcode.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import frappe
|
||||
from io import BytesIO
|
||||
from barcode import EAN13
|
||||
from barcode.writer import ImageWriter
|
||||
|
||||
@frappe.whitelist()
|
||||
def generateBarcode(string):
|
||||
rv = BytesIO()
|
||||
EAN13(str(100000902922), writer=ImageWriter()).write(rv)
|
||||
print(rv.decode('UTF-8'))
|
||||
|
||||
lookup = {
|
||||
" ": 0,
|
||||
"!": 1,
|
||||
'"': 2,
|
||||
"#": 3,
|
||||
"$": 4,
|
||||
"%": 5,
|
||||
"&": 6,
|
||||
"‘": 7,
|
||||
"(": 8,
|
||||
")": 9,
|
||||
"*": 10,
|
||||
"+": 11,
|
||||
",": 12,
|
||||
"-": 13,
|
||||
".": 14,
|
||||
"/": 15,
|
||||
"0": 16,
|
||||
"1": 17,
|
||||
"2": 18,
|
||||
"3": 19,
|
||||
"4": 20,
|
||||
"5": 21,
|
||||
"6": 22,
|
||||
"7": 23,
|
||||
"8": 24,
|
||||
"9": 25,
|
||||
":": 26,
|
||||
";": 27,
|
||||
"<": 28,
|
||||
"=": 29,
|
||||
">": 30,
|
||||
"?": 31,
|
||||
"@": 32,
|
||||
"A": 33,
|
||||
"B": 34,
|
||||
"C": 35,
|
||||
"D": 36,
|
||||
"E": 37,
|
||||
"F": 38,
|
||||
"G": 39,
|
||||
"H": 40,
|
||||
"I": 41,
|
||||
"J": 42,
|
||||
"K": 43,
|
||||
"L": 44,
|
||||
"M": 45,
|
||||
"N": 46,
|
||||
"O": 47,
|
||||
"P": 48,
|
||||
"Q": 49,
|
||||
"R": 50,
|
||||
"S": 51,
|
||||
"T": 52,
|
||||
"U": 53,
|
||||
"V": 54,
|
||||
"W": 55,
|
||||
"X": 56,
|
||||
"Y": 57,
|
||||
"Z": 58,
|
||||
"[": 59,
|
||||
"\\": 60,
|
||||
"]": 61,
|
||||
"^": 62,
|
||||
"_": 63,
|
||||
"`": 64,
|
||||
"a": 65,
|
||||
"b": 66,
|
||||
"c": 67,
|
||||
"d": 68,
|
||||
"e": 69,
|
||||
"f": 70,
|
||||
"g": 71,
|
||||
"h": 72,
|
||||
"i": 73,
|
||||
"j": 74,
|
||||
"k": 75,
|
||||
"l": 76,
|
||||
"m": 77,
|
||||
"n": 78,
|
||||
"o": 79,
|
||||
"p": 80,
|
||||
"q": 81,
|
||||
"r": 82,
|
||||
"s": 83,
|
||||
"t": 84,
|
||||
"u": 85,
|
||||
"v": 86,
|
||||
"w": 87,
|
||||
"x": 88,
|
||||
"y": 89,
|
||||
"z": 90,
|
||||
"{": 91,
|
||||
"|": 92,
|
||||
"}": 93,
|
||||
"~": 94,
|
||||
"Ã": 95,
|
||||
"Ä": 96,
|
||||
"Å": 97,
|
||||
"Æ": 98,
|
||||
"Ç": 99,
|
||||
"È": 100,
|
||||
"É": 101,
|
||||
"Ê": 102,
|
||||
"Ë": 103,
|
||||
"Ì": 104,
|
||||
"Í": 105
|
||||
}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def generateBarcodeGlyphs(data):
|
||||
code = chr(204)
|
||||
checksum = 104
|
||||
|
||||
for i in range(len(data)):
|
||||
code += data[i]
|
||||
checksum += lookup[data[i]] * (i + 1)
|
||||
|
||||
code += list(lookup.keys())[list(lookup.values()).index(checksum % 103)]
|
||||
|
||||
# append stop
|
||||
code += chr(206)
|
||||
|
||||
return code
|
||||
Reference in New Issue
Block a user