lims: add relation to Department in Product type and show it in Samples

This commit is contained in:
Adrián Bernardi 2020-04-20 11:34:40 -03:00
parent a907e12adc
commit 22cfb5d2c5
10 changed files with 74 additions and 4 deletions

View file

@ -656,6 +656,7 @@ class ProductType(ModelSQL, ModelView):
code = fields.Char('Code', required=True)
description = fields.Char('Description', required=True)
restricted_entry = fields.Boolean('Restricted entry')
department = fields.Many2One('company.department', 'Department')
@classmethod
def __setup__(cls):

View file

@ -861,6 +861,7 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
Method = pool.get('lims.lab.method')
WaitingTime = pool.get('lims.lab.method.results_waiting')
AnalysisLaboratory = pool.get('lims.analysis-laboratory')
ProductType = pool.get('lims.product.type')
Notebook = pool.get('lims.notebook')
Company = pool.get('company.company')
@ -909,6 +910,7 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
decimals = 2
report = False
results_estimated_waiting = None
cursor.execute('SELECT results_estimated_waiting '
'FROM "' + WaitingTime._table + '" '
'WHERE method = %s '
@ -922,15 +924,25 @@ class EntryDetailAnalysis(ModelSQL, ModelView):
'FROM "' + Method._table + '" '
'WHERE id = %s', (detail.method.id,))
res = cursor.fetchone()
results_estimated_waiting = res and res[0] or None
if res:
results_estimated_waiting = res[0]
department = None
cursor.execute('SELECT department '
'FROM "' + AnalysisLaboratory._table + '" '
'WHERE analysis = %s '
'AND laboratory = %s',
(detail.analysis.id, detail.laboratory.id))
res = cursor.fetchone()
department = res and res[0] or None
if res and res[0]:
department = res[0]
else:
cursor.execute('SELECT department '
'FROM "' + ProductType._table + '" '
'WHERE id = %s', (fraction.product_type.id,))
res = cursor.fetchone()
if res and res[0]:
department = res[0]
for i in range(0, repetitions + 1):
notebook_line = {

View file

@ -4224,6 +4224,10 @@ msgctxt "field:lims.planification.search_fractions.detail,create_date2:"
msgid "Create Date"
msgstr "Fecha de creación"
msgctxt "field:lims.planification.search_fractions.detail,department:"
msgid "Department"
msgstr "Departamento"
msgctxt "field:lims.planification.search_fractions.detail,fraction:"
msgid "Fraction"
msgstr "Fracción"
@ -4464,6 +4468,10 @@ msgctxt "field:lims.product.type,code:"
msgid "Code"
msgstr "Código"
msgctxt "field:lims.product.type,department:"
msgid "Department"
msgstr "Departamento"
msgctxt "field:lims.product.type,description:"
msgid "Description"
msgstr "Descripción"
@ -5021,6 +5029,10 @@ msgctxt "field:lims.sample,date:"
msgid "Date"
msgstr "Fecha de ingreso"
msgctxt "field:lims.sample,department:"
msgid "Department"
msgstr "Departamento"
msgctxt "field:lims.sample,entry:"
msgid "Entry"
msgstr "Ingreso"

View file

@ -3719,6 +3719,8 @@ class SearchFractionsDetail(ModelSQL, ModelView):
'get_service_field')
completion_percentage = fields.Function(fields.Numeric('Complete',
digits=(1, 4)), 'get_completion_percentage')
department = fields.Function(fields.Many2One('company.department',
'Department'), 'get_department', searcher='search_department')
session_id = fields.Integer('Session ID')
@classmethod
@ -3781,6 +3783,18 @@ class SearchFractionsDetail(ModelSQL, ModelView):
result[d.id] = getattr(d.fraction.sample, name, None)
return result
@classmethod
def get_department(cls, details, name):
result = {}
for d in details:
field = getattr(d.product_type, name, None)
result[d.id] = field.id if field else None
return result
@classmethod
def search_department(cls, name, clause):
return [('product_type.' + name,) + tuple(clause[1:])]
class SearchFractions(Wizard):
'Search Fractions'

View file

@ -2335,6 +2335,8 @@ class Sample(ModelSQL, ModelView):
('completion_percentage', '<=', 1),
]),
'get_completion_percentage')
department = fields.Function(fields.Many2One('company.department',
'Department'), 'get_department', searcher='search_department')
@classmethod
def __setup__(cls):
@ -2838,6 +2840,18 @@ class Sample(ModelSQL, ModelView):
Decimal(accepted) / Decimal(total)
).quantize(Decimal(str(10 ** -digits)))
@classmethod
def get_department(cls, samples, name):
result = {}
for s in samples:
field = getattr(s.product_type, name, None)
result[s.id] = field.id if field else None
return result
@classmethod
def search_department(cls, name, clause):
return [('product_type.' + name,) + tuple(clause[1:])]
class DuplicateSampleStart(ModelView):
'Copy Sample'

View file

@ -12,4 +12,5 @@
<field name="report_date"/>
<field name="create_date2" widget="date"/>
<field name="completion_percentage" widget="progressbar"/>
<field name="department"/>
</tree>

View file

@ -6,4 +6,6 @@
<field name="description"/>
<label name="restricted_entry"/>
<field name="restricted_entry"/>
<label name="department"/>
<field name="department"/>
</form>

View file

@ -3,4 +3,5 @@
<field name="code"/>
<field name="description"/>
<field name="restricted_entry"/>
<field name="department"/>
</tree>

View file

@ -20,6 +20,7 @@
<field name="zone"/>
<field name="trace_report"/>
<field name="urgent"/>
<field name="department"/>
<field name="confirmed" tree_invisible="1" />
<field name="has_results_report" tree_invisible="1" />
</tree>

View file

@ -282,6 +282,7 @@ class EntryDetailAnalysis(metaclass=PoolMeta):
Method = pool.get('lims.lab.method')
WaitingTime = pool.get('lims.lab.method.results_waiting')
AnalysisLaboratory = pool.get('lims.analysis-laboratory')
ProductType = pool.get('lims.product.type')
Notebook = pool.get('lims.notebook')
Company = pool.get('company.company')
@ -342,6 +343,7 @@ class EntryDetailAnalysis(metaclass=PoolMeta):
decimals = 2
report = False
results_estimated_waiting = None
cursor.execute('SELECT results_estimated_waiting '
'FROM "' + WaitingTime._table + '" '
'WHERE method = %s '
@ -355,15 +357,25 @@ class EntryDetailAnalysis(metaclass=PoolMeta):
'FROM "' + Method._table + '" '
'WHERE id = %s', (detail.method.id,))
res = cursor.fetchone()
results_estimated_waiting = res and res[0] or None
if res:
results_estimated_waiting = res[0]
department = None
cursor.execute('SELECT department '
'FROM "' + AnalysisLaboratory._table + '" '
'WHERE analysis = %s '
'AND laboratory = %s',
(detail.analysis.id, detail.laboratory.id))
res = cursor.fetchone()
department = res and res[0] or None
if res and res[0]:
department = res[0]
else:
cursor.execute('SELECT department '
'FROM "' + ProductType._table + '" '
'WHERE id = %s', (fraction.product_type.id,))
res = cursor.fetchone()
if res and res[0]:
department = res[0]
for i in range(0, repetitions + 1):
notebook_line = {