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

NDEV-60 Status inconsistences in Analyses in secondary Analysis Requests #214

Merged
merged 4 commits into from
Aug 7, 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
19 changes: 18 additions & 1 deletion bika/lims/browser/js/bika.lims.analysisrequest.add_by_col.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ function AnalysisRequestAddByCol() {
uids = [uid, $("#bika_setup").attr("bika_analysisspecs_uid")]
element = $("tr[fieldname=Specification] td[arnum=" + arnum + "] input")[0]
filter_combogrid(element, "getClientUID", uids)
element = $("tr[fieldname=Sample] td[arnum=" + arnum + "] input")[0]
filter_combogrid(element, "getClientUID", uids);
}
/**
* If client only has one contact, then Auto-complete the Contact field.
Expand Down Expand Up @@ -1472,6 +1474,7 @@ function AnalysisRequestAddByCol() {
'_authenticator': $('input[name="_authenticator"]').val()
},
function (data) {
var filled = [];
for (var i = 0; i < data.length; i++) {
var fieldname = data[i][0];
var fieldvalue = data[i][1];
Expand All @@ -1482,6 +1485,13 @@ function AnalysisRequestAddByCol() {
var element = $('#' + fieldname + '-' + arnum)[0]
$(element).attr('uid', fieldvalue)
$(element).val(fieldvalue)
// Sometimes, there are both <fieldname_uid> and
// <fieldname> keys in the data dictionary. In
// those cases, the field that ends with '_uid'
// gets preference over the field that doeesn't
// ends with '_uid' when setting the state value.
filled.push(fieldname);
state_set(arnum, fieldname, fieldvalue);
}
// This
else {
Expand Down Expand Up @@ -1518,7 +1528,14 @@ function AnalysisRequestAddByCol() {
default:
console.log('Unhandled field type for field ' + fieldname + ': ' + element.type)
}
state_set(arnum, fieldname, fieldvalue)
if (filled.indexOf(fieldname) === -1) {
// Sometimes, there are both <fieldname_uid> and
// <fieldname> keys in the data dictionary. In
// those cases, the field that ends with '_uid'
// gets preference over the field that doeesn't
// ends with '_uid' when setting the state value.
state_set(arnum, fieldname, fieldvalue);
}
}
}
})
Expand Down
6 changes: 6 additions & 0 deletions bika/lims/content/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,12 @@ def getPreparationWorkflows(self):
prep_workflows.append([workflow_id, workflow.title])
return DisplayList(prep_workflows)

def getSamplePartitions(self):
"""Returns the Sample Partitions associated to this Sample
"""
partitions = self.objectValues('SamplePartition')
return partitions

@deprecated('[1705] Use events.after_no_sampling_workflow from '
'bika.lims.workflow.sample')
@security.public
Expand Down
44 changes: 29 additions & 15 deletions bika/lims/utils/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,21 @@ def create_analysisrequest(client, request, values, analyses=None,
# Create sample partitions
if not partitions:
partitions = [{'services': service_uids}]

part_num = 0
prefix = sample.getId() + "-P"
if secondary:
# Always create new partitions if is a Secondary AR, cause it does
# not make sense to reuse the partitions used in a previous AR!
sparts = sample.getSamplePartitions()
for spart in sparts:
spartnum = int(spart.getId().split(prefix)[1])
if spartnum > part_num:
part_num = spartnum

for n, partition in enumerate(partitions):
# Calculate partition id
partition_prefix = sample.getId() + "-P"
partition_id = '%s%s' % (partition_prefix, n + 1)
partition_id = '%s%s' % (prefix, part_num + 1)
partition['part_id'] = partition_id
# Point to or create sample partition
if partition_id in sample.objectIds():
Expand All @@ -107,6 +118,7 @@ def create_analysisrequest(client, request, values, analyses=None,
partition,
analyses
)
part_num += 1

# At this point, we have a fully created AR, with a Sample, Partitions and
# Analyses, but the state of all them is the initial ("sample_registered").
Expand All @@ -127,7 +139,11 @@ def create_analysisrequest(client, request, values, analyses=None,
# children) to fit with the Sample Partition's current state
sampleactions = getReviewHistoryActionsList(sample)
doActionsFor(ar, sampleactions)

# We need to transition the partition manually
# Transition pre-preserved partitions
for partition in partitions:
part = partition['object']
doActionsFor(part, sampleactions)
else:
# If Preservation is required for some partitions, and the SamplingWorkflow
# is disabled, we need to transition to to_be_preserved manually.
Expand All @@ -147,18 +163,16 @@ def create_analysisrequest(client, request, values, analyses=None,
doActionFor(p, 'sample_due')
doActionFor(sample, lowest_state)

# Transition pre-preserved partitions
for p in partitions:
if 'prepreserved' in p and p['prepreserved']:
part = p['object']
state = workflow.getInfoFor(part, 'review_state')
if state == 'to_be_preserved':
doActionFor(part, 'preserve')

# Once the ar is fully created, check if there are rejection reasons
reject_field = values.get('RejectionReasons', '')
if reject_field and reject_field.get('checkbox', False):
doActionFor(ar, 'reject')
# Transition pre-preserved partitions
for p in partitions:
if 'prepreserved' in p and p['prepreserved']:
part = p['object']
doActionFor(part, 'preserve')

# Once the ar is fully created, check if there are rejection reasons
reject_field = values.get('RejectionReasons', '')
if reject_field and reject_field.get('checkbox', False):
doActionFor(ar, 'reject')

return ar

Expand Down