This question has been flagged
2 Replies
3206 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.

Avatar
Discard

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

Author

I made a mistake with default_code field. Thank you.

Best Answer

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.


Avatar
Discard
Author

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.

Nice!!

Author

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

Best Answer

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.

Avatar
Discard
Author

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

ask the question. I cant answer you here :/