コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
3196 ビュー

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

アバター
破棄
最善の回答

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!

アバター
破棄
著作者

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.

著作者

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

著作者 最善の回答

The version of Odoo is 17

アバター
破棄
関連投稿 返信 ビュー 活動
5
10月 24
15267
3
8月 22
11680
2
2月 19
3855
2
6月 16
5855
3
12月 22
7171