Skip to content

Commit ff1a051

Browse files
#7, #8, #9 pdf creation button and label format, heavy changes
1 parent bfcc9d6 commit ff1a051

File tree

7 files changed

+595
-7
lines changed

7 files changed

+595
-7
lines changed

labels/api_labels.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
from frappe.utils import get_site_name
1010

1111
from labels.resources.pdf_sticker_generator import create_labels_pdf, create_file_doctype_and_attach
12+
from labels.resources.label_setup import new_create_labels_pdf
13+
1214

1315
# This method is for debugging purposes only!
16+
"""
1417
@frappe.whitelist()
1518
def test_method(sticker_type):
1619
return "https://www.google.com/"
20+
"""
1721

1822
@frappe.whitelist()
1923
def process_labels(dict_data, sticker_type, production_date, expiration_date):
@@ -48,4 +52,9 @@ def process_labels(dict_data, sticker_type, production_date, expiration_date):
4852

4953
# en_US: The value returnes is the URL location of the file, generated as a public file.
5054
# es: El valor retornado es la url ubicacion del archivo ya generado como publico
51-
return label_file_status
55+
return label_file_status
56+
57+
@frappe.whitelist()
58+
def process_labels_2(dict_data, sticker_type, production_date, expiration_date):
59+
result = new_create_labels_pdf()
60+
return result

labels/public/js/labels.js

+282
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,286 @@ frappe.ui.form.on("Production Plan", {
8282
}
8383
});
8484

