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č

onchange method not working (no error displayed)

Naroči se

Get notified when there's activity on this post

This question has been flagged
many2oneonchangeonchange_event
1 Odgovori
5635 Prikazi
Avatar
Diego Calzadilla

Hi, I have defined these classes:

    class brand(osv.osv):

        _name = "cm.brand"

        _columns = {

              'name': fields.char('Marca', size=30)

        }

    class model(osv.osv):

         _name = "cm.model"

         _columns = {

              'name': fields.char('Modelo', size=30)

        }

    class cm_application_data_line(osv.osv):

          _name = "cm.application.data.line"

          _columns = {

              'comun_denominador_id': fields.many2one('comun.denominador', 'Comun denominador', required=True, ondelete='cascade'),

              'brand': fields.many2one('cm.brand', 'Marca', required=True, ondelete='restrict'),

              'date_beg': fields.selection([(num, str(num)) for num in range(1980, (datetime.now().year)+1 )], 'Año inicial'),

              'dateend': fields.selection([(num, str(num)) for num in range(1980, (datetime.now().year)+1 )], 'Año final'),

              'model': fields.many2one('cm.model', 'Modelo', required=True, ondelete='restrict')

        }


I did this to get a page view on my 'comun.denominador' new model:

    class comun_denominador(osv.osv):

        _name='comun.denominador'

        _rec_name='comun_denominador'

        _columns = {       

            'comun_denominador': fields.char('Común denominador', size=10),

            'application_data_comun_denominador_ids': fields.one2many('cm.application.data.line', 'comun_denominador_id', 'Datos de aplicación del común denominador')

           }

And xml view:


<notebook>

     <page string="Datos de aplicación">

         <field name="application_data_comun_denominador_ids" widget="one2many_list" context="{'show_attribute': False}">

             <tree string="Aplicación" editable="bottom">

                 <field name="brand" />

                 <field name="model" /> 

                 <field name="date_beg"/>

                 <field name="dateend"/>

             </tree>

         </field>

     </page>

</notebook>


So far, everything is fine. Now, in product.template form view I added exactly the same page in form view and added a field 'cm_id' making reference to 'comun.denominador' model, so that when users chooses 'cm_id', on_change method brings all values from page in 'comun.denominador' to my new page in 'product.template':

XML sample in product.template:

<xpath expr="//field[@name='sale_ok']" position="after">

     <separator colspan="2" string="Común denominador"/>

         <field name="cm_id" on_change="on_change_cm_id(cm_id)"/>

</xpath>

<xpath expr="//page[@string='Sales']" position="after">

     <page string="Datos de aplicación">

         <field name="application_data_product_template_ids" widget="one2many_list" context="{'show_attribute': False}">

             <tree string="Aplicación" editable="bottom">

                 <field name="brand" />

                 <field name="model" /> 

                 <field name="date_beg"/>

                 <field name="dateend"/>

             </tree>

         </field>

     </page>

</xpath>


New class and product.template inheritance:

class product_template_application_data_line(osv.osv):

     _name = "product.template.application.data.line"

     _rec_name = 'brand'

     _columns = {

         'product_template_id': fields.many2one('product.template', 'Product template', required=True, ondelete='cascade'),

         'brand': fields.many2one('cm.brand', 'Marca', required=True, ondelete='restrict'),

         'date_beg': fields.selection([(num, str(num)) for num in range(1980, (datetime.now().year)+1 )], 'Año inicial'),

         'dateend': fields.selection([(num, str(num)) for num in range(1980, (datetime.now().year)+1 )], 'Año final'),

         'model': fields.many2one('cm.model', 'Modelo', required=True, ondelete='restrict')

       }


class comun_denominador_product_template(osv.osv):

     _inherit = 'product.template'

     _name='product.template'

     def on_change_cm_id(self,cr, uid, ids,cm_id,context=None):

         context=context or {}

         application_data_product_template = []

         dict = {}

         if ids:

             application_ids = self.pool.get('product.template.application.data.line').search(cr, uid,[('product_template_id','in',ids)])

             self.pool.get('product.template.application.data.line').unlink(cr, uid, application_ids)

         application_cm_ids = []

         application_cm_ids = self.pool.get('cm.application.data.line').search(cr, uid, [('comun_denominador_id', '=', cm_id)])

         for application_id in self.pool.get('cm.application.data.line').read(cr, uid, application_cm_ids, ['brand', 'date_beg', 'dateend', 'model']):

                     application_data_product_template.append((0,0,{'brand':application_id['brand'][0],'date_beg':application_id['date_beg'], 'dateend':application_id['dateend'], 'model':application_id['model'][0]})) 

        dict.update(application_data_product_template_ids=application_data_product_template)

        return {'dict':dict}

      _columns = {

                   'cm_id' : fields.many2one('comun.denominador','Común denominador', select=True, ondelete='cascade'),

                   'application_data_product_template_ids': fields.one2many('product.template.application.data.line', 'product_template_id', 'Datos de aplicación de la tabla de producto')

        }


When I select cm_id, I see no error log, what is more, setting up debugger my on_change function returns a dict like this:

    dict: {'application_data_product_template_ids': [(0, 0, {'brand': 2, 'date_beg': 1995, 'dateend': 2009, 'model': 5}), (0, 0, {'brand': 1, 'date_beg': 1995, 'dateend': 2006, 'model': 2})]}


However, my page values on product.template don't get uploaded.

Please, some suggestions!!

1
Avatar
Opusti
Avatar
Diego Calzadilla
Avtor Best Answer

I answer my own question:

The problem is that I called my dictionary : 'dict', this is not allowed, it must be named 'value' according to documentation!

Hope this is helpful for someone else!

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
when i select the category in the sale list the regarding product must shown in the product id in the bill list by onchange
many2one onchange
Avatar
0
dec. 18
13
Onchange many2one partner_bank_id Solved
many2one onchange
Avatar
Avatar
1
maj 16
5130
Change purchase order lines with @api.onchange()? Solved
many2one api inherit onchange onchange_event
Avatar
Avatar
Avatar
3
jun. 19
8467
Create dynamic selection on many2one fields with onchange
many2one onchange dynamic
Avatar
Avatar
1
sep. 23
7525
Create new Many2One records in @api.onchange method
many2one create onchange
Avatar
Avatar
1
avg. 22
9033
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