تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    الحصول على عرض توضيحي
  • الأسعار
  • المساعدة

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • إدارة علاقات العملاء
  • e-Commerce
  • المحاسبة
  • المخزون
  • PoS
  • المشروع
  • MRP
All apps
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

How to filter records based on groups?

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
securityfilterdomaingroups
3 الردود
27983 أدوات العرض
الصورة الرمزية
Anas Taji

My goal is to build a domain filter (group rule) to achieve the following scenario:

We have 2 groups G1 & G2, users of G1 can see records created by any member of G1, but not records created by G2 members and vice versa. If user u1 is a member of both G1 & G2, then u1 can see records created by both groups users. Administrator can see all records.

3
الصورة الرمزية
إهمال
الصورة الرمزية
Anas Taji
الكاتب أفضل إجابة

Thanks to Nishant for giving us a good solution. however, this solution is more flexible.

def _groups_id(self, cr, uid, context=None):
    all_groups=self.pool.get('res.groups')
    all_categ =self.pool.get('ir.module.category')
    all_users =self.pool.get('res.users')
    # You need to replace 'Fleet' with your module name. e.g Warehous, Sales ...etc
    c_ids = all_categ.search(cr,uid,[('name','=','Fleet')])
    fleet_g_ids = all_groups.search(cr,uid,[('category_id','in',c_ids)])
    if not fleet_g_ids: return False
    user_group = all_users.browse(cr, uid, uid,context=context).groups_id
    user_group_ids = [ r.id for r in user_group]

    vals = []
    for fg_id in fleet_g_ids:
        if fg_id in user_group_ids:
            vals.append(fg_id)

    if not vals: return False
    return [(6, 0, vals)]


_columns = {
    'groups_id': fields.many2many('res.groups', 'fleet_vehicle_group_rel', 'vid', 'gid', 'Vehicle'),
            }

_defaults = {
    'groups_id': _groups_id,
    }

The domain filter (Groups Rule):

[('groups_id','in',[g.id for g in user.groups_id])]

This will completely solve the scenario, also you don't have to change the source code each time you add/remove a group.

Regards..%

3
الصورة الرمزية
إهمال
Nishant Kashyap

Well, I will try this solution as soon as possible...But I think that you figured out this approach because of the answer I posted .. And you unvoted it and remove the correct answer sign as well.. Thank you for showing this gratitude.

Anas Taji
الكاتب

1- I have mentioned you at the beginning of the post.and offered my thanks.

2- I didn't removed my vote, just the best answer sign.(you still have my vote)

3- I gave you two arbitrary votes on some of your answers in return (at the time i did so).

4- This is a better and more flexibile approach for others to follow.

And i still offer my best thanks and regards..%

Nishant Kashyap

Thank you for that , Thankyou.

Samir GUESMI

Getting me an error : Uncaught Error: Expected "]", got "(name)"

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

Hey Man Dont use the Functional field on the record rules , they wont help you, because record use applies to the record(Direct from the Database) And the functional fields are calculated when the records are shown, so they wont help you in achieveing what you are looking for.Instead try this:

_columns={
     'g1_group':fields.many2one('res.groups', string='G1 Group'),
     'g2_group':fields.many2one('res.groups', string='G2 Group'),
}

def _g1_group(self, cr, uid, context=None):
    all_groups=self.pool.get('res.groups')
    all_users =self.pool.get('res.users')
    g1_ids = all_groups.search(cr,uid,[('name','=','G1 Group')])
    if not g1_ids: return False
    if not g1_ids in all_users.browse(cr, uid, uid,context=context).groups_id:
        return False
    edit_group = all_groups.browse(cr, uid, g1_ids[0],context=context).id
    return edit_group

def _g2_group(self, cr, uid, context=None):
    all_groups=self.pool.get('res.groups')
    all_users =self.pool.get('res.users')
    g2_ids = all_groups.search(cr,uid,[('name','=','G2 Group')])
    if not g2_ids: return False
    if not g2_ids in all_users.browse(cr, uid, uid,context=context).groups_id:
        return False
    edit_group = all_groups.browse(cr, uid, g2_ids[0],context=context).id
    return edit_group

_defaults = {
    'g1_group':lambda self, cr, uid, context:self._g1_group( cr, uid, context=None)
    'g2_group':lambda self, cr, uid, context:self._g2_group( cr, uid, context=None)
}

In the Record rule check Whether the entered user is in the group so that he can see the records.

[('g1_group','in',[g.id for g in user.groups_id])]

to check for the g2 group:

[('g2_group','in',[g.id for g in user.groups_id])]

I hope this may help you.

2
الصورة الرمزية
إهمال
Anas Taji
الكاتب

Thanks Nishant, your suggested code solved the problem, but one final thing to discuss before marking the question as solved.

We need to add new field+method+default_value into the source code along with a rule for each new group in the future, as well as no user can be a member for two groups at the same time.

Can we think of a more flexible approach?

Nishant Kashyap

Well, You can add a user in different groups,And a user can be a member of two or more groups at a time, for example lets say g1_group=1 and g2_group=2 so it will check [(1,'in',[1,2,3,45,24])] in record rule.[1,2,3,45,24] is the id of other groups of the user.Well this is the default way, you can check the Setting--->Security---->Record Rules then there "Discussion group" object, there they are doing the same thing.Otherwise: You need to override def fnct_search for the functional field.Due to lack of documentation I did not able to achieve what I was looking for,

Anas Taji
الكاتب

yes you are right, user can be a member of multiple groups with no problems. however, we still need to write codes each time we decide to add a new group.

I will try to improve the code to gain more flexibility, and post back here.

Thanks again..%

luis

this is exactly what i need, can you put the steps to follow, i mean do i need to create a module with .py file, xml and so.

my goal is to do this on account.invoice, res.partner and product.product . I hope that I make myself clear. thank you for your help.

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

if you set the store=True the domain will filter you data from database. So delete the store=True , you will get the _search_user_ids..!!

0
الصورة الرمزية
إهمال
Anas Taji
الكاتب

Thanks for trying to help, but _search_user_ids..!! didn't get called.

هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
How can i select only the users belongs to a particular group in a many2many field تم الحل
filter domain users groups may2many
الصورة الرمزية
الصورة الرمزية
2
فبراير 22
8908
Filter many2one field with functional field
filter domain
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
5
سبتمبر 20
13586
Security Fear: Make fields of a model secret without using groups attribute
security groups
الصورة الرمزية
0
نوفمبر 15
5666
Problem with column iteration in domain filter
filter domain
الصورة الرمزية
1
مارس 15
6236
How to allow read parent tasks to followers
filter domain
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
2
مارس 15
8425
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now