Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

How to use dynamic values in domain filter?

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
filterdomaincode
6 Réponses
71981 Vues
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
Ignorer
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Meilleure réponse

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
Ignorer
vivek
Auteur

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.
Meilleure réponse

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
Ignorer
vivek
Auteur

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
Auteur

:) 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
Auteur Meilleure réponse

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
Ignorer
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
Auteur

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)
Meilleure réponse

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
Ignorer
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
Meilleure réponse

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

Regards,

1
Avatar
Ignorer
vivek
Auteur

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
Meilleure réponse

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

Hope it helps,

Thanks

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Filter many2one field with functional field
filter domain
Avatar
Avatar
Avatar
5
sept. 20
13477
Problem with column iteration in domain filter
filter domain
Avatar
1
mars 15
6128
How to allow read parent tasks to followers
filter domain
Avatar
Avatar
Avatar
2
mars 15
8320
Problem with ilike operator in openerp 7
filter code
Avatar
Avatar
2
mars 15
7586
How to set default filter for an addon?
filter domain
Avatar
0
mars 15
4660
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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