diff --git a/.gitignore b/.gitignore index 652fbdc..ca3fb77 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ latest_updates.json .wnf-lang-status *.egg-info dist/ -erpnext/docs/current +label_printing/public/dist +label_printing/docs/current *.swp *.swo __pycache__ @@ -15,3 +16,4 @@ __pycache__ .idea/ .vscode/ node_modules/ +.backportrc.json \ No newline at end of file diff --git a/label_printing/api.py b/label_printing/api.py index d969ccd..ea9595f 100644 --- a/label_printing/api.py +++ b/label_printing/api.py @@ -5,20 +5,15 @@ import os import json from frappe import _ - -from frappe.utils.pdf import get_pdf, cleanup -from frappe.core.doctype.access_log.access_log import make_access_log -from PyPDF2 import PdfFileWriter -from frappe.utils.jinja import render_template +from PyPDF2 import PdfWriter @frappe.whitelist() def print_label(values): values = json.loads(values) - printer_setting = frappe.db.get_single_value( - 'Label Printer Settings', 'label_printer'), - print_format = frappe.db.get_single_value( - 'Label Printer Settings', 'label_print_format') + + print_format = frappe.get_value( + "Label Printer", values["printer_select"], "label_print_format") for label in values["labels"]: doc = frappe.new_doc('Label') @@ -40,19 +35,20 @@ def print_label(values): newdoc = doc.insert() print_label_by_server( - "Label", newdoc.name, label["label_qty"], printer_setting[0], print_format, doc=None, no_letterhead=0, file_path=None) + "Label", newdoc.name, label["label_qty"], values["printer_select"], print_format, doc=None, no_letterhead=0, file_path=None) return 200 def print_label_by_server(doctype, name, qty, printer_setting, print_format=None, doc=None, no_letterhead=0, file_path=None): pdf_options = { - 'page-width': '{0}mm'.format(frappe.db.get_single_value('Label Printer Settings', 'label_width')), - 'page-height': '{0}mm'.format(frappe.db.get_single_value('Label Printer Settings', 'label_height')), + 'page-width': '{0}mm'.format(frappe.get_value("Label Printer", printer_setting, "label_width")), + 'page-height': '{0}mm'.format(frappe.get_value("Label Printer", printer_setting, "label_height")), } print_settings = frappe.get_doc( "Network Printer Settings", printer_setting) + try: import cups except ImportError: @@ -62,27 +58,39 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None cups.setServer(print_settings.server_ip) cups.setPort(print_settings.port) conn = cups.Connection() - output = PdfFileWriter() + output = PdfWriter() output = frappe.get_print(doctype, name, print_format, doc=doc, no_letterhead=no_letterhead, as_pdf=True, output=output, pdf_options=pdf_options) if not file_path: file_path = os.path.join( - "/", "tmp", "frappe-pdf-{0}.pdf".format(frappe.generate_hash())) - output.write(open(file_path, "wb")) - for _ in range(qty): - conn.printFile(print_settings.printer_name, file_path, name, {}) - except IOError as e: - if ("ContentNotFoundError" in e.message + "/", "tmp", f"frappe-pdf-{frappe.generate_hash()}.pdf") + output.write(open(file_path, "wb")) + for _ in range(qty): + conn.printFile(print_settings.printer_name, + file_path, name, {}) + + except OSError as e: + if ( + "ContentNotFoundError" in e.message or "ContentOperationNotPermittedError" in e.message or "UnknownContentError" in e.message - or "RemoteHostClosedError" in e.message): + or "RemoteHostClosedError" in e.message + ): frappe.throw(_("PDF generation failed")) except cups.IPPError: frappe.throw(_("Printing failed")) - finally: - return @frappe.whitelist() def get_associated_stockentry(workorder): return frappe.get_last_doc('Stock Entry', filters={"work_order": workorder}) + +# @frappe.whitelist() +# def get_label_printers(): +# label_printing_settings = frappe.get_doc('Label Printing Settings') +# label_printer_names = [] +# +# for x in label_printing_settings.label_printers: +# label_printer_names.append(x.label_printer) +# +# return(label_printer_names) diff --git a/label_printing/hooks.py b/label_printing/hooks.py index f63346a..9515d32 100644 --- a/label_printing/hooks.py +++ b/label_printing/hooks.py @@ -1,4 +1,4 @@ -from . import __version__ as app_version +from frappe import _ app_name = "label_printing" app_title = "Label Printing" @@ -8,13 +8,14 @@ app_icon = "octicon octicon-file-directory" app_color = "grey" app_email = "admin@canetzberger.design" app_license = "MIT" +required_apps = ["erpnext"] # Includes in # ------------------ # include js, css files in header of desk.html # app_include_css = "/assets/label_printing/css/label_printing.css" -app_include_js = "/assets/js/label_printing.min.js" +app_include_js = "label_printing.bundle.js" # include js, css files in header of web template # web_include_css = "/assets/label_printing/css/label_printing.css" @@ -148,30 +149,6 @@ app_include_js = "/assets/js/label_printing.min.js" # auto_cancel_exempted_doctypes = ["Auto Repeat"] -# User Data Protection -# -------------------- - -user_data_fields = [ - { - "doctype": "{doctype_1}", - "filter_by": "{filter_by}", - "redact_fields": ["{field_1}", "{field_2}"], - "partial": 1, - }, - { - "doctype": "{doctype_2}", - "filter_by": "{filter_by}", - "partial": 1, - }, - { - "doctype": "{doctype_3}", - "strict": False, - }, - { - "doctype": "{doctype_4}" - } -] - # Authentication and authorization # -------------------------------- @@ -179,9 +156,9 @@ user_data_fields = [ # "label_printing.auth.validate" # ] -jenv = { +jinja = { "methods": [ - "generateBarcode:label_printing.utils.barcode.generateBarcode", - "get_code128_glyphs:label_printing.utils.barcode.generateBarcodeGlyphs" + "label_printing.utils.barcode.generateBarcode", + "label_printing.utils.barcode.generateBarcodeGlyphs" ] } diff --git a/label_printing/label_printing/doctype/label_printer_settings/__init__.py b/label_printing/label_printing/doctype/label_printer/__init__.py similarity index 100% rename from label_printing/label_printing/doctype/label_printer_settings/__init__.py rename to label_printing/label_printing/doctype/label_printer/__init__.py diff --git a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.json b/label_printing/label_printing/doctype/label_printer/label_printer.json similarity index 55% rename from label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.json rename to label_printing/label_printing/doctype/label_printer/label_printer.json index e4acf58..7116298 100644 --- a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.json +++ b/label_printing/label_printing/doctype/label_printer/label_printer.json @@ -1,7 +1,7 @@ { "actions": [], - "allow_rename": 1, - "creation": "2022-02-09 11:54:25.055075", + "autoname": "field:label_printer", + "creation": "2022-11-09 10:36:02.195555", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -15,48 +15,47 @@ { "fieldname": "label_printer", "fieldtype": "Link", + "in_list_view": 1, "label": "Label Printer", - "options": "Network Printer Settings" + "options": "Network Printer Settings", + "reqd": 1, + "unique": 1 }, { - "description": "in mm", "fieldname": "label_height", "fieldtype": "Int", - "label": "Label Height" + "in_list_view": 1, + "label": "Label Height", + "reqd": 1 }, { - "description": "in mm", "fieldname": "label_width", "fieldtype": "Int", - "label": "Label Width" + "in_list_view": 1, + "label": "Label Width", + "reqd": 1 }, { "fieldname": "label_print_format", "fieldtype": "Link", + "in_list_view": 1, "label": "Label Print Format", - "options": "Print Format" + "options": "Print Format", + "reqd": 1 } ], "index_web_pages_for_search": 1, - "issingle": 1, + "istable": 1, "links": [], - "modified": "2022-04-03 14:50:49.776678", + "modified": "2022-11-09 12:27:38.327808", "modified_by": "Administrator", "module": "Label Printing", - "name": "Label Printer Settings", + "name": "Label Printer", + "name_case": "Title Case", + "naming_rule": "By fieldname", "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "print": 1, - "read": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], + "permissions": [], "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.py b/label_printing/label_printing/doctype/label_printer/label_printer.py similarity index 82% rename from label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.py rename to label_printing/label_printing/doctype/label_printer/label_printer.py index 6850848..04e075c 100644 --- a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.py +++ b/label_printing/label_printing/doctype/label_printer/label_printer.py @@ -4,5 +4,5 @@ # import frappe from frappe.model.document import Document -class LabelPrinterSettings(Document): +class LabelPrinter(Document): pass diff --git a/label_printing/label_printing/doctype/label_printing_settings/__init__.py b/label_printing/label_printing/doctype/label_printing_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.js b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.js similarity index 76% rename from label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.js rename to label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.js index e68904e..87d7498 100644 --- a/label_printing/label_printing/doctype/label_printer_settings/label_printer_settings.js +++ b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.js @@ -1,7 +1,7 @@ // Copyright (c) 2022, CAnetzberger Design and contributors // For license information, please see license.txt -frappe.ui.form.on('Label Printer Settings', { +frappe.ui.form.on('Label Printing Settings', { // refresh: function(frm) { // } diff --git a/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.json b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.json new file mode 100644 index 0000000..085bab7 --- /dev/null +++ b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.json @@ -0,0 +1,50 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2022-02-09 11:54:25.055075", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "enable_label_printing", + "label_printers" + ], + "fields": [ + { + "default": "0", + "fieldname": "enable_label_printing", + "fieldtype": "Check", + "label": "Enable Label Printing" + }, + { + "depends_on": "enable_label_printing", + "fieldname": "label_printers", + "fieldtype": "Table", + "label": "Label Printers", + "options": "Label Printer" + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2022-11-09 10:42:37.066676", + "modified_by": "Administrator", + "module": "Label Printing", + "name": "Label Printing Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.py b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.py new file mode 100644 index 0000000..8462858 --- /dev/null +++ b/label_printing/label_printing/doctype/label_printing_settings/label_printing_settings.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, CAnetzberger Design and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class LabelPrintingSettings(Document): + pass diff --git a/label_printing/label_printing/doctype/label_printer_settings/test_label_printer_settings.py b/label_printing/label_printing/doctype/label_printing_settings/test_label_printing_settings.py similarity index 69% rename from label_printing/label_printing/doctype/label_printer_settings/test_label_printer_settings.py rename to label_printing/label_printing/doctype/label_printing_settings/test_label_printing_settings.py index 0e3fef6..78e0ae0 100644 --- a/label_printing/label_printing/doctype/label_printer_settings/test_label_printer_settings.py +++ b/label_printing/label_printing/doctype/label_printing_settings/test_label_printing_settings.py @@ -4,5 +4,5 @@ # import frappe import unittest -class TestLabelPrinterSettings(unittest.TestCase): +class TestLabelPrintingSettings(unittest.TestCase): pass diff --git a/label_printing/label_printing/print_format/label/label.json b/label_printing/label_printing/print_format/label/label.json index a24a99e..cf23602 100644 --- a/label_printing/label_printing/print_format/label/label.json +++ b/label_printing/label_printing/print_format/label/label.json @@ -2,22 +2,28 @@ "absolute_value": 0, "align_labels_right": 0, "creation": "2022-03-01 09:42:22.551134", - "css": ".print-format {\n\tmargin: 0;\n\tpadding: 0;\n margin-left: 1mm;\n margin-right: 1mm;\n margin-top: 1mm;\n margin-bottom: 1mm;\n\twidth: 100mm;\n\tmax-height: 39mm;\n}\n\n.page-size {\n\twidth: 104mm;\n\theight: 40mm;\n}\n\n.label-wrapper {\n\twidth: 100mm;\n\ttext-align: center;\n\tdisplay: -webkit-box;\n\t/* wkhtmltopdf uses this one */\n\tdisplay: -webkit-flex;\n\tdisplay: flex;\n\t-webkit-box-pack: center;\n\t/* wkhtmltopdf uses this one */\n\t-webkit-justify-content: center;\n\tjustify-content: center;\n\tfont-size: 15px;\n}\n\n.left-wrapper {\n\twidth: 80mm;\n}\n\n.left-wrapper div {\n\twhite-space: nowrap;\n\tfont-size: 12px;\n}\n\n.right-wrapper {\n\twidth: 20mm;\n\ttext-align: right;\n}\n\n.label-wrapper h4 {\n\tmargin: 0;\n\tword-break: break-all;\n\tfont-size: 23px;\n}\n\n.label-wrapper h4 small {\n\tcolor: black;\n}\n\n", + "css": ".print-format {\n\tmargin: 0;\n\tpadding: 0;\n margin-left: 1mm;\n margin-right: 1mm;\n margin-top: 1mm;\n margin-bottom: 1mm;\n\twidth: 100mm;\n\tmax-height: 39mm;\n}\n\n.page-size {\n\twidth: 104mm;\n\theight: 40mm;\n}\n\n.label-wrapper {\n\twidth: 100mm;\n\ttext-align: center;\n\tdisplay: -webkit-box;\n\t/* wkhtmltopdf uses this one */\n\tdisplay: -webkit-flex;\n\tdisplay: flex;\n\t-webkit-box-pack: center;\n\t/* wkhtmltopdf uses this one */\n\t-webkit-justify-content: center;\n\tjustify-content: center;\n\tfont-size: 15px;\n}\n\n.left-wrapper {\n\twidth: 80mm;\n}\n\n.left-wrapper div {\n\twhite-space: nowrap;\n\tfont-size: 12px;\n}\n\n.right-wrapper {\n\twidth: 20mm;\n\ttext-align: right;\n}\n\n.label-wrapper h4 {\n\tmargin: 0;\n\twhite-space: nowrap;\n\tfont-size: 23px;\n}\n\n.label-wrapper h4 small {\n\tcolor: black;\n}\n\n", "custom_format": 1, "disabled": 0, "doc_type": "Label", "docstatus": 0, "doctype": "Print Format", "font": "Default", + "font_size": 0, "html": "{% if doc.customer %}\n
\n\n
\n {% if doc.item_code %}\n

