Skip to Content
Menu
This question has been flagged
3 Replies
5778 Views

I've made a fucntion inside a model how I can execute the fucntion everytime the user see the view

Avatar
Discard

You need these tips: https://goo.gl/8HgnCF

Best Answer

Compute method would do the job you are looking for.

Try following code:

@api.multi
def _calc_something(self):
for rec in self:
rec.compute_field = rec.field1 + rec.field2 # your logic goes here...


compute_field = fields.Float(string='My Compute Field', compute='_calc_something')

Add your compute field (compute_field) in the tree and/or form view so that it will call the function everytime the record is loaded.


Avatar
Discard
Best Answer

Hello Wildhen,


In Odoo, You can define a compute/functional field and define a method for that field.


Compute method will be called when user see the form view. You have to create a compute field with store=False. You must display your output in that compute field.


It is necessary to display compute field in form view otherwise compute method will not be called.


If in case you do not want to add a field, you can override ORM's a method called " def fields_view_get". This method is called when a view is loaded.

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard