Skip to content

Commit 4687875

Browse files
Pau Solivaramonski
Pau Soliva
authored andcommitted
PR-2205: Issue-2204: Conditional Email Notification on AR retract #2205 (#318)
* Allow more than 6 Schemata before transforming into a selection box. * porting bikasetup.py * analysis request workflow * Max tab 10 * NotifyOnARRetract missing in bikasetup
1 parent 4149a34 commit 4687875

File tree

3 files changed

+346
-191
lines changed

3 files changed

+346
-191
lines changed

bika/lims/browser/analysisrequest/workflow.py

+3-64
Original file line numberDiff line numberDiff line change
@@ -573,70 +573,9 @@ def workflow_action_retract_ar(self):
573573
# picked up and is under investigation.
574574
# A much possible information is provided in the email, linking
575575
# to the AR online.
576-
laboratory = self.context.bika_setup.laboratory
577-
lab_address = "<br/>".join(laboratory.getPrintAddress())
578-
mime_msg = MIMEMultipart('related')
579-
mime_msg['Subject'] = t(_("Erroneus result publication from ${request_id}",
580-
mapping={"request_id": ar.getRequestID()}))
581-
mime_msg['From'] = formataddr(
582-
(encode_header(laboratory.getName()),
583-
laboratory.getEmailAddress()))
584-
to = []
585-
contact = ar.getContact()
586-
if contact:
587-
to.append(formataddr((encode_header(contact.Title()),
588-
contact.getEmailAddress())))
589-
for cc in ar.getCCContact():
590-
formatted = formataddr((encode_header(cc.Title()),
591-
cc.getEmailAddress()))
592-
if formatted not in to:
593-
to.append(formatted)
594-
595-
managers = self.context.portal_groups.getGroupMembers('LabManagers')
596-
for bcc in managers:
597-
user = self.portal.acl_users.getUser(bcc)
598-
if user:
599-
uemail = user.getProperty('email')
600-
ufull = user.getProperty('fullname')
601-
formatted = formataddr((encode_header(ufull), uemail))
602-
if formatted not in to:
603-
to.append(formatted)
604-
mime_msg['To'] = ','.join(to)
605-
aranchor = "<a href='%s'>%s</a>" % (ar.absolute_url(),
606-
ar.getRequestID())
607-
naranchor = "<a href='%s'>%s</a>" % (newar.absolute_url(),
608-
newar.getRequestID())
609-
addremarks = ('addremarks' in self.request
610-
and ar.getRemarks()) \
611-
and ("<br/><br/>"
612-
+ _("Additional remarks:")
613-
+ "<br/>"
614-
+ ar.getRemarks().split("===")[1].strip()
615-
+ "<br/><br/>") \
616-
or ''
617-
sub_d = dict(request_link=aranchor,
618-
new_request_link=naranchor,
619-
remarks=addremarks,
620-
lab_address=lab_address)
621-
body = Template("Some errors have been detected in the results report "
622-
"published from the Analysis Request $request_link. The Analysis "
623-
"Request $new_request_link has been created automatically and the "
624-
"previous has been invalidated.<br/>The possible mistake "
625-
"has been picked up and is under investigation.<br/><br/>"
626-
"$remarks $lab_address").safe_substitute(sub_d)
627-
msg_txt = MIMEText(safe_unicode(body).encode('utf-8'),
628-
_subtype='html')
629-
mime_msg.preamble = 'This is a multi-part MIME message.'
630-
mime_msg.attach(msg_txt)
631-
try:
632-
host = getToolByName(self.context, 'MailHost')
633-
host.send(mime_msg.as_string(), immediate=True)
634-
except Exception as msg:
635-
message = _('Unable to send an email to alert lab '
636-
'client contacts that the Analysis Request has been '
637-
'retracted: ${error}',
638-
mapping={'error': safe_unicode(msg)})
639-
self.context.plone_utils.addPortalMessage(message, 'warning')
576+
bika_setup = api.get_bika_setup()
577+
if bika_setup.getNotifyOnARRetract():
578+
self.notify_ar_retract(ar, newar)
640579

641580
message = _('${items} invalidated.',
642581
mapping={'items': ar.getRequestID()})

0 commit comments

Comments
 (0)