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

I wanna change required field value before "Save" via button click, but call button will write values first -- required fields may not have filled in, problem here.

So, change values in frontend should avoid this problem, that's why I want to know how to do it.

I'm using Odoo 9, ideas from other version will be also useful, please share your solution.

Avatar
Discard

can you be more specific about your issue?

Best Answer

If you have predefined values for your fields, you can use "default" attribute on your fields or "default_get" method to set the default values to the fields.

If your fields depends on other field(s), you can either use "compute" or "onchange" methods to set the value.

-------------------------------UPDATE-------------------------------------

    @api.multi
def action_add(self):
for rec in self:
rec.result = rec.number1 + rec.number2

@api.multi
def action_multi(self):
for rec in self:
rec.result = rec.number1 * rec.number2

Call these methods from your buttons. This way you can use the fields for the calculation and store the value in another field. Make sure your fields must be of type either integer or float if you are doing mathematical calculation.

Avatar
Discard
Author

For example, I have three fields "number1", "number2", "result"(required), and I want to use two buttons -- "Add" and "Multi" -- to calculate the "result" field value.

I know can add one field like "calculate method" Selection and "onchange" method, but the demand is should add button to do that.

Author

Thanks for your updating, but as I said in question "button call will call 'write' method first" and result field is required that leads to be unable to save values. Maybe Odoo10+ don't have this problem, but I'm using Odoo9. So, I wanna modify frontend JavaScript for manually calling some methods maybe in data.js or date_model.js to change values.

So why don't you make it optional field (remove required)?

Related Posts Replies Views Activity
0
Sep 23
496
0
Sep 23
450
2
Feb 23
9253
6
Oct 23
19269
1
Aug 22
5317