-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to select the number of sample sticker copies for printing #618
Ability to select the number of sample sticker copies for printing #618
Conversation
…s to send both template and copies when changes in the form are detected.
…lse get the number from the request. 2- Correct constructor
…oose-sticker-number-to-print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juangallostra , some changes are required. Also remember to never duplicate code, especially if is js
bika/lims/browser/stickers.py
Outdated
self.context = context | ||
self.request = request | ||
|
||
super(Sticker, self).__init__(context, request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to call the constructor from the super class at the very beginning, rather than at the end of the __init__
function
bika/lims/browser/stickers.py
Outdated
self.current_item = None | ||
self.rendered_items = [] | ||
self.copies_count = None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove whitespaces here
bika/lims/browser/stickers.py
Outdated
@@ -149,7 +159,8 @@ def _populateItems(self, item): | |||
return [[None, None, item]] | |||
items = [] | |||
for part in parts: | |||
items.append([ar, sample, part]) | |||
for copy in range(self.copies_count): | |||
items.append([ar, sample, part]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that in this loop we are dealing with partitions (e.g. a Sample can have more than one partition and we ensure here we print a sticker for every single partition) and is never called when the object is a Worksheet or a Batch for instance (see L1575 and L159).
Add this logic into a function _resolve_number_of_copies
and call it before L95 https://github.com/senaite/senaite.core/pull/618/files#diff-288974376469bb5c86e96399ce16a703R94
$('#stickers-wrapper').fadeIn(); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all this update_sticker_copies(copies, template)
function, reuse reload
function instead.
reload($('select#template').val(), $('#copies_count').val()); | ||
}); | ||
$('#copies_count').change(function(e) { | ||
update_sticker_copies($('#copies_count').val(), $('select#template').val()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a new function, reuse reload
, it already provides the functionality you need:
$('#copies_count').change(function(e) {
reload($('select#template').val(), $('#copies_count').val());
});
<div class='sticker' | ||
tal:content='structure python:view.renderItem()'></div> | ||
</tal:sticker> | ||
<tal:sticker define="item_id python:sticker[2].getId() if sticker else None;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to figure out about that view.rendered_items
. I understand why you need to remove it, cause each time the function nextItem
is called, the current item is added in this view.rendered_items
list, preventing you to display a label for a given object more than once. The thing is that I am not sure for what view.rendered_items
var is used other than this condition... Anyhow, add a condition
for at least check if item_id
is not None
(note that in define
attribute there is the possibility to set a none
value to item_id
, which is something weird again...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xispa I also checked the use of rendered_items
and agree in that it was only used in the check that I removed to be able to print more than one copy. I am then going to remove rendered_items
from the code.
…ew method and make it also work with Batches and Worksheets
…the same functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @juangallostra . Just one thing you missed, please add an entry in CHANGES.rst
Description of the issue/feature this PR addresses
Add the possibility of selecting the number of copies to print for sample/sample partition/batch/worksheet stickers. Also, add a setup field to set the default number of copies.
Current behavior before PR
There wasn't the option of selecting the number of copies to print for sample/sample partition/batch/worksheet stickers.
Desired behavior after PR is merged
The number of copies for sample/sample partition/batch/worksheet stickers can be modified from the view and a default number of sticker copies can be set in the Stickers setup page.
Screenshots (optional)
Below there are two screenshots presenting the new functionality:
Stickers setup

Stickers preview
--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.