Fixed Qty
This commit is contained in:
@@ -1,20 +1,24 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe, os
|
import frappe
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
from frappe import _
|
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 frappe.core.doctype.access_log.access_log import make_access_log
|
||||||
from PyPDF2 import PdfFileWriter
|
from PyPDF2 import PdfFileWriter
|
||||||
|
from frappe.utils.jinja import render_template
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def print_label(values):
|
def print_label(values):
|
||||||
values = json.loads(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"]:
|
for label in values["labels"]:
|
||||||
doc = frappe.new_doc('Label')
|
doc = frappe.new_doc('Label')
|
||||||
@@ -28,13 +32,15 @@ def print_label(values):
|
|||||||
doc.customer = values["customer"]
|
doc.customer = values["customer"]
|
||||||
if "batch" in values:
|
if "batch" in values:
|
||||||
doc.batch = values["batch"]
|
doc.batch = values["batch"]
|
||||||
if "qty" in label:
|
if "item_qty" in label:
|
||||||
doc.qty = label["item_qty"]
|
doc.qty = label["item_qty"]
|
||||||
if "information" in label:
|
if "information" in label:
|
||||||
doc.information = label["information"]
|
doc.information = label["information"]
|
||||||
newdoc = doc.insert()
|
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
|
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')),
|
'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:
|
try:
|
||||||
import cups
|
import cups
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -56,12 +63,14 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
|
|||||||
cups.setPort(print_settings.port)
|
cups.setPort(print_settings.port)
|
||||||
conn = cups.Connection()
|
conn = cups.Connection()
|
||||||
output = PdfFileWriter()
|
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:
|
if not file_path:
|
||||||
file_path = os.path.join("/", "tmp", "frappe-pdf-{0}.pdf".format(frappe.generate_hash()))
|
file_path = os.path.join(
|
||||||
output.write(open(file_path,"wb"))
|
"/", "tmp", "frappe-pdf-{0}.pdf".format(frappe.generate_hash()))
|
||||||
|
output.write(open(file_path, "wb"))
|
||||||
for _ in range(qty):
|
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:
|
except IOError as e:
|
||||||
if ("ContentNotFoundError" in e.message
|
if ("ContentNotFoundError" in e.message
|
||||||
or "ContentOperationNotPermittedError" in e.message
|
or "ContentOperationNotPermittedError" in e.message
|
||||||
@@ -76,4 +85,4 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_associated_stockentry(workorder):
|
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": [
|
"field_order": [
|
||||||
"label_printer",
|
"label_printer",
|
||||||
"label_height",
|
"label_height",
|
||||||
"label_width"
|
"label_width",
|
||||||
|
"label_print_format"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -28,12 +29,18 @@
|
|||||||
"fieldname": "label_width",
|
"fieldname": "label_width",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Label Width"
|
"label": "Label Width"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "label_print_format",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Label Print Format",
|
||||||
|
"options": "Print Format"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-02-09 11:54:25.055075",
|
"modified": "2022-04-03 14:50:49.776678",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Label Printing",
|
"module": "Label Printing",
|
||||||
"name": "Label Printer Settings",
|
"name": "Label Printer Settings",
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
"absolute_value": 0,
|
"absolute_value": 0,
|
||||||
"align_labels_right": 0,
|
"align_labels_right": 0,
|
||||||
"creation": "2022-03-01 09:42:22.551134",
|
"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,
|
"custom_format": 1,
|
||||||
"disabled": 0,
|
"disabled": 0,
|
||||||
"doc_type": "Label",
|
"doc_type": "Label",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Print Format",
|
"doctype": "Print Format",
|
||||||
"font": "Default",
|
"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,
|
"idx": 0,
|
||||||
"line_breaks": 0,
|
"line_breaks": 0,
|
||||||
"modified": "2022-03-01 09:43:42.031856",
|
"modified": "2022-04-03 14:52:16.543089",
|
||||||
"modified_by": "christian@prothmann.com",
|
"modified_by": "Administrator",
|
||||||
"module": "Label Printing",
|
"module": "Label Printing",
|
||||||
"name": "Label",
|
"name": "Label",
|
||||||
"owner": "christian@prothmann.com",
|
"owner": "christian@prothmann.com",
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ function setupLabelsDialog(page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fields.total_amount = doc.qty
|
fields.total_amount = doc.qty
|
||||||
fields.labels[0].qty_per_label = doc.qty
|
|
||||||
d.fields_dict.labels.refresh();
|
d.fields_dict.labels.refresh();
|
||||||
|
|
||||||
} else if (fields.doctype === "Item") {
|
} else if (fields.doctype === "Item") {
|
||||||
|
|||||||
Reference in New Issue
Block a user