Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Odoo fields_view_get dynamically after all records being loaded and fields_view_get function called

Tags:

I’d like to trigger the fields_view_get function dynamically after doing some functions. I override the function fields_view_get and return my results. This gets affected on XML view only at first time the actual function called. So I need to refresh the view to get affect new values on arch.

Is there any way to make the odoo view get changed with fields_view_get function even after the function was called for the first time?

My attempt:

# here fields view get changes the button string from getting arch # I overrided the fields_view_get on event model and its get affected and works # perfectly when I click on main menu Event.but not after the records loaded.  @api.multi def send_mail_event(self):     x = self.event_id.fields_view_get(view_id=None, view_type='form', toolbar=False, submenu=False)     self.send_mail_event_reg_link(test=True)     return x 
like image 803
Hilar AK Avatar asked Aug 28 '17 07:08

Hilar AK


1 Answers

The fields_view_get gets called from the load_views at https://github.com/odoo/odoo/blob/10.0/odoo/models.py#L1334 and the load_views gets called by the web client's view manager at https://github.com/odoo/odoo/blob/10.0/addons/web/static/src/js/view_manager.js#L130

Now, see in the view_manager.js where is the load_view called from and when. We can see that it is called at https://github.com/odoo/odoo/blob/10.0/addons/web/static/src/js/view_manager.js#L182 which is the call that interests us.

The willStart function if you see on the widget.js is called when the widget is attached on the DOM it manages. The attachment happens only once when the dom is loaded.

So, to recap, the fields_view_get is run once when the page is loaded and if you want to call it again you are going to need to do it from the js/web client side of things by calling the load_views javascript function.

But usually in Odoo, try to avoid web client extensions if possible. If you want to make changes on the current view based on actions of the user you can use onchange or any other backend hook.

like image 188
George Daramouskas Avatar answered Feb 23 '23 00:02

George Daramouskas