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

Make automatic sticker printing work with 'registered' option activated #720

Merged
merged 4 commits into from
Mar 13, 2018
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 @@ -16,6 +16,7 @@ Changelog

**Fixed**

- #720 Make automatic sticker printing work with 'registered' option activated
- #716 Samples from inside Batch are not filtered correctly
- #707 AR Add: Set default contact on client change
- #700 Fix filtering by review state in aggregated list of analyses
Expand Down
14 changes: 8 additions & 6 deletions bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json
from datetime import datetime
from collections import OrderedDict

import magnitude
from BTrees.OOBTree import OOBTree
Expand Down Expand Up @@ -1845,7 +1846,7 @@ def ajax_submit(self):
return {'errors': errors}

# Process Form
ARs = []
ARs = OrderedDict()
for n, record in enumerate(valid_records):
client_uid = record.get("Client")
client = self.get_object_by_uid(client_uid)
Expand All @@ -1862,7 +1863,9 @@ def ajax_submit(self):
except (KeyError, RuntimeError) as e:
errors["message"] = e.message
return {"errors": errors}
ARs.append(ar.Title())
# We keep the title to check if AR is newly created
# and UID to print stickers
ARs[ar.Title()] = ar.UID()

_attachments = []
for attachment in attachments.get(n, []):
Expand All @@ -1881,20 +1884,19 @@ def ajax_submit(self):
level = "error"
elif len(ARs) > 1:
message = _('Analysis requests ${ARs} were successfully created.',
mapping={'ARs': safe_unicode(', '.join(ARs))})
mapping={'ARs': safe_unicode(', '.join(ARs.keys()))})
else:
message = _('Analysis request ${AR} was successfully created.',
mapping={'AR': safe_unicode(ARs[0])})
mapping={'AR': safe_unicode(ARs.keys()[0])})

# Display a portal message
self.context.plone_utils.addPortalMessage(message, level)

# Automatic label printing won't print "register" labels for Secondary. ARs
bika_setup = api.get_bika_setup()
auto_print = bika_setup.getAutoPrintStickers()

# https://github.com/bikalabs/bika.lims/pull/2153
new_ars = [a for a in ARs if a[-1] == '1']
new_ars = [uid for key, uid in ARs.items() if key[-1] == '1']

if 'register' in auto_print and new_ars:
return {
Expand Down