Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

How to filter an ManytoOne field using domain filter.

Odoberať

Get notified when there's activity on this post

This question has been flagged
many2onedomain_filterfilteringdropdownlistodoo17
2 Replies
1464 Zobrazenia
Avatar
imrantc

Hi all, 

i have 2 models , 

Passport and Employees

class PassportManagementModels(models.Model):    
_name = 'om_hrm.passport'
_description = 'Passport Master'
_inherit = ['mail.thread']
_rec_name = "passport_no"
passport_no = fields.Char(string='Passport Number',size=16,required=True) PassportIssueDate = fields.Date(string='Passport Issue Date', required=True) PassportExpiryDate =fields.Date(string="Expiry Date",required=True) PassportNationality =fields.Char(string="Nationality",size=20,required=True) Passportdob = fields.Date(string="Date of Birth",required=True)
Passportholdername = fields.Char(string="Holder Full Name",required=True) Passportpossesionwith = fields.Selection([("admin","Admin"),("staff","Staff"),("other","Other")],string="Possesion With!")
passport_doc_ids = fields.Many2many('ir.attachment',string='Passport Documents',ondelete='cascade')
_sql_constraints = [        ('key_uniq', 'unique (passport_no)', 'PassportNo must be unique.')    ]
class EmployeesManagementModels(models.Model):    
_name = 'om_hrm.employee' _description = 'Employee Master'
_inherit = ['mail.thread']
_rec_name = "full_Name"
employeeId = fields.Char(string='Employee id',required= True)
passport_id = fields.Many2one('om_hrm.passport', string='Passport', ondelete='set null',domain=lambda self:[('id','=',self._get_assigned_passport_ids())])
@api.onchange('passport_id')
def onchange_passport_id(self): # Refresh the domain for passport_id to show only unassigned passports
self._get_assigned_passport_ids()

@api.model
def _get_assigned_passport_ids(self): # Get a list of all passport IDs already assigned to any employee
allemployees = self.search([])
print("Employees list:",allemployees)
assigned_passport_ids = self.search([]).mapped('passport_id.id') print("Assigned Passport IDs:", assigned_passport_ids)
return assigned_passport_ids

i want to see the passports which are not assigned to any employees,like fetching all passport and checking if the employee table contains the id then it shouldnt show in the dropdown list.

Any help is appreciated, thanks.

0
Avatar
Zrušiť
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Please check the below code


Python

class EmployeesManagementModels(models.Model):    
_name = 'om_hrm.employee'
_description = 'Employee Master'
_inherit = ['mail.thread']

employeeId = fields.Char(string='Employee id',required= True)
assigned_passport_ids = fields.Many2many(
'om_hrm.passport', string="Assigned Passport",
compute="_compute_assigned_passport_ids")
passport_id = fields.Many2one(
'om_hrm.passport', string='Passport',
domain="[('id', 'not in', assigned_passport_ids)]")

@api.depends('passport_id')
def _compute_assigned_passport_ids(self):
for rec in self:
assigned_passport_ids = self.search([]).mapped('passport_id.id')
rec.assigned_passport_ids = assigned_passport_ids

XML


<record id="om_hrm_employee_view_form" model="ir.ui.view">
<field name="name">om_hrm.employee.view.form</field>
<field name="model">om_hrm.employee</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="employeeId"/>
<field name="assigned_passport_ids"
widget="many2many_tags" invisible="1"/>
<field name="passport_id"/>
</group>
</sheet>
<chatter/>
</form>
</field>
</record>

Hope it helps.

0
Avatar
Zrušiť
Avatar
Manish Bohra
Best Answer

Hello, 

There are multiple solution but you can do one thing add one employee field in 'om_hrm.passport' table. 

When you link any employee with passport in case you map the employee. 

After you can do one thing in case of domain apply condition domain=[('employee_id','=',False)]

Thanks.

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Domain Filtering help opposite of child_of opperator Solved
domain_filter filtering
Avatar
Avatar
1
mar 15
14596
How can I dynamically filter many2one fields in Odoo 17 models? Solved
many2one domain_filter dynamic filter
Avatar
Avatar
Avatar
Avatar
3
aug 25
3207
Filter product in order line using code
filtering order.lines odoo17
Avatar
Avatar
1
sep 24
1183
How to remove 'Create' and 'Edit' in the Many2one field of all models? Solved
views many2one odoo17
Avatar
Avatar
Avatar
3
júl 24
4613
how to load one to many field in pos session odoo17?
pos many2one odoo17
Avatar
0
jún 24
70
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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