تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
1351 أدوات العرض

I am trying to add record rule:



class ResPartner(models.Model):
_inherit = 'res.partner'

@api.model
def _search(self, args, offset=0, limit=None, order=None, access_rights_uid=None):

if not self.env.user.has_group('hat_sales_updates.part_restrict_group'):
args = [('team_id', '=', self.env.user.sale_team_id.id)] + args
else:
args = [(1, '=', 1)] + args

return super(ResPartner, self)._search(args, offset=offset, limit=limit, order=order,
access_rights_uid=access_rights_uid)

but the error ocures:
maximum recursion depth exceeded while calling a Python object
in odoo17
in xml user access error occures:



الصورة الرمزية
إهمال
أفضل إجابة

1. XML Access Rule:

The XML definition you provided for restricting partner access seems correct, but you might need to double-check a few things:

  • Make sure the group hat_sales_updates.part_restrict_group is properly assigned to the intended users.
  • Ensure that the field team_id exists in the res.partner model and is correctly populated.

2. Maximum Recursion Depth Issue:

The recursion error usually occurs because the _search method is being called repeatedly without an exit condition. This may be happening because your method is causing an infinite loop. The _search method might be invoking itself indirectly.

Here's a refined version of your _search method that should help avoid recursion:



class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def _search(self, args, offset=0, limit=None, order=None, access_rights_uid=None):
        # Avoid recursion by checking the environment
        if self.env.context.get('prevent_recursion', False):
            return super(ResPartner, self)._search(args, offset=offset, limit=limit, order=order,
                                                   access_rights_uid=access_rights_uid)

        if not self.env.user.has_group('hat_sales_updates.part_restrict_group'):
            args = [('team_id', '=', self.env.user.sale_team_id.id)] + args

            # Set a context key to prevent recursion
            ctx = dict(self.env.context, prevent_recursion=True)
            return super(ResPartner, self.with_context(ctx))._search(args, offset=offset, limit=limit, order=order,
                                                                    access_rights_uid=access_rights_uid)

        return super(ResPartner, self)._search(args, offset=offset, limit=limit, order=order, access_rights_uid=access_rights_uid)

   

The line self.env.context.get('prevent_recursion', False) checks if recursion prevention is already in place.

  • self.with_context(ctx) sets a context variable prevent_recursion to avoid further recursion calls.


You might also need to update your access rules. Make sure you have a record rule like this:


    Partner restricted to sales team
    
    
    [('team_id', '=', user.sale_team_id.id)]

Try these adjustments, and restart your Odoo server to apply the changes.

الصورة الرمزية
إهمال
أفضل إجابة

Hi Asma,
Did you find any solution for it?

الصورة الرمزية
إهمال
أفضل إجابة

I think u should use xml ir.rule only

You need to add another record rule for hat_sales_updates.admin (if you have any) with domain_force 1=1 too this way will help Michell Admin can accessible

الصورة الرمزية
إهمال