Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Need help with domain in Many2one field

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
domainpyhtonv17
3 Odpowiedzi
7943 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
IRIG Events
Autor Najlepsza odpowiedź

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
Awatar
Odrzuć
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

Awatar
Cybrosys Techno Solutions Pvt.Ltd
Najlepsza odpowiedź

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
Awatar
Odrzuć
Awatar
Mily Shajan
Najlepsza odpowiedź

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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Connecting a Namecheap domain with the Odoo app hosted on an AWS EC2 instance
domain ec2 v17
Awatar
Awatar
2
lut 24
2862
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Awatar
Awatar
1
paź 25
1258
How to add a new Many2one field in res.config.settings? Rozwiązane
v17
Awatar
Awatar
Awatar
Awatar
4
paź 25
3603
Add field to ALL models in Odoo
v17
Awatar
Awatar
Awatar
2
wrz 25
2272
How to disable Email notification - You have been assigned to Rozwiązane
v17
Awatar
Awatar
Awatar
Awatar
4
wrz 25
7626
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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