Skip to content

Commit

Permalink
Merge pull request #1814 from naralabs/issue/LIMS-2266-create-parts
Browse files Browse the repository at this point in the history
Crating partitions through Add form, doesn't create partitions.
  • Loading branch information
xispa committed Jul 1, 2016
2 parents 0453784 + 9c79dac commit 1428bab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
1 change: 0 additions & 1 deletion bika/lims/browser/analysisrequest/add.py
@@ -1,6 +1,5 @@
import json
from bika.lims.utils.sample import create_sample
from bika.lims.utils.samplepartition import create_samplepartition
from bika.lims.workflow import doActionFor
import plone

Expand Down
24 changes: 15 additions & 9 deletions bika/lims/utils/analysisrequest.py
Expand Up @@ -37,17 +37,19 @@ def create_analysisrequest(context, request, values, analyses=None,
# Gather neccesary tools
workflow = getToolByName(context, 'portal_workflow')
bc = getToolByName(context, 'bika_catalog')

# Analyses are analyses services
analyses_services = analyses
analyses = []
# It's necessary to modify these and we don't want to pollute the
# parent's data
values = values.copy()
analyses = analyses if analyses else []
analyses_services = analyses_services if analyses_services else []
anv = values['Analyses'] if values.get('Analyses', None) else []
analyses = anv + analyses
analyses_services = anv + analyses_services

if not analyses:
if not analyses_services:
raise RuntimeError(
"create_analysisrequest: no analyses provided")
"create_analysisrequest: no analyses services provided")

# Create new sample or locate the existing for secondary AR
if not values.get('Sample', False):
Expand All @@ -74,9 +76,13 @@ def create_analysisrequest(context, request, values, analyses=None,
workflow.doActionFor(ar, action)

# Set analysis request analyses
service_uids = _resolve_items_to_service_uids(analyses)
analyses = ar.setAnalyses(service_uids, prices=prices, specs=specifications)

service_uids = _resolve_items_to_service_uids(analyses_services)
# processForm already has created the analyses, but here we create the
# analyses with specs and prices. This function, even it is called 'set',
# deletes the old analyses, so eventually we obtain the desired analyses.
ar.setAnalyses(service_uids, prices=prices, specs=specifications)
# Gettin the ar objects
analyses = ar.getAnalyses(full_objects=True)
# Continue to set the state of the AR
skip_receive = ['to_be_sampled', 'sample_due', 'sampled', 'to_be_preserved']
if secondary:
Expand All @@ -98,7 +104,7 @@ def create_analysisrequest(context, request, values, analyses=None,
if not secondary:
# Create sample partitions
if not partitions:
partitions = [{'services': analyses}]
partitions = [{'services': service_uids}]
for n, partition in enumerate(partitions):
# Calculate partition id
partition_prefix = sample.getId() + "-P"
Expand Down
10 changes: 9 additions & 1 deletion bika/lims/utils/samplepartition.py
Expand Up @@ -33,6 +33,14 @@ def set_container_preservation(context, container, data):


def create_samplepartition(context, data, analyses=[]):
"""
This function creates a partition object.
:returns: a whole partition object
:data: is a dictionary with some important data to create the partition,
where the most important keys are: part_id and services
{'part_id':xx, 'container_uid', xxxx, 'services': xxxx, 'part_id':xxx, ...}
:analyses: A list of full object analyses
"""
partition = _createObjectByType('SamplePartition', context, data['part_id'])
partition.unmarkCreationFlag()
# Determine if the sampling workflow is enabled
Expand Down Expand Up @@ -72,7 +80,7 @@ def create_samplepartition(context, data, analyses=[]):
for analysis in analyses:
analysis.setSamplePartition(partition)
# Perform the appropriate workflow action
workflow_action = 'sampling_workflow' if workflow_enabled \
workflow_action = 'sampling_workflow' if workflow_enabled \
else 'no_sampling_workflow'
context.portal_workflow.doActionFor(partition, workflow_action)
# Return the created partition
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Expand Up @@ -2,6 +2,7 @@
------------------
LIMS-2261: Cannot create analysis request
LIMS-1562: Using a Sample Round. Basic form and printed form
LIMS-2266: Crating partitions through Add form, doesn't create partitions.
HEALTH-394: Sample sticker layout. 2 new sticker layouts, 2 stickers per row
LIMS-2032: AS Methods initialise with 1st available Instrument (loading setup data)
LIMS-2014: I can only select a Default Method for an AS if Manual results capture is on
Expand Down

0 comments on commit 1428bab

Please sign in to comment.