lims: sample: fix annulled state computation (2)

This commit is contained in:
Adrián Bernardi 2021-07-09 10:43:26 -03:00
parent 31f6bddf40
commit 48da1207b4

View file

@ -3352,10 +3352,20 @@ class Sample(ModelSQL, ModelView):
'INNER JOIN "' + Fraction._table + '" f '
'ON f.id = s.fraction '
'WHERE f.sample = %s '
'AND nl.annulled = FALSE',
'AND nl.annulled = TRUE',
(self.id,))
if cursor.fetchone()[0] == 0:
return 'annulled'
annulled_lines = cursor.fetchone()[0]
if annulled_lines > 0:
cursor.execute('SELECT COUNT(*) '
'FROM "' + NotebookLine._table + '" nl '
'INNER JOIN "' + Service._table + '" s '
'ON s.id = nl.service '
'INNER JOIN "' + Fraction._table + '" f '
'ON f.id = s.fraction '
'WHERE f.sample = %s',
(self.id,))
if cursor.fetchone()[0] == annulled_lines:
return 'annulled'
if self.laboratory_end_date:
return 'lab_pending_acceptance'
if self.laboratory_start_date: