Skip to content
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

Merged
merged 24 commits into from
Jan 31, 2018
Merged

Ability to select the number of sample sticker copies for printing #618

merged 24 commits into from
Jan 31, 2018

Conversation

juangallostra
Copy link
Contributor

@juangallostra juangallostra commented Jan 30, 2018

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
selection_003

Stickers preview

selection_004

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

@juangallostra juangallostra requested a review from Espurna January 30, 2018 11:49
Copy link
Member

@xispa xispa left a 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

self.context = context
self.request = request

super(Sticker, self).__init__(context, request)
Copy link
Member

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

self.current_item = None
self.rendered_items = []
self.copies_count = None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove whitespaces here

@@ -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])
Copy link
Member

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();
});
}

Copy link
Member

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());
Copy link
Member

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;">
Copy link
Member

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...)

Copy link
Contributor Author

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.

Copy link
Member

@xispa xispa left a 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

@xispa xispa merged commit cdd11c1 into senaite:master Jan 31, 2018
@juangallostra juangallostra deleted the choose-sticker-number-to-print branch April 4, 2018 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants