From e9036988241fa29649883ee7496677660feed601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Sat, 7 Sep 2019 00:08:50 +0200 Subject: [PATCH 1/3] Allow to auto-receive samples when creator is a lab contact --- bika/lims/content/bikasetup.py | 13 +++++++++++++ bika/lims/workflow/analysisrequest/events.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/bika/lims/content/bikasetup.py b/bika/lims/content/bikasetup.py index deb249a4ed..e57f8c5a8e 100644 --- a/bika/lims/content/bikasetup.py +++ b/bika/lims/content/bikasetup.py @@ -528,6 +528,19 @@ def getCounterTypes(self, instance=None): " when 'Sampling workflow' is active") ), ), + BooleanField( + "AutoreceiveSamples", + schemata="Sampling", + default=False, + widget=BooleanWidget( + label=_("Auto-receive samples"), + description=_( + "Select to receive the samples automatically when created by " + "lab personnel and sampling workflow is disabled. Samples " + "created by client contacts won't be received automatically" + ), + ), + ), BooleanField( 'ShowPartitions', schemata="Appearance", diff --git a/bika/lims/workflow/analysisrequest/events.py b/bika/lims/workflow/analysisrequest/events.py index 6b902f01c5..d7297424cd 100644 --- a/bika/lims/workflow/analysisrequest/events.py +++ b/bika/lims/workflow/analysisrequest/events.py @@ -24,6 +24,7 @@ from bika.lims.interfaces import IReceived, IVerified, IAnalysisRequestPartition from bika.lims.utils import changeWorkflowState from bika.lims.utils.analysisrequest import create_retest +from bika.lims.workflow import doActionFor as do_action_for from bika.lims.workflow import get_prev_status_from_history from bika.lims.workflow.analysisrequest import AR_WORKFLOW_ID, \ do_action_to_descendants, do_action_to_analyses, do_action_to_ancestors @@ -41,6 +42,22 @@ def before_sample(analysis_request): analysis_request.setSampler(api.get_current_user().id) +def after_no_sampling_workflow(analysis_request): + """Function triggered after "no_sampling_workflow transition for the + Analysis Request passed in is performed + """ + setup = api.get_setup() + if setup.getAutoreceiveSamples(): + # Auto-receive samples is enabled. Receive the sample automatically, + # but only if the current user is a laboratory contact + user = api.get_current_user() + contact = api.get_user_contact(user, contact_types=["LabContact"]) + if contact: + # Note that if current user does not have privileges to receive, + # the sample won't be transitioned, even if we call do_action_for + do_action_for(analysis_request, "receive") + + def after_reject(analysis_request): """Method triggered after a 'reject' transition for the Analysis Request passed in is performed. Cascades the transition to descendants (partitions) From 04be00522051974d021d92f9b1afe37889a81b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Sat, 7 Sep 2019 00:13:33 +0200 Subject: [PATCH 2/3] Updated changelog --- CHANGES.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f8d5064d33..098c52ec46 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,8 @@ Changelog **Added** -- #1431 Added Submitter column in Sample's analyses listing +- #1436 Setting in setup for auto-reception of samples upon creation +- #1433 Added Submitter column in Sample's analyses listing - #1422 Notify user with failing addresses when emailing of results reports - #1420 Allow to detach a partition from its primary sample - #1410 Email API From bcc3c5f7ff8224b9b24deabb2ffb3b2a962980d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Fri, 20 Sep 2019 10:32:26 +0200 Subject: [PATCH 3/3] do_action_for takes care of permissions already --- bika/lims/workflow/analysisrequest/events.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bika/lims/workflow/analysisrequest/events.py b/bika/lims/workflow/analysisrequest/events.py index d7297424cd..59777059f4 100644 --- a/bika/lims/workflow/analysisrequest/events.py +++ b/bika/lims/workflow/analysisrequest/events.py @@ -48,14 +48,10 @@ def after_no_sampling_workflow(analysis_request): """ setup = api.get_setup() if setup.getAutoreceiveSamples(): - # Auto-receive samples is enabled. Receive the sample automatically, - # but only if the current user is a laboratory contact - user = api.get_current_user() - contact = api.get_user_contact(user, contact_types=["LabContact"]) - if contact: - # Note that if current user does not have privileges to receive, - # the sample won't be transitioned, even if we call do_action_for - do_action_for(analysis_request, "receive") + # Auto-receive samples is enabled. Note transition to "received" state + # will only take place if the current user has enough privileges (this + # is handled by do_action_for already). + do_action_for(analysis_request, "receive") def after_reject(analysis_request):