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 create a domain for field in parent.parent model?

S'inscrire

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

Cette question a été signalée
domaino2mm2o
2 Réponses
30556 Vues
Avatar
Juan Marquez

I have 3 models:

seniat_form_86:

'line_ids':fields.one2many('seniat.form.86.lines','line_id','Tax lines',readonly=True, states={'draft':[('readonly',False)]}),
'invoice_ids':fields.one2many('account.invoice','num_import_form_id','Related invoices',readonly=True),

seniat_form_86_lines:

'line_id':fields.many2one('seniat.form.86', 'Line', required=True, ondelete='cascade'),
'line_vat_ids':fields.one2many('seniat.form_86.lines.vat','line_vat_id','Vat lines',attrs="{'readonly':[('vat_detail','=',True)],'required':[('vat_detail','=',True)]}"),

seniat_form_86_lines_vat:

'line_vat_id':fields.many2one('seniat.form.86.lines', 'Vat line', required=True, ondelete='cascade'),
'invoice_id': fields.many2one('account.invoice', 'Invoice Reference', ondelete='restrict', select=True, required=True),

...

as you can see the 3 models are "master-detail" interrelated.

I need to set a domain for seniat_form_86_lines_vat.invoice_id like this:

domain="[('id','in',line_vat_id.line_id.invoice_ids)]"

Error: NameError: name 'line_vat_id' is not defined if widget="selection" in view

I want to filter seniat_form_86_lines_vat.invoice_id with only invoices listed in seniat_form_86.invoice_ids.

Note: Server 6.0

Note 2: I also try with:

domain="[('id','in',parent.parent.invoice_ids)]"
domain="[('id','in',parent.line_id.invoice_ids)]"
domain="[('id','in',parent.invoice_ids)]"

Thanks.

0
Avatar
Ignorer
Avatar
Juan Marquez
Auteur Meilleure réponse

Hi, Mohammad thanks for your fast answer but when I try to implement it I note this:

The on_change method is never called

view:

<field name="line_vat_id" invisible="1" on_change="on_change_line_vat_id(line_vat_id)"/>

Full view

   <record model="ir.ui.view" id="view_seniat_form_86_form">
        <field name="name">seniat.form.86.form</field>
        <field name="model">seniat.form.86</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form>
                <group col="8" colspan="8">
                    <field name="name"/>
                    <field name="ref"/>
                    <field name="broker_id"/>
                    <field name="date"/>
                </group>
                <notebook colspan="4">
                    <page string="General info">
                        <group col="8" colspan="8">
                            <field name="ref_reg"/>
                            <field name="date_reg"/>
                            <field name="ref_liq"/>
                            <field name="date_liq"/>
                        </group>
                        <field name="custom_id" colspan="4"/>
                        <field name="line_ids" colspan="4" nolabel="1">
                            <tree string="Tax lines">
                                <field name="tax_code"/>
                                <field name="amount" sum="Amount total"/>
                            </tree>
                            <form string="Tax lines">
                                <group col="8" colspan="8">
                                    <field name="tax_code" colspan="6"/>
                                    <field name="amount"/>
                                </group>
                                <field name="vat_detail" invisible="1"/>
                                <field name="line_vat_ids" colspan="4" nolabel="1" attrs="{'invisible':[('vat_detail','!=',True)]}">
                                    <tree string="Vat tax detail" editable="bottom">
                                        <field name="line_vat_id" invisible="1" on_change="on_change_line_vat_id(line_vat_id)"/>
                                        <field name="invoice_id" on_change="on_change_invoice_id(invoice_id)"/>
                                        <field name="partner_id"/>
                                        <field name="reference"/>
                                        <field name="acc_tax_id" widget="selection"/>
                                        <field name="base_amount" on_change="on_change_amount(acc_tax_id, base_amount, tax_amount)"/>
                                        <field name="tax_amount" on_change="on_change_amount(acc_tax_id, base_amount, tax_amount)" sum="Tax amount total"/>
                                    </tree>
                                    <form>
                                        <field name="line_vat_id" invisible="1" on_change="on_change_line_vat_id(line_vat_id)"/>
                                        <field name="invoice_id" on_change="on_change_invoice_id(invoice_id)"/>
                                        <field name="partner_id"/>
                                        <field name="reference"/>
                                        <field name="acc_tax_id" widget="selection"/>
                                        <field name="base_amount" on_change="on_change_amount(acc_tax_id, base_amount, tax_amount)"/>
                                        <field name="tax_amount" on_change="on_change_amount(acc_tax_id, base_amount, tax_amount)"/>
                                    </form>
                                </field>    
                            </form>
                        </field>    
                        <field name="amount_total"/>
                    </page>    
                    <page string="Other">
                        <label string="Notes" colspan="4"/>
                        <field name="narration" colspan="4" nolabel="1"/>  
                        <field name="invoice_ids" colspan="4" nolabel="1"/>  
                        <field name="move_id"/>
                        <field name="company_id"/>
                    </page>    
                </notebook>    
                <group col="8" colspan="8">
                    <field name="state"/>
                    <button name="button_open" icon="gtk-go-forward" string="Open" states="draft,done" colspan="1"/>
                    <button name="button_done" icon="gtk-ok" string="Done" states="open" colspan="1"/>
                    <button name="button_cancel" icon="gtk-cancel" string="Cancel" states="draft,open" colspan="1"/>
                    <button name="button_draft" icon="terp-stock_effects-object-colorize" string="Reset to draft" states="cancel" colspan="1"/>
                </group>
            </form>
        </field>
    </record>

model:

def on_change_line_vat_id(self, cr, uid, ids, line_vat_id):
    '''
    Create a domain to filter invoice_id for invoices listed in seniat_form_86.invoice_ids only
    '''
    res = {}
    if line_vat_id:
        line_obj = self.pool.get('seniat.form.86.lines')
        invoices = [i.id for i in line_obj.browse(cr, uid, line_vat_id).line_id.invoice_ids]
        res = {'domain': {'invoice_id': [('id','in',invoices)]}}
    return res

The method on_change_line_vat_id only is called when I make the field visible and change it manually. How I can set this domain in new or edited records?

Thanks.

0
Avatar
Ignorer
Avatar
Mohammad Alhashash
Meilleure réponse

In seniat_form_86_lines_vat create an on_change method for the field line_vat_id (make it invisible). The on_change method should return a domain for invoice_id using a list.

it should be something like this:

def def onchange_line_id(self, cr, uid, ids, line_vat_id)
    line_obj = self.pool['seniat.form.86.lines']
    invoices = [i.id for i in 
                line_obj.browse(cr, uid, id[0]).line_id.invoice_ids]
    return {'domain':
               {'invoice_id': [('id','in',invoices)]}
           }
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é
Display based on the row I click
o2m m2o
Avatar
Avatar
1
déc. 19
3950
How to add set domain fields O2M relate to a self define M2M model to avoid duplicate
domain o2m m2m
Avatar
Avatar
1
déc. 17
7018
How to onchange m2o and o2m?
o2m onchange m2o
Avatar
0
mars 15
5512
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Avatar
0
févr. 19
4741
naked domain set up Résolu
domain
Avatar
Avatar
Avatar
Avatar
3
juil. 25
5913
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