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

How to write this domain for a one2many field on a view?

S'inscrire

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

Cette question a été signalée
domainformviewmany2oneone2many
3 Réponses
27258 Vues
Avatar
Pascal Tremblay

Hello guys!

I really have problem with domain for one2many field.

In the res.company form, I select some partners for the field line_of_business_ids. I save this and it works.

In the view view_partner_property_form (see below) the field line_business_ids of the partner should only offer the values available in the field line_of_business_ids of his own and only company_id. Every partner has a company_id field. And any company has a line_of_business_ids field (in my case). 

I'm not able to write this domain myself.

Could you help me?

Thanks to help

I actually have this code :

In Python

class Partner(models.Model):
_inherit = "res.partner"
     related_business_id = fields.Many2one('res.partner', string='Related business line')
     line_business_ids = fields.One2many(comodel_name='res.partner', inverse_name='related_business_id')

class res_company(models.Model):
_inherit = "res.company"
     line_of_business_ids = fields.Many2many(comodel_name='res.partner')

In the xml view

<record id="view_partner_property_form" model="ir.ui.view">
    <field name="name">base.view.partner.form.inherit.vtm2</field>
     <field name="model">res.partner</field>
     <field name="inherit_id" ref="base.view_partner_form" />
     <field name="arch" type="xml">
         <field name="category_id" position="after">
            <field name="line_business_ids" widget="many2many_tags"
                attrs="{'invisible': [('is_company','=', False)]}"
                options="{'no_create_edit': True}"
                domain="[('id', 'in', 'company_id.line_of_business_ids.ids')]" />
        </field>
    </field>
</record>


See image of the situation



Edit #1

I have tried all this domains. No success...

domain="[('company_id.line_of_business_ids', 'in', id )]"

domain="[('id', 'in', company_id.line_of_business_ids)]

domain="[ ( 'company_id.line_of_business_ids', '=', [ (6, [0], [id]) ] ) ]

domain="[('company_id.line_of_business_ids.id', 'in', company_id.line_of_business_ids )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.ids )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.id )]"

domain="[('company_id.line_of_business_ids', '=', company_id.line_of_business_ids.partner_id.id )]"

domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids )]"

domain="[('company_id.line_of_business_ids', 'in', company_id.line_of_business_ids[0][2] )]"


1
Avatar
Ignorer
Avatar
Akhil P Sivan
Meilleure réponse

Hi, 

Pardon me if I misunderstood your requirement. But please clarify the following.

Why can't you use a related One2many field on res.partner to company_id.line_of_business_ids, which could be a readonly field. Since a partner is supposed to have only one company_id, I think no need to use a Many2many field in res.company, you could have use a One2many field. For related fields, both field types should be same.

Then on the partner form, in line_business_ids you can only see the partners added on his company.

For eg:

class Partner(models.Model):
    _inherit = "res.partner"
    line_business_ids = fields.One2many(related='company_id.line_of_business_ids', readonly=True, string="Line business ids")

class res_company(models.Model):
    _inherit = "res.company"
    line_of_business_ids = fields.One2many('res.partner','company_id',string="Line of business ids")
3
Avatar
Ignorer
Pascal Tremblay
Auteur

Mister Sivan, I want to send you 1000 thanks for this precious answer. I will publish my solution soon.

A chance you have been there!

Akhil P Sivan

Good to know that my answer helps you :)

Avatar
Pascal Tremblay
Auteur Meilleure réponse

Big thanks to mister Sivan for his help. It was precious!

Here is our complete solution

In Python, with more significant names

class Partner(models.Model):
    _inherit = "res.partner"

    customer_of_division_id = fields.Many2one(comodel_name='res.partner', domain="[('division_of_company_id','=',company_id)]", string='Customer of the division')
    division_of_company_id = fields.Many2one('res.company', string='Division of the company')

class res_company(models.Model):
    _inherit = "res.company"
   
    division_ids = fields.One2many('res.partner','division_of_company_id', string="Divisions of this company")


In views

<record id="view_company_form" model="ir.ui.view">
            <field name="name">base.view.company.form.inherited.vtm2</field>
            <field name="model">res.company</field>
            <field name="inherit_id" ref="base.view_company_form" />
            <field name="arch" type="xml">
                <field name="website" position="after">
                    <field name="division_ids" widget="many2many_tags" string="Divisions of this company" />
                </field>
            </field>
</record>


<record id="view_partner_property_form_inherit" model="ir.ui.view">
            <field name="name">base.view.partner.form.inherit.vtm2</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form" />
            <field name="arch" type="xml">
                <field name="category_id" position="after">
                      <field name="customer_of_division_id" />
                    <field name="division_of_company_id" />
               </field>
            </field>
</record>


In images






1
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é
domain in many2one that in One2many field Résolu
domain many2one one2many
Avatar
1
oct. 22
4006
Don't show equipment more than once
domain many2one one2many
Avatar
Avatar
1
août 19
3075
Odoo 9: Set domain for field in One2many
domain many2one one2many
Avatar
Avatar
1
sept. 17
5957
Display One2many field multiple time in same form Résolu
domain form one2many
Avatar
Avatar
1
août 16
9545
Why is my many2one field not displayed the same way at this two places? Résolu
address form view many2one
Avatar
Avatar
5
févr. 17
6554
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