lims, lims_analysis_sheet: notebook rules: allow to set target method

This commit is contained in:
Adrián Bernardi 2022-11-11 19:47:59 -03:00
parent 68f7a4b27c
commit 1f3e8979a4
4 changed files with 63 additions and 12 deletions

View File

@ -770,6 +770,12 @@ class NotebookRule(ModelSQL, ModelView):
('type', '=', 'analysis'),
('behavior', '!=', 'additional'),
])
target_method = fields.Many2One('lims.lab.method', 'Target Method',
domain=[('id', 'in', Eval('target_method_domain'))],
depends=['target_method_domain'])
target_method_domain = fields.Function(fields.Many2Many('lims.lab.method',
None, None, 'Target Method domain'),
'on_change_with_target_method_domain')
target_field = fields.Many2One('ir.model.field', 'Target Field',
domain=[('id', 'in', Eval('target_field_domain'))],
depends=['target_field_domain', 'action'], states={
@ -808,6 +814,13 @@ class NotebookRule(ModelSQL, ModelView):
def get_target_field_domain(self, name=None):
return self.default_target_field_domain()
@fields.depends('target_analysis', '_parent_target_analysis.methods')
def on_change_with_target_method_domain(self, name=None):
methods = []
if self.target_analysis and self.target_analysis.methods:
methods = [m.id for m in self.target_analysis.methods]
return methods
def eval_condition(self, line):
for condition in self.conditions:
if not condition.eval_condition(line):
@ -835,10 +848,13 @@ class NotebookRule(ModelSQL, ModelView):
if not typification:
return
existing_line = NotebookLine.search([
clause = [
('notebook', '=', line.notebook),
('analysis', '=', self.target_analysis),
], order=[('repetition', 'DESC')], limit=1)
]
if self.target_method:
clause.append(('method', '=', self.target_method))
existing_line = NotebookLine.search(clause)
if not existing_line:
self._exec_add_service(line, typification[0])
@ -860,7 +876,9 @@ class NotebookRule(ModelSQL, ModelView):
return
laboratory_id = laboratories[0]
method_id = typification.method and typification.method.id or None
method_id = self.target_method and self.target_method.id or None
if not method_id:
method_id = typification.method and typification.method.id or None
cursor.execute('SELECT DISTINCT(device) '
'FROM "' + AnalysisDevice._table + '" '
@ -909,10 +927,16 @@ class NotebookRule(ModelSQL, ModelView):
if line.analysis == self.target_analysis:
notebook_line = NotebookLine(line.id)
else:
target_line = NotebookLine.search([
clause = [
('notebook', '=', line.notebook),
('analysis', '=', self.target_analysis),
], order=[('repetition', 'DESC')], limit=1)
('accepted', '=', False),
('annulled', '=', False),
]
if self.target_method:
clause.append(('method', '=', self.target_method))
target_line = NotebookLine.search(clause,
order=[('repetition', 'DESC')], limit=1)
if not target_line:
return
notebook_line = target_line[0]

View File

@ -5675,6 +5675,14 @@ msgctxt "field:lims.rule,target_field_domain:"
msgid "Target Field domain"
msgstr "Dominio para Campo destino"
msgctxt "field:lims.rule,target_method:"
msgid "Target Method"
msgstr "Método destino"
msgctxt "field:lims.rule,target_method_domain:"
msgid "Target Method domain"
msgstr "Dominio para Método destino"
msgctxt "field:lims.rule,value:"
msgid "Value"
msgstr "Valor"

View File

@ -8,6 +8,8 @@
<field name="action"/>
<label name="target_analysis"/>
<field name="target_analysis"/>
<label name="target_method"/>
<field name="target_method"/>
<label name="target_field"/>
<field name="target_field"/>
<label name="value"/>

View File

@ -78,6 +78,8 @@ class NotebookRule(metaclass=PoolMeta):
return super().eval_condition(line)
def eval_sheet_condition(self, line):
if not self.analysis_sheet:
return False
for condition in self.conditions:
if not condition.eval_sheet_condition(line):
return False
@ -106,7 +108,8 @@ class NotebookRule(metaclass=PoolMeta):
return
existing_line = self._get_existing_line(
line.notebook_line.notebook.id, self.target_analysis.id)
line.notebook_line.notebook.id, self.target_analysis.id,
self.target_method and self.target_method.id or None)
if not existing_line:
self._exec_sheet_add_service(line, typification[0])
@ -131,7 +134,9 @@ class NotebookRule(metaclass=PoolMeta):
return
laboratory_id = laboratories[0]
method_id = typification.method and typification.method.id or None
method_id = self.target_method and self.target_method.id or None
if not method_id:
method_id = typification.method and typification.method.id or None
cursor.execute('SELECT DISTINCT(device) '
'FROM "' + AnalysisDevice._table + '" '
@ -201,6 +206,7 @@ class NotebookRule(metaclass=PoolMeta):
else:
sheet_line = self._get_existing_line(
line.notebook_line.notebook.id, self.target_analysis.id,
self.target_method and self.target_method.id or None,
Transaction().context.get('lims_interface_compilation'))
if not sheet_line:
return
@ -238,10 +244,16 @@ class NotebookRule(metaclass=PoolMeta):
if line.notebook_line.analysis == self.target_analysis:
notebook_line = NotebookLine(line.notebook_line.id)
else:
target_line = NotebookLine.search([
clause = [
('notebook', '=', line.notebook_line.notebook),
('analysis', '=', self.target_analysis),
], order=[('repetition', 'DESC')], limit=1)
('accepted', '=', False),
('annulled', '=', False),
]
if self.target_method:
clause.append(('method', '=', self.target_method))
target_line = NotebookLine.search(clause,
order=[('repetition', 'DESC')], limit=1)
if not target_line:
return
notebook_line = target_line[0]
@ -309,16 +321,21 @@ class NotebookRule(metaclass=PoolMeta):
except Exception as e:
return
def _get_existing_line(self, notebook_id, analysis_id,
def _get_existing_line(self, notebook_id, analysis_id, method_id,
compilation_id=None):
pool = Pool()
NotebookLine = pool.get('lims.notebook.line')
Data = pool.get('lims.interface.data')
notebook_lines = NotebookLine.search([
clause = [
('notebook', '=', notebook_id),
('analysis', '=', analysis_id),
])
('accepted', '=', False),
('annulled', '=', False),
]
if method_id:
clause.append(('method', '=', method_id))
notebook_lines = NotebookLine.search(clause)
nl_ids = [nl.id for nl in notebook_lines]
if not compilation_id:
return bool(len(nl_ids))