lims_analysis_sheet: add wizard to validate limits
This commit is contained in:
parent
c34aaf5653
commit
d17a2c0992
|
@ -62,6 +62,7 @@ def register():
|
|||
notebook.RepeatAnalysis,
|
||||
notebook.CalculateExpressions,
|
||||
notebook.ResultsVerification,
|
||||
notebook.LimitsValidation,
|
||||
notebook.EvaluateRules,
|
||||
notebook.EditGroupedData,
|
||||
module='lims_analysis_sheet', type_='wizard')
|
||||
|
|
|
@ -470,7 +470,7 @@ msgstr "Editar datos"
|
|||
|
||||
msgctxt "model:ir.action,name:wiz_analysis_sheet_evaluate_rules"
|
||||
msgid "Evaluate Rules"
|
||||
msgstr "05) Evaluar Reglas de cuaderno"
|
||||
msgstr "06) Evaluar Reglas de cuaderno"
|
||||
|
||||
msgctxt "model:ir.action,name:wiz_analysis_sheet_export_file"
|
||||
msgid "Export Analysis Sheet File"
|
||||
|
@ -480,6 +480,10 @@ msgctxt "model:ir.action,name:wiz_analysis_sheet_import_file"
|
|||
msgid "Import Analysis Sheet File"
|
||||
msgstr "Importar archivo de datos"
|
||||
|
||||
msgctxt "model:ir.action,name:wiz_analysis_sheet_limits_validation"
|
||||
msgid "Limits Validation"
|
||||
msgstr "05) Validación de límites"
|
||||
|
||||
msgctxt "model:ir.action,name:wiz_analysis_sheet_open_data"
|
||||
msgid "Open Analysis Sheet Data"
|
||||
msgstr "Abrir datos de Hoja de análisis"
|
||||
|
@ -558,11 +562,15 @@ msgid "Template \"%(template)s\" has no associated report"
|
|||
msgstr "La plantilla «%(template)s» no tiene informe asociado"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_template_not_result_field"
|
||||
msgid "The template does not have a column for the result field"
|
||||
msgid "The template does not have a column for the Result field"
|
||||
msgstr "La plantilla no tiene una columna para el campo Resultado"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_template_not_result_modifier_field"
|
||||
msgid "The template does not have a column for the Result modifier field"
|
||||
msgstr "La plantilla no tiene una columna para el campo Modificador de resultado"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_template_not_verification_field"
|
||||
msgid "The template does not have a column for the verification field"
|
||||
msgid "The template does not have a column for the Verification field"
|
||||
msgstr "La plantilla no tiene una columna para el campo Verificación"
|
||||
|
||||
msgctxt "model:ir.sequence,name:seq_analysis_sheet"
|
||||
|
|
|
@ -20,10 +20,13 @@
|
|||
<field name="text">Template "%(template)s" has no associated report</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_template_not_result_field">
|
||||
<field name="text">The template does not have a column for the result field</field>
|
||||
<field name="text">The template does not have a column for the Result field</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_template_not_result_modifier_field">
|
||||
<field name="text">The template does not have a column for the Result modifier field</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_template_not_verification_field">
|
||||
<field name="text">The template does not have a column for the verification field</field>
|
||||
<field name="text">The template does not have a column for the Verification field</field>
|
||||
</record>
|
||||
<record model="ir.message" id="delete_done_sheet">
|
||||
<field name="text">You cannot delete an Analysis Sheet in "Done" state</field>
|
||||
|
|
|
@ -821,44 +821,28 @@ class ResultsVerification(Wizard):
|
|||
def transition_verify(self):
|
||||
pool = Pool()
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
ModelField = pool.get('ir.model.field')
|
||||
Field = pool.get('lims.interface.table.field')
|
||||
Data = pool.get('lims.interface.data')
|
||||
|
||||
sheet_id = self._get_analysis_sheet_id()
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
table_id = sheet.compilation.table.id
|
||||
|
||||
nl_result_field, = ModelField.search([
|
||||
('model.model', '=', 'lims.notebook.line'),
|
||||
('name', '=', 'result'),
|
||||
])
|
||||
result_column = Field.search([
|
||||
('table', '=', sheet.compilation.table.id),
|
||||
('transfer_field', '=', True),
|
||||
('related_line_field', '=', nl_result_field),
|
||||
])
|
||||
result_column = self._get_template_column(
|
||||
'result', table_id)
|
||||
if not result_column:
|
||||
raise UserError(gettext(
|
||||
'lims_analysis_sheet.msg_template_not_result_field'))
|
||||
raise UserError(gettext('lims_analysis_sheet.'
|
||||
'msg_template_not_result_field'))
|
||||
result_field = result_column.name
|
||||
|
||||
nl_verification_field, = ModelField.search([
|
||||
('model.model', '=', 'lims.notebook.line'),
|
||||
('name', '=', 'verification'),
|
||||
])
|
||||
verification_column = Field.search([
|
||||
('table', '=', sheet.compilation.table.id),
|
||||
('transfer_field', '=', True),
|
||||
('related_line_field', '=', nl_verification_field),
|
||||
])
|
||||
verification_column = self._get_template_column(
|
||||
'verification', table_id)
|
||||
if not verification_column:
|
||||
raise UserError(gettext(
|
||||
'lims_analysis_sheet.msg_template_not_verification_field'))
|
||||
raise UserError(gettext('lims_analysis_sheet.'
|
||||
'msg_template_not_verification_field'))
|
||||
verification_field = verification_column.name
|
||||
|
||||
result_field = result_column[0].name
|
||||
verification_field = verification_column[0].name
|
||||
notebook_lines = {}
|
||||
with Transaction().set_context(
|
||||
lims_interface_table=sheet.compilation.table.id):
|
||||
with Transaction().set_context(lims_interface_table=table_id):
|
||||
lines = Data.search([('compilation', '=', sheet.compilation.id)])
|
||||
for line in lines:
|
||||
nl = line.notebook_line
|
||||
|
@ -877,6 +861,22 @@ class ResultsVerification(Wizard):
|
|||
|
||||
return 'end'
|
||||
|
||||
def _get_template_column(self, field_name, table_id):
|
||||
pool = Pool()
|
||||
ModelField = pool.get('ir.model.field')
|
||||
Field = pool.get('lims.interface.table.field')
|
||||
|
||||
nl_field, = ModelField.search([
|
||||
('model.model', '=', 'lims.notebook.line'),
|
||||
('name', '=', field_name),
|
||||
])
|
||||
table_column = Field.search([
|
||||
('table', '=', table_id),
|
||||
('transfer_field', '=', True),
|
||||
('related_line_field', '=', nl_field),
|
||||
])
|
||||
return table_column and table_column[0] or None
|
||||
|
||||
def _get_result_verification(self, result, notebook_line):
|
||||
pool = Pool()
|
||||
Range = pool.get('lims.range')
|
||||
|
@ -996,6 +996,128 @@ class ResultsVerification(Wizard):
|
|||
return 'reload'
|
||||
|
||||
|
||||
class LimitsValidation(Wizard):
|
||||
'Limits Validation'
|
||||
__name__ = 'lims.analysis_sheet.limits_validation'
|
||||
|
||||
start_state = 'check'
|
||||
check = StateTransition()
|
||||
validate_limits = StateTransition()
|
||||
|
||||
def _get_analysis_sheet_id(self):
|
||||
return Transaction().context.get('lims_analysis_sheet', None)
|
||||
|
||||
def transition_check(self):
|
||||
AnalysisSheet = Pool().get('lims.analysis_sheet')
|
||||
|
||||
sheet_id = self._get_analysis_sheet_id()
|
||||
if sheet_id:
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
if sheet.state in ('active', 'validated'):
|
||||
return 'validate_limits'
|
||||
|
||||
return 'end'
|
||||
|
||||
def transition_validate_limits(self):
|
||||
pool = Pool()
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
Data = pool.get('lims.interface.data')
|
||||
NotebookLine = pool.get('lims.notebook.line')
|
||||
|
||||
unattended = Transaction().context.get('unattended', False)
|
||||
|
||||
sheet_id = self._get_analysis_sheet_id()
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
table_id = sheet.compilation.table.id
|
||||
|
||||
result_column = self._get_template_column(
|
||||
'result', table_id)
|
||||
if not result_column:
|
||||
if unattended:
|
||||
return 'end'
|
||||
raise UserError(gettext('lims_analysis_sheet.'
|
||||
'msg_template_not_result_field'))
|
||||
result_field = result_column.name
|
||||
|
||||
result_modifier_column = self._get_template_column(
|
||||
'result_modifier', table_id)
|
||||
if not result_modifier_column:
|
||||
if unattended:
|
||||
return 'end'
|
||||
raise UserError(gettext('lims_analysis_sheet.'
|
||||
'msg_template_not_result_modifier_field'))
|
||||
result_modifier_field = result_modifier_column.name
|
||||
|
||||
with Transaction().set_context(lims_interface_table=table_id):
|
||||
lines = Data.search([('compilation', '=', sheet.compilation.id)])
|
||||
for line in lines:
|
||||
nl = line.notebook_line
|
||||
if not nl:
|
||||
continue
|
||||
|
||||
result = getattr(line, result_field)
|
||||
if not result:
|
||||
continue
|
||||
result_modifier = getattr(line, result_modifier_field) or 'eq'
|
||||
if result_modifier != 'eq':
|
||||
continue
|
||||
try:
|
||||
value = float(result)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
try:
|
||||
dl = float(nl.detection_limit)
|
||||
ql = float(nl.quantification_limit)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
ll = nl.lower_limit and float(nl.lower_limit) or None
|
||||
ul = nl.upper_limit and float(nl.upper_limit) or None
|
||||
|
||||
data = {}
|
||||
if (ll and value < ll) or (ul and value > ul):
|
||||
raise UserError(gettext(
|
||||
'lims.msg_error_limits_allowed',
|
||||
line=nl.rec_name))
|
||||
if dl < value and value < ql:
|
||||
data[result_field] = str(ql)
|
||||
data[result_modifier_field] = 'low'
|
||||
elif value < dl:
|
||||
data[result_field] = None
|
||||
data[result_modifier_field] = 'nd'
|
||||
elif value == dl:
|
||||
data[result_field] = str(ql)
|
||||
data[result_modifier_field] = 'low'
|
||||
else:
|
||||
data[result_modifier_field] = 'eq'
|
||||
|
||||
if data:
|
||||
Data.write([line], data)
|
||||
if data[result_modifier_field] != 'eq':
|
||||
NotebookLine.write([nl], {'backup': str(value)})
|
||||
|
||||
return 'end'
|
||||
|
||||
def _get_template_column(self, field_name, table_id):
|
||||
pool = Pool()
|
||||
ModelField = pool.get('ir.model.field')
|
||||
Field = pool.get('lims.interface.table.field')
|
||||
|
||||
nl_field, = ModelField.search([
|
||||
('model.model', '=', 'lims.notebook.line'),
|
||||
('name', '=', field_name),
|
||||
])
|
||||
table_column = Field.search([
|
||||
('table', '=', table_id),
|
||||
('transfer_field', '=', True),
|
||||
('related_line_field', '=', nl_field),
|
||||
])
|
||||
return table_column and table_column[0] or None
|
||||
|
||||
def end(self):
|
||||
return 'reload'
|
||||
|
||||
|
||||
class EvaluateRules(Wizard):
|
||||
'Evaluate Rules'
|
||||
__name__ = 'lims.analysis_sheet.evaluate_rules'
|
||||
|
|
|
@ -90,6 +90,19 @@
|
|||
<field name="action" ref="wiz_analysis_sheet_results_verification"/>
|
||||
</record>
|
||||
|
||||
<!-- Wizard Limits Validation -->
|
||||
|
||||
<record model="ir.action.wizard" id="wiz_analysis_sheet_limits_validation">
|
||||
<field name="name">Limits Validation</field>
|
||||
<field name="wiz_name">lims.analysis_sheet.limits_validation</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.keyword" id="wiz_analysis_sheet_limits_validation_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">lims.interface.data,-1</field>
|
||||
<field name="action" ref="wiz_analysis_sheet_limits_validation"/>
|
||||
</record>
|
||||
|
||||
<!-- Wizard Evaluate Rules -->
|
||||
|
||||
<record model="ir.action.wizard" id="wiz_analysis_sheet_evaluate_rules">
|
||||
|
|
Loading…
Reference in New Issue