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

using function in domain filter

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
functiondomain
4 Odpowiedzi
74965 Widoki
Awatar
Muszik Adrián

i want to use a function's return as a domain filter.

'product_id' : fields.many2one('product.product', 'products', domain=[('id', 'in',lambda self,cr,uid,ids, context: self._get_technic_warehause(cr,uid,ids,context))])

like that but it sadly wont work.... this is the error i get

2013-12-07 09:59:49,686 16226 ERROR test werkzeug: Error on request:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 159, in run_wsgi
    execute(app)
  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 146, in execute
    application_iter = app(environ, start_response)
  File "/opt/openerp/server/openerp/service/wsgi_server.py", line 417, in application
    return application_unproxied(environ, start_response)
  File "/opt/openerp/server/openerp/service/wsgi_server.py", line 403, in application_unproxied
    result = handler(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 528, in __call__
    return self.dispatch(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 487, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 411, in __call__
    return self.app(environ, start_response)
  File "/opt/openerp/web/addons/web/http.py", line 553, in dispatch
    result = handler(request)
  File "/opt/openerp/web/addons/web/http.py", line 618, in <lambda>
    return lambda request: JsonRequest(request).dispatch(method)
  File "/opt/openerp/web/addons/web/http.py", line 251, in dispatch
    body = simplejson.dumps(response)
  File "/usr/share/pyshared/simplejson/__init__.py", line 321, in dumps
    return _default_encoder.encode(obj)
  File "/usr/share/pyshared/simplejson/encoder.py", line 237, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/share/pyshared/simplejson/encoder.py", line 311, in iterencode
    return _iterencode(o, 0)
  File "/usr/share/pyshared/simplejson/encoder.py", line 213, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <function <lambda> at 0x535c230> is not JSON serializable

the function returns a list of Ids, but here is the function itself:

def _get_technic_warehause(self, cr, uid,ids, context=None):
        data = self.browse(cr, uid, ids, context=context)[0]
        pdb.set_trace()
        if data.technic_id.id:
            location_obj = self.pool.get('stock.location')
            lines_ids = location_obj.search(cr, uid, [('user_id', '=', data.technic_id.id)])
            #res = {data['id'] : []}
            res = []
            for line_id in lines_ids:
                prod_info = location_obj._product_get(cr, uid, line_id, context=context)
                for prod_id in prod_info.keys():
                    if prod_info[prod_id] != 0.0:
                        #res[data['id']].append(prod_id)
                        res.append(prod_id)
            return res
        #return {}

is there anyway in openerp to make this work? I know that openerp doesn't allow function fields in domain filter sadly, but anyway to get around it?

1
Awatar
Odrzuć
Awatar
Henri-Maxime Ducoulombier
Najlepsza odpowiedź

Hello there,

I found out how to (very simple) solve this problem. I'm working with Odoo v8 (I don't know if it's working with v7), and all you have to do is to define a function that will return a JSON serializable domain (in fact, a domain as if you had put it directly in your field definition). Here's me code :

class myClass(models.Model)

    ...

    @api.model
    def _getUserGroupId(self):
        return [('groups_id', '=', self.env.ref('module.xml_id').id)]

    rel_ids = fields.Many2many(comodel_name='res.users', relation='my_relation_table_name', column1='rel_id', column2='user_id', string='Relation field', domain=_getUserGroupId)

Hope this helps.

 

5
Awatar
Odrzuć
Awatar
klacus
Najlepsza odpowiedź

Hi.

You can avoid the problem with the new field in python.  This field is must point a fiunction (field.function) and call the function with this. Call the procedure with this function, and the field will be get the result of the function. The doamin will be accept it, you need to hide the new field and you finish with this.

 

 

Sorry for the original hungarian post. :-) +2 pls. :-)

L.

1
Awatar
Odrzuć
Awatar
Abdul Nazar
Najlepsza odpowiedź

Here i am going to give a example of filter employee by his related user.

In Python:

@api.model    def _get_emp_domain(self):
    domain = []    ctx = self.env.context
    if ('user' in self.env.context and 'user' in self.env.context and 'cond' in self.env.context) and ctx.get('val') and ctx.get('cond') and ctx.get('val'):
        domain = [(ctx.get('user'),ctx.get('cond'),ctx.get('val'))]
    return domain


employee_id = fields.Many2one('hr.employee', string="Employee", domain=lambda self:self._get_emp_domain(), required=True,  default=_get_employee)


In XML:

<record id="action_my_custom" model="ir.actions.act_window">

        <field name="name">My List</field>

        <field name="res_model">my.custom</field>

        <field name="view_type">form</field>

        <field name="view_mode">tree,form</field>

        <field name="domain">[('employee_id.user_id','=',uid)]</field>

        <field name="context">{'user': 'user_id','cond': '=','val': uid}</field>

        <field name="view_id" eval="False"/>

        <field name="search_view_id" ref="view_my_custom_filter"/>

    </record>


I hope it will be helpful for you....

 
          

0
Awatar
Odrzuć
Awatar
bernscheinder
Najlepsza odpowiedź

Hi adrian,

Have you solved this bug please, I need something like this!

 

Sincerly,

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ść
New api search domain id and condition? Rozwiązane
function domain api
Awatar
Awatar
1
paź 15
10010
production of not enough materials for a PO
function
Awatar
Awatar
Awatar
2
wrz 25
1110
POS Product Category Community Edition
function
Awatar
Awatar
1
wrz 25
1784
Options for collections management addons for museums or private collection
function
Awatar
0
lip 25
1174
naked domain set up Rozwiązane
domain
Awatar
Awatar
Awatar
Awatar
3
lip 25
5964
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