lims_interface/lims_analysis_sheet: adjustment in workflow
This commit is contained in:
parent
887dcaaccf
commit
a69550606b
|
@ -58,21 +58,24 @@ class Compilation(metaclass=PoolMeta):
|
|||
|
||||
super(Compilation, cls).confirm(compilations)
|
||||
|
||||
lines_to_write = []
|
||||
now = datetime.now()
|
||||
today = now.date()
|
||||
for c in compilations:
|
||||
with Transaction().set_context(
|
||||
lims_interface_table=c.table.id):
|
||||
with Transaction().set_context(lims_interface_table=c.table.id):
|
||||
lines = Data.search([('compilation', '=', c.id)])
|
||||
for line in lines:
|
||||
if line.annulled and line.notebook_line:
|
||||
lines_to_write.append(line.notebook_line)
|
||||
if lines_to_write:
|
||||
NotebookLine.write(lines_to_write, {
|
||||
'result_modifier': 'na',
|
||||
'annulled': True,
|
||||
'annulment_date': datetime.now(),
|
||||
'report': False,
|
||||
})
|
||||
nb_line = line.notebook_line
|
||||
if not nb_line:
|
||||
continue
|
||||
data = {'end_date': today}
|
||||
if line.annulled:
|
||||
data.update({
|
||||
'result_modifier': 'na',
|
||||
'annulled': True,
|
||||
'annulment_date': now,
|
||||
'report': False,
|
||||
})
|
||||
NotebookLine.write([nb_line], data)
|
||||
|
||||
|
||||
class Column(metaclass=PoolMeta):
|
||||
|
|
|
@ -7,7 +7,7 @@ from decimal import Decimal
|
|||
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
|
||||
from trytond.wizard import Wizard, StateView, StateAction, Button
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import PYSONEncoder, Eval, Bool
|
||||
from trytond.pyson import PYSONEncoder, Eval, Bool, If
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
|
@ -234,26 +234,37 @@ class AnalysisSheet(Workflow, ModelSQL, ModelView):
|
|||
cls._transitions |= set((
|
||||
('draft', 'active'),
|
||||
('active', 'validated'),
|
||||
('validated', 'active'),
|
||||
('validated', 'done'),
|
||||
))
|
||||
cls._buttons.update({
|
||||
'activate': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
'invisible': ~Eval('state').in_(['draft', 'validated']),
|
||||
'icon': If(Eval('state') == 'draft', 'tryton-forward',
|
||||
'tryton-back'),
|
||||
'depends': ['state'],
|
||||
},
|
||||
'view_data': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'export_file': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'print_report': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'validate_': {
|
||||
'invisible': Eval('state') != 'active',
|
||||
'icon': 'tryton-forward',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'confirm': {
|
||||
'invisible': Eval('state') != 'validated',
|
||||
'icon': 'tryton-ok',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -705,26 +705,33 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
('draft', 'active'),
|
||||
('active', 'draft'),
|
||||
('active', 'validated'),
|
||||
('validated', 'active'),
|
||||
('validated', 'done'),
|
||||
))
|
||||
cls._buttons.update({
|
||||
'view_data': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'draft': {
|
||||
'invisible': Eval('state') != 'active',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'activate': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
'invisible': ~Eval('state').in_(['draft', 'validated']),
|
||||
'depends': ['state'],
|
||||
},
|
||||
'collect': {
|
||||
'invisible': Eval('state') != 'active',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'validate_': {
|
||||
'invisible': Eval('state') != 'active',
|
||||
'depends': ['state'],
|
||||
},
|
||||
'confirm': {
|
||||
'invisible': Eval('state') != 'validated',
|
||||
'depends': ['state'],
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1031,31 +1038,30 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
Field = pool.get('lims.interface.table.field')
|
||||
|
||||
for c in compilations:
|
||||
result_fields = {}
|
||||
fields = Field.search([
|
||||
fields = {}
|
||||
columns = Field.search([
|
||||
('table', '=', c.table),
|
||||
('transfer_field', '=', True),
|
||||
])
|
||||
for field in fields:
|
||||
result_fields[field.name] = {
|
||||
'type': field.type,
|
||||
'field_name': field.related_line_field.name,
|
||||
for column in columns:
|
||||
fields[column.name] = {
|
||||
'type': column.type,
|
||||
'field_name': column.related_line_field.name,
|
||||
}
|
||||
with Transaction().set_context(
|
||||
lims_interface_table=c.table):
|
||||
lines = Data.search([
|
||||
('compilation', '=', c.id),
|
||||
])
|
||||
for l in lines:
|
||||
nb_line = l.notebook_line
|
||||
print('*** nb_line:', nb_line)
|
||||
if result_fields:
|
||||
for res in result_fields:
|
||||
# TODO: check values and correct type
|
||||
value = getattr(l, res)
|
||||
print('RES: ', res, ': ', value, ' - ',
|
||||
result_fields[res]['type'],
|
||||
result_fields[res]['field_name'])
|
||||
if not fields:
|
||||
continue
|
||||
with Transaction().set_context(lims_interface_table=c.table):
|
||||
lines = Data.search([('compilation', '=', c.id)])
|
||||
for line in lines:
|
||||
nb_line = line.notebook_line
|
||||
if not nb_line:
|
||||
continue
|
||||
print('## nb_line:', nb_line.id)
|
||||
for alias, field in fields.items():
|
||||
# TODO: check values and correct type
|
||||
value = getattr(line, alias)
|
||||
print(' * Field:', alias, ':', value, ' - ',
|
||||
field['field_name'])
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -1067,30 +1073,26 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
|
||||
for c in compilations:
|
||||
result_fields = {}
|
||||
fields = Field.search([
|
||||
('table', '=', c.table),
|
||||
fields = {}
|
||||
columns = Field.search([
|
||||
('table', '=', c.table.id),
|
||||
('transfer_field', '=', True),
|
||||
])
|
||||
for field in fields:
|
||||
result_fields[field.name] = {
|
||||
'type': field.type,
|
||||
'field_name': field.related_line_field.name,
|
||||
}
|
||||
with Transaction().set_context(
|
||||
lims_interface_table=c.table):
|
||||
lines = Data.search([
|
||||
('compilation', '=', c.id),
|
||||
])
|
||||
for l in lines:
|
||||
nb_line = l.notebook_line
|
||||
if nb_line and result_fields:
|
||||
data = {}
|
||||
for res in result_fields:
|
||||
value = getattr(l, res)
|
||||
data[result_fields[res]['field_name']] = value
|
||||
if data:
|
||||
NotebookLine.write([nb_line], data)
|
||||
for column in columns:
|
||||
fields[column.name] = column.related_line_field.name
|
||||
if not fields:
|
||||
continue
|
||||
with Transaction().set_context(lims_interface_table=c.table):
|
||||
lines = Data.search([('compilation', '=', c.id)])
|
||||
for line in lines:
|
||||
nb_line = line.notebook_line
|
||||
if not nb_line:
|
||||
continue
|
||||
data = {}
|
||||
for alias, nl_field in fields.items():
|
||||
data[nl_field] = getattr(line, alias)
|
||||
if data:
|
||||
NotebookLine.write([nb_line], data)
|
||||
|
||||
|
||||
class CompilationOrigin(ModelSQL, ModelView):
|
||||
|
|
Loading…
Reference in New Issue