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
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

Domain filtering many2one field dependent onchange from other field

S'inscrire

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

Cette question a été signalée
many2onemany2manyonchangecontextdomain_filter
1 Répondre
8137 Vues
Avatar
Theis Dræberg

We need to domain filter options in a many2one field, based on selected value in another field.


Our setup example:


In Model A we have following many2one fields:

Product type (x_studio_field_C8Ncm)

Product (x_studio_field_y8xyP)


We need product to be domain filtered based on value set in product type.

Ie. if we choose product type: phone it has to filter options in products like iPhone, Galaxy etc. Not Macbook or whatever.


After extensively searching the forums and reading various linked documentations on api.onchange functions, I tried many compute field variations like this:


from odoo import api

@api.onchange('x_studio_field_C8Ncm')

def onchange_partner_id(self):

    for rec in self:

        return {'domain': {'x_studio_field_y8xyP': [('x_studio_field_C8Ncm_id', '=', self.x_studio_field_C8Ncm.id)]}}


With dependency:  x_studio_field_C8Ncm

However it returns error: 

raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes)))
ValueError: forbidden opcode(s) in "from odoo import api\r\n@api.onchange('x_studio_field_C8Ncm')\r\ndef onchange_partner_id(self):\r\n    for rec in self:\r\n        return {'domain': {'x_studio_field_y8xyP': [('x_studio_field_C8Ncm_id', '=', self.x_studio_field_C8Ncm.id)]}}": IMPORT_NAME, IMPORT_FROM


We are running Odoo 13.0 and odoo studio.


Ps. we also have a many2many field where we want similar domain filtering based on other field value. But may put that in different question if the same function cant be applied?


Please help.

0
Avatar
Ignorer
Avatar
Niyas Raphy (Walnut Software Solutions)
Meilleure réponse

Hi,

From the below line change the self to rec and try,


return {'domain': {'x_studio_field_y8xyP': [('x_studio_field_C8Ncm_id', '=', self.x_studio_field_C8Ncm.id)]}}

Change it to

return {'domain': {'x_studio_field_y8xyP': [('x_studio_field_C8Ncm_id', '=', rec.x_studio_field_C8Ncm.id)]}}


Also you can get more info here: How To Give Domain For A Field Based On Another Field

Thanks

0
Avatar
Ignorer
Theis Dræberg
Auteur

Thanks for your quick reply. However it still returns same error.

Theis Dræberg
Auteur

Note that we cant edit directly via .py file.

But are using compute field via odoo studio. If that makes a difference?

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é
Filtering relationship field Selection Based on another field in CRM Module
many2many context domain_filter
Avatar
Avatar
Avatar
2
nov. 24
3584
How to give Domain filter for one2many field base on the condition of another field? (Odoo 13) Résolu
many2one one2many onchange domain_filter
Avatar
Avatar
2
juil. 22
12643
Is it possible to get ids for filter from a Many2many relation that is on user. Résolu
many2one many2many domain_filter odoo10
Avatar
Avatar
1
nov. 19
6826
how i Populate Many2One field on change of another field on v8?
many2one many2many onchange odooV8
Avatar
Avatar
Avatar
2
juin 15
8888
Onchange: How to change the shown values from a Many2one field, based on selection field? Résolu
many2one selection onchange domain_filter Odoo13
Avatar
Avatar
1
avr. 20
6107
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