lims_analysis_sheet: allow disable analysis sheet templates

This commit is contained in:
Adrián Bernardi 2021-07-15 11:11:33 -03:00
parent da66fbae2f
commit 66d6eafd00
7 changed files with 87 additions and 45 deletions

View File

@ -22,6 +22,10 @@ msgctxt "field:lims.analysis_sheet,date:"
msgid "Date"
msgstr "Fecha"
msgctxt "field:lims.analysis_sheet,interface:"
msgid "Interface"
msgstr "Interfaz"
msgctxt "field:lims.analysis_sheet,laboratory:"
msgid "Laboratory"
msgstr "Laboratorio"

View File

@ -29,21 +29,27 @@ class NotebookLine(metaclass=PoolMeta):
def get_analysis_sheet_template(self):
cursor = Transaction().connection.cursor()
pool = Pool()
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND method = %s',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND ta.method = %s',
(self.analysis.id, self.method.id))
template = cursor.fetchone()
if not template:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND method IS NULL',
(self.analysis.id, ))
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'WHERE ta.analysis = %s '
'AND ta.method IS NULL',
(self.analysis.id,))
template = cursor.fetchone()
return template and template[0] or None

View File

@ -143,6 +143,7 @@ class SearchAnalysisSheet(Wizard):
Fraction = pool.get('lims.fraction')
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
Analysis = pool.get('lims.analysis')
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
cursor.execute('SELECT nl.id '
@ -196,10 +197,13 @@ class SearchAnalysisSheet(Wizard):
result = []
for nl in notebook_lines:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(nl[0], nl[1]))
template = cursor.fetchone()
if template:
@ -493,6 +497,7 @@ class RelateTechnicians(metaclass=PoolMeta):
NotebookLine = pool.get('lims.notebook.line')
RelateTechniciansDetail4 = pool.get(
'lims.planification.relate_technicians.detail4')
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
Service = pool.get('lims.service')
@ -523,10 +528,13 @@ class RelateTechnicians(metaclass=PoolMeta):
exclude_relateds_clause,
(planification_id,))
for x in cursor.fetchall():
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(x[1], x[2]))
template = cursor.fetchone()
t = template and template[0] or None
@ -952,10 +960,13 @@ class SamplesPendingPlanning(ModelSQL, ModelView):
result = []
for nl in notebook_lines:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(nl[0], nl[1]))
template_id = cursor.fetchone()
if template_id:

View File

@ -9,7 +9,8 @@ from sql import Table, Column, Literal, Null
from sql.aggregate import Count
from sql.conditionals import Coalesce
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
from trytond.model import Workflow, ModelView, ModelSQL, DeactivableMixin, \
fields, Unique
from trytond.wizard import Wizard, StateTransition, StateView, StateAction, \
Button
from trytond.pool import Pool
@ -22,7 +23,7 @@ from trytond.modules.lims_interface.interface import str2date, \
get_model_resource
class TemplateAnalysisSheet(ModelSQL, ModelView):
class TemplateAnalysisSheet(DeactivableMixin, ModelSQL, ModelView):
'Analysis Sheet Template'
__name__ = 'lims.template.analysis_sheet'
@ -90,6 +91,7 @@ class TemplateAnalysisSheet(ModelSQL, ModelView):
Fraction = pool.get('lims.fraction')
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
Analysis = pool.get('lims.analysis')
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
result = {
@ -155,10 +157,13 @@ class TemplateAnalysisSheet(ModelSQL, ModelView):
templates = {}
for nl in notebook_lines:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(nl[0], nl[1]))
template = cursor.fetchone()
if not template:
@ -186,6 +191,7 @@ class TemplateAnalysisSheet(ModelSQL, ModelView):
Fraction = pool.get('lims.fraction')
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
Analysis = pool.get('lims.analysis')
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
date_from = context.get('date_from') or str(date.min)
@ -250,10 +256,13 @@ class TemplateAnalysisSheet(ModelSQL, ModelView):
urgent_templates = []
for nl in urgent_lines:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(nl[0], nl[1]))
template = cursor.fetchone()
if not template:

View File

@ -8,6 +8,8 @@
<field name="report"/>
<label name="controls_required"/>
<field name="controls_required"/>
<label name="active"/>
<field name="active"/>
<notebook>
<page string="Analysis" id="analysis">
<field name="analysis" colspan="4"/>

View File

@ -46,6 +46,7 @@ class BoardLaboratory(metaclass=PoolMeta):
Fraction = pool.get('lims.fraction')
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
Analysis = pool.get('lims.analysis')
Template = pool.get('lims.template.analysis_sheet')
TemplateAnalysis = pool.get('lims.template.analysis_sheet.analysis')
cursor.execute('SELECT nl.id '
@ -95,10 +96,13 @@ class BoardLaboratory(metaclass=PoolMeta):
result = []
for nl in notebook_lines:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND (method = %s OR method IS NULL)',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND (ta.method = %s OR ta.method IS NULL)',
(nl[0], nl[1]))
template = cursor.fetchone()
if template:

View File

@ -180,19 +180,25 @@ class Typification(metaclass=PoolMeta):
result = {}
for t in typifications:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND method = %s',
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'AND ta.analysis = %s '
'AND ta.method = %s',
(t.analysis.id, t.method.id))
template_id = cursor.fetchone()
result[t.id] = None
if not template_id:
cursor.execute('SELECT template '
'FROM "' + TemplateAnalysis._table + '" '
'WHERE analysis = %s '
'AND method IS NULL',
(t.analysis.id, ))
cursor.execute('SELECT t.id '
'FROM "' + Template._table + '" t '
'INNER JOIN "' + TemplateAnalysis._table + '" ta '
'ON t.id = ta.template '
'WHERE t.active IS TRUE '
'WHERE ta.analysis = %s '
'AND ta.method IS NULL',
(t.analysis.id,))
template_id = cursor.fetchone()
if template_id:
template = Template(template_id[0])