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

PR2158 Stickers on listing plus autoprint generates PDF #321

Merged
merged 7 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
------------------

**Added**
- BC-99: Added Print Stickers button to AR listings

- Issue-288: Worksheet: "Print" does not display/print partial results
https://github.com/senaite/bika.lims/issues/288
Expand Down
77 changes: 56 additions & 21 deletions bika/lims/browser/analysisrequest/analysisrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@

import json
import traceback
from plone.api import user

from DateTime import DateTime
from Products.Archetypes import PloneMessageFactory as PMF
from Products.CMFCore.permissions import ModifyPortalContent
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from collective.taskqueue.interfaces import ITaskQueue
from plone import api
from plone.app.layout.globals.interfaces import IViewView
from plone.protect import CheckAuthenticator
from plone.protect import PostOnly
from zope.component import queryUtility
from zope.interface import implements

from bika.lims import bikaMessageFactory as _
from bika.lims import logger
from bika.lims.browser.analysisrequest.analysisrequests_filter_bar \
Expand All @@ -30,6 +23,12 @@
from bika.lims.permissions import Verify as VerifyPermission
from bika.lims.utils import getUsers
from bika.lims.utils import t
from collective.taskqueue.interfaces import ITaskQueue
from plone.app.layout.globals.interfaces import IViewView
from plone.protect import CheckAuthenticator
from plone.protect import PostOnly
from zope.component import queryUtility
from zope.interface import implements


