Odoo Help

0

On_change: help!

By
Uillino
on 8/7/15, 5:20 AM 888 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"?>
<openerp>
<data>

<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">
<search>
<field name="sdescription"/>
</search>
</field>
</record>

<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)"/>
</tree>
</field>
</record>

<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">
<group>
<field name="sdescription" on_change="uppercase(sdescription)"/>
</group>
</form>
</field>
</record>
 
<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>
</record>

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

</data>
</openerp>

but it doesn't work. Any idea?

Thanks!


-------------------------------

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.

Uillino
on 8/7/15, 6:20 AM
1
Drees Far
On 8/7/15, 5:46 AM

Here is the way friend:

Python:

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.

Regards.


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.

Uillino
on 8/7/15, 6:03 AM

Nice!!

Drees Far
on 8/7/15, 6:08 AM

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

Uillino
on 8/7/15, 6:21 AM
1

Hi,

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.

Thanks.

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

Uillino
on 8/7/15, 6:18 AM

ask the question. I cant answer you here :/

Drees Far
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.

Register

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)

Stats

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