تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (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
حول هذا المنتدى
المساعدة

Conditionally apply Domain on a field

اشتراك

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

لقد تم الإبلاغ عن هذا السؤال
domainv7domainscondition
3 الردود
29247 أدوات العرض
الصورة الرمزية
Shaumyadeep Chaudhuri

Is it posssible to apply a domain only when some condition is true otherwise the domain should not be applied in V7

For eg. in a many2one field to hr.employee, the manager should be able to see only the employee under him but someone from the hr department should be able to view all the employees in the view.

1
الصورة الرمزية
إهمال
Shaumyadeep Chaudhuri
الكاتب

No one know how to do it? is it even possible?

الصورة الرمزية
Shaumyadeep Chaudhuri
الكاتب أفضل إجابة

I solved the problem I couldn't find a regular way to do what i wanted. I feel this is a bit hackish way to achieve what i wanted; what i did was override the fields-view_get method and implemented what i wanted in that. here's a sample code of what i did, maybe it'll help other looking to implement similar functionality

def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):

    """
    Overrides orm field_view_get.
    @return: Dictionary of Fields, arch and toolbar.
    """

    res = {}
    res = super(employee_exit, self).fields_view_get(cr, user, view_id, view_type,
                                                   context, toolbar=toolbar, submenu=submenu)

    hr_employee = self.pool.get('hr.employee')
    emp = hr_employee.search(cr, user, [('user_id', '=', user)])[0]
    logged_employee = hr_employee.browse(cr, user, emp)
    from lxml import etree
    doc=etree.XML(res['arch'])
    for node in doc.xpath("//field[@name='target_employee_id']"):
        if not logged_employee.department_id.name == "Human Resources":        
            node.set('domain', "['&','|',('parent_id.user_id', '=', uid),('department_id.manager_id.user_id','=',uid),('user_id','!=',uid)]")
        elif logged_employee.department_id.manager_id.user_id.id==user:
            node.set('domain', "[('user_id','!=',uid)]")
        else:
            node.set('domain', "['&','&',('user_id','!=',uid),('user_id','!=',"+str(logged_employee.department_id.manager_id.user_id.id)+\
                     "),('user_id','!=',"+str(logged_employee.parent_id.user_id.id)+")]")
    res['arch']=etree.tostring(doc)
    return res

EDIT: I can't mark this as the answer as i don't have sufficient points. if somebody finds it useful and doesn't know of any better method please mark this as the answer so it may be visible to others in need at the top

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

Funny enough, the question and the example provided can have two different answers:

Is it possible to have a a "conditional" domain?

Yes, by building the domain in a smart way, using OR (|) operators. For example, on a particular Model having a company_id field, you could use:

['|',('company_id','child_of',[user.company_id.id]),('company_id','=',False)]

Here the "child of" condition will only be enforced if the record's "company_id" has a value.

The manager should see only his employees, but hr department should see all

To easiest way to achieve this is to have two user Groups. The Managers group has a record rule to view only his employees and the HR manager group has a record rule to see all employees. You can find a similar example in the CRM app: there is a "Sales / See Own Leads" group and a "Sales / See All Leads" group.

Record rules apply to current record based on User attributes. You would need to know the Department to use for the current User, but AFAIK that info is not available in the User model. You would somehow need to have a department_id in the User and then could create a record rule (or many2one domain) similar to:

['|',('department_id','child_of',[user.department_id.id]),(False,'=',user.department_id)]
2
الصورة الرمزية
إهمال
Shaumyadeep Chaudhuri
الكاتب

Thanks, that was educational but i have a many2one field to hr.employee which is being displayed in the view obviously as a dropdown, now what i want is if the logged in user has department the HR then when he uses the drop down he should be able to see all the employees of the other departments and all the employees below him in HR Department, but if the logged in user is a not of the HR Department and uses the dropdown he should be able to see only the employees he the parent of. Also please explain in the above example which company_id do you mean the user.company_id or 'company_id'

Daniel Reis

Expanded the answer. The feature you need would ge a great addition to lp:openerp-hrms.

Shaumyadeep Chaudhuri
الكاتب

So in short its not posssible to get exactly what i need with exisiting functionality?

Umashankar Subramani

res.user doesnt have any field like department_id.... how is it possible to use this?....i have got error.....

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

Unfortunately, you cannot add the same fieldname twice with an "invisible" condition and different domains (only the last fields domain has effect).

A domain like 

"(False,'=',user.department_id)"

 will lead to 

"ValueError: Invalid leaf (False, '=', False)"

To use different domains, you can use multiple fields, where the latter ones are related to the first.

parent_target_employee_id = fields.Many2one(
related="target_employee_id",
domain=[...],
)
# or add the domain in the view only

While I like this solution the most, it has a side effects: the write method will be called multiple times. This is at least how Odoo 14 works: the related keyword causes a "write" call on the target, which is "self" in those cases. This can be ignored for simple models, but if the write method performs a lot of checks and is not side effect free, the approach to override _fields_view_get is a more performant solution.


0
الصورة الرمزية
إهمال
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

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

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
Add my own domain via NameCheap in Odoo
domain domains
الصورة الرمزية
الصورة الرمزية
2
ديسمبر 20
6267
How to Set Fixed Filter for a User / User group ?
domain v7
الصورة الرمزية
الصورة الرمزية
1
أغسطس 15
6589
'on_change' alternative for dynamic domain on form edit تم الحل
domain on_change v7
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
5
مايو 24
26057
Are Odoo free domains applicable to free users? تم الحل
domain free domains
الصورة الرمزية
الصورة الرمزية
1
مايو 24
7461
WEBSITE NOT WORKING!!! PLEASE HELP!
domain domains website
الصورة الرمزية
0
يناير 24
2183
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "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