Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to set filter on a pre-defined field of another model

Naroči se

Get notified when there's activity on this post

This question has been flagged
filteroverridefilter_domainodoo16features
3 Odgovori
3602 Prikazi
Avatar
Masood Zarei

Hi friends,

I have a new model that aims to extend 'res.partner' model.

Now, I want to set a filter on the 'country_id' field of 'res.partner' model to show just some countries that their's list is set in Config Params(For this, I've also set a new field in the Config Params that the user can choose some countries, so I want the field of Country in the contact page to show just those selected ids).

How can I do that? What is the best solution?


I've done the following:

widly_used_countries=fields.Many2many(
​string='Widly Used Countries',
​comodel_name="res.country",
​compute="_compute_widly_used_countries",
​store=True
)

def_compute_widly_used_countries(self):
​country_ids=eval(self.env['ir.config_parameter'].sudo().get_param('exchange.widely_used_countries'))
​domain=[('id', 'in', country_ids)]
​self.widly_used_countries=self.env['res.country'].search(domain)

And my soultion is to override country_id field as follow:

country_id=fields.Many2one(

​comodel_name="res.country",

​​domain="[('id', 'in', widly_used_countries)]"

)


And now when I upgrade the module, Odoo raises the error that the 'widly_used_countries' should be presented in the view.

To do so, I've also defined a new view inheriting the 'base.view_partner_form'.

But in each place I put 'widly_used_countries', the Odoo error still remains.

I don't know why?


0
Avatar
Opusti
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi

The error that you are getting is because the widly_used_countries field is not defined in the view that you are inheriting. To fix this, you need to add the widly_used_countries field to the view.
 You can do this by adding the following code to the view:
 <field name="widly_used_countries" widget="many2many_list" />

Hope it helps

0
Avatar
Opusti
Avatar
CandidRoot Solutions Private Limited
Best Answer

Hello 

i have checked your exising code. i would suggest you to inherit res.partner form view and add domain in view for country_id field as below instead of writing in python code.

domain="[('id', 'in', widly_used_countries)]"

Thanks & Regards,

​

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat

0
Avatar
Opusti
Avatar
Mehjabin Farsana
Best Answer

Hi,

It looks like the error that you are facing is due to the view inheritance.

please make sure that , you have the widly_used_countries field available in the res.partner model to avoid any issues during view inheritance.


Define a new view in your custom module that inherits the base.view_partner_form view and add your field in this view



Hope this will help you

thanks



0
Avatar
Opusti
Masood Zarei
Avtor

As I said, I did what you offered

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Odoo16 CE: add search filter for CRM activity deadline through frontend
filter_domain odoo16features
Avatar
Avatar
1
jul. 23
2869
Filter One2many field in res.partner Solved
filter one2many odoo16features
Avatar
Avatar
1
jan. 24
2607
v16: Domain filter is not working in categ_id ( Product Category )
filter domain odoo16features
Avatar
Avatar
1
okt. 23
2570
odoo16: filter with List of distinct Mobile numbers to select
filter activity odoo16features
Avatar
1
sep. 23
2520
How to filter records based on a parent field's id Solved
many2many filter_domain odoo16features
Avatar
Avatar
2
mar. 23
3704
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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