From 5932213764338402851cb799091b9710feb08cb5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Jun 2022 09:26:09 +0200 Subject: [PATCH 1/3] save sid in html label --- ereuse_devicehub/resources/device/models.py | 6 ++++++ ereuse_devicehub/templates/labels/print_labels.html | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 18487ba5..8b2fb93b 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -401,6 +401,12 @@ class Device(Thing): return history + @property + def sid(self): + actions = [x for x in self.actions if x.t == 'Snapshot' and x.sid] + if actions: + return actions[0] + @property def tradings(self): return {str(x.id): self.trading(x.lot) for x in self.actions if x.t == 'Trade'} diff --git a/ereuse_devicehub/templates/labels/print_labels.html b/ereuse_devicehub/templates/labels/print_labels.html index 3c9ffaae..07b8c113 100644 --- a/ereuse_devicehub/templates/labels/print_labels.html +++ b/ereuse_devicehub/templates/labels/print_labels.html @@ -35,7 +35,8 @@
{{ dev.devicehub_id }} + data-model="{{ dev.model or '' }}" + data-sid="{{ dev.sid or '' }}">{{ dev.devicehub_id }}
@@ -103,6 +104,10 @@ +
+ + +
From dd68c5c410a0cc1a9ae1249d14aae31be048012e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Jun 2022 11:59:22 +0200 Subject: [PATCH 2/3] fix dev.sid --- ereuse_devicehub/resources/device/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 8b2fb93b..c42d9bec 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -405,7 +405,7 @@ class Device(Thing): def sid(self): actions = [x for x in self.actions if x.t == 'Snapshot' and x.sid] if actions: - return actions[0] + return actions[0].sid @property def tradings(self): From a65e93b470086d48e945dee148b3a8c7c00133d5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 8 Jun 2022 11:59:47 +0200 Subject: [PATCH 3/3] add sid in template --- ereuse_devicehub/static/js/print.pdf.js | 17 +++++++++++++++++ .../templates/labels/print_labels.html | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/static/js/print.pdf.js b/ereuse_devicehub/static/js/print.pdf.js index f0b1817c..019b6510 100644 --- a/ereuse_devicehub/static/js/print.pdf.js +++ b/ereuse_devicehub/static/js/print.pdf.js @@ -24,6 +24,7 @@ function save_settings() { var sizePreset = $("#printerType").val(); var data = {"height": height, "width": width, "sizePreset": sizePreset}; data['dhid'] = $("#dhidCheck").prop('checked'); + data['sid'] = $("#sidCheck").prop('checked'); data['qr'] = $("#qrCheck").prop('checked'); data['serial_number'] = $("#serialNumberCheck").prop('checked'); data['manufacturer'] = $("#manufacturerCheck").prop('checked'); @@ -39,6 +40,7 @@ function load_settings() { $("#printerType").val(data.sizePreset); $("#qrCheck").prop('checked', data.qr); $("#dhidCheck").prop('checked', data.dhid); + $("#sidCheck").prop('checked', data.sid); $("#serialNumberCheck").prop('checked', data.serial_number); $("#manufacturerCheck").prop('checked', data.manufacturer); $("#modelCheck").prop('checked', data.model); @@ -50,6 +52,7 @@ function reset_settings() { $("#printerType").val('brotherSmall'); $("#qrCheck").prop('checked', true); $("#dhidCheck").prop('checked', true); + $("#sidCheck").prop('checked', true); $("#serialNumberCheck").prop('checked', false); $("#manufacturerCheck").prop('checked', false); $("#modelCheck").prop('checked', false); @@ -74,6 +77,11 @@ function change_check() { } else { $(".dhid").hide(); } + if ($("#sidCheck").prop('checked')) { + $(".sid").show(); + } else { + $(".sid").hide(); + } if ($("#serialNumberCheck").prop('checked')) { $(".serial_number").show(); } else { @@ -109,6 +117,9 @@ function printpdf() { min_tag_side = (Math.min(height, width)/2) + border; var last_tag_code = ''; + if ($("#sidCheck").prop('checked')) { + height += line; + }; if ($("#serialNumberCheck").prop('checked')) { height += line; }; @@ -145,6 +156,12 @@ function printpdf() { space += line; } }; + if ($("#sidCheck").prop('checked')) { + var sn = $(y).data('sid'); + pdf.setFontSize(15); + pdf.text(sn, border, space); + space += line; + }; if ($("#serialNumberCheck").prop('checked')) { var sn = $(y).data('serial-number'); pdf.setFontSize(12); diff --git a/ereuse_devicehub/templates/labels/print_labels.html b/ereuse_devicehub/templates/labels/print_labels.html index 07b8c113..e0693c98 100644 --- a/ereuse_devicehub/templates/labels/print_labels.html +++ b/ereuse_devicehub/templates/labels/print_labels.html @@ -39,6 +39,11 @@ data-sid="{{ dev.sid or '' }}">{{ dev.devicehub_id }}
+