Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • 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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

onchange method not working (no error displayed)

Subscribe

Get notified when there's activity on this post

This question has been flagged
many2oneonchangeonchange_event
1 Reply
5629 Views
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
Discard
Avatar
Diego Calzadilla
Author 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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
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
May 16
5127
Change purchase order lines with @api.onchange()? Solved
many2one api inherit onchange onchange_event
Avatar
Avatar
Avatar
3
Jun 19
8465
Create dynamic selection on many2one fields with onchange
many2one onchange dynamic
Avatar
Avatar
1
Sep 23
7517
Create new Many2One records in @api.onchange method
many2one create onchange
Avatar
Avatar
1
Aug 22
9029
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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