Odoo Help


On_change: help!

on 8/7/15, 5:20 AM 1,062 views

I'm tryng to write into my db in uppercase. I've used the on change method in this way:

# -*- encoding: utf-8 -*-
from openerp import models, fields

class mymodule_tbl(models.Model):
_name = 'tbl
_description = 'Insert into my db'

sdescription = fields.Text('Description', required=True)

def uppercase(self, cr, uid, ids, sdescription, context=None):
result = {'value': {'sdescription': str(sdescription).upper()}}
return result
<?xml version="1.0" encoding="utf-8"?>

<record id="view_mymodule_tbl_search" model="ir.ui.view">
<field name="name">MyModule</field>
<field name="model">tbl/field>
<field name="arch" type="xml">
<field name="sdescription"/>

<record id="view_mymodule_tbl_tree" model="ir.ui.view">
<field name="name">mymodule_tbl.tree.view</field>
<field name="model">tbl/field>
<field name="arch" type="xml">
<tree string="MyModule" export="false">
<field name="sdescription" on_change="uppercase(sdescription)"/>

<record id="view_mymodule_tbl_form" model="ir.ui.view">
<field name="name">mymodule_tbl.form.view</field>
<field name="model">tb</field>
<field name="arch" type="xml">
<form string="mymodule tbl" duplicate="false">
<field name="sdescription" on_change="uppercase(sdescription)"/>
<record id="action_mymodule_tbl" model="ir.actions.act_window">
<field name="name">Tbl</field>
<field name="res_model">tbl/field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" eval="False"/>
<field name="context">{}</field>

<menuitem action="action_mymodule_tbl" id="menu_action_mymodule_tbl" parent="mail.mail_feeds" sequence="70"/>


but it doesn't work. Any idea?



I've edited my post with the right code.

You want to set value in default_code field? and default_code field is available in view?

Solanki Shamji
on 8/7/15, 5:52 AM

I made a mistake with default_code field. Thank you.

on 8/7/15, 6:20 AM

Vale Trood

--Vale Trood--

| 5 2 7
Tunis, France
--Vale Trood--

Vale Trood
On 8/7/15, 5:46 AM

Here is the way friend:


def uppercase(self, cr, uid, ids, sdescription, context=None):

result = {'value': {'default_code': str(sdescription).upper()}}

return result


def on_change_sdescription_id(self, cr, uid, ids, sdescription, context=None): 

res = {'value':{'sdescriptiont': self.uppercase(cr, uid, ids, sdescription,context=context),



return res

And XML:

<field name="sdescription" on_change="on_change_sdescription_id(sdescription)"/>

Try it and tell me if its okay.


Thank you very much! I've noticed that my cose is good too. I made a mistake writing 'default_code' instead of 'sdescription' in my uppercase function.

on 8/7/15, 6:03 AM


Vale Trood
on 8/7/15, 6:08 AM

What if I want to use this function with two different fields?

on 8/7/15, 6:21 AM

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 8/7/15, 5:50 AM


you need to write your on change as like below.

def uppercase(self, cr, uid, ids, sdescription, context=None):
result = {'value': {'sdescription': str(sdescription).upper()}}
return result

Might it will work.


What if I want to use this function with two different fields?

on 8/7/15, 6:18 AM

ask the question. I cant answer you here :/

Vale Trood
on 8/7/15, 6:55 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/7/15, 5:20 AM
Seen: 1062 times
Last updated: 8/7/15, 6:29 AM