Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

how to create a domain for field in parent.parent model?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
domaino2mm2o
2 Răspunsuri
30527 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Juan Marquez
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Mohammad Alhashash
Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Display based on the row I click
o2m m2o
Imagine profil
Imagine profil
1
dec. 19
3934
How to add set domain fields O2M relate to a self define M2M model to avoid duplicate
domain o2m m2m
Imagine profil
Imagine profil
1
dec. 17
7011
How to onchange m2o and o2m?
o2m onchange m2o
Imagine profil
0
mar. 15
5497
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Imagine profil
0
feb. 19
4727
naked domain set up Rezolvat
domain
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
iul. 25
5851
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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