Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1438 มุมมอง

I have tried to modify the search method in Odoo 17 to show only the contacts the user has permission to view based on tags. However, this has not worked, even though it was functional in version 16 without any issues. Here is the code:

from odoo import fields, models,api

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

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

user = self.env.user
if not user.view_all_contacts:
allowed_categories = user.allowed_partner_category_ids.ids

if allowed_categories:
args = args or []
args.append(('category_id', 'in', allowed_categories))
else:

args = args or []
args.append(('id', '=', -1))

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



from odoo import api, fields, models


class ResUsers(models.Model):
_inherit = "res.users"

allowed_partner_category_ids = fields.Many2many(
string="Allowed Partner Categories",
comodel_name="res.partner.category",
relation="prt_user_partner_category_rel",
column1="user_id",
column2="category_id",
)

view_all_contacts = fields.Boolean(
string="View All Contacts",
help="If checked, this user will be able to view all contacts without restrictions.",
)



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ม.ค. 25
1229
7
ธ.ค. 24
8106
0
ก.ค. 24
1176
1
เม.ย. 24
1819
0
พ.ค. 24
1592