Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
domaino2mm2o
2 Odgovori
30569 Prikazi
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
Opusti
Avatar
Juan Marquez
Avtor 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
Opusti
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
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Display based on the row I click
o2m m2o
Avatar
Avatar
1
dec. 19
3956
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
7022
How to onchange m2o and o2m?
o2m onchange m2o
Avatar
0
mar. 15
5521
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Avatar
0
feb. 19
4743
naked domain set up Solved
domain
Avatar
Avatar
Avatar
Avatar
3
jul. 25
5942
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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