Rename ir.model.field 'field_description' into 'string'
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Rename ir.model.field 'field_description' into 'string'
|
||||
* Replace docstring of models by __string__
|
||||
* Rename ir.model 'name' field into 'string' and 'model' into 'name'
|
||||
|
||||
Version 7.4.0 - 2024-11-04
|
||||
|
||||
@@ -24,7 +24,7 @@ CREATE TABLE ir_model_field (
|
||||
model VARCHAR NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
relation VARCHAR,
|
||||
field_description VARCHAR,
|
||||
string VARCHAR,
|
||||
ttype VARCHAR,
|
||||
help TEXT,
|
||||
module VARCHAR,
|
||||
|
||||
@@ -25,7 +25,7 @@ CREATE TABLE ir_model_field (
|
||||
model VARCHAR,
|
||||
name VARCHAR,
|
||||
relation VARCHAR,
|
||||
field_description VARCHAR,
|
||||
string VARCHAR,
|
||||
ttype VARCHAR,
|
||||
help TEXT,
|
||||
module VARCHAR,
|
||||
|
||||
+20
-25
@@ -248,6 +248,7 @@ class ModelField(
|
||||
ModelSQL, ModelView):
|
||||
"Model field"
|
||||
__name__ = 'ir.model.field'
|
||||
_rec_name = 'string'
|
||||
name = fields.Char('Name', required=True,
|
||||
states={
|
||||
'readonly': Bool(Eval('module')),
|
||||
@@ -263,12 +264,12 @@ class ModelField(
|
||||
states={
|
||||
'readonly': Bool(Eval('module')),
|
||||
})
|
||||
field_description = fields.Char('Field Description', translate=True,
|
||||
string = fields.Char(
|
||||
"String", translate=True,
|
||||
loading='lazy',
|
||||
states={
|
||||
'readonly': Bool(Eval('module')),
|
||||
},
|
||||
depends=['module'])
|
||||
})
|
||||
ttype = fields.Char('Field Type',
|
||||
states={
|
||||
'readonly': Bool(Eval('module')),
|
||||
@@ -323,6 +324,9 @@ class ModelField(
|
||||
where=table._temp_model == model.id))
|
||||
table_h.drop_column('_temp_model')
|
||||
|
||||
# Migration from 7.4: rename field_description into string
|
||||
table_h.column_rename('field_description', 'string')
|
||||
|
||||
super().__register__(module)
|
||||
|
||||
@classmethod
|
||||
@@ -335,7 +339,7 @@ class ModelField(
|
||||
.select(
|
||||
ir_model_field.id.as_('id'),
|
||||
ir_model_field.name.as_('name'),
|
||||
ir_model_field.field_description.as_('field_description'),
|
||||
ir_model_field.string.as_('string'),
|
||||
ir_model_field.ttype.as_('ttype'),
|
||||
ir_model_field.relation.as_('relation'),
|
||||
ir_model_field.module.as_('module'),
|
||||
@@ -357,7 +361,7 @@ class ModelField(
|
||||
cursor.execute(*ir_model_field.insert([
|
||||
ir_model_field.model,
|
||||
ir_model_field.name,
|
||||
ir_model_field.field_description,
|
||||
ir_model_field.string,
|
||||
ir_model_field.ttype,
|
||||
ir_model_field.relation,
|
||||
ir_model_field.help,
|
||||
@@ -373,13 +377,13 @@ class ModelField(
|
||||
module_name,
|
||||
access,
|
||||
]]))
|
||||
elif (model_fields[field_name]['field_description'] != field.string
|
||||
elif (model_fields[field_name]['string'] != field.string
|
||||
or model_fields[field_name]['ttype'] != field._type
|
||||
or model_fields[field_name]['relation'] != relation
|
||||
or model_fields[field_name]['help'] != field.help
|
||||
or model_fields[field_name]['access'] != access):
|
||||
cursor.execute(*ir_model_field.update([
|
||||
ir_model_field.field_description,
|
||||
ir_model_field.string,
|
||||
ir_model_field.ttype,
|
||||
ir_model_field.relation,
|
||||
ir_model_field.help,
|
||||
@@ -417,17 +421,9 @@ class ModelField(
|
||||
"could not delete field: %s.%s", model, field,
|
||||
exc_info=True)
|
||||
|
||||
@staticmethod
|
||||
def default_name():
|
||||
return 'No Name'
|
||||
|
||||
@staticmethod
|
||||
def default_field_description():
|
||||
return 'No description available'
|
||||
|
||||
def get_rec_name(self, name):
|
||||
if self.field_description:
|
||||
return '%s (%s)' % (self.field_description, self.name)
|
||||
if self.string:
|
||||
return '%s (%s)' % (self.string, self.name)
|
||||
else:
|
||||
return self.name
|
||||
|
||||
@@ -438,7 +434,7 @@ class ModelField(
|
||||
else:
|
||||
bool_op = 'OR'
|
||||
return [bool_op,
|
||||
('field_description',) + tuple(clause[1:]),
|
||||
('string',) + tuple(clause[1:]),
|
||||
('name',) + tuple(clause[1:]),
|
||||
]
|
||||
|
||||
@@ -452,7 +448,7 @@ class ModelField(
|
||||
], limit=1)
|
||||
if fields:
|
||||
field, = fields
|
||||
name = field.field_description
|
||||
name = field.string
|
||||
cls._get_name_cache.set((model, field), name)
|
||||
else:
|
||||
name = field
|
||||
@@ -465,8 +461,7 @@ class ModelField(
|
||||
|
||||
to_delete = []
|
||||
if Transaction().context.get('language'):
|
||||
if 'field_description' in fields_names \
|
||||
or 'help' in fields_names:
|
||||
if 'string' in fields_names or 'help' in fields_names:
|
||||
if 'model' not in fields_names:
|
||||
fields_names.append('model')
|
||||
to_delete.append('model')
|
||||
@@ -477,11 +472,11 @@ class ModelField(
|
||||
res = super(ModelField, cls).read(ids, fields_names)
|
||||
|
||||
if (Transaction().context.get('language')
|
||||
and ('field_description' in fields_names
|
||||
and ('string' in fields_names
|
||||
or 'help' in fields_names)):
|
||||
trans_args = []
|
||||
for rec in res:
|
||||
if 'field_description' in fields_names:
|
||||
if 'string' in fields_names:
|
||||
trans_args.append((
|
||||
rec['model'] + ',' + rec['name'],
|
||||
'field', Transaction().language, None))
|
||||
@@ -491,12 +486,12 @@ class ModelField(
|
||||
'help', Transaction().language, None))
|
||||
Translation.get_sources(trans_args)
|
||||
for rec in res:
|
||||
if 'field_description' in fields_names:
|
||||
if 'string' in fields_names:
|
||||
res_trans = Translation.get_source(
|
||||
rec['model'] + ',' + rec['name'],
|
||||
'field', Transaction().language)
|
||||
if res_trans:
|
||||
rec['field_description'] = res_trans
|
||||
rec['string'] = res_trans
|
||||
if 'help' in fields_names:
|
||||
res_trans = Translation.get_source(
|
||||
rec['model'] + ',' + rec['name'],
|
||||
|
||||
@@ -81,7 +81,7 @@ def html_editor(request, pool, model, record, field):
|
||||
title = '%(model)s "%(name)s" %(field)s - %(title)s' % {
|
||||
'model': field.model_ref.name,
|
||||
'name': record.rec_name,
|
||||
'field': field.field_description,
|
||||
'field': field.string,
|
||||
'title': request.args.get('title', "Tryton"),
|
||||
}
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ class Translation(
|
||||
if name.split(',')[0] in ('ir.model.field', 'ir.model'):
|
||||
field_name = name.split(',')[1]
|
||||
if name.split(',')[0] == 'ir.model.field':
|
||||
if field_name == 'field_description':
|
||||
if field_name == 'string':
|
||||
ttype = 'field'
|
||||
else:
|
||||
ttype = 'help'
|
||||
@@ -452,7 +452,7 @@ class Translation(
|
||||
model_name, field_name = name.split(',')
|
||||
if model_name in ('ir.model.field', 'ir.model'):
|
||||
if model_name == 'ir.model.field':
|
||||
if field_name == 'field_description':
|
||||
if field_name == 'string':
|
||||
ttype = 'field'
|
||||
else:
|
||||
ttype = 'help'
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="string"/>
|
||||
<field name="string"/>
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
|
||||
<label name="model_ref"/>
|
||||
<field name="model_ref"/>
|
||||
<newline/>
|
||||
|
||||
<label name="ttype"/>
|
||||
<field name="ttype"/>
|
||||
<label name="relation"/>
|
||||
<field name="relation"/>
|
||||
<label name="field_description"/>
|
||||
<field name="field_description" colspan="3"/>
|
||||
<label name="help" yfill="1"/>
|
||||
<field name="help" colspan="3"/>
|
||||
<label name="access"/>
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="name" expand="2"/>
|
||||
<field name="string" expand="2"/>
|
||||
<field name="name" expand="1" optional="1"/>
|
||||
<field name="model_ref" expand="1"/>
|
||||
<field name="ttype" optional="0"/>
|
||||
<field name="relation" expand="1" optional="1"/>
|
||||
<field name="field_description" expand="1" optional="0"/>
|
||||
<field name="access" optional="1"/>
|
||||
<field name="module_ref" optional="1"/>
|
||||
</tree>
|
||||
|
||||
@@ -577,7 +577,7 @@ class FieldTranslate(Field):
|
||||
model_data = ModelData.__table__()
|
||||
model_field = ModelField.__table__()
|
||||
msg_trans = Translation.__table__()
|
||||
if name == 'field_description':
|
||||
if name == 'string':
|
||||
type_ = 'field'
|
||||
else:
|
||||
type_ = 'help'
|
||||
@@ -633,7 +633,7 @@ class FieldTranslate(Field):
|
||||
res_id = -1
|
||||
elif Model.__name__ == 'ir.model.field':
|
||||
name_ = Concat(Concat(table.model, ','), table.name)
|
||||
if name == 'field_description':
|
||||
if name == 'string':
|
||||
type_ = 'field'
|
||||
else:
|
||||
type_ = 'help'
|
||||
|
||||
@@ -64,11 +64,11 @@ class IrTestCase(ModuleTestCase):
|
||||
ModelField = pool.get('ir.model.field')
|
||||
|
||||
field, = ModelField.search([
|
||||
('field_description', '=', "Name"),
|
||||
('string', '=', "Name"),
|
||||
('model', '=', 'ir.lang'),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(field.field_description, "Name")
|
||||
self.assertEqual(field.string, "Name")
|
||||
|
||||
@with_transaction()
|
||||
def test_model_field_search_order_description(self):
|
||||
@@ -77,12 +77,11 @@ class IrTestCase(ModuleTestCase):
|
||||
ModelField = pool.get('ir.model.field')
|
||||
|
||||
fields = ModelField.search([
|
||||
('field_description', 'in', ["Name", "Code"]),
|
||||
('string', 'in', ["Name", "Code"]),
|
||||
('model', '=', 'ir.lang'),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(
|
||||
[f.field_description for f in fields], ["Code", "Name"])
|
||||
self.assertEqual([f.string for f in fields], ["Code", "Name"])
|
||||
|
||||
@with_transaction()
|
||||
def test_model_field_lazy(self):
|
||||
@@ -91,11 +90,11 @@ class IrTestCase(ModuleTestCase):
|
||||
ModelField = pool.get('ir.model.field')
|
||||
|
||||
field, = ModelField.search([
|
||||
('field_description', '=', "ID"),
|
||||
('string', '=', "ID"),
|
||||
('model', '=', 'ir.lang'),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(field.field_description, "ID")
|
||||
self.assertEqual(field.string, "ID")
|
||||
|
||||
@with_transaction()
|
||||
def test_sequence_substitutions(self):
|
||||
|
||||
Reference in New Issue
Block a user