lims_analysis_sheet: Sheets: show when samples do not have all template analysis

This commit is contained in:
Adri?n Bernardi 2020-02-19 19:17:26 -03:00
parent 42c8acc4a5
commit 78f929d99d
3 changed files with 42 additions and 0 deletions

View file

@ -172,6 +172,8 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
], 'State', required=True, readonly=True)
planification = fields.Many2One('lims.planification', 'Planification',
readonly=True)
incomplete_sample = fields.Function(fields.Boolean('Incomplete sample'),
'get_incomplete_sample')
@classmethod
def __setup__(cls):
@ -247,6 +249,41 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
result[s.id] = len(list(set(samples)))
return result
@classmethod
def get_incomplete_sample(cls, sheets, name):
pool = Pool()
Data = pool.get('lims.interface.data')
NotebookLine = pool.get('lims.notebook.line')
result = {}
for s in sheets:
result[s.id] = False
nl_field = (s.template.interface.notebook_line_field and
s.template.interface.notebook_line_field.alias or None)
if not nl_field:
continue
with Transaction().set_context(
lims_interface_table=s.compilation.table.id):
samples = {}
lines = Data.search([('compilation', '=', s.compilation.id)])
for line in lines:
nl = getattr(line, nl_field)
if not nl:
continue
nl = NotebookLine(nl)
if nl.fraction.id not in samples:
samples[nl.fraction.id] = []
samples[nl.fraction.id].append(nl.analysis.id)
template_analysis = [ta.analysis.id
for ta in s.template.analysis]
result[s.id] = False
for k, v in samples.items():
if not all(x in v for x in template_analysis):
result[s.id] = True
break
return result
@classmethod
def create(cls, vlist):
vlist = cls.set_number(vlist)

View file

@ -22,6 +22,10 @@ msgctxt "field:lims.analysis_sheet,id:"
msgid "ID"
msgstr "ID"
msgctxt "field:lims.analysis_sheet,incomplete_sample:"
msgid "Incomplete sample"
msgstr "Muestra incompleta"
msgctxt "field:lims.analysis_sheet,laboratory:"
msgid "Laboratory"
msgstr "Laboratorio"

View file

@ -9,4 +9,5 @@
<field name="state"/>
<button name="activate" string="Activate"/>
<field name="number"/>
<field name="incomplete_sample"/>
</tree>