1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
from bika.lims import api |
9
|
|
|
from bika.lims import logger |
10
|
|
|
from bika.lims import workflow as wf |
11
|
|
|
from bika.lims.workflow.analysis import events as analysis_events |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def after_submit(reference_analysis): |
15
|
|
|
"""Method triggered after a 'submit' transition for the reference analysis |
16
|
|
|
passed in is performed. |
17
|
|
|
Delegates to bika.lims.workflow.analysis.events.after_submit |
18
|
|
|
""" |
19
|
|
|
analysis_events.after_submit(reference_analysis) |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
def after_verify(reference_analysis): |
23
|
|
|
"""Function called after a 'verify' transition for the reference analysis |
24
|
|
|
passed in is performed |
25
|
|
|
Delegates to bika.lims.workflow.analysis.events.after_verify |
26
|
|
|
""" |
27
|
|
|
analysis_events.after_verify(reference_analysis) |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def after_unassign(reference_analysis): |
31
|
|
|
"""Removes the reference analysis from the system |
32
|
|
|
""" |
33
|
|
|
ref_sample = reference_analysis.aq_parent |
34
|
|
|
ref_sample.manage_delObjects([reference_analysis.getId()]) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
def after_retract(reference_analysis): |
38
|
|
|
"""Function triggered after a 'retract' transition for the reference |
39
|
|
|
analysis passed in is performed. The reference analysis transitions to |
40
|
|
|
"retracted" state and a new copy of the reference analysis is created |
41
|
|
|
""" |
42
|
|
|
reference = reference_analysis.getSample() |
43
|
|
|
service = reference_analysis.getAnalysisService() |
44
|
|
|
worksheet = reference_analysis.getWorksheet() |
45
|
|
|
instrument = reference_analysis.getInstrument() |
46
|
|
|
if worksheet: |
47
|
|
|
# This a reference analysis in a worksheet |
48
|
|
|
slot = worksheet.get_slot_position_for(reference_analysis) |
49
|
|
|
refgid = reference_analysis.getReferenceAnalysesGroupID() |
50
|
|
|
ref = worksheet.add_reference_analysis(reference, service, slot, refgid) |
51
|
|
|
if not ref: |
52
|
|
|
logger.warn("Cannot add a retest for reference analysis {} into {}" |
53
|
|
|
.format(reference_analysis.getId(), worksheet.getId())) |
54
|
|
|
return |
55
|
|
|
|
56
|
|
|
ref.setRetestOf(reference_analysis) |
57
|
|
|
ref.setResult(reference_analysis.getResult()) |
58
|
|
|
if instrument: |
59
|
|
|
ref.setInstrument(instrument) |
60
|
|
|
instrument.reindexObject() |
61
|
|
|
|
62
|
|
|
# Try to rollback the worksheet to prevent inconsistencies |
63
|
|
|
wf.doActionFor(worksheet, "rollback_to_open") |
64
|
|
|
|
65
|
|
|
elif instrument: |
66
|
|
|
# This is an internal calibration test |
67
|
|
|
instrument.addReferences(reference, [api.get_uid(service)]) |
68
|
|
|
instrument.reindexObject() |
69
|
|
|
|