Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
831 Tampilan

I make a new field in res.user called user_new_option and I want to add this value in the 
XML context  

<record model="ir.actions.act_window" id="model_user_new">
<field name="name">model.user.new</field>
<field name="res_model">model.user.new</field>
<field name="view_mode">tree,form</field>
<field name="context">{'user_new_option': uid}</field>
</record>

how can I do this. 

Avatar
Buang
Jawaban Terbai

Hi,

Please refer to the code:


<record model="ir.actions.act_window" id="model_user_new">

    <field name="name">model.user.new</field>

    <field name="res_model">model.user.new</field>

    <field name="view_mode">tree,form</field>

    <field name="context">{'user_new_option': user.user_new_option}</field>

</record>



Hope it helps.

Avatar
Buang
Jawaban Terbai

You can set the default value of field just need to add "default_" before the field like like default_user_new_option.

You can write code like below : 

<record model="ir.actions.act_window" id="model_user_new">
  ​<field name="name">model.user.new</field>
  ​<field name="res_model">model.user.new</field>
​<field name="view_mode">tree,form</field>
  ​<field name="context">{'default_user_new_option': uid}</field> </record> 

Avatar
Buang
Penulis

my friend, I do not want to set a default value, I just want to set the value from field "user_new_option" in the context "user_new_option"
like
user_new_option = self.env.user.user_new_option
how can I do something like this

Jawaban Terbai

How to set a default value for a field when creating a new record using the context?

Here's how it's done:


<record model="ir.actions.act_window" id="model_user_new"> <field name="name">model.user.new</field> <field name="res_model">model.user.new</field> <field name="view_mode">tree,form</field> <field name="context">{'default_user_new_option': 123}</field> </record>

Avatar
Buang
Penulis

I want to get the value from the field in res.user because I want to make it changeable when I change it in the user form It changed in the context

Penulis

I mean to get it from the user like self.env.user.user_new_option

Post Terkait Replies Tampilan Aktivitas
3
Jul 25
7240
1
Mei 25
1247
2
Jan 25
2025
1
Jan 25
1487
1
Agu 24
1963