Skip to content

Commit

Permalink
Fix Traceback when invalidating a Sample with Remarks (senaite#2129)
Browse files Browse the repository at this point in the history
* Omit Remarks field when creating a retest from an invalidated sample

* Do not reindex unless non-temporary when Remarks value is set

* Changelog

* Misspelling

* Add doctest that checks if value for Remarks field is copied in retests
  • Loading branch information
xispa committed Sep 13, 2022
1 parent 97ce14b commit 62b538b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
2.3.0 (unreleased)
------------------

- #2129 Fix Traceback when invalidating a Sample with Remarks
- #2128 Fix referenceresults widget view mode
- #2127 Fix instrument expiry date display in listing view
- #2123 Add Sample Form: Save and Copy Action
- #2119 Fix linked client contact user can not see existing samples
Expand Down
14 changes: 8 additions & 6 deletions src/bika/lims/browser/fields/remarksfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,16 @@ def set(self, instance, value, **kwargs):
# Store the data
ObjectField.set(self, instance, history)

# N.B. ensure updated catalog metadata for the snapshot
instance.reindexObject()
if not api.is_temporary(instance):

# notify object edited event
event.notify(ObjectEditedEvent(instance))
# N.B. ensure updated catalog metadata for the snapshot
instance.reindexObject()

# notify new remarks for e.g. later email notification etc.
event.notify(RemarksAddedEvent(instance, history))
# notify object edited event
event.notify(ObjectEditedEvent(instance))

# notify new remarks for e.g. later email notification etc.
event.notify(RemarksAddedEvent(instance, history))

def to_safe_html(self, html):
# see: Products.PortalTransforms.tests.test_xss
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/utils/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def create_retest(ar):
actions_pool.queue_pool()

# Create the Retest (Analysis Request)
ignore = ['Analyses', 'DatePublished', 'Invalidated', 'Sample']
ignore = ['Analyses', 'DatePublished', 'Invalidated', 'Sample', 'Remarks']
retest = _createObjectByType("AnalysisRequest", ar.aq_parent, tmpID())
copy_field_values(ar, retest, ignore_fieldnames=ignore)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,48 @@ User with other roles cannot:
Reset settings:

>>> setRoles(portal, TEST_USER_ID, ['LabManager',])


Remarks field is not copied from invalidated to retest
......................................................

Create a Sample and receive:

>>> ar = new_ar([Cu])
>>> success = do_action_for(ar, "receive")

Add some Remarks:

>>> ar.setRemarks("This is the first remark")
>>> ar.setRemarks("This is the second remark")
>>> ar.getRemarks()
[{...}]

Submit results and verify them:

>>> setup.setSelfVerificationEnabled(True)
>>> for analysis in ar.getAnalyses(full_objects=True):
... analysis.setResult(12)
... submitted = do_action_for(analysis, "submit")
... verified = do_action_for(analysis, "verify")
>>> setup.setSelfVerificationEnabled(False)
>>> api.get_workflow_status_of(ar)
'verified'

Invalidate the sample:

>>> success = do_action_for(ar, "invalidate")
>>> api.get_workflow_status_of(ar)
'invalid'

>>> retest = ar.getRetest()
>>> retest
<AnalysisRequest at /plone/clients/client-1/W-0004-R01>

The value for Remarks field has not been copied to the retest:

>>> retest.getRemarks()
[]

>>> ar.getRemarks()
[{...}]

0 comments on commit 62b538b

Please sign in to comment.