class AnalysisRequestsView(BikaListingView):
Expand Down Expand Up @@ -228,7 +227,10 @@ def __init__(self, context, request):
{'id': 'republish'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'Progress',
'getRequestID',
Expand Down Expand Up @@ -269,7 +271,10 @@ def __init__(self, context, request):
{'id': 'submit'},
{'id': 'cancel'},
],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -306,7 +311,10 @@ def __init__(self, context, request):
'transitions': [{'id': 'preserve'},
{'id': 'cancel'},
],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -341,7 +349,10 @@ def __init__(self, context, request):
'transitions': [{'id': 'sample'},
{'id': 'cancel'},
],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -382,7 +393,10 @@ def __init__(self, context, request):
{'id': 'receive'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -419,7 +433,10 @@ def __init__(self, context, request):
'transitions': [{'id': 'prepublish'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -458,7 +475,10 @@ def __init__(self, context, request):
{'id': 'prepublish'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -495,7 +515,10 @@ def __init__(self, context, request):
'transitions': [{'id': 'publish'},
{'id': 'cancel'},
],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -613,7 +636,10 @@ def __init__(self, context, request):
'sort_on': 'Created',
'sort_order': 'reverse'},
'transitions': [],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns':['getRequestID',
'getSample',
'BatchID',
Expand Down Expand Up @@ -659,7 +685,10 @@ def __init__(self, context, request):
{'id': 'republish'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -707,7 +736,10 @@ def __init__(self, context, request):
{'id': 'republish'},
{'id': 'cancel'},
{'id': 'reinstate'}],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['Priority',
'getRequestID',
'getSample',
Expand Down Expand Up @@ -744,7 +776,10 @@ def __init__(self, context, request):
'sort_on': 'Created',
'sort_order': 'reverse'},
'transitions': [],
'custom_actions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['getRequestID',
'getSample',
'BatchID',
Expand Down Expand Up @@ -1018,7 +1053,7 @@ def folderitem(self, obj, item, index):
# Thee conditions to improve performance, some functions to check
# the condition need to get the full analysis request.
if states_dict.get('review_state', '') == 'to_be_verified':
allowed = api.user.has_permission(
allowed = user.has_permission(
VerifyPermission,
username=self.member.getUserName())
# TODO-performance: isUserAllowedToVerify getts all analysis
Expand Down
22 changes: 22 additions & 0 deletions bika/lims/browser/bika_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ def workflow_action_copy_to_new(self):
self.request.response.redirect(url)
return

def workflow_action_print_stickers(self):
"""Invoked from AR or Sample listings in the current context, passing
the uids of the selected items and default sticker template as
request parameters to the stickers rendering machinery, that
generates the PDF
"""
uids = self.request.form.get("uids", [])
if not uids:
message = self.context.translate(
_("No ARs have been selected"))
self.context.plone_utils.addPortalMessage(message, 'info')
self.destination_url = self.context.absolute_url()
self.request.response.redirect(self.destination_url)
return

url = '{0}/sticker?autoprint=1&template={1}&items={2}'.format(
self.context.absolute_url(),
self.portal.bika_setup.getAutoStickerTemplate(),
','.join(uids)
)
self.request.response.redirect(url)

def __call__(self):
form = self.request.form
plone.protect.CheckAuthenticator(form)
Expand Down
32 changes: 28 additions & 4 deletions bika/lims/browser/sample/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ def __init__(self, context, request):
'getDatePreserved',
'getPreserver',
'DateReceived',
'state_title']},
'state_title'],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],},
{'id': 'to_be_sampled',
'title': _('To be sampled'),
'contentFilter': {'review_state': ('to_be_sampled',
Expand All @@ -213,6 +217,10 @@ def __init__(self, context, request):
'state_title'],
'transitions': [
{'id': 'schedule_sampling'}, {'id': 'sample'}],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
},
{'id': 'sample_due',
'title': _('Due'),
Expand Down Expand Up @@ -263,7 +271,11 @@ def __init__(self, context, request):
'getSampler',
'getDatePreserved',
'getPreserver',
'DateReceived']},
'DateReceived'],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],},
{'id':'expired',
'title': _('Expired'),
'contentFilter':{'review_state':'expired',
Expand All @@ -287,7 +299,11 @@ def __init__(self, context, request):
'getSampler',
'getDatePreserved',
'getPreserver',
'DateReceived']},
'DateReceived'],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],},
{'id':'disposed',
'title': _('Disposed'),
'contentFilter':{'review_state':'disposed',
Expand All @@ -311,7 +327,11 @@ def __init__(self, context, request):
'getSampler',
'getDatePreserved',
'getPreserver',
'DateReceived']},
'DateReceived'],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],},
{'id':'cancelled',
'title': _('Cancelled'),
'contentFilter': {'cancellation_state': 'cancelled',
Expand Down Expand Up @@ -344,6 +364,10 @@ def __init__(self, context, request):
'sort_order': 'reverse',
'sort_on': 'created'},
'transitions': [],
'custom_actions': [{
'id': 'print_stickers',
'title': _('Print stickers'),
'url': 'workflow_action?action=print_stickers'}],
'columns': ['getSampleID',
'Client',
'Creator',
Expand Down
16 changes: 12 additions & 4 deletions bika/lims/browser/templates/stickers_preview.pt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
$('#print-button').click(function(e) {
e.preventDefault();
printPdf();
window.location = $('#cancel-button').attr('data-url');
});
$('#cancel-button').click(function(e) {
e.preventDefault();
Expand Down Expand Up @@ -188,14 +189,21 @@
'<input type="hidden" name="pdf" value="1" />' +
'<textarea name="style">' + style + '</textarea>' +
'</form>';
$('body').html(form);
document.forms.topdf.submit();
var pdfwindow = window.open();
$(pdfwindow.document.body).html(form);
pdfwindow.document.forms.topdf.submit();
}

// If autoprint=1, render the pdf automatically
var autoprint = $.query.get('autoprint');
if (autoprint == '1') {
printPdf();
window.location = $('#cancel-button').attr('data-url');
}
});
</script>
</head>
<body tal:attributes="onload python:'this.print()' if view.request.get('autoprint', False) else '';
data-itemsurl python:view.getItemsURL();">
<body tal:attributes="data-itemsurl python:view.getItemsURL();">
<div id='sticker-preview-wrapper'>
<div id="sticker-preview-header">
<div id='options-handler'>
Expand Down