Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2424 Lượt xem
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
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhấ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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 2 16
5831
1
thg 3 15
11509
sequence odoo16 Đã xử lý
1
thg 3 23
2970
1
thg 9 16
2766
1
thg 2 16
5244