\n {{doc.item_code}}\n

\n {% endif %}\n\n {% if doc.item_name%}\n

\n {{doc.item_name}}\n

\n {% endif %}\n\n\n {% if doc.customer %}\n
{{doc.customer}}
\n {% endif %}\n\n {% if doc.delivery_date %}\n
\n {{_(\"Delivery Date\")}} {{frappe.utils.formatdate(doc.delivery_date, \"dd.MM.YYYY\")}}\n
\n {% endif %}\n\n {% if doc.batch %}\n
\n {{_(\"Batch\")}} {{doc.batch}}\n
\n {% endif %}\n\n {% if doc.qty %}\n
\n {{_(\"Qty\")}} {{ doc.qty }}\n
\n {% endif %}\n\n {% if doc.information%}\n
\n {{doc.information}}\n
\n {% endif %}\n\n\n
\n \n
\n \n
\n
\n\n{% else %}\n\n
\n\n
\n {% if doc.item_code %}\n

\n {{doc.item_code}}\n

\n {% endif %}\n\n\n {% if doc.batch %}\n
\n {{_(\"Batch\")}} {{doc.batch}}\n
\n {% endif %}\n\n\n {% if doc.information%}\n
\n {{doc.information}}\n
\n {% endif %}\n\n\n
\n
\n\n{% endif %}", "idx": 0, "line_breaks": 0, - "modified": "2022-04-03 14:52:16.543089", + "margin_bottom": 0.0, + "margin_left": 0.0, + "margin_right": 0.0, + "margin_top": 0.0, + "modified": "2022-11-10 12:13:59.766486", "modified_by": "Administrator", "module": "Label Printing", "name": "Label", "owner": "christian@prothmann.com", "print_format_builder": 1, + "print_format_builder_beta": 0, "print_format_type": "Jinja", "raw_printing": 0, "show_section_headings": 0, diff --git a/label_printing/public/build.json b/label_printing/public/build.json deleted file mode 100644 index e7c4825..0000000 --- a/label_printing/public/build.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "js/label_printing.min.js": [ - "public/js/label_printing_desk.js" - ] -} \ No newline at end of file diff --git a/label_printing/public/js/label_printing.bundle.js b/label_printing/public/js/label_printing.bundle.js new file mode 100644 index 0000000..5bf2e98 --- /dev/null +++ b/label_printing/public/js/label_printing.bundle.js @@ -0,0 +1 @@ +import './label_printing_desk'; \ No newline at end of file diff --git a/label_printing/public/js/label_printing_desk.js b/label_printing/public/js/label_printing_desk.js index 535d228..9a46bec 100644 --- a/label_printing/public/js/label_printing_desk.js +++ b/label_printing/public/js/label_printing_desk.js @@ -28,6 +28,8 @@ function setupLabelsDialog(page) { } } + let label_printer_names + let d = new frappe.ui.Dialog({ title: __("Print Labels"), fields: [{ @@ -87,6 +89,17 @@ function setupLabelsDialog(page) { fieldname: 'batch', fieldtype: 'Data' }, + { + fieldtype: 'Section Break', + label: __('Printer') + }, + { + label: __("Printer Select"), + options: ['Labeldrucker Werk 1 (Ind. 6)', 'Labeldrucker Werk 2 (Bre. 19)'], + fieldname: 'printer_select', + fieldtype: 'Select', + default: 'Labeldrucker Werk 1(Ind. 6)' + }, { fieldtype: 'Section Break', label: __('Labels') diff --git a/label_printing/public/node_modules b/label_printing/public/node_modules index 207db1a..b34ef5a 120000 --- a/label_printing/public/node_modules +++ b/label_printing/public/node_modules @@ -1 +1 @@ -/Volumes/development/frappe/frappe-bench/apps/label_printing/node_modules \ No newline at end of file +/home/frappe/frappe-bench/apps/label_printing/node_modules \ No newline at end of file