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

Dataerror updating function field of one2many object using on_change event

Subscribe

Get notified when there's activity on this post

This question has been flagged
one2manyon_changefunction_field
5711 Views
Avatar
Alexei R. Acosta

Hello I'm updating a function field of one2many object using on_change event. I pass the one2many object as a parameter of on_change function , and then I return it updated. Every it's ok, but when I create a new one2many object, Openerp show this error:

Client Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/common/http.py", line 180, in dispatch response["result"] = method(controller, self, **self.params) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/controllers/main.py", line 882, in get return self.do_get(req, model, ids, fields) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/controllers/main.py", line 904, in do_get records = Model.read(ids, fields, req.session.eval_context(req.context)) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/common/openerplib/main.py", line 250, in proxy args, kw) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/common/openerplib/main.py", line 117, in proxy result = self.connector.send(self.service_name, method, *args) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/common/http.py", line 611, in send raise fault

Server Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/addons/web/common/http.py", line 592, in send result = openerp.netsvc.dispatch_rpc(service_name, method, args) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/netsvc.py", line 360, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/service/web_services.py", line 572, in dispatch res = fn(db, uid, params) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/osv.py", line 167, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/osv.py", line 121, in wrapper return f(self, dbname, args, *kwargs) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/osv.py", line 176, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/osv.py", line 164, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/orm.py", line 3381, in read result = self._read_flat(cr, user, select, fields, context, load) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/osv/orm.py", line 3440, in _read_flat cr.execute(query, (tuple(sub_ids),)) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/sql_db.py", line 152, in wrapper return f(self, args, *kwargs) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_1-py2.7.egg/openerp/sql_db.py", line 212, in execute res = self._obj.execute(query, params) DataError: invalid input syntax for integer: "one2many_v_id_1027" LINE 1: ..._obra_evacuacion" WHERE df_obra_evacuacion.id IN ('one2many_...

here is my code:

In conjunto_hidraulico.py class:

_columns = {
   .....
    # Obras de evacuacion
    'obra_evacuacion_ids': fields.one2many('df.obra.evacuacion', 'conjunto_hidraulico_id',
                                           string='Evacuation works', required=False),
    ......
}    

def onchange_obra_evacuacion(self, cr, uid,ids,obra_evacuacion_ids,context=None):
    if context==None:
        context={}
    if(obra_evacuacion_ids):
        ##### update tree view with calculated values ###
        compuerta_obj = self.pool.get('df.compuerta')   #objeto que tiene todas las compuertas creadas hasta ahora
        for evacuation_work in obra_evacuacion_ids:
            cant = 0
            count = 0
            text = ""
            if evacuation_work[0] == 0 or (evacuation_work[0] == 1 and evacuation_work[2].has_key('compuerta_ids')):
                for gate in evacuation_work[2]['compuerta_ids']:
                    mode = gate[0]
                    if mode == 0 or mode == 1 or mode == 4:
                        cant = cant + 1     #calculate number of gates
                        if gate[2] and gate[2].has_key('numero'):       #create working order string
                            if count == 0:
                                text += str(gate[2]['numero'])
                            else:
                                text += "-" + str(gate[2]['numero'])
                        else:
                            gate_aux = compuerta_obj.browse(cr, uid, gate[1], context=context)
                            if count == 0:
                                text += str(gate_aux.numero)
                            else:
                                text += "-" + str(gate_aux.numero)
                    elif mode == 5:
                        cant = 0
                    count += 1
                evacuation_work[2]['cantidad_compuertas'] = cant
                evacuation_work[2]['regimen_trabajo'] = text

        return {'value':{
            'obra_evacuacion_ids': obra_evacuacion_ids
        }}

In conjunto_hidraulico_view.xml:

<field colspan="4" name="obra_evacuacion_ids" nolabel="1" on_change="onchange_obra_evacuacion(obra_evacuacion_ids)"/>

In obra_evacuacion.py class:

    _columns = {
        .....        
    'compuerta_ids': fields.one2many('df.compuerta', 'obra_evacuacion_id', 'Gates', required=False),
    'cantidad_compuertas': fields.function(gates_count, type='string', method=True, string="Amount of gates",
                                           help="Quantity of gates in case of 'Spillway' category"),
    'regimen_trabajo': fields.function(working_order, type='string', method=True, string="Gates's working regime",
                                       help="Working regime of the gates in case of 'Spillway' category"),
   }

Thanks is advanced.

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
How to use Onchange function in one2many
one2many on_change
Avatar
Avatar
1
Mar 15
6521
key Error function field error for O2M field. when opening form view of employee got below error
one2many function_field v10
Avatar
1
May 18
5663
create and edit items of a one2many field through on_change method
one2many on_change active_id
Avatar
0
Jan 17
9572
How to write function fields for many2one or one2many?
many2one one2many function_field
Avatar
Avatar
2
May 16
7424
Display fields.function on tree view Solved
treeview one2many function_field
Avatar
Avatar
Avatar
4
Jan 24
13366
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