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

How filter x2many?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
filterdomainx2many
3 Odpowiedzi
12917 Widoki
Awatar
Vasiliy Birukov

Is it possible filter list of x2many records in form view?

For example:

1)Show only first 5 lines.

2)Show only records, that have fields according to some domain.

6
Awatar
Odrzuć
Awatar
Andreas Brueckl
Najlepsza odpowiedź

Regarding the change of the limit of one2many fields please refer to question https://accounts.openerp.com/forum/Help-1/question/6627/

Regarding the filter I had the same requirement for one of our modules and I have solved it with the following steps. Assume that you have the following one2many field which you want to filter:

'line_ids': fields.one2many('your.model', 'script_id', 'Lines'),
  1. Add a filter field to your model:

    'ir_filter_id': fields.many2one('ir.filters', 'Additional Filter', domain=[('model_id', '=', 'your.model')]),
    
  2. Add a one2many function field to your model:

    def _get_lines(self, cr, uid, ids, fields, args, context=None):
        line_obj = self.pool.get('your.model')
        res = {}
        for script in self.browse(cr, uid, ids):
            args = [('script_id', '=', script.id)]
            if script.ir_filter_id:
                args += eval(script.ir_filter_id.domain)
            line_ids = line_obj.search(cr, uid, args)
            res[script.id] = line_ids
        return res
    
    def _set_lines(self, cr, uid, id, name, value, inv_arg, context):
        line_obj = self.pool.get('your.model')
        for line in value:
            if line[0] == 1: # one2many Update
                line_id = line[1]
                line_obj.write(cr, uid, [line_id], line[2])
        return True
    
    'view_line_ids': fields.function(_get_lines, fnct_inv=_set_lines, string='Lines', relation="your.model", method=True, type="one2many"),
    
  3. Add the two fields to your form view

So you can filter your one2many field with any domain. You only have to be aware of the following points:

- The filter is stored in the DB and all users have the same filter - You have to save the form view so that the current filter becomes active

8
Awatar
Odrzuć
priyankahdp

please help me for this issue..

http://help.openerp.com/question/8391/how-to-load-child-records-to-fields/

Timo Talvitie, Vizucom Oy

Big thanks for posting this, it worked nicely after adding also checks for line[0] being 0 or 2 (create or delete). I think there shouldn't have to be this much magic involved when wanting to filter a basic o2m field, though.

Awatar
Vasiliy Birukov
Autor Najlepsza odpowiedź

Thanks to Andreas Brueckl for idea with second functional 'view' field, example first case may be (filter first 5):

def _get_lines(self, cr, uid, ids, name, arg, context=None):
        line_obj = self.pool.get('your.model')
        res = {}
        number = 5
        for script in self.browse(cr, uid, ids, context=context):
            line_ids = line_obj.search(cr, uid,[('script_id', '=', script.id)], limit=number)
            res[script.id] = line_ids
        return res

'view_line_ids': fields.function(_get_lines, relation="your.model", method=True, type="one2many"),
5
Awatar
Odrzuć
Awatar
Gabriel
Najlepsza odpowiedź

Thanks to Andreas for this detailed answer, the fnct_inv definition saved me some time. I would suggest for others that might need it, you can add:

elif line[0] == 0: # one2many create
     self.create(cr, uid, line[2])

to the _set_lines function if you want to create new record.

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ść
Filter many2one field with functional field
filter domain
Awatar
Awatar
Awatar
5
wrz 20
13577
How to set default filter for an addon?
filter domain
Awatar
0
mar 15
4745
Problem with column iteration in domain filter
filter domain
Awatar
1
mar 15
6228
How to allow read parent tasks to followers
filter domain
Awatar
Awatar
Awatar
2
mar 15
8414
How to use dynamic values in domain filter? Rozwiązane
filter domain code
Awatar
Awatar
Awatar
Awatar
Awatar
6
maj 24
72053
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