Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How to filter an ManytoOne field using domain filter.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
many2onedomain_filterfilteringdropdownlistodoo17
2 Respostes
1513 Vistes
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
Descartar
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
Descartar
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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
Domain Filtering help opposite of child_of opperator Solved
domain_filter filtering
Avatar
Avatar
1
de març 15
14630
How can I dynamically filter many2one fields in Odoo 17 models? Solved
many2one domain_filter dynamic filter
Avatar
Avatar
Avatar
Avatar
3
d’ag. 25
3377
Filter product in order line using code
filtering order.lines odoo17
Avatar
Avatar
1
de set. 24
1209
How to remove 'Create' and 'Edit' in the Many2one field of all models? Solved
views many2one odoo17
Avatar
Avatar
Avatar
3
de jul. 24
4740
how to load one to many field in pos session odoo17?
pos many2one odoo17
Avatar
0
de juny 24
70
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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