Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
3363 Visualizações

Dear community,


I need your help. I'm trying to change the string dynamically, the string is getting with value other field of the model. Is it posible?


For example

I have a field with name 'var1' and 'valuevar1', I want to get the value of the 'valuevar1 and put the value in the name of the other string.



Kind regards

Avatar
Cancelar
Melhor resposta

I'm not entirely sure what you want to achieve, but you can use a compute field for this (https://www.odoo.com/documentation/17.0/developer/tutorials/getting_started/09_compute_onchange.html). The code should look something like this:

var1 = fields.Char(compute="_compute_dynamic_string")

@api.depends('valuevar1')
def _compute_dynamic_string(self):
​for record in self:
​record.var1 = record.valuevar1
​return True

I hope this helps!

Avatar
Cancelar
Autor

Dear Jort,

I want to change de name of the column of the view, I don't want to change the value of the field.

Exemple :

<field name="var1" string="valuevar1_field_value" />

Kind regards

In that case I misunderstood. Your use case is a bit more complicated, but you can check out the following blog post, which might help you further:

https://www.cybrosys.com/blog/how-to-dynamically-change-label-string

If you want real time updates you would have to use javascript for this, i.e., when the value of 'valuevar1' changes in the view then the field string should update as well.

Autor

Thanks Jort,

I have changed a little bit the code for it's running in odoo 17

the new code is :

@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
if view_type == 'form':
parameters = self.env['ir.config_parameter'].sudo()
name_var1 = parameters.get_param('app1.var1')
if (name_var1 != False):
for node in arch.xpath(
"//field[@name='var1']"
):
node.attrib['string'] = name_var1
return arch, view

Kind regards

Kind regard

Autor Melhor resposta

The version of Odoo is 17

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
5
out. 24
15999
3
ago. 22
11805
2
fev. 19
3991
2
jun. 16
5920
3
dez. 22
7296