Printing done
This commit is contained in:
73
label_printing/api.py
Normal file
73
label_printing/api.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe, 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
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def print_label(values):
|
||||
values = json.loads(values)
|
||||
printer_setting = frappe.db.get_single_value('Label Printer Settings', 'label_printer'),
|
||||
|
||||
|
||||
for label in values["labels"]:
|
||||
doc = frappe.new_doc('Label')
|
||||
doc.item_code = values["item_code"]
|
||||
doc.item_name = values["item_name"]
|
||||
doc.delivery_date = values["delivery_date"]
|
||||
doc.customer = values["customer"]
|
||||
doc.batch = values["batch"]
|
||||
doc.qty = label["item_qty"]
|
||||
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)
|
||||
|
||||
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-height': frappe.db.get_single_value('Label Printer Settings', 'label_height'),
|
||||
'page-width': frappe.db.get_single_value('Label Printer Settings', 'label_width'),
|
||||
}
|
||||
print_settings = frappe.get_doc("Network Printer Settings", printer_setting)
|
||||
try:
|
||||
import cups
|
||||
except ImportError:
|
||||
frappe.throw(_("You need to install pycups to use this feature!"))
|
||||
|
||||
try:
|
||||
cups.setServer(print_settings.server_ip)
|
||||
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)
|
||||
print("Here")
|
||||
print(output)
|
||||
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
|
||||
or "ContentOperationNotPermittedError" in e.message
|
||||
or "UnknownContentError" 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": "PRO-01530"})
|
||||
|
||||
396
label_printing/public/js/label_printing.min.js
vendored
396
label_printing/public/js/label_printing.min.js
vendored
@@ -1,396 +1,2 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
var script = {
|
||||
name: "LabelPrintingDialog",
|
||||
props: [],
|
||||
methods: {},
|
||||
};
|
||||
|
||||
/* script */
|
||||
var __vue_script__ = script;
|
||||
|
||||
/* template */
|
||||
var __vue_render__ = function() {
|
||||
var _vm = this;
|
||||
var _h = _vm.$createElement;
|
||||
var _c = _vm._self._c || _h;
|
||||
return _vm._m(0)
|
||||
};
|
||||
var __vue_staticRenderFns__ = [
|
||||
function() {
|
||||
var _vm = this;
|
||||
var _h = _vm.$createElement;
|
||||
var _c = _vm._self._c || _h;
|
||||
return _c("li", { staticClass: "nav-item" }, [
|
||||
_c("a", { staticClass: "nav-link label-printing-icon text-muted" }, [
|
||||
_c("i", {
|
||||
staticClass: "fa fa-tag fa-lg",
|
||||
attrs: { "aria-hidden": "true" }
|
||||
})
|
||||
])
|
||||
])
|
||||
}
|
||||
];
|
||||
__vue_render__._withStripped = true;
|
||||
|
||||
/* style */
|
||||
var __vue_inject_styles__ = function (inject) {
|
||||
if (!inject) { return }
|
||||
inject("data-v-0458d41e_0", { source: "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", map: {"version":3,"sources":[],"names":[],"mappings":"","file":"label_printing_dialog.vue"}, media: undefined });
|
||||
|
||||
};
|
||||
/* scoped */
|
||||
var __vue_scope_id__ = undefined;
|
||||
/* module identifier */
|
||||
var __vue_module_identifier__ = undefined;
|
||||
/* functional template */
|
||||
var __vue_is_functional_template__ = false;
|
||||
/* component normalizer */
|
||||
function __vue_normalize__(
|
||||
template, style, script,
|
||||
scope, functional, moduleIdentifier,
|
||||
createInjector, createInjectorSSR
|
||||
) {
|
||||
var component = (typeof script === 'function' ? script.options : script) || {};
|
||||
|
||||
// For security concerns, we use only base name in production mode.
|
||||
component.__file = "/Volumes/development/frappe/frappe-bench/apps/label_printing/label_printing/public/js/label_printing_dialog.vue";
|
||||
|
||||
if (!component.render) {
|
||||
component.render = template.render;
|
||||
component.staticRenderFns = template.staticRenderFns;
|
||||
component._compiled = true;
|
||||
|
||||
if (functional) { component.functional = true; }
|
||||
}
|
||||
|
||||
component._scopeId = scope;
|
||||
|
||||
{
|
||||
var hook;
|
||||
if (style) {
|
||||
hook = function(context) {
|
||||
style.call(this, createInjector(context));
|
||||
};
|
||||
}
|
||||
|
||||
if (hook !== undefined) {
|
||||
if (component.functional) {
|
||||
// register for functional component in vue file
|
||||
var originalRender = component.render;
|
||||
component.render = function renderWithStyleInjection(h, context) {
|
||||
hook.call(context);
|
||||
return originalRender(h, context)
|
||||
};
|
||||
} else {
|
||||
// inject component registration as beforeCreate hook
|
||||
var existing = component.beforeCreate;
|
||||
component.beforeCreate = existing ? [].concat(existing, hook) : [hook];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return component
|
||||
}
|
||||
/* style inject */
|
||||
function __vue_create_injector__() {
|
||||
var head = document.head || document.getElementsByTagName('head')[0];
|
||||
var styles = __vue_create_injector__.styles || (__vue_create_injector__.styles = {});
|
||||
var isOldIE =
|
||||
typeof navigator !== 'undefined' &&
|
||||
/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());
|
||||
|
||||
return function addStyle(id, css) {
|
||||
if (document.querySelector('style[data-vue-ssr-id~="' + id + '"]')) { return } // SSR styles are present.
|
||||
|
||||
var group = isOldIE ? css.media || 'default' : id;
|
||||
var style = styles[group] || (styles[group] = { ids: [], parts: [], element: undefined });
|
||||
|
||||
if (!style.ids.includes(id)) {
|
||||
var code = css.source;
|
||||
var index = style.ids.length;
|
||||
|
||||
style.ids.push(id);
|
||||
|
||||
if (isOldIE) {
|
||||
style.element = style.element || document.querySelector('style[data-group=' + group + ']');
|
||||
}
|
||||
|
||||
if (!style.element) {
|
||||
var el = style.element = document.createElement('style');
|
||||
el.type = 'text/css';
|
||||
|
||||
if (css.media) { el.setAttribute('media', css.media); }
|
||||
if (isOldIE) {
|
||||
el.setAttribute('data-group', group);
|
||||
el.setAttribute('data-next-index', '0');
|
||||
}
|
||||
|
||||
head.appendChild(el);
|
||||
}
|
||||
|
||||
if (isOldIE) {
|
||||
index = parseInt(style.element.getAttribute('data-next-index'));
|
||||
style.element.setAttribute('data-next-index', index + 1);
|
||||
}
|
||||
|
||||
if (style.element.styleSheet) {
|
||||
style.parts.push(code);
|
||||
style.element.styleSheet.cssText = style.parts
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
} else {
|
||||
var textNode = document.createTextNode(code);
|
||||
var nodes = style.element.childNodes;
|
||||
if (nodes[index]) { style.element.removeChild(nodes[index]); }
|
||||
if (nodes.length) { style.element.insertBefore(textNode, nodes[index]); }
|
||||
else { style.element.appendChild(textNode); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* style inject SSR */
|
||||
|
||||
|
||||
|
||||
__vue_normalize__(
|
||||
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
||||
__vue_inject_styles__,
|
||||
__vue_script__,
|
||||
__vue_scope_id__,
|
||||
__vue_is_functional_template__,
|
||||
__vue_module_identifier__,
|
||||
__vue_create_injector__,
|
||||
undefined
|
||||
);
|
||||
|
||||
$(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(page) {
|
||||
setupLabelsDialog(page);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
function setupLabelsDialog(page) {
|
||||
var cur_frm = page.view.cur_frm;
|
||||
|
||||
var fields = {
|
||||
doctype: '',
|
||||
docname: ' ',
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
delivery_date: '',
|
||||
customer: '',
|
||||
batch: '',
|
||||
information: '',
|
||||
total_amount: 0,
|
||||
labels: [{
|
||||
qty_per_label: 0,
|
||||
is_warehouse: 0,
|
||||
information: '',
|
||||
}],
|
||||
preview: __('Click "Render Preview"')
|
||||
};
|
||||
|
||||
|
||||
if (cur_frm !== null) {
|
||||
if (cur_frm.doctype === "Work Order" || cur_frm.doctype === "Item") {
|
||||
if (cur_frm.docname) {
|
||||
fields.doctype = cur_frm.doctype;
|
||||
fields.docname = cur_frm.docname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var d = new frappe.ui.Dialog({
|
||||
title: __("Print Labels"),
|
||||
fields: [{
|
||||
label: __("Reference Doctype"),
|
||||
options: ['Work Order', 'Item'],
|
||||
fieldname: 'doctype',
|
||||
fieldtype: 'Select',
|
||||
default: fields.doctype,
|
||||
},
|
||||
{
|
||||
label: __("Get data"),
|
||||
fieldname: 'get_data',
|
||||
fieldtype: 'Button',
|
||||
click: function () {
|
||||
handleDataFetch();
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
label: __("Reference Docname"),
|
||||
fieldname: 'docname',
|
||||
fieldtype: 'Dynamic Link',
|
||||
options: 'doctype',
|
||||
},
|
||||
{
|
||||
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: false,
|
||||
in_place_edit: true,
|
||||
data: fields.labels,
|
||||
get_data: function () {
|
||||
return fields.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 primary_action(values) {
|
||||
fields = values;
|
||||
|
||||
frappe.call({
|
||||
method: "label_printing.label_printing.api.create_labels",
|
||||
args: {
|
||||
values: fields
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message === 200) {
|
||||
frappe.show_alert("Label printing successful", 5);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
d.hide();
|
||||
}
|
||||
});
|
||||
handleDataFetch();
|
||||
|
||||
d.show();
|
||||
|
||||
|
||||
// handle dpctype change
|
||||
d.fields_dict.doctype.$input.on('change', function() {
|
||||
d.fields_dict.docname.refresh();
|
||||
});
|
||||
|
||||
function handleDataFetch() {
|
||||
fields = d.get_values();
|
||||
if (fields.doctype && fields.docname) {
|
||||
var doc = get_doc(fields.doctype, fields.docname);
|
||||
|
||||
if (fields.doctype === "Work Order") {
|
||||
var item = get_doc("Item", doc.production_item);
|
||||
fields.item_code = item.item_code;
|
||||
fields.item_name = item.item_name;
|
||||
fields.delivery_date = doc.expected_delivery_date;
|
||||
|
||||
if (item.associated_company) {
|
||||
var customer = get_doc("Customer", item.associated_company);
|
||||
if (customer.short_name) {
|
||||
fields.customer = customer.short_name;
|
||||
} else {
|
||||
fields.customer = item.associated_company;
|
||||
}
|
||||
}
|
||||
|
||||
fields.total_amount = doc.qty;
|
||||
fields.labels[0].qty_per_label = doc.qty;
|
||||
d.fields_dict.labels.refresh();
|
||||
|
||||
} else if (fields.doctype === "Item") {
|
||||
var item$1 = get_doc("Item", doc.item_code);
|
||||
|
||||
fields.item_code = doc.item_code;
|
||||
fields.item_name = doc.item_name;
|
||||
|
||||
if (item$1.associated_company) {
|
||||
var customer$1 = get_doc("Customer", doc.associated_company);
|
||||
if (customer$1.short_name) {
|
||||
fields.customer = customer$1.short_name;
|
||||
} else {
|
||||
fields.customer = doc.associated_company;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
d.set_values(fields);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function get_doc(doctype, docname) {
|
||||
var res;
|
||||
frappe.call({
|
||||
method: "frappe.client.get",
|
||||
async: false,
|
||||
args: {
|
||||
doctype: doctype,
|
||||
name: docname,
|
||||
},
|
||||
callback: function callback(r) {
|
||||
if (r.message) {
|
||||
res = r.message;
|
||||
}
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
}());
|
||||
!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)})})}();
|
||||
//# sourceMappingURL=label_printing.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,8 +1,6 @@
|
||||
import LabelPrintingDialog from "./label_printing_dialog.vue";
|
||||
|
||||
$(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(page) {
|
||||
$(".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 (page) {
|
||||
setupLabelsDialog(page);
|
||||
});
|
||||
|
||||
@@ -15,7 +13,7 @@ function setupLabelsDialog(page) {
|
||||
|
||||
let fields = {
|
||||
doctype: '',
|
||||
docname: ' ',
|
||||
docname: '',
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
delivery_date: '',
|
||||
@@ -24,11 +22,9 @@ function setupLabelsDialog(page) {
|
||||
information: '',
|
||||
total_amount: 0,
|
||||
labels: [{
|
||||
qty_per_label: 0,
|
||||
is_warehouse: 0,
|
||||
information: '',
|
||||
}],
|
||||
preview: __('Click "Render Preview"')
|
||||
item_qty: 0,
|
||||
label_qty: 0,
|
||||
}]
|
||||
};
|
||||
|
||||
|
||||
@@ -44,99 +40,100 @@ function setupLabelsDialog(page) {
|
||||
let d = new frappe.ui.Dialog({
|
||||
title: __("Print Labels"),
|
||||
fields: [{
|
||||
label: __("Reference Doctype"),
|
||||
options: ['Work Order', 'Item'],
|
||||
fieldname: 'doctype',
|
||||
fieldtype: 'Select',
|
||||
default: fields.doctype,
|
||||
label: __("Reference Doctype"),
|
||||
options: ['Work Order', 'Item'],
|
||||
fieldname: 'doctype',
|
||||
fieldtype: 'Select',
|
||||
default: fields.doctype,
|
||||
},
|
||||
{
|
||||
label: __("Get data"),
|
||||
fieldname: 'get_data',
|
||||
fieldtype: 'Button',
|
||||
click: () => {
|
||||
handleDataFetch()
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
label: __("Reference Docname"),
|
||||
fieldname: 'docname',
|
||||
fieldtype: 'Data',
|
||||
options: 'doctype',
|
||||
default: fields.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: false,
|
||||
in_place_edit: true,
|
||||
data: fields.labels,
|
||||
get_data: () => {
|
||||
return fields.labels;
|
||||
},
|
||||
fields: [{
|
||||
fieldtype: 'Int',
|
||||
fieldname: "item_qty",
|
||||
in_list_view: 1,
|
||||
label: __('Item Qty')
|
||||
},
|
||||
{
|
||||
label: __("Get data"),
|
||||
fieldname: 'get_data',
|
||||
fieldtype: 'Button',
|
||||
click: () => {
|
||||
handleDataFetch()
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
label: __("Reference Docname"),
|
||||
fieldname: 'docname',
|
||||
fieldtype: 'Dynamic Link',
|
||||
options: 'doctype',
|
||||
},
|
||||
{
|
||||
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: false,
|
||||
in_place_edit: true,
|
||||
data: fields.labels,
|
||||
get_data: () => {
|
||||
return fields.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'
|
||||
},
|
||||
]
|
||||
label: __("Label Qty"),
|
||||
fieldname: 'label_qty',
|
||||
in_list_view: 1,
|
||||
fieldtype: 'Int'
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
primary_action_label: 'Print',
|
||||
primary_action(values) {
|
||||
fields = values
|
||||
|
||||
frappe.call({
|
||||
method: "label_printing.label_printing.api.create_labels",
|
||||
method: "label_printing.api.print_label",
|
||||
args: {
|
||||
values: fields
|
||||
},
|
||||
callback: function(r) {
|
||||
callback: function (r) {
|
||||
if (r.message === 200) {
|
||||
frappe.show_alert("Label printing successful", 5);
|
||||
}
|
||||
@@ -147,12 +144,11 @@ function setupLabelsDialog(page) {
|
||||
}
|
||||
});
|
||||
handleDataFetch();
|
||||
|
||||
d.show();
|
||||
|
||||
|
||||
|
||||
// handle dpctype change
|
||||
d.fields_dict.doctype.$input.on('change', function() {
|
||||
d.fields_dict.doctype.$input.on('change', function () {
|
||||
d.fields_dict.docname.refresh();
|
||||
});
|
||||
|
||||
@@ -160,12 +156,24 @@ function setupLabelsDialog(page) {
|
||||
fields = d.get_values()
|
||||
if (fields.doctype && fields.docname) {
|
||||
let doc = get_doc(fields.doctype, fields.docname)
|
||||
|
||||
if (fields.doctype === "Work Order") {
|
||||
let item = get_doc("Item", doc.production_item)
|
||||
let se = 1
|
||||
frappe.call({
|
||||
method: "label_printing.api.get_associated_stockentry",
|
||||
async: false,
|
||||
args: { workorder: fields.docname },
|
||||
callback(r) {
|
||||
if (r.message) {
|
||||
fields.batch = r.message.items[r.message.items.length - 1].batch_no
|
||||
}
|
||||
}
|
||||
})
|
||||
fields.item_code = item.item_code
|
||||
fields.item_name = item.item_name
|
||||
fields.delivery_date = doc.expected_delivery_date
|
||||
fields.labels[0].item_qty = doc.qty
|
||||
fields.labels[0].label_qty = 1
|
||||
|
||||
if (item.associated_company) {
|
||||
let customer = get_doc("Customer", item.associated_company)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<template>
|
||||
<li 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>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "LabelPrintingDialog",
|
||||
props: [],
|
||||
methods: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
1
label_printing/public/node_modules
Symbolic link
1
label_printing/public/node_modules
Symbolic link
@@ -0,0 +1 @@
|
||||
/home/frappe/frappe-bench/apps/label_printing/node_modules
|
||||
Reference in New Issue
Block a user