lims, lims_analysis_sheet, lims_planning_automatic: automatic plan lines
created by notebook rules
This commit is contained in:
parent
dad37cdc64
commit
01d493d422
|
@ -923,6 +923,7 @@ class NotebookRule(ModelSQL, ModelView):
|
|||
('analysis_detail', 'in', [d.id for d in analysis_detail])])
|
||||
if notebook_lines:
|
||||
NotebookLine.write(notebook_lines, {'rule': self.id})
|
||||
return notebook_lines
|
||||
|
||||
def _exec_edit(self, line):
|
||||
pool = Pool()
|
||||
|
|
|
@ -128,9 +128,6 @@ class NotebookRule(metaclass=PoolMeta):
|
|||
Service = pool.get('lims.service')
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
NotebookLine = pool.get('lims.notebook.line')
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
|
||||
today = date.today()
|
||||
|
||||
cursor.execute('SELECT DISTINCT(laboratory) '
|
||||
'FROM "' + AnalysisLaboratory._table + '" '
|
||||
|
@ -181,18 +178,28 @@ class NotebookRule(metaclass=PoolMeta):
|
|||
('analysis_detail', 'in', [d.id for d in analysis_detail])])
|
||||
if notebook_lines:
|
||||
NotebookLine.write(notebook_lines, {'rule': self.id})
|
||||
self._add_service_to_sheet(notebook_lines)
|
||||
return notebook_lines
|
||||
|
||||
sheet = AnalysisSheet(Transaction().context.get(
|
||||
'lims_analysis_sheet'))
|
||||
notebook_lines = [nl for nl in notebook_lines if
|
||||
nl.get_analysis_sheet_template() == sheet.template.id]
|
||||
if notebook_lines:
|
||||
NotebookLine.write(notebook_lines, {'start_date': today})
|
||||
analysis_details = [nl.analysis_detail
|
||||
for nl in notebook_lines]
|
||||
EntryDetailAnalysis.write(analysis_details,
|
||||
{'state': 'planned'})
|
||||
sheet.create_lines(notebook_lines)
|
||||
def _add_service_to_sheet(self, notebook_lines):
|
||||
pool = Pool()
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
NotebookLine = pool.get('lims.notebook.line')
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
|
||||
today = date.today()
|
||||
|
||||
sheet = AnalysisSheet(Transaction().context.get(
|
||||
'lims_analysis_sheet'))
|
||||
notebook_lines = [nl for nl in notebook_lines if
|
||||
nl.get_analysis_sheet_template() == sheet.template.id]
|
||||
if notebook_lines:
|
||||
NotebookLine.write(notebook_lines, {'start_date': today})
|
||||
analysis_details = [nl.analysis_detail
|
||||
for nl in notebook_lines]
|
||||
EntryDetailAnalysis.write(analysis_details,
|
||||
{'state': 'planned'})
|
||||
sheet.create_lines(notebook_lines)
|
||||
|
||||
def _exec_sheet_edit(self, line):
|
||||
pool = Pool()
|
||||
|
|
|
@ -16,6 +16,7 @@ def register():
|
|||
Pool.register(
|
||||
planification.Planification,
|
||||
laboratory.Laboratory,
|
||||
laboratory.NotebookRule,
|
||||
entry.Entry,
|
||||
sample.Sample,
|
||||
module='lims_planning_automatic', type_='model')
|
||||
|
|
|
@ -1,12 +1,67 @@
|
|||
# This file is part of lims_planning_automatic module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
from datetime import date
|
||||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class Laboratory(metaclass=PoolMeta):
|
||||
__name__ = 'lims.laboratory'
|
||||
|
||||
automatic_planning = fields.Boolean('Automatic Planning')
|
||||
|
||||
|
||||
class NotebookRule(metaclass=PoolMeta):
|
||||
__name__ = 'lims.rule'
|
||||
|
||||
def _exec_add_service(self, line, typification):
|
||||
notebook_lines = super()._exec_add_service(line, typification)
|
||||
self._automatic_plan(notebook_lines)
|
||||
return notebook_lines
|
||||
|
||||
def _exec_sheet_add_service(self, line, typification):
|
||||
notebook_lines = super()._exec_sheet_add_service(line, typification)
|
||||
self._automatic_plan(notebook_lines)
|
||||
return notebook_lines
|
||||
|
||||
def _automatic_plan(self, notebook_lines):
|
||||
pool = Pool()
|
||||
EntryDetailAnalysis = pool.get('lims.entry.detail.analysis')
|
||||
NotebookLine = pool.get('lims.notebook.line')
|
||||
AnalysisSheet = pool.get('lims.analysis_sheet')
|
||||
Planification = pool.get('lims.planification')
|
||||
|
||||
if not notebook_lines:
|
||||
return
|
||||
|
||||
today = date.today()
|
||||
|
||||
entries = []
|
||||
sheet_id = Transaction().context.get('lims_analysis_sheet', None)
|
||||
if sheet_id:
|
||||
sheet = AnalysisSheet(sheet_id)
|
||||
nlines_same_sheet, nlines_other_sheet = [], []
|
||||
for nl in notebook_lines:
|
||||
if nl.get_analysis_sheet_template() == sheet.template.id:
|
||||
nlines_same_sheet.append(nl)
|
||||
else:
|
||||
nlines_other_sheet.append(nl)
|
||||
if nlines_same_sheet: # no need to plan
|
||||
NotebookLine.write(nlines_same_sheet, {'start_date': today})
|
||||
analysis_details = [nl.analysis_detail
|
||||
for nl in nlines_same_sheet]
|
||||
EntryDetailAnalysis.write(analysis_details,
|
||||
{'state': 'planned'})
|
||||
sheet.create_lines(nlines_same_sheet)
|
||||
entries = list(set(nl.sample.entry for nl in nlines_other_sheet))
|
||||
else:
|
||||
entries = list(set(nl.sample.entry for nl in notebook_lines))
|
||||
if entries:
|
||||
Planification.automatic_plan(entries=entries)
|
||||
|
||||
def _add_service_to_sheet(self, notebook_lines):
|
||||
# overwritten by _automatic_plan when calling _exec_sheet_add_service
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue