lims_industry: results report: show components list in tree view

This commit is contained in:
Adrián Bernardi 2021-06-22 17:10:36 -03:00
parent b10b7e9475
commit 2853dd1aeb
4 changed files with 154 additions and 0 deletions

View file

@ -398,6 +398,10 @@ msgctxt "field:lims.product.type,attribute_set:"
msgid "Attribute Set"
msgstr "Conjunto de atributos"
msgctxt "field:lims.results_report,components_list:"
msgid "Components"
msgstr "Componentes"
msgctxt "field:lims.results_report,equipments_list:"
msgid "Equipments"
msgstr "Equipos"
@ -406,6 +410,10 @@ msgctxt "field:lims.results_report,plants_list:"
msgid "Plants"
msgstr "Plantas"
msgctxt "field:lims.results_report.version.detail,components_list:"
msgid "Components"
msgstr "Componentes"
msgctxt "field:lims.results_report.version.detail,equipments_list:"
msgid "Equipments"
msgstr "Equipos"

View file

@ -17,6 +17,8 @@ class ResultsReport(metaclass=PoolMeta):
'get_plants_list', searcher='search_plants_list')
equipments_list = fields.Function(fields.Char('Equipments'),
'get_equipments_list', searcher='search_equipments_list')
components_list = fields.Function(fields.Char('Components'),
'get_components_list', searcher='search_components_list')
@classmethod
def get_plants_list(cls, reports, name):
@ -164,6 +166,82 @@ class ResultsReport(metaclass=PoolMeta):
return [('id', '=', -1)]
return [('id', 'in', details_ids)]
@classmethod
def get_components_list(cls, reports, name):
cursor = Transaction().connection.cursor()
pool = Pool()
ComponentType = pool.get('lims.component.type')
Component = pool.get('lims.component')
Sample = pool.get('lims.sample')
Fraction = pool.get('lims.fraction')
Notebook = pool.get('lims.notebook')
ResultsSample = pool.get('lims.results_report.version.detail.sample')
ResultsDetail = pool.get('lims.results_report.version.detail')
ResultsVersion = pool.get('lims.results_report.version')
result = {}
for r in reports:
result[r.id] = ''
cursor.execute('SELECT DISTINCT(ct.name) '
'FROM "' + ComponentType._table + '" ct '
'INNER JOIN "' + Component._table + '" c '
'ON ct.id = c.type '
'INNER JOIN "' + Sample._table + '" s '
'ON c.id = s.component '
'INNER JOIN "' + Fraction._table + '" f '
'ON s.id = f.sample '
'INNER JOIN "' + Notebook._table + '" n '
'ON f.id = n.fraction '
'INNER JOIN "' + ResultsSample._table + '" rs '
'ON n.id = rs.notebook '
'INNER JOIN "' + ResultsDetail._table + '" rd '
'ON rs.version_detail = rd.id '
'INNER JOIN "' + ResultsVersion._table + '" rv '
'ON rd.report_version = rv.id '
'WHERE rv.results_report = %s '
'ORDER BY ct.name', (r.id,))
samples = [x[0] for x in cursor.fetchall()]
if samples:
result[r.id] = ', '.join(samples)
return result
@classmethod
def search_components_list(cls, name, clause):
cursor = Transaction().connection.cursor()
pool = Pool()
ComponentType = pool.get('lims.component.type')
Component = pool.get('lims.component')
Sample = pool.get('lims.sample')
Fraction = pool.get('lims.fraction')
Notebook = pool.get('lims.notebook')
ResultsSample = pool.get('lims.results_report.version.detail.sample')
ResultsDetail = pool.get('lims.results_report.version.detail')
ResultsVersion = pool.get('lims.results_report.version')
value = clause[2]
cursor.execute('SELECT rv.results_report '
'FROM "' + ComponentType._table + '" ct '
'INNER JOIN "' + Component._table + '" c '
'ON ct.id = c.type '
'INNER JOIN "' + Sample._table + '" s '
'ON c.id = s.component '
'INNER JOIN "' + Fraction._table + '" f '
'ON s.id = f.sample '
'INNER JOIN "' + Notebook._table + '" n '
'ON f.id = n.fraction '
'INNER JOIN "' + ResultsSample._table + '" rs '
'ON n.id = rs.notebook '
'INNER JOIN "' + ResultsDetail._table + '" rd '
'ON rs.version_detail = rd.id '
'INNER JOIN "' + ResultsVersion._table + '" rv '
'ON rd.report_version = rv.id '
'WHERE ct.name ILIKE %s',
(value,))
details_ids = [x[0] for x in cursor.fetchall()]
if not details_ids:
return [('id', '=', -1)]
return [('id', 'in', details_ids)]
class ResultsReportVersionDetail(metaclass=PoolMeta):
__name__ = 'lims.results_report.version.detail'
@ -172,6 +250,8 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
'get_plants_list', searcher='search_plants_list')
equipments_list = fields.Function(fields.Char('Equipments'),
'get_equipments_list', searcher='search_equipments_list')
components_list = fields.Function(fields.Char('Components'),
'get_components_list', searcher='search_components_list')
@classmethod
def get_plants_list(cls, details, name):
@ -295,6 +375,70 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
return [('id', '=', -1)]
return [('id', 'in', details_ids)]
@classmethod
def get_components_list(cls, details, name):
cursor = Transaction().connection.cursor()
pool = Pool()
ComponentType = pool.get('lims.component.type')
Component = pool.get('lims.component')
Sample = pool.get('lims.sample')
Fraction = pool.get('lims.fraction')
Notebook = pool.get('lims.notebook')
ResultsSample = pool.get('lims.results_report.version.detail.sample')
result = {}
for d in details:
result[d.id] = ''
cursor.execute('SELECT DISTINCT(ct.name) '
'FROM "' + ComponentType._table + '" ct '
'INNER JOIN "' + Component._table + '" c '
'ON ct.id = c.type '
'INNER JOIN "' + Sample._table + '" s '
'ON c.id = s.component '
'INNER JOIN "' + Fraction._table + '" f '
'ON s.id = f.sample '
'INNER JOIN "' + Notebook._table + '" n '
'ON f.id = n.fraction '
'INNER JOIN "' + ResultsSample._table + '" rs '
'ON n.id = rs.notebook '
'WHERE rs.version_detail = %s '
'ORDER BY ct.name', (d.id,))
samples = [x[0] for x in cursor.fetchall()]
if samples:
result[d.id] = ', '.join(samples)
return result
@classmethod
def search_components_list(cls, name, clause):
cursor = Transaction().connection.cursor()
pool = Pool()
ComponentType = pool.get('lims.component.type')
Component = pool.get('lims.component')
Sample = pool.get('lims.sample')
Fraction = pool.get('lims.fraction')
Notebook = pool.get('lims.notebook')
ResultsSample = pool.get('lims.results_report.version.detail.sample')
value = clause[2]
cursor.execute('SELECT rs.version_detail '
'FROM "' + ComponentType._table + '" ct '
'INNER JOIN "' + Component._table + '" c '
'ON ct.id = c.type '
'INNER JOIN "' + Sample._table + '" s '
'ON c.id = s.component '
'INNER JOIN "' + Fraction._table + '" f '
'ON s.id = f.sample '
'INNER JOIN "' + Notebook._table + '" n '
'ON f.id = n.fraction '
'INNER JOIN "' + ResultsSample._table + '" rs '
'ON n.id = rs.notebook '
'WHERE ct.name ILIKE %s',
(value,))
details_ids = [x[0] for x in cursor.fetchall()]
if not details_ids:
return [('id', '=', -1)]
return [('id', 'in', details_ids)]
class ResultsReportVersionDetailSample(metaclass=PoolMeta):
__name__ = 'lims.results_report.version.detail.sample'

View file

@ -3,5 +3,6 @@
<xpath expr="/tree/field[@name='samples_list']" position="after">
<field name="plants_list"/>
<field name="equipments_list"/>
<field name="components_list"/>
</xpath>
</data>

View file

@ -3,5 +3,6 @@
<xpath expr="/tree/field[@name='samples_list']" position="after">
<field name="plants_list"/>
<field name="equipments_list"/>
<field name="components_list"/>
</xpath>
</data>