Hello,
i want to ask you, how to update the current field from button.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
i want to ask you, how to update the current field from button.
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
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 |
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up