24

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
bfontaine
  • 14,702
  • 12
  • 64
  • 87
Hilar AK
  • 1,579
  • 8
  • 24
  • 2
    can you please give more detail what you try to achieve. – Heroic Sep 05 '17 at 09:33
  • 1
    simply need to trigger the fields_view_get function , But odoo only calls one time and after loaded all data its uses the manipulations on loaded content, actuallt I tries to change the string of button with some other data. but its only getr affected after a relaod. so I tried to call fields view get. bu it doesnt take effect @Heroic – Hilar AK Sep 05 '17 at 10:10
  • 1
    Instead of doing that you can add multiple button and based on the condition you can make it visible or invisible. like attrs="{'invisible': [('show_leaves','=', False)]}" – Heroic Sep 05 '17 at 10:51
  • 1
    actually i am adding data ie, the next execution time of mail queue with string – Hilar AK Sep 05 '17 at 11:29
  • 1
    You can do it by adding state button , for that you have to add one field and write your execution time to that particular field and then add state button. – Heroic Sep 05 '17 at 11:36
  • state button means? class="oe_stat" ?? – Hilar AK Sep 06 '17 at 03:21
  • I mean , class="oe_stat_button" – Heroic Sep 06 '17 at 03:23
  • so can i add it in list view? – Hilar AK Sep 06 '17 at 03:23
  • no you can not add it in list view – Heroic Sep 06 '17 at 03:24
  • But my button is on list view and thats why I changed the button string using updating arch – Hilar AK Sep 06 '17 at 03:25
  • `actuallt I tries to change the string of button with some other data` When do you want the text string of the button changed? – George Daramouskas Sep 06 '17 at 09:03
  • when the form is laoded , – Hilar AK Sep 08 '17 at 03:09
  • i didn't understand exactly what you want, may be it can be don without triggering the `fields_view_get` at all, when you click on the menu you open a list view the buttons have a text and you want to change that text after what after clicking on it? you want to change all button string or for that record only? – Charif DZ Oct 28 '17 at 07:26
  • simply can we trigger the fields_view_get function from a custom function after the form is loaded? – Hilar AK Oct 30 '17 at 11:44
  • I called the fields view get function and got the arch values, but how could i make them effect on views? Here in form I have a button which will fetch the next execution time from ir.cron model. this is actually updating if whenever the fields view get function loaded, else it is idle. not updated. If we need to update the button string we have to click on the main menu again, for eg: Accounting or Sales, if button is on invoice form. This is actually not a good method I think if we need to know the exact time change. @Tchi-Odoo – Hilar AK Oct 30 '17 at 11:50
  • really intersting what you want to do but i think you need to power of javascript here to refresh the view. from what i understand the button string will be loaded in the first time only. can you put example of the string what will contains when it changes. and what is the event that changes the string is it after a period of time or when the user click on the button it self?!! – Charif DZ Oct 30 '17 at 14:32
  • @Tchi-Odoo You are right, I made it with a reload already, but here i asked to get a good method, its related to mail scheduling time, while button click. so i made it with a reload now. I am sure we can achieve with the backbone js odoo – Hilar AK Oct 31 '17 at 04:06

1 Answers1

6

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.

George Daramouskas
  • 3,470
  • 3
  • 18
  • 48
  • https://github.com/odoo/odoo/blob/856908b3e61e79691cb4730267b7be08ef50b15f/addons/web/static/src/js/services/data_manager.js#L74 I solved my problem from here – HERAwais Jun 24 '20 at 11:14