[REF] base: rename ir.server.object.lines type field to evaluation_type
Purpose of this commit is to rename type column to something matching the the real business use of the field. That way it is easier to find and grep in the code. It also lessens potential conflicts with type build-in python function. It also lessens conflicts when using the field in JS as type is a build-in attribute. Renaming type column is a long-living issue. We choose to do it at the beginning of the v13 development to catch errors as soon as possible. This commit is linked to task ID 1896245. It is also a subpart of community PR #27599.
This commit is contained in:
committed by
Thibault Delavallée
parent
fb7ac56d65
commit
77e5e8b7ff
@@ -601,11 +601,11 @@ class IrServerObjectLines(models.Model):
|
||||
"When Formula type is selected, this field may be a Python expression "
|
||||
" that can use the same values as for the code field on the server action.\n"
|
||||
"If Value type is selected, the value will be used directly without evaluation.")
|
||||
type = fields.Selection([
|
||||
evaluation_type = fields.Selection([
|
||||
('value', 'Value'),
|
||||
('reference', 'Reference'),
|
||||
('equation', 'Python expression')
|
||||
], 'Evaluation Type', default='value', required=True, change_default=True)
|
||||
], 'Evaluation Type', default='value', required=True, change_default=True, oldname='type')
|
||||
resource_ref = fields.Reference(
|
||||
string='Record', selection='_selection_target_model',
|
||||
compute='_compute_resource_ref', inverse='_set_resource_ref')
|
||||
@@ -615,10 +615,10 @@ class IrServerObjectLines(models.Model):
|
||||
models = self.env['ir.model'].search([])
|
||||
return [(model.model, model.name) for model in models]
|
||||
|
||||
@api.depends('col1.relation', 'value', 'type')
|
||||
@api.depends('col1.relation', 'value', 'evaluation_type')
|
||||
def _compute_resource_ref(self):
|
||||
for line in self:
|
||||
if line.type in ['reference', 'value'] and line.col1 and line.col1.relation:
|
||||
if line.evaluation_type in ['reference', 'value'] and line.col1 and line.col1.relation:
|
||||
value = line.value or ''
|
||||
try:
|
||||
value = int(value)
|
||||
@@ -634,7 +634,7 @@ class IrServerObjectLines(models.Model):
|
||||
|
||||
@api.onchange('resource_ref')
|
||||
def _set_resource_ref(self):
|
||||
for line in self.filtered(lambda line: line.type == 'reference'):
|
||||
for line in self.filtered(lambda line: line.evaluation_type == 'reference'):
|
||||
if line.resource_ref:
|
||||
line.value = str(line.resource_ref.id)
|
||||
|
||||
@@ -643,7 +643,7 @@ class IrServerObjectLines(models.Model):
|
||||
result = dict.fromkeys(self.ids, False)
|
||||
for line in self:
|
||||
expr = line.value
|
||||
if line.type == 'equation':
|
||||
if line.evaluation_type == 'equation':
|
||||
expr = safe_eval(line.value, eval_context)
|
||||
elif line.col1.ttype in ['many2one', 'integer']:
|
||||
try:
|
||||
|
||||
@@ -105,8 +105,8 @@ class TestServerActions(TestServerActionsBase):
|
||||
'crud_model_id': self.res_country_model.id,
|
||||
'link_field_id': False,
|
||||
'fields_lines': [(5,),
|
||||
(0, 0, {'col1': self.res_country_name_field.id, 'value': 'record.name', 'type': 'equation'}),
|
||||
(0, 0, {'col1': self.res_country_code_field.id, 'value': 'record.name[0:2]', 'type': 'equation'})],
|
||||
(0, 0, {'col1': self.res_country_name_field.id, 'value': 'record.name', 'evaluation_type': 'equation'}),
|
||||
(0, 0, {'col1': self.res_country_code_field.id, 'value': 'record.name[0:2]', 'evaluation_type': 'equation'})],
|
||||
})
|
||||
run_res = self.action.with_context(self.context).run()
|
||||
self.assertFalse(run_res, 'ir_actions_server: create record action correctly finished should return False')
|
||||
|
||||
@@ -302,9 +302,9 @@
|
||||
<field name="fields_lines">
|
||||
<tree string="Field Mappings" editable="bottom">
|
||||
<field name="col1" domain="['|', ('model_id', '=', parent.crud_model_id), ('model_id', '=', parent.model_id)]"/>
|
||||
<field name="type"/>
|
||||
<field name="resource_ref" attrs="{'readonly': [('type', '!=', 'reference')]}" options="{'hide_model': True}"/>
|
||||
<field name="value" attrs="{'readonly': [('type', '=', 'reference')]}" force_save="1"/>
|
||||
<field name="evaluation_type"/>
|
||||
<field name="resource_ref" attrs="{'readonly': [('evaluation_type', '!=', 'reference')]}" options="{'hide_model': True}"/>
|
||||
<field name="value" attrs="{'readonly': [('evaluation_type', '=', 'reference')]}" force_save="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
Reference in New Issue
Block a user