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
The
fields_view_getgets called from theload_viewsat https://github.com/odoo/odoo/blob/10.0/odoo/models.py#L1334 and theload_viewsgets 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#L130Now, see in the
view_manager.jswhere is theload_viewcalled 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
willStartfunction 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_getis 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 theload_viewsjavascript 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
onchangeor any other backend hook.