Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

How to use dynamic values in domain filter?

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
filterdomaincode
6 Antworten
71984 Ansichten
Avatar
vivek

Hi,

The following is my line of code and is working,

'user_id': fields.many2one('res.users', 'Responsible', track_visibility='onchange', domain="[('emp_department_id', '=', 10)]"),

Now i want replace that employee department id and that should be the value returned by a function,

say something similar to this

def test():
     return department id of the login users

'user_id': fields.many2one('res.users', 'Responsible', track_visibility='onchange', domain="[('emp_department_id', '=', self.test())]"),

I know the above statement is not valid since the whole thing is a dict and domain is one of the key in the dict and its value is string. I want this concept to be done somehow.

I am even ok for some crooked ideas. Thanks for your time.

3
Avatar
Verwerfen
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Beste Antwort

You can use on_change. Write a onchange on emp_department_id and in that onchange method you can return domain for your user_id field.

Have a look at the example of onchange which returns value, domain and warning.

2
Avatar
Verwerfen
vivek
Autor

Thanks sudhir, It's a one2many field(res.users) i've used in project -> task form. All the users are listed there and i want to show users whose department is equal to the login person's department. Hope you exactly understand what i want and guide me to do that. Expecting your reply hopefully. Thanks

evon_dun

Can we add date range fields and print its value in the reports too? I added two fields date_from and date_to and tried to print its value. Please help if someone knows. Here is the link to my question http://help.openerp.com/question/28218/how-to-use-data-of-a-date-range-from-search-view-in-my-openoffice-report/

Avatar
ClueLogics Technologies Pvt. Ltd.
Beste Antwort

Hey vivek

just do like below

remove domain from below field (.py), like this

'user_id': fields.many2one('res.users', 'Responsible'),

for dynamic domain , you should have an another field

in view code will be like this :

 <field name="myfirst_field" on_change="get_domain_useer_id()" />
 <field name="user_id" />

after this you should add a function in your model object

  def get_domain_useer_id(self,cr,uid,ids,context=None):
    mach=[]
    lids=self.pool.get('res.users').search(cr,uid,[('active','=',True)])
    return {'domain':{'user_id':[('id','in',lids)]}}

This is just example to see all active user for dynamic domain you can add more effective code as you want

good luck

Thanks

8
Avatar
Verwerfen
vivek
Autor

Thanks a good idea sandeep, but what happens if the users has not changed the first field or in my case i do not have any first field to select. I just having the user field for selection and values must not be available even before doing anything in the form. Thanks!!

ClueLogics Technologies Pvt. Ltd.

if you don't have first field then , where is a need of dynamic domain,,,,,, i think then no need of dynamic domain

vivek
Autor

:) yeah i don't need a dynamic domain, i have to use dynamic values in the domain filter. as i've narrated in the ques i want to take the login users department id and place them in the domain filter. That should be applicable for the values when loading the form itself. I am open for clarification.

ClueLogics Technologies Pvt. Ltd.

we can get login user directly , you know uid just put uid in domain but without method we can't get his depratment id ,, give me time ..... what can i do for you ......:)

Obay Albadri

but in domain we can't just say: domain = "[('emp_department_id', '=', uid.department_id)]" ?!

evon_dun

Can we add date range fields and print its value in the reports too? I added two fields date_from and date_to and tried to print its value. Please help if someone knows. Here is the link to my question http://help.openerp.com/question/28218/how-to-use-data-of-a-date-range-from-search-view-in-my-openoffice-report/

vimal j

why did u create mach=[] in function get_domain_useer_id.

vimal j

why did u add mach=[] in function get_domain_useer_id? Is there any specific reason for that?

vimal j

why did u add mach=[] in function get_domain_useer_id? Is there any specific reason for that?

Avatar
vivek
Autor Beste Antwort

Hi,

The below is working for me to give dynamic values for domain filters for a particular field.

I've placed the below code in fields_view_get() method.

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    login_user_dpt_id = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).emp_department_id
    for node in eview.xpath("//field[@name='user_id']"):
        if login_user_dpt_id:
            user_filter =  "[('emp_department_id', '='," + str(login_user_dpt_id.id) + " )]"
            node.set('domain',user_filter)

Thanks for all your replies and time.

3
Avatar
Verwerfen
Obay Albadri

vivak, i had a long path to git to this and now my problem start from here, what if 'user_filter' depends on other field value in the same form (eg. 'status')?, how i can get it?

vivek
Autor

In python, you can access all the fields' values obay. And so u use them in the place where i have login_user_dpt_id and set something like this st = self.browse(cr,uid,id,context) and then your operation and finally the conditino like this user_filter = "[('emp_department_id', '='," + str(your final constructed condition) + " )]". Please check and clarify. Sorry for late reply as i didn't notice it.

bala

Hi vivek, I am from Madurai. i have also same problem. could you explain briefly? I tried your code which you posted. Nothing happening. pls help.

Avatar
Niyas Raphy (Walnut Software Solutions)
Beste Antwort

Hi,

Other than returning domain in onchange method, you can use the web domain field module from oca for the same:  Web Domain Field


See this: Return Dynamic Domain For Field In Odoo


How to use:

.. code-block:: xml

<field name="product_id_domain" invisible="1"/>
<field name="product_id" domain="product_id_domain"/>


.. code-block:: python

product_id_domain = fields.Char(
compute="_compute_product_id_domain",
readonly=True,
store=False,
)

@api.multi
@api.depends('name')
def _compute_product_id_domain(self):
for rec in self:
rec.product_id_domain = json.dumps(
[('type', '=', 'product'), ('name', 'like', rec.name)]
)

Returning domain from the onchange function: How To Give Domain For A Field Based On Another Field

Thanks

1
Avatar
Verwerfen
joe

as there is no api.multi in odoo v14 it is not work there it gives me error from js.

Niyas Raphy (Walnut Software Solutions)

if you remove api.multi it will work in v14

Avatar
Cristian Salamea
Beste Antwort

You can redefine fields_view_get method and build your own domain and set it on view modifying with lxml.

Regards,

1
Avatar
Verwerfen
vivek
Autor

Thanks for your reply cristian, is it possible to give some reference links?

Cristian Salamea

Hi, you can read the doc here: http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html and some example in code: http://bazaar.launchpad.net/~ocb/ocb-addons/6.1/view/head:/account/account_invoice.py#L337

Avatar
Adil Akbar
Beste Antwort

You can follow this: https://youtu.be/XGqXEL2qQmE

Hope it helps,

Thanks

0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
Filter many2one field with functional field
filter domain
Avatar
Avatar
Avatar
5
Sept. 20
13478
Problem with column iteration in domain filter
filter domain
Avatar
1
März 15
6129
How to allow read parent tasks to followers
filter domain
Avatar
Avatar
Avatar
2
März 15
8322
Problem with ilike operator in openerp 7
filter code
Avatar
Avatar
2
März 15
7586
How to set default filter for an addon?
filter domain
Avatar
0
März 15
4664
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Ausbildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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