Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3359 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
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 Nejlepší odpověď

The version of Odoo is 17

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
5
říj 24
15963
3
srp 22
11804
2
úno 19
3987
2
čvn 16
5918
3
pro 22
7292