85+
frappe.ui.form.on("Purchase Receipt", {
86+
refresh: function (frm) {
87+
88+
// Agrega un icon-button a la barra de la pagina
89+
cur_frm.page.add_action_icon(__("fa fa-file-pdf-o"), function () {
90+
91+
// Instanciando un dialogo con sus propiedades
92+
let dialog = new frappe.ui.Dialog({
93+
title: __('Generar Stickers'),
94+
fields: [
95+
{
96+
fieldtype: 'Select',
97+
fieldname: 'sticker_type',
98+
label: __('Estilo de sticker'),
99+
reqd: true,
100+
options: [
101+
"Sticker sin fechas",
102+
"Sticker con fecha de cosecha",
103+
"Sticker con fecha de vencimiento",
104+
"Sticker con todos los datos"
105+
],
106+
description: __('Seleccione el estilo de sticker que desee generar')
107+
},
108+
{
109+
fieldtype: 'Button',
110+
fieldname: 'btn_generar',
111+
label: __('Generar Stickers'),
112+
options: '',
113+
description: __(''),
114+
}
115+
]
116+
});
117+
118+
// Muestra el dialogo
119+
dialog.show();
120+
121+
// Agrega un event lister al boton del dialogo
122+
dialog.fields_dict.btn_generar.$wrapper.on('click', function (e) {
123+
var estilo_sticker = '0';
124+
125+
if (dialog.fields_dict.sticker_type.value == 'Sticker sin fechas') {
126+
estilo_sticker = '0';
127+
}
128+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de cosecha') {
129+
estilo_sticker = '1';
130+
}
131+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de vencimiento') {
132+
estilo_sticker = '2';
133+
}
134+
if (dialog.fields_dict.sticker_type.value == 'Sticker con todos los datos') {
135+
estilo_sticker = '3';
136+
}
137+
138+
// Frappe call that simply opens a google page in a new tab or window (for debugging API methods.)
139+
/*
140+
frappe.call({
141+
method: "labels.api_labels2.test_method",
142+
args: {
143+
sticker_type: estilo_sticker
144+
},
145+
callback: function (r) {
146+
// El valor retornado, es la url de la ubicacion del archivo
147+
window.open(r.message);
148+
}
149+
});
150+
*/
151+
frappe.call({
152+
method: "labels.api_labels.process_labels_2",
153+
args: {
154+
/*
155+
dict_data: cur_frm.doc.po_items,
156+
sticker_type: estilo_sticker,
157+
production_date: cur_frm.doc.label_production_date,
158+
expiration_date: cur_frm.doc.label_expiration_date
159+
*/
160+
// Dummy Data
161+
dict_data: 1,
162+
sticker_type: 1,
163+
production_date: 1,
164+
expiration_date: 1
165+
},
166+
callback: function (r) {
167+
// We show an alert that the stickers have been generated
168+
frappe.show_alert({
169+
indicator: 'orange',
170+
message: r.message
171+
});
172+
}
173+
});
174+
});
175+
});
176+
}
177+
});
178+
179+
frappe.ui.form.on("Delivery Note", {
180+
refresh: function (frm) {
181+
182+
// Agrega un icon-button a la barra de la pagina
183+
cur_frm.page.add_action_icon(__("fa fa-file-pdf-o"), function () {
184+
185+
// Instanciando un dialogo con sus propiedades
186+
let dialog = new frappe.ui.Dialog({
187+
title: __('Generar Stickers'),
188+
fields: [
189+
{
190+
fieldtype: 'Select',
191+
fieldname: 'sticker_type',
192+
label: __('Estilo de sticker'),
193+
reqd: true,
194+
options: [
195+
"Sticker sin fechas",
196+
"Sticker con fecha de cosecha",
197+
"Sticker con fecha de vencimiento",
198+
"Sticker con todos los datos"
199+
],
200+
description: __('Seleccione el estilo de sticker que desee generar')
201+
},
202+
{
203+
fieldtype: 'Button',
204+
fieldname: 'btn_generar',
205+
label: __('Generar Stickers'),
206+
options: '',
207+
description: __(''),
208+
}
209+
]
210+
});
211+
212+
// Muestra el dialogo
213+
dialog.show();
214+
215+
// Agrega un event lister al boton del dialogo
216+
dialog.fields_dict.btn_generar.$wrapper.on('click', function (e) {
217+
var estilo_sticker = '0';
218+
219+
if (dialog.fields_dict.sticker_type.value == 'Sticker sin fechas') {
220+
estilo_sticker = '0';
221+
}
222+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de cosecha') {
223+
estilo_sticker = '1';
224+
}
225+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de vencimiento') {
226+
estilo_sticker = '2';
227+
}
228+
if (dialog.fields_dict.sticker_type.value == 'Sticker con todos los datos') {
229+
estilo_sticker = '3';
230+
}
231+
232+
// Frappe call that simply opens a google page in a new tab or window (for debugging API methods.)
233+
/*
234+
frappe.call({
235+
method: "labels.api_labels2.test_method",
236+
args: {
237+
sticker_type: estilo_sticker
238+
},
239+
callback: function (r) {
240+
// El valor retornado, es la url de la ubicacion del archivo
241+
window.open(r.message);
242+
}
243+
});
244+
*/
245+
frappe.call({
246+
method: "labels.api_labels.process_labels_2",
247+
args: {
248+
/*
249+
dict_data: cur_frm.doc.po_items,
250+
sticker_type: estilo_sticker,
251+
production_date: cur_frm.doc.label_production_date,
252+
expiration_date: cur_frm.doc.label_expiration_date
253+
*/
254+
// Dummy Data
255+
dict_data: 1,
256+
sticker_type: 1,
257+
production_date: 1,
258+
expiration_date: 1
259+
},
260+
callback: function (r) {
261+
// We show an alert that the stickers have been generated
262+
frappe.show_alert({
263+
indicator: 'orange',
264+
message: r.message
265+
});
266+
}
267+
});
268+
});
269+
});
270+
}
271+
});
272+
273+
frappe.ui.form.on("Stock Entry", {
274+
refresh: function (frm) {
275+
276+
// Agrega un icon-button a la barra de la pagina
277+
cur_frm.page.add_action_icon(__("fa fa-file-pdf-o"), function () {
278+
279+
// Instanciando un dialogo con sus propiedades
280+
let dialog = new frappe.ui.Dialog({
281+
title: __('Generar Stickers'),
282+
fields: [
283+
{
284+
fieldtype: 'Select',
285+
fieldname: 'sticker_type',
286+
label: __('Estilo de sticker'),
287+
reqd: true,
288+
options: [
289+
"Sticker sin fechas",
290+
"Sticker con fecha de cosecha",
291+
"Sticker con fecha de vencimiento",
292+
"Sticker con todos los datos"
293+
],
294+
description: __('Seleccione el estilo de sticker que desee generar')
295+
},
296+
{
297+
fieldtype: 'Button',
298+
fieldname: 'btn_generar',
299+
label: __('Generar Stickers'),
300+
options: '',
301+
description: __(''),
302+
}
303+
]
304+
});
305+
306+
// Muestra el dialogo
307+
dialog.show();
308+
309+
// Agrega un event lister al boton del dialogo
310+
dialog.fields_dict.btn_generar.$wrapper.on('click', function (e) {
311+
var estilo_sticker = '0';
312+
313+
if (dialog.fields_dict.sticker_type.value == 'Sticker sin fechas') {
314+
estilo_sticker = '0';
315+
}
316+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de cosecha') {
317+
estilo_sticker = '1';
318+
}
319+
if (dialog.fields_dict.sticker_type.value == 'Sticker con fecha de vencimiento') {
320+
estilo_sticker = '2';
321+
}
322+
if (dialog.fields_dict.sticker_type.value == 'Sticker con todos los datos') {
323+
estilo_sticker = '3';
324+
}
325+
326+
// Frappe call that simply opens a google page in a new tab or window (for debugging API methods.)
327+
/*
328+
frappe.call({
329+
method: "labels.api_labels2.test_method",
330+
args: {
331+
sticker_type: estilo_sticker
332+
},
333+
callback: function (r) {
334+
// El valor retornado, es la url de la ubicacion del archivo
335+
window.open(r.message);
336+
}
337+
});
338+
*/
339+
frappe.call({
340+
method: "labels.api_labels.process_labels_2",
341+
args: {
342+
/*
343+
dict_data: cur_frm.doc.po_items,
344+
sticker_type: estilo_sticker,
345+
production_date: cur_frm.doc.label_production_date,
346+
expiration_date: cur_frm.doc.label_expiration_date
347+
*/
348+
// Dummy Data
349+
dict_data: 1,
350+
sticker_type: 1,
351+
production_date: 1,
352+
expiration_date: 1
353+
},
354+
callback: function (r) {
355+
// We show an alert that the stickers have been generated
356+
frappe.show_alert({
357+
indicator: 'orange',
358+
message: r.message
359+
});
360+
}
361+
});
362+
});
363+
});
364+
}
365+
});
366+
85367
console.log("'Labels' has been loaded.");

labels/public/js/labels.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)