lims_analysis_sheet/lims_interface: execute some wizards when confirming sheets

This commit is contained in:
Adrián Bernardi 2020-11-02 18:10:45 -03:00
parent 9e981cee80
commit ca50736e84
2 changed files with 63 additions and 3 deletions

View File

@ -504,10 +504,13 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
@Workflow.transition('done')
def confirm(cls, sheets):
Compilation = Pool().get('lims.interface.compilation')
cls.exec_sheet_wizards(sheets)
cls.check_results(sheets)
cls.check_controls(sheets)
Compilation.confirm([s.compilation for s in sheets])
cls.confirm_compilations(sheets)
with Transaction().set_context(avoid_accept_result=True):
Compilation.confirm([s.compilation for s in sheets])
cls.exec_notebook_wizards(sheets)
cls.confirm_compilations(sheets)
@classmethod
def check_results(cls, sheets):
@ -575,12 +578,59 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
raise UserError(gettext(
'lims_analysis_sheet.msg_sheet_not_controls'))
@classmethod
def exec_sheet_wizards(cls, sheets):
pool = Pool()
EvaluateRules = pool.get('lims.analysis_sheet.evaluate_rules',
type='wizard')
# Evaluate Sheet Rules
for s in sheets:
session_id, _, _ = EvaluateRules.create()
evaluate_rules = EvaluateRules(session_id)
with Transaction().set_context(lims_analysis_sheet=s.id):
evaluate_rules.transition_evaluate()
return
@classmethod
def exec_notebook_wizards(cls, sheets):
pool = Pool()
Data = pool.get('lims.interface.data')
EvaluateRules = pool.get('lims.notebook.evaluate_rules',
type='wizard')
# Evaluate Notebook Rules
for s in sheets:
notebook_lines = []
with Transaction().set_context(
lims_interface_table=s.compilation.table.id):
lines = Data.search([('compilation', '=', s.compilation.id)])
for line in lines:
nb_line = line.notebook_line
if not nb_line:
continue
if nb_line.end_date:
continue
notebook_lines.append(nb_line)
if not notebook_lines:
continue
session_id, _, _ = EvaluateRules.create()
evaluate_rules = EvaluateRules(session_id)
with Transaction().set_context(lims_analysis_sheet=s.id):
evaluate_rules.evaluate_rules(notebook_lines)
return
@classmethod
def confirm_compilations(cls, sheets):
pool = Pool()
Data = pool.get('lims.interface.data')
NotebookLine = pool.get('lims.notebook.line')
avoid_accept_result = Transaction().context.get('avoid_accept_result',
False)
now = datetime.now()
today = now.date()
for s in sheets:
@ -604,6 +654,12 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
'annulment_date': now,
'report': False,
})
# if already avoided in compilations then accept here
elif (avoid_accept_result and
nb_line.laboratory.automatic_accept_result):
#data['end_date'] = today
data['accepted'] = True
data['acceptance_date'] = now
NotebookLine.write([nb_line], data)
def get_new_compilation(self, defaults={}):

View File

@ -1747,6 +1747,9 @@ class Compilation(Workflow, ModelSQL, ModelView):
Field = pool.get('lims.interface.table.field')
NotebookLine = pool.get('lims.notebook.line')
avoid_accept_result = Transaction().context.get('avoid_accept_result',
False)
now = datetime.now()
#today = now.date()
for c in compilations:
@ -1775,7 +1778,8 @@ class Compilation(Workflow, ModelSQL, ModelView):
if nl_field == 'result':
data[nl_field] = round(
float(data[nl_field]), nb_line.decimals)
if nb_line.laboratory.automatic_accept_result:
if (not avoid_accept_result and
nb_line.laboratory.automatic_accept_result):
#data['end_date'] = today
data['accepted'] = True
data['acceptance_date'] = now