Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    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
    Výroba
    • 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
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
domaino2mm2o
2 Replies
30513 Zobrazenia
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
Zrušiť
Avatar
Juan Marquez
Autor Best Answer

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
Zrušiť
Avatar
Mohammad Alhashash
Best Answer

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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Display based on the row I click
o2m m2o
Avatar
Avatar
1
dec 19
3929
How to add set domain fields O2M relate to a self define M2M model to avoid duplicate
domain o2m m2m
Avatar
Avatar
1
dec 17
7010
How to onchange m2o and o2m?
o2m onchange m2o
Avatar
0
mar 15
5490
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Avatar
0
feb 19
4723
naked domain set up Solved
domain
Avatar
Avatar
Avatar
Avatar
3
júl 25
5828
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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