Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    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
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

How to write Record Rule with domain based on the company_dependent Fields

Subscribe

Get notified when there's activity on this post

This question has been flagged
odoo12.0
3 Replies
10639 Views
Avatar
Mohammed Zubair

I want to write a record rule with domain based on the company_dependent fields (means that field value is storing in ir.property Model). 

Means, I have one field i.e. x_company_dependent_field in product.category Model and I want to write one record rule in product. In record-rule domain, I want to compare the product.category fields value with the User fields i.e. x_any_field (normal field).



so that domain can be like below.

Like(domain),  [('categ_id.x_company_dependent_field', '=', user.x_any_field)]


I have tried with same but not working.

But when I am giving 'False' value then showing me products.


Like,  [('categ_id.x_company_dependent_field', '=', False)]


How can we handle this part ?

odoo12

Thanks in advance

0
Avatar
Discard
Avatar
Mohammed Zubair
Author Best Answer

I got the problem area for record-rule on company-dependent fields in multi-company case.

When we work with multi-company scenario that means if user logged into their account system should show his company in code i.e. self.env.user.company_id. Instead of this everytime system takes ADMIN(2) user company.

So that record-rule does not satisfied.

Problem-statement

Followings are the output from odoo files.

file: odoo/models.py [def _search(). line-4130]

Working-Condiiton with Main Company

When I login with the current company then query prepare with proper product.category company dependent fields. In this condition domain is properly taking main company id i.e. 3.

below is final query :

auto-prepared domain: ir.property() -->[('fields_id', '=', 10385), ('company_id', 'in', [3, False]), ('value_reference', 'in', ['x_business_team,2', 'x_business_team,5'])] 

ir.property query

 <osv.Query: "SELECT ... FROM "ir_property" WHERE ((("ir_property"."fields_id" = %s)  AND  (("ir_property"."company_id" in (%s)) OR "ir_property"."company_id" IS NULL))  AND  ("ir_property"."value_reference" in (%s,%s)))" with params: [10385, 3, 'x_business_team,2', 'x_business_team,5']>

Query:

<osv.Query: "SELECT ... FROM "product_category" WHERE ("product_category"."id" in (%s,%s,%s,%s,%s,%s,%s,%s))" with params: [14, 15, 16, 17, 18, 64, 40, 71]>


we can see, quer is taking product.category proper id based on the company-dependent fields i.e. from ir.property

SELECT count(1) FROM "product_template" LEFT JOIN 

                (SELECT res_id, value FROM "ir_translation"

                 WHERE type='model' AND name=%s AND lang=%s AND value!='')

             as "product_template__name" ON ("product_template"."id" = "product_template__name"."res_id") WHERE (("product_template"."active" = %s)  AND  ("product_template"."type" in (%s,%s))) AND ((((("product_template"."company_id" in (%s,%s))  OR  ("product_template"."company_id" in (%s)))  OR  "product_template"."company_id" IS NULL )  OR  ("product_template"."id" in (SELECT "product_template_id" FROM "x_product_template_res_partner_rel" WHERE "res_partner_id" IN %s)))  AND  ("product_template"."categ_id" in (%s,%s,%s,%s,%s,%s,%s,%s))) ['product.template,name', 'en_US', True, 'consu', 'product', 3, 1, 3, (8,), 14, 64, 15, 16, 17, 18, 71, 40]


Not working-condition with other company

When I login with the other company then query prepare with product.category company dependent fields as FALSE condition. Because in condition domain, we can see its taking main company i.e. id=3 but current company is 10.

auto-prepared domain:  ir.property() [('fields_id', '=', 10385), ('company_id', 'in', [3, False]), ('value_reference', 'in', ['x_business_team,33'])]

ir.property query

"SELECT ... FROM "ir_property" WHERE ((("ir_property"."fields_id" = %s)  AND  (("ir_property"."company_id" in (%s)) OR "ir_property"."company_id" IS NULL))  AND  ("ir_property"."value_reference" in (%s)))" with params: [10385, 3, 'x_business_team,33']>

Query

<osv.Query: "SELECT ... FROM "product_category" WHERE FALSE" with params: []>

But here is coming as False.


SELECT count(1) FROM "product_template" LEFT JOIN 

                (SELECT res_id, value FROM "ir_translation"

                 WHERE type='model' AND name=%s AND lang=%s AND value!='')

             as "product_template__name" ON ("product_template"."id" = "product_template__name"."res_id") 

