Odoo Help

Welcome!

This community 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.

1

Split value in char field & convert into into integer using python code

By
rosey
on 4/24/14, 4:23 AM 1,797 views

I want to know, how to split value entered in char field and convert each values into integer.

I have a textbox, when i enter date as 1428.1.2. I want to split date (.)

My code is

for self_data in self.browse(cr, uid, ids, context=context):

islamic_date = self_data.islamic_date islamic_date = '%.2f' % islamic_date list = islamic_date.split('.') yr = islamic_date(int(list[0])) mth = islamic_date(int(list[1])) day = islamic_date(int(list[2])) Hijri2Gregorian(yr,mth,day)

return res

_columns = { 'islamic_date' : fields.char('Islamic Date'), 'english_date' : fields.function(_get_hijri_date,type='date', select=True,string='English Date'), }

Is the code right?

4

Hardikgiri Goswami

--Hardikgiri Goswami--
1123
| 2 1 5
Rajkot, India
--Hardikgiri Goswami--

OpenERP/Odoo Customization/Integration Expert / Python Programmer

Skype ID : hardikgiri.goswami

Hardikgiri Goswami
On 4/24/14, 7:37 AM

Just Remove this line from your code.

islamic_date = '%.2f' % islamic_date

I removed and work, but still error.

rosey
on 4/24/14, 7:45 AM

yr = islamic_date(str(list[0])) TypeError: 'unicode' object is not callable Error occured

rosey
on 4/24/14, 7:49 AM

Because there is no function named islamic_date(). and islamic_date is string field. It is not a FUNCTION. so you can not do islamic_date(str(list[0])).

Hardikgiri Goswami
on 4/24/14, 10:53 AM

you can do something like this yr = int(list[0]) mth = int(list[1]) day = int(list[2])

Hardikgiri Goswami
on 4/24/14, 10:55 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/24/14, 4:23 AM
Seen: 1797 times
Last updated: 3/16/15, 8:10 AM