mirror of
https://github.com/Kalenis/kalenislims.git
synced 2023-12-14 07:13:04 +01:00
lims_interface: always add field notebook_line in compilation data
This commit is contained in:
parent
4b3be9794d
commit
c0f3afa631
|
@ -71,6 +71,10 @@ class Adapter:
|
|||
obj = fields.Integer('Sequence')
|
||||
obj.name = 'sequence'
|
||||
res['sequence'] = obj
|
||||
obj = fields.Many2One('lims.notebook.line', 'Notebook Line')
|
||||
obj.name = 'notebook_line'
|
||||
obj.readonly = True
|
||||
res['notebook_line'] = obj
|
||||
|
||||
return res
|
||||
|
||||
|
@ -101,6 +105,8 @@ class Data(sequence_ordered(), ModelSQL, ModelView):
|
|||
|
||||
compilation = fields.Many2One('lims.interface.compilation', 'Compilation',
|
||||
required=True, ondelete='CASCADE')
|
||||
notebook_line = fields.Many2One('lims.notebook.line', 'Notebook Line',
|
||||
readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -179,6 +185,7 @@ class Data(sequence_ordered(), ModelSQL, ModelView):
|
|||
def fields_get(cls, fields_names=None):
|
||||
Model = Pool().get('ir.model')
|
||||
res = super(Data, cls).fields_get(fields_names)
|
||||
|
||||
table = cls.get_table()
|
||||
for field in table.fields_:
|
||||
res[field.name] = {
|
||||
|
@ -220,7 +227,8 @@ class Data(sequence_ordered(), ModelSQL, ModelView):
|
|||
|
||||
fields_names = [
|
||||
'compilation',
|
||||
'sequence'
|
||||
'sequence',
|
||||
'notebook_line',
|
||||
]
|
||||
for field in table.fields_:
|
||||
fields_names.append(field.name)
|
||||
|
@ -356,6 +364,7 @@ class Data(sequence_ordered(), ModelSQL, ModelView):
|
|||
records = cls.read([x.id for x in records if x.id])
|
||||
for record in records:
|
||||
del record['id']
|
||||
del record['notebook_line']
|
||||
return cls.create(records)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -123,7 +123,7 @@ def get_model_resource(model_name, value, field_name):
|
|||
rec_name = 'id'
|
||||
try:
|
||||
value = int(value)
|
||||
except:
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'lims_interface.invalid_fixed_value_many2one_id',
|
||||
name=field_name))
|
||||
|
@ -225,13 +225,6 @@ class Interface(Workflow, ModelSQL, ModelView):
|
|||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state', 'id'])
|
||||
notebook_line_field = fields.Many2One('lims.interface.column',
|
||||
'Notebook line field',
|
||||
domain=[('interface', '=', Eval('id')),
|
||||
('related_model.model', '=', 'lims.notebook.line')],
|
||||
states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state', 'id'])
|
||||
charset = fields.Selection([
|
||||
(None, ''),
|
||||
('utf-8', 'UTF-8'),
|
||||
|
@ -375,9 +368,9 @@ class Interface(Workflow, ModelSQL, ModelView):
|
|||
current_icon = None
|
||||
for line in self.table.fields_:
|
||||
if line.type in ('datetime', 'timestamp'):
|
||||
fields.append('<field name="%s" widget="date"/>\n' %
|
||||
fields.append('<field name="%s" widget="date"/>' %
|
||||
line.name)
|
||||
fields.append('<field name="%s" widget="time"/>\n' %
|
||||
fields.append('<field name="%s" widget="time"/>' %
|
||||
line.name)
|
||||
continue
|
||||
if line.type == 'icon':
|
||||
|
@ -390,12 +383,14 @@ class Interface(Workflow, ModelSQL, ModelView):
|
|||
if line.type == 'image':
|
||||
attributes.append('widget="image"')
|
||||
|
||||
fields.append('<field name="%s" %s/>\n' % (line.name,
|
||||
fields.append('<field name="%s" %s/>' % (line.name,
|
||||
' '.join(attributes)))
|
||||
|
||||
fields.append('<field name="notebook_line"/>')
|
||||
|
||||
xml = ('<?xml version="1.0"?>\n'
|
||||
'<tree sequence="sequence" editable="bottom">\n'
|
||||
'%s'
|
||||
'%s\n'
|
||||
'</tree>') % ('\n'.join(fields))
|
||||
return {
|
||||
'type': 'tree',
|
||||
|
@ -413,7 +408,7 @@ class Interface(Workflow, ModelSQL, ModelView):
|
|||
'</group>' % (line.name, line.name))
|
||||
continue
|
||||
if line.type == 'icon':
|
||||
fields.append('<image name="%s"/>\n' %
|
||||
fields.append('<image name="%s"/>' %
|
||||
(line.name))
|
||||
continue
|
||||
|
||||
|
@ -421,12 +416,15 @@ class Interface(Workflow, ModelSQL, ModelView):
|
|||
if line.type == 'image':
|
||||
attributes.append('widget="image"')
|
||||
|
||||
fields.append('<field name="%s" %s/>\n' % (line.name,
|
||||
fields.append('<field name="%s" %s/>' % (line.name,
|
||||
' '.join(attributes)))
|
||||
|
||||
fields.append('<label name="notebook_line"/>')
|
||||
fields.append('<field name="notebook_line"/>')
|
||||
|
||||
xml = ('<?xml version="1.0"?>\n'
|
||||
'<form>\n'
|
||||
'%s'
|
||||
'%s\n'
|
||||
'</form>') % '\n'.join(fields)
|
||||
return {
|
||||
'type': 'form',
|
||||
|
@ -585,14 +583,14 @@ class Column(sequence_ordered(), ModelSQL, ModelView):
|
|||
if self.type_ == 'boolean':
|
||||
try:
|
||||
int(self.fixed_value)
|
||||
except:
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'lims_interface.invalid_fixed_value_boolean',
|
||||
name=self.name))
|
||||
elif self.type_ == 'date':
|
||||
try:
|
||||
str2date(self.fixed_value, self.interface.language)
|
||||
except:
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'lims_interface.invalid_fixed_value_date',
|
||||
name=self.name))
|
||||
|
@ -603,7 +601,7 @@ class Column(sequence_ordered(), ModelSQL, ModelView):
|
|||
ftype = FIELD_TYPE_PYTHON[self.type_]
|
||||
try:
|
||||
ftype(self.fixed_value)
|
||||
except:
|
||||
except Exception:
|
||||
raise UserError(gettext(
|
||||
'lims_interface.invalid_fixed_value',
|
||||
value=self.fixed_value, name=self.name))
|
||||
|
@ -834,9 +832,8 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
line[field[0]] = self._get_formula_value(field, line)
|
||||
|
||||
nb_line = self._get_notebook_line(line)
|
||||
if nb_line and self.interface.notebook_line_field:
|
||||
nbl_alias = self.interface.notebook_line_field.alias
|
||||
line[nbl_alias] = nb_line.id
|
||||
if nb_line:
|
||||
line['notebook_line'] = nb_line.id
|
||||
data.append(line)
|
||||
count += 1
|
||||
imported_files.append(origin)
|
||||
|
@ -914,10 +911,8 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
field, line)
|
||||
|
||||
nb_line = self._get_notebook_line(line)
|
||||
if nb_line and self.interface.notebook_line_field:
|
||||
nbl_alias = \
|
||||
self.interface.notebook_line_field.alias
|
||||
line[nbl_alias] = nb_line.id
|
||||
if nb_line:
|
||||
line['notebook_line'] = nb_line.id
|
||||
data.append(line)
|
||||
|
||||
imported_files.append(origin)
|
||||
|
@ -993,8 +988,7 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
if (self.interface.analysis_field and
|
||||
self.interface.fraction_field and
|
||||
self.interface.repetition_field and
|
||||
self.interface.notebook_line_field):
|
||||
self.interface.repetition_field):
|
||||
analysis_value = line[self.interface.analysis_field.alias]
|
||||
fraction_value = line[self.interface.fraction_field.alias]
|
||||
repetition_value = line[self.interface.repetition_field.alias]
|
||||
|
@ -1029,12 +1023,6 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
Field = pool.get('lims.interface.table.field')
|
||||
|
||||
for c in compilations:
|
||||
nbl_alias = None
|
||||
if c.interface.notebook_line_field:
|
||||
nbl_alias = c.interface.notebook_line_field.alias
|
||||
if not nbl_alias:
|
||||
raise UserError(gettext(
|
||||
'lims_interface.no_notebook_line_field_defined'))
|
||||
result_fields = {}
|
||||
fields = Field.search([
|
||||
('table', '=', c.table),
|
||||
|
@ -1051,8 +1039,8 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
('compilation', '=', c.id)
|
||||
])
|
||||
for l in lines:
|
||||
nbl_id = getattr(l, nbl_alias)
|
||||
print('*** nbl_id: ', nbl_id)
|
||||
nb_line = l.notebook_line
|
||||
print('*** nb_line:', nb_line)
|
||||
if result_fields:
|
||||
for res in result_fields:
|
||||
# TODO: check values and correct type
|
||||
|
@ -1071,9 +1059,6 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
NotebookLine = pool.get('lims.notebook.line')
|
||||
|
||||
for c in compilations:
|
||||
nbl_alias = None
|
||||
if c.interface.notebook_line_field:
|
||||
nbl_alias = c.interface.notebook_line_field.alias
|
||||
result_fields = {}
|
||||
fields = Field.search([
|
||||
('table', '=', c.table),
|
||||
|
@ -1090,15 +1075,14 @@ class Compilation(Workflow, ModelSQL, ModelView):
|
|||
('compilation', '=', c.id)
|
||||
])
|
||||
for l in lines:
|
||||
nbl_id = getattr(l, nbl_alias)
|
||||
if nbl_id and result_fields:
|
||||
nbl = NotebookLine.browse([nbl_id])
|
||||
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 nbl and data:
|
||||
NotebookLine.write(nbl, data)
|
||||
if data:
|
||||
NotebookLine.write(nb_line, data)
|
||||
|
||||
|
||||
class CompilationOrigin(ModelSQL, ModelView):
|
||||
|
|
|
@ -46,10 +46,6 @@ msgctxt "field:lims.interface,name:"
|
|||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
||||
msgctxt "field:lims.interface,notebook_line_field:"
|
||||
msgid "Notebook line field"
|
||||
msgstr "Campo Línea de cuaderno"
|
||||
|
||||
msgctxt "field:lims.interface,repetition_field:"
|
||||
msgid "Repetition field"
|
||||
msgstr "Campo Repetición"
|
||||
|
@ -198,6 +194,10 @@ msgctxt "field:lims.interface.data,compilation:"
|
|||
msgid "Compilation"
|
||||
msgstr "Compilación"
|
||||
|
||||
msgctxt "field:lims.interface.data,notebook_line:"
|
||||
msgid "Notebook Line"
|
||||
msgstr "Línea de cuaderno"
|
||||
|
||||
msgctxt "field:lims.interface.table,fields_:"
|
||||
msgid "Fields"
|
||||
msgstr "Campos"
|
||||
|
@ -352,12 +352,6 @@ msgctxt "model:ir.message,text:invalid_fixed_value_type"
|
|||
msgid "The field type in \"%(name)s\" is not valid for fixed values."
|
||||
msgstr "El Tipo de campo en \"%(name)s\" no es válido para valores fijos."
|
||||
|
||||
msgctxt "model:ir.message,text:no_notebook_line_field_defined"
|
||||
msgid "No field was defined for the Notebook line in the device interface."
|
||||
msgstr ""
|
||||
"Falta definir en la interfaz cuál es el campo que refiere a la Línea de "
|
||||
"cuaderno."
|
||||
|
||||
msgctxt "model:ir.model.button,string:lims_interface_activate_button"
|
||||
msgid "Activate"
|
||||
msgstr "Activar"
|
||||
|
|
|
@ -24,8 +24,5 @@
|
|||
<record model="ir.message" id="duplicated_origin_file">
|
||||
<field name="text">File "%(file_name)s" already exists as origin.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="no_notebook_line_field_defined">
|
||||
<field name="text">No field was defined for the Notebook line in the device interface.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -45,7 +45,9 @@ class Table(ModelSQL, ModelView):
|
|||
('create_date', fields.Timestamp),
|
||||
('write_date', fields.Timestamp),
|
||||
('compilation', fields.Integer),
|
||||
('sequence', fields.Integer)):
|
||||
('sequence', fields.Integer),
|
||||
('notebook_line', fields.Integer),
|
||||
):
|
||||
sql_type = field._sql_type
|
||||
table.add_column(name, sql_type)
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
<label name="repetition_field"/>
|
||||
<field name="repetition_field"/>
|
||||
</group>
|
||||
<label name="notebook_line_field"/>
|
||||
<field name="notebook_line_field"/>
|
||||
</page>
|
||||
<page id="template" string="Template">
|
||||
<label name="template_type"/>
|
||||
|
|
Loading…
Reference in a new issue