WHERE ("product_product"."active" = %s) AND ("product_product"."product_tmpl_id"="product_product__product_tmpl_id"."id") AND (FALSE  AND  ("product_product__product_tmpl_id"."categ_id" in (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s))) AND ((((("product_product__product_tmpl_id"."company_id" in (%s,%s))  OR  ("product_product__product_tmpl_id"."company_id" in (%s)))  OR  "product_product__product_tmpl_id"."company_id" IS NULL )  OR  ("product_product__product_tmpl_id"."id" in (SELECT "product_template_id" FROM "x_product_template_res_partner_rel" WHERE "res_partner_id" IN %s)))  AND  FALSE)


That means, because of the company comparison it is not taking product.category company-dependent fields value from ir.property model.


Solutions

In ir.rule model, method: def domain_get(), we can make self as current company after check 'force_company' not in self.env.context. by using,

self = self.with_context({'force_company': self.env.user.company_id.id})

then call super method.

In ir.rule model, method: def _compute_domain_keys(), we can append 'force_company' in returned list after super method call.

res.append('force_company')


working query:

its taking proper company i.e. 10 in domain

ir.property query:

 ir.property() [('fields_id', '=', 10385), ('company_id', 'in', [10, False]), ('value_reference', 'in', ['x_business_team,33', 'x_business_team,34'])]


<osv.Query: "SELECT ... FROM "ir_property" WHERE ((("ir_property"."fields_id" = %s)  AND  (("ir_property"."company_id" in (%s)) OR "ir_property"."company_id" IS NULL))  AND  ("ir_property"."value_reference" in (%s,%s)))" with params: [10385, 10, 'x_business_team,33', 'x_business_team,34']>

<osv.Query: "SELECT ... FROM "ir_property" WHERE ((("ir_property"."fields_id" = %s)  AND  (("ir_property"."company_id" in (%s)) OR "ir_property"."company_id" IS NULL))  AND  ("ir_property"."value_reference" in (%s,%s)))" with params: [10385, 10, 'x_business_team,33', 'x_business_team,34']>


product.category query:

<osv.Query: "SELECT ... FROM "product_category" WHERE ("product_category"."id" in (%s,%s,%s))" with params: [70, 71, 72]>


main query:

SELECT count(1) FROM "product_template" LEFT JOIN 

                (SELECT res_id, value FROM "ir_translation"

                 WHERE type='model' AND name=%s AND lang=%s AND value!='')

             as "product_template__name" ON ("product_template"."id" = "product_template__name"."res_id") WHERE (("product_template"."active" = %s)  AND  ("product_template"."type" in (%s,%s))) AND ((((("product_template"."company_id" in (%s,%s))  OR  ("product_template"."company_id" in (%s)))  OR  "product_template"."company_id" IS NULL )  OR  ("product_template"."id" in (SELECT "product_template_id" FROM "x_product_template_res_partner_rel" WHERE "res_partner_id" IN %s)))  AND  (("product_template"."categ_id" in (%s,%s,%s))  AND  (("product_template"."categ_id" in (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s))  OR  ("product_template"."categ_id" in (%s,%s,%s))))) ['product.template,name', 'en_US', True, 'consu', 'product', 10, 1, 10, (6662,), 70, 71, 72, 38, 39, 1, 56, 3, 14, 65, 79, 80, 81, 64, 15, 16, 17, 18, 86, 70, 71, 72, 82, 83, 84, 76, 77, 78, 66, 68, 67, 85, 73, 74, 75, 40, 41, 42, 43, 44, 57, 45, 46, 48, 49, 50, 51, 52, 55, 53, 54, 47, 70, 71, 72]

0
Avatar
Discard
Avatar
Adil Akbar
Best Answer

Hi, 

You can see following for this:

https://youtu.be/GkNgc-fZO-I

Hope it helps,

Thanks

0
Avatar
Discard
Avatar
Jaga
Best Answer

Try this example :           

self.write({'list_price': value})

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
अक्तू॰ 25
1946
loan request
odoo12.0
Avatar
Avatar
1
सित॰ 23
3981
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
मई 23
2939
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
अप्रैल 23
3691
Inherit Element form kanban View Solved
odoo12.0
Avatar
Avatar
1
मार्च 23
2861
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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