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

[SEARCH] How to search in Odoo 16

Subscriure's

Get notified when there's activity on this post

This question has been flagged
many2oneone2manysearchid
3 Respostes
4955 Vistes
Avatar
BB

I have 2 model: contract, tenant.

I want to know tenant_id have in contract. 


Model Contract: 

class PmaContract(models.Model):    
​_name = "pma.contract"   
​_inherit = ["mail.thread", "mail.activity.mixin"]   
​_description = "Manage contract"
    ​state = fields.Selection([
​ ​("draft", "Draft"),           
​ ​("to_link", "To link"),
          ("active", "Active"),           
​ ​("expired", "Expired"),           
​ ​("liquidated", "Liquidated")],       
​ ​string="Status",       
​ ​copy=False, index=True, readonly=True, store=True)
    ​lessor = fields.Many2one("res.users",string="Party A (Lessor)",store=True,        required=True,    )
    apartment = fields.Many2one("pma.apartment", string="Apartment name", required=True)
    room = fields.Many2one("pma.apartment.room",string="Room name", domain="[('apartment', '=', apartment)]",        ondelete="restrict",        store=True,        required=True,    )    floor = fields.Many2one(related="room.floor")
    duration_from = fields.Date(string="From", store=True, required=True)    duration_to = fields.Date(string="To", store=True, required=True)
    lessee = fields.Many2one("pma.tenant", string="Representative", store=True, ondelete="restrict", required=True, domain="[('owner', '=', lessor)]",    )
​name = fields.Char(string="Contract ID", compute="_compute_name", store=True)   
​member = fields.Many2many("pma.tenant", store=True, string="Member",domain="[('owner', '=', lessor), ('id', '!=', lessee)]",)

Model Tenant: class PmaTenant(models.Model):   
​_inherit = "pma.tenant"
    ​ ​contract_id = fields.One2many("pma.contract", "lessee", string="Contract", copy=True)
I want to get Tenant(lessee) when contract have status = "active", "liquidated" and don't have in contract.

Please help me ....

0
Avatar
Descartar
Avatar
BB
Autor Best Answer

I have 2 model: Contract & Room. 


In model room I have a selection field to set state for room. 


They are my model:


- Room:

	​
class PmaApartmentRoom(models.Model):    
​_inherit = "pma.apartment.room"
    contract = fields.One2many("pma.contract", "room", string="Contract")
    state = fields.Selection([
​ ​("available", "Available"),
​ ​("rented", "Rented")],
​ ​string="Status", copy=False,
​ ​index=True, readonly=True, store=True, tracking=True)
  class PmaContract(models.Model):   
​_name = "pma.contract"   
​_inherit = ["mail.thread", "mail.activity.mixin"]   
​_description = "Manage contract"
    state = fields.Selection([
​ ​("draft", "Draft"),           
​ ​("to_link", "To link"), 
        ​("active", "Active"),
        ("expired", "Expired"), 
        ("liquidated", "Liquidated")],       
​ ​string="Status", default="draft", copy=False,       
​ ​ index=True, readonly=True, store=True, tracking=True,)
   
​room = fields.Many2one("pma.apartment.room", string="Room name",        ​ ​domain="[('apartment', '=', apartment)]",        ​ ​ ​ ​ ​ ​ondelete="restrict", store=True, required=True, tracking=True)
State of contract = "active" => state of room = "rented".

State of contract in ["draft", "to_link", "expried", "liquidated"] => state of room = "available"


Please help me ....


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

Hi,

Use Odoo's domain filter to limit your search results to tenants (lessees) with contracts with the status "active" or "liquidated" but no other statuses. These domain requirements can help you achieve this:

tenants_active_liquidated_contracts = self.env['pma.tenant'].search([
    ('contract_id.state', 'in', ['active', 'liquidated']),
    ('contract_id', '!=', False),
])

# You currently have a list of tenants with active or liquidated contracts.
for tenant in tenants_active_liquidated_contracts:
    print("Tenant Name:", tenant.name)  # Replace 'name' with the actual field you want to display


To find tenants who meet the required criteria, we use the search method on the pma.tenant model. We use a domain filter to check if the contract_id field (One2many) is not empty, meaning the tenant has contracts. The state of the contracts (contract_id.state) is also checked to see if it falls within the category of "active" or "liquidated" statuses. The tenants who have contracts with the stated statuses and who don't have contracts with other statuses will be listed for you. The tenant information can then be accessed by iterating through this recordset as needed


Hope it helps

0
Avatar
Descartar
Avatar
Savya Sachin
Best Answer

Hi,

Try like this in order to get tenants which satisfy your condition mentioned above,

tenant_ids = self.env['pma.tenant'].search(['|',('contract_id.state', 'in', ['active', 'liquidated']),
('contract_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
How do I put One2many after Many2one defined? - transient module states reset
many2one one2many
Avatar
1
de març 23
3225
Odoo Studio how to set a chain of multiple and related Many2one within a One2many lines
many2one one2many
Avatar
0
de des. 22
3820
filter according to comodel's fields
many2one one2many
Avatar
0
de juny 21
3520
Show self related record value in tree view for custom model Solved
date many2one one2many search self.env.search
Avatar
Avatar
1
de des. 20
4434
How to display other fields of a onetomany relation ?
many2one one2many
Avatar
0
de juny 20
6381
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