Skip to Content
Menu
This question has been flagged
2 Replies
9792 Views

Hello,

i want to ask you, how to update the current field from button. 

Avatar
Discard
Best Answer

Hi Zakaria,

You'll first have to create a button in XML. If you need to inherit an existing view your code should look something like this:

<odoo>
  <data>
    <record id="some_id" model="ir.ui.view">
<field name="name">your.record.name</field>
<field name="model">your.model</field>
<field name="inherit_id" ref="module.view_name"/>
<field name="arch" type="xml">
<xpath expr=//form/header" position="inside">
<button name="change_text" string="Change text" type="object"/>
</xpath>
</field>
</record>
 </data> </odoo>


Otherwise you can simply add the button:

<button name="change_text" string="Change text" type="object"/>

Then you need to write the Python code to trigger the button click:

@api.multi
def change_value(self):
self.your_field = 'new value'

If you would then click on the button the value of the field 'your_field' would change to 'new value'.

P.S: If you can already know the input or don't need a button click then use an @api.onchange on the field to change the value. The code would look like this:

@api.onchange('your_field')
def change_field_value(self):
self.your_field = 'new value'

Regards,

Yenthe

Avatar
Discard
Best Answer

Dear Zakaria


You can do that by using write function like this

 

     def act_button(self):
              self.write({'your_field_name':value})

or 

              self.your_field_name= value

l hope I helped you ...
Avatar
Discard