İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
2427 Görünümler
here is my code in models.py file
class ResUsers(models.Model):
_inherit = 'res.users'

def __init__(self, pool, cr):
init_res = super(ResUsers, self).__init__(pool, cr)
type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
type(self).SELF_WRITEABLE_FIELDS.extend(['token', 'checkin'])
type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
type(self).SELF_READABLE_FIELDS.extend(['token', 'checkin'])
return init_res

token = fields.Char("Device Token", default="[]", groups="base.group_user")
checkin = fields.Boolean(string='Check-in', default=False, groups="base.group_user")


@api.model
def create(self, vals):
user = super(ResUsers, self).sudo().create(vals)
_logger.info("user %s", user)
# user.action_create_employee()
return user
​the error i'm getting due to this code is
RecursionError: maximum recursion depth exceeded while calling a Python object



thanks in advance
Avatar
Vazgeç
En İyi Yanıt

Hi,


Try this code:


from odoo import models, fields, api


class ResUsers(models.Model):

    _inherit = 'res.users'


    token = fields.Char("Device Token", default="[]", groups="base.group_user")

    checkin = fields.Boolean(string='Check-in', default=False, groups="base.group_user")


    @api.model

    def create(self, vals):

        user = super(ResUsers, self).sudo().create(vals)

        _logger.info("user %s", user)

        # user.action_create_employee()

        return user


It seems like you were trying to modify the SELF_WRITEABLE_FIELDS and SELF_READABLE_FIELDS attributes of the model, but this is usually not done in the __init__ method. If you need to modify these attributes, it's better to do it directly in the class definition.




Hope it helps

Avatar
Vazgeç
En İyi Yanıt

The error message “RecursionError: maximum recursion depth exceeded while calling a Python object” is a safety mechanism in Python. It prevents your program from entering an infinite loop and using up all the stack space. This error usually occurs when the base case of a recursive function is not defined correctly.


In your case, the error might be due to the way you’re calling the super function in your __init__ method. When you call super(ResUsers, self).__init__(pool, cr), it calls the __init__ method of the parent class, which is res.users. If res.users is also inheriting from ResUsers, it will call the __init__ method of ResUsers again, leading to an infinite loop.


Here’s how you can fix this: 


class ResUsers(models.Model):

    _inherit = 'res.users'


    def __init__(self, pool, cr):

        super(models.Model, self).__init__(pool, cr)  # Call the __init__ method of models.Model instead of res.users

        type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)

        type(self).SELF_WRITEABLE_FIELDS.extend(['token', 'checkin'])

        type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)

        type(self).SELF_READABLE_FIELDS.extend(['token', 'checkin'])


    token = fields.Char("Device Token", default="[]", groups="base.group_user")

    checkin = fields.Boolean(string='Check-in', default=False, groups="base.group_user")


    @api.model

    def create(self, vals):

        user = super(ResUsers, self).sudo().create(vals)

        _logger.info("user %s", user)

        return user


This code calls the __init__ method of models.Model instead of res.users, which should prevent the infinite loop.

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Şub 16
5831
1
Mar 15
11513
sequence odoo16 Çözüldü
1
Mar 23
2971
1
Eyl 16
2766
1
Şub 16
5244