This question has been flagged
3 Replies
5495 Views

hello ,

how can i call class function to run automaticaly when its view opens,  without use the option 'compute' on fields?

ex:

class test(models.Model):

    def autoRun(self):

        /// function code

    name = fields.Char('name', compute='autoRun')
# i  w'ld like run autoRun() without use compute on a field

Avatar
Discard

Try onchange for the specified field.

Best Answer

I think a fields_view_get method would be of use to you in this case. fields_view_get method is executed whenever a view loads. Try this below code.

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(ChrimsAccountGroup, self).fields_view_get(view_id=view_id, view_type=view_type,
toolbar=toolbar, submenu=submenu)
# Write your code here which should be executed on view load
return res

Hope it solves your issue.


Avatar
Discard

Hii,

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(saleOrder, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
if view_type == 'search':

for lead in self.env['sale.order'].sudo().search([]):
lead.access_compute_level_users()

return res
when i load the compute function with field view get function loading issue is generated how can i solve this

Best Answer

call your function on default create function.

@api.model
def create(self, values):
# Call your function here
autoRun()
return super(test, self).create(values)


Avatar
Discard