Fixed Qty
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe, os
|
||||
import frappe
|
||||
import os
|
||||
import json
|
||||
from frappe import _
|
||||
|
||||
|
||||
from frappe.utils.pdf import get_pdf,cleanup
|
||||
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
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def print_label(values):
|
||||
values = json.loads(values)
|
||||
printer_setting = frappe.db.get_single_value('Label Printer Settings', 'label_printer'),
|
||||
|
||||
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')
|
||||
|
||||
for label in values["labels"]:
|
||||
doc = frappe.new_doc('Label')
|
||||
@@ -28,13 +32,15 @@ def print_label(values):
|
||||
doc.customer = values["customer"]
|
||||
if "batch" in values:
|
||||
doc.batch = values["batch"]
|
||||
if "qty" in label:
|
||||
if "item_qty" in label:
|
||||
doc.qty = label["item_qty"]
|
||||
if "information" in label:
|
||||
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)
|
||||
# TODO comment in
|
||||
# print_label_by_server(
|
||||
# "Label", newdoc.name, label["label_qty"], printer_setting[0], print_format, doc=None, no_letterhead=0, file_path=None)
|
||||
|
||||
return 200
|
||||
|
||||
@@ -45,7 +51,8 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
|
||||
'page-height': '{0}mm'.format(frappe.db.get_single_value('Label Printer Settings', 'label_height')),
|
||||
}
|
||||
|
||||
print_settings = frappe.get_doc("Network Printer Settings", printer_setting)
|
||||
print_settings = frappe.get_doc(
|
||||
"Network Printer Settings", printer_setting)
|
||||
try:
|
||||
import cups
|
||||
except ImportError:
|
||||
@@ -56,17 +63,19 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
|
||||
cups.setPort(print_settings.port)
|
||||
conn = cups.Connection()
|
||||
output = PdfFileWriter()
|
||||
output = frappe.get_print(doctype, name, print_format, doc=doc, no_letterhead=no_letterhead, as_pdf = True, output = output, pdf_options=pdf_options)
|
||||
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"))
|
||||
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, {})
|
||||
conn.printFile(print_settings.printer_name, file_path, name, {})
|
||||
except IOError 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"))
|
||||
@@ -76,4 +85,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": workorder})
|
||||
return frappe.get_last_doc('Stock Entry', filters={"work_order": workorder})
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"field_order": [
|
||||
"label_printer",
|
||||
"label_height",
|
||||
"label_width"
|
||||
"label_width",
|
||||
"label_print_format"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -28,12 +29,18 @@
|
||||
"fieldname": "label_width",
|
||||
"fieldtype": "Int",
|
||||
"label": "Label Width"
|
||||
},
|
||||
{
|
||||
"fieldname": "label_print_format",
|
||||
"fieldtype": "Link",
|
||||
"label": "Label Print Format",
|
||||
"options": "Print Format"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2022-02-09 11:54:25.055075",
|
||||
"modified": "2022-04-03 14:50:49.776678",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Label Printing",
|
||||
"name": "Label Printer Settings",
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
"absolute_value": 0,
|
||||
"align_labels_right": 0,
|
||||
"creation": "2022-03-01 09:42:22.551134",
|
||||
"css": ".print-format { margin: 0; padding: 0; width: 104mm; max-height: 40mm; } .page-size { width: 104mm; } .label-wrapper { width: 100%; text-align: center; display: -webkit-box; /* wkhtmltopdf uses this one */ display: -webkit-flex; display: flex; -webkit-box-pack: center; /* wkhtmltopdf uses this one */ -webkit-justify-content: center; justify-content: center; font-size: 19px; } .left-wrapper { width: 80%; } .left-wrapper div { white-space: nowrap; font-size: 15px; } .right-wrapper { width: 20%; text-align: right; } .label-wrapper h4 { margin: 0; word-break: break-all; font-size: 25px; } .label-wrapper h4 small { color: black; } .barcode { font-family: 'Libre Barcode 128', cursive; font-size: 30px; }",
|
||||
"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",
|
||||
"custom_format": 1,
|
||||
"disabled": 0,
|
||||
"doc_type": "Label",
|
||||
"docstatus": 0,
|
||||
"doctype": "Print Format",
|
||||
"font": "Default",
|
||||
"html": "<div class=\"label-wrapper\">\n\n <div class=\"left-wrapper\">\n {% if doc.item_code %}\n <h4>\n <strong>{{doc.item_code}}</strong>\n </h4>\n {% endif %}\n\n {% if doc.item_name%}\n <h4>\n <small> {{doc.item_name}}</small>\n </h4>\n {% endif %}\n\n\n {% if doc.customer %}\n <div>{{doc.customer}}</div>\n {% endif %}\n\n {% if doc.delivery_date %}\n <div>\n <strong> {{_(\"Delivery Date\")}} </strong> {{frappe.utils.formatdate(doc.delivery_date, \"dd.MM.YYYY\")}}\n </div>\n {% endif %}\n\n {% if doc.batch %}\n <div>\n <strong>{{_(\"Batch\")}} </strong> {{doc.batch}}\n </div>\n {% endif %}\n\n {% if doc.qty %}\n <div>\n <strong>{{_(\"Qty\")}} </strong> {{ doc.qty }}\n </div>\n {% endif %}\n\n {% if doc.information%}\n <div>\n {{doc.information}}\n </div>\n {% endif %}\n\n\n </div>\n \n <div class=\"right-wrapper\">\n <img src=\"/files/hp_logo_black.jpg\" style=\"width: 50%;\">\n </div>\n\n\n</div>",
|
||||
"html": "{% if doc.customer %}\n<div class=\"label-wrapper\">\n\n <div class=\"left-wrapper\">\n {% if doc.item_code %}\n <h4>\n <strong>{{doc.item_code}}</strong>\n </h4>\n {% endif %}\n\n {% if doc.item_name%}\n <h4>\n <small> {{doc.item_name}}</small>\n </h4>\n {% endif %}\n\n\n {% if doc.customer %}\n <div>{{doc.customer}}</div>\n {% endif %}\n\n {% if doc.delivery_date %}\n <div>\n <strong> {{_(\"Delivery Date\")}} </strong> {{frappe.utils.formatdate(doc.delivery_date, \"dd.MM.YYYY\")}}\n </div>\n {% endif %}\n\n {% if doc.batch %}\n <div>\n <strong>{{_(\"Batch\")}} </strong> {{doc.batch}}\n </div>\n {% endif %}\n\n {% if doc.qty %}\n <div>\n <strong>{{_(\"Qty\")}} </strong> {{ doc.qty }}\n </div>\n {% endif %}\n\n {% if doc.information%}\n <div>\n {{doc.information}}\n </div>\n {% endif %}\n\n\n </div>\n \n <div class=\"right-wrapper\">\n <img src=\"/files/hp_logo_black.jpg\" style=\"width: 30px;\">\n </div>\n</div>\n\n{% else %}\n\n<div class=\"label-wrapper\">\n\n <div class=\"left-wrapper\">\n {% if doc.item_code %}\n <h4 style=\"font-size: 30px; white-space: normal; padding: 2mm;\">\n <strong>{{doc.item_code}}</strong>\n </h4>\n {% endif %}\n\n\n {% if doc.batch %}\n <div style=\"font-size: 15px;\">\n <strong>{{_(\"Batch\")}} </strong> {{doc.batch}}\n </div>\n {% endif %}\n\n\n {% if doc.information%}\n <div>\n {{doc.information}}\n </div>\n {% endif %}\n\n\n </div>\n</div>\n\n{% endif %}",
|
||||
"idx": 0,
|
||||
"line_breaks": 0,
|
||||
"modified": "2022-03-01 09:43:42.031856",
|
||||
"modified_by": "christian@prothmann.com",
|
||||
"modified": "2022-04-03 14:52:16.543089",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Label Printing",
|
||||
"name": "Label",
|
||||
"owner": "christian@prothmann.com",
|
||||
|
||||
@@ -179,7 +179,6 @@ function setupLabelsDialog(page) {
|
||||
}
|
||||
|
||||
fields.total_amount = doc.qty
|
||||
fields.labels[0].qty_per_label = doc.qty
|
||||
d.fields_dict.labels.refresh();
|
||||
|
||||
} else if (fields.doctype === "Item") {
|
||||
|
||||
Reference in New Issue
Block a user