mirror of
https://github.com/beak-insights/felicity-lims.git
synced 2025-02-24 08:53:00 +08:00
fidex ar cancellations and bulk rejection errors
This commit is contained in:
parent
fa2be4dbd5
commit
1aba6c91b2
2 changed files with 17 additions and 11 deletions
|
@ -250,7 +250,7 @@ async def cancel_samples(info, samples: List[int]) -> ResultedSampleActionRespon
|
|||
# only samples with unassigned analyses can be cancelled
|
||||
analysis_results = await sample.get_analysis_results()
|
||||
match = [result.assigned for result in analysis_results]
|
||||
if not all(match):
|
||||
if any(match):
|
||||
return_samples.append(sample)
|
||||
continue
|
||||
|
||||
|
@ -356,22 +356,29 @@ async def reject_samples(
|
|||
if not sample:
|
||||
return OperationError(error=f"Sample with uid {_sam.uid} not found")
|
||||
|
||||
reasons = []
|
||||
for re_uid in _sam.reasons:
|
||||
reason = await analysis_models.RejectionReason.get(uid=re_uid)
|
||||
if not reason:
|
||||
return OperationError(
|
||||
error=f"RejectionReason with uid {re_uid} not found"
|
||||
)
|
||||
reasons.append(reason)
|
||||
|
||||
sample = await sample.reject(reasons=reasons, rejected_by=felicity_user)
|
||||
if sample:
|
||||
return_samples.append(sample)
|
||||
# TODO: Transactions
|
||||
sample = await sample.reject(rejected_by=felicity_user)
|
||||
await analysis_models.Sample.table_insert(
|
||||
analysis_models.sample_rejection_reason,
|
||||
{
|
||||
"sample_uid": sample.uid,
|
||||
"rejection_reason_uid": reason.uid
|
||||
}
|
||||
)
|
||||
|
||||
if sample.status == states.sample.REJECTED:
|
||||
for analyte in sample.analysis_results:
|
||||
await analyte.cancel(cancelled_by=felicity_user)
|
||||
if sample:
|
||||
return_samples.append(sample)
|
||||
|
||||
if sample.status == states.sample.REJECTED:
|
||||
for analyte in sample.analysis_results:
|
||||
await analyte.cancel(cancelled_by=felicity_user)
|
||||
|
||||
return SampleListingType(return_samples)
|
||||
|
||||
|
|
|
@ -667,11 +667,10 @@ class Sample(Auditable, BaseMPTT):
|
|||
return copy, invalidated
|
||||
return copy, self
|
||||
|
||||
async def reject(self, reasons, rejected_by):
|
||||
async def reject(self, rejected_by):
|
||||
statuses = [states.sample.RECEIVED, states.sample.EXPECTED]
|
||||
if self.status in statuses:
|
||||
self.status = states.sample.REJECTED
|
||||
self.rejection_reasons = reasons
|
||||
self.received_by_uid = rejected_by.uid
|
||||
self.updated_by_uid = rejected_by.uid # noqa
|
||||
rejected = await self.save()
|
||||
|
|
Loading…
Reference in a new issue