Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Need help with domain in Many2one field

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
domainpyhtonv17
3 Replies
7842 Rodiniai
Portretas
IRIG Events

Hello,


I am struggling a bit with something and I am hoping that somebody here with a lot more experience can help me. 


I am creating a module where I have a few models, the relevant ones are: 

  • event
  • venue
  • hall
  • stand

This module is to manage stands in tradeshows, so an event can have a lot of stands, but only one venue, and a venue can have many halls and each hall can have many stands. 

At the moment it works, I am using Many2one fields to link everything up and it works. However, when I create a stand, I want to filter the options of the hall where the stand will be, to display only the available halls of the venue where the parent event is happening. 

I have been trying to accomplish that filter by using this in the stand model:

  ​event_id = fields.Many2one('dev.event', string='Event')
hall_id = fields.Many2one('dev.hall', string='Hall',
​ ​ ​ ​ ​ ​ ​domain="[('venue_id','=','event_id.venue_id')]")

Although the code doesnt throw an error, it also doesnt show any results.


I also tried taking the aproach of using a function for the domain... but that fell beyond my current experience, so I couldnt make it work.


Any help will be greatly appreciated.



1
Portretas
Atmesti
Portretas
IRIG Events
Autorius Best Answer

Hello


Mily Shajan


Thank you very much for the links. I followed the video, but when I got to download the web_domain_field module, it says it is deprecated, therefore I will leave it as a last resort.


Cybrosys


Thank you for the snippet. unfortuanately for some reason the domain does not get applied on return. I added a sneaky print() statement to verify that the function was firing and it is, but the domain remains unchanged in the field. 


Also, the isue of using the on_change hook is that it will only fire when the field is actually changed, so when I edit the record without changing the event it will display the unfiltered options. I have figured that if I create another field to display the name of the venue from a computed field, the function will fire when event is modified and also when the record is loaded. However, although the function does fire, the domain still doesnt get applied on return. Could it have some sort of typo or something?


@api.depends('event_id')

def compute_hall_ids(self):

        domain = []

        for rec in self:

            print(f'The venue Id of the event {rec.event_id.name} is: {rec.event_id.venue_id.id}')

            rec.venue_name = rec.event_id.venue_id.name

            domain = [('venue_id.id', '=', rec.event_id.venue_id.id)]

        print(domain)

        return {'domain': {'hall_id': domain}}


The printout I get for the domain is  [('venue_id', '=', 7)] as an example



cheers!


FINAL SOLUTION:

After reading the documentation more in depth, I found out that the @api.onchange and @api.depends decorators, will not fire the return statement, so that is why it wasnt being applied. 

Using the web_domain_field module did the trick for me. Even on V17. 

Cheers!



1
Portretas
Atmesti
Nicolás

Hi!
I am dealing with the same issue, working with odoo 17.

So to summarize, the only way you could solve it was by intslaling the Web Domain Field module? (https://apps.odoo.com/apps/modules/12.0/web_domain_field)

Thank you,
Nicolás

Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

You can solve the issue by applying the domain dynamically.

    


@api.onchange('event_id')

def _onchange_event_id(self):

   if self.event_id:

       domain = [('venue_id', '=', self.event_id.venue_id.id)]

   else:

       domain = []

   return {'domain': {'hall_id': domain}}


You can also refer to How to Apply Dynamic Domain for Relational Fields in 


Hope it helps

0
Portretas
Atmesti
Portretas
Mily Shajan
Best Answer

Hi 

Create a dynamic domain for the field. Check this reference to set a dynamic domain for the field

Dynamic Domain for a field

Domain for Relational Fields in Odoo


Regards

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

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

Registracija
Related Posts Replies Rodiniai Veikla
Connecting a Namecheap domain with the Odoo app hosted on an AWS EC2 instance
domain ec2 v17
Portretas
Portretas
2
vas. 24
2814
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Portretas
Portretas
1
spal. 25
1199
How to add a new Many2one field in res.config.settings? Solved
v17
Portretas
Portretas
Portretas
Portretas
4
spal. 25
3496
Add field to ALL models in Odoo
v17
Portretas
Portretas
Portretas
2
rugs. 25
2209
How to disable Email notification - You have been assigned to Solved
v17
Portretas
Portretas
Portretas
Portretas
4
rugs. 25
7527
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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