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

Odoo 13 : Problems with one2many/many2one filters

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
many2oneone2manyFiltersOdoo13
1 Odpowiedz
2216 Widoki
Awatar
Tessa Roberts

Hello everyone !


I'm having problems creating filters for "one2many" and "many2one" fields.


For one of the projects I'm working on in Odoo v13, there is a custom model named "res.partner.contact".


In the "res.partner" model definition, a "one2many" field of type "res.partner.contact" has been added. 

This field is called "contacts" and is labelled "Partner contacts". 

This new "res.partner.contact" model contains the contact's name, date of birth and relationship to the "res.partner". And a "many2one" field of type "res.partner".


"res.partner" model definition


class ResPartner(models.Model):
    _inherit = "res.partner"
    _description="Partners"
    [...]
  contacts = fields.One2many('res.partner.contact', 'partner_id',string='Partner contacts')
   [...]



"res.partner.contact" model definition


class ResPartnerContact(models.Model): 
_name = 'res.partner.contact'
    _description = "Contacts"
    [...]
    name = fields.Char(string="Name")    
    birthdate = fields.Date(string="Birthdate")
    partner_id = fields.Many2one('res.partner', string='Partner', ondelete='cascade')
[...]


In the definition of the "res.partner" search view, I'd like to add a filter to filter partners by it's contacts date of birth. 

In fact, I want to filter out all partners whose contact's date of birth falls between two given dates. 


I've tried several different filter definitions, but the wrong partners are filtered out. 

(The contacts of the filtered partners have a date of birth outside the given date range).


Example of one the filter's domain I tried to declare in the res.partner search view

domain="[('contacts.birthdate', '>=', time.strftime('2019-07-31')),('contacts.birthdate', '<=', time.strftime('2020-08-01'))]"


When I apply this filter, literally one of the first results in the list of filtered "res.partner" contains a single contact whose date of birth is "2019-05-12". So the filter doesn't work.


If I put only one of the conditions in the domain, the filter works correctly.

The "&" operation does not appear to perform the join between the two conditions.


I can't add a field with fixed dates to facilitate the filter in the "res.partner.contact" model because these dates are likely to change from one year to the next.


Has anyone created filters with similar functionality?

Do you have any idea what I could do to achieve my goal, if possible?


Thank you in advance,


Mélanie


0
Awatar
Odrzuć
Awatar
Tessa Roberts
Autor Najlepsza odpowiedź

Hi everyone,


Here's what I ended up doing to "solve" my problem.

I added a computed boolean field in the "res.partner.contact" model.


in_date_range = fields.Boolean('In date range', compute=_compute_field, search="_search_field")


Here are the compute and search functions for this field : 


     from datetime import datetime, date

def _compute_field(self):
        date_from = datetime.strptime('2019-08-01', "%Y-%m-%d")
        date_to = datetime.strptime('2020-07-31', "%Y-%m-%d")
        for record in self:
            if record.birthdate != False and record.birthdate >= date_from.date() and record.birthdate and record.in_date_range = True
            else:
                record.in_date_range = False
    def _search_field(self, operator, value):
        recs = self.search([]).filtered(lambda x : x.in_date_range is True)
        if recs:
            return [('id', 'in', [x.id for x in recs])]


In the search view of the "res.partner" model, I've added a filter with the following domain:


domain="[('contacts.in_date_range', '=', True)]"


I would have preferred to be able to search directly by dates, but that doesn't seem possible and this solution works.

The next step will be to make the search function dynamic by allowing the user to enter dates.


I'm going to close this post.

If by some miracle I find another solution, I might come and update it if I can.


Goodbye


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ść
Create/Update: a mandatory field is not set
error many2one one2many Odoo13 mandatory-field
Awatar
Awatar
1
paź 23
3829
How do I put One2many after Many2one defined? - transient module states reset
many2one one2many
Awatar
1
mar 23
3102
Odoo Studio how to set a chain of multiple and related Many2one within a One2many lines
many2one one2many
Awatar
0
gru 22
3751
Automatically open many2one or one2many field without clicking external link icon
code many2one one2many Odoo13 odoo13
Awatar
0
paź 22
2747
filter according to comodel's fields
many2one one2many
Awatar
0
cze 21
3466
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