Odoo Help


Update my fields as per Excel..Odoo V 8.0

Mazhar Iqbal Rana
on 1/15/15, 4:03 AM 1,083 views

So, I am having the code to update my field task_name from similar excel field.


But Things are not going to happen.. Please give a loot at the vode below

   excel_file= fields.Char('/home/mazhar/Desktop/Odoo project activity list.xlsx',size = 250),
    sheet_name =fields.Char('Activities Sheet'),
    db_name = fields.Char('spectec'),


 def action_list(self,cr,uid,ids,context=None):
        #wbk = xlwt.Workbook()
        #sheet1 = wbk.add_sheet('my sheet')  

        #return out

        for data2 in self.browse(cr, uid, ids, context=context):
            file_path = data2.excel_file
            sheet_name_1 = data2.sheet_name
            db_name_1 = data2.db_name
       # connection for DB
            conn_string = "dbname='"+ db_name_1+"' user='admin' password='admin' host='localhost'"
            conn = psycopg2.connect(conn_string)
            cursor = conn.cursor()
        # read the excel file
            wb_c = openpyxl.reader.excel.load_workbook(file_path)
            s_c  = wb_c.get_sheet_by_name(name=sheet_name_1)
            d_c = s_c.calculate_dimension()
            r_c = s_c.range(d_c)
        for row in r_c:
            task_name_from_excel =row[0].value
            statement = "select task_name from activity_track where LOWER(name)=LOWER('"+task_name_from_excel+"')"
            task_name = cursor.fetchone()

Pleae need your sincere guidance



Thanks..But action_list is my button name which will be clicked and update the field

Mazhar Iqbal Rana
on 1/15/15, 5:27 AM

method name : action_list is ok... and button is ok.. no prob with it.. read the rest of comments ;)

on 1/15/15, 5:32 AM

You mean I should use something like this cr.execute("SELECT anyvalues FROM anytable WHERE id =%s",ids) result= map(lambda x: x[0], cr.fetchall())

Mazhar Iqbal Rana
on 1/15/15, 6:05 AM

Also please answer my other question for excel also plzz.. In Odoo forum..About showing table on front end Thanks

Mazhar Iqbal Rana
on 1/15/15, 6:06 AM

jup.. you got the point of cr.execute... other question.. please provide link to it so i don't need to search..

on 1/15/15, 6:14 AM

Here is the Link https://www.odoo.com/forum/help-1/question/buttton-click-event-73086 I have an excel file and that file has some values. I have a condition like if I select some check box then 2nd value from database will be shown only on button click and then save as excel will take place (one more button will be there in wizard view I am getting). So, what you suggest.. I should upload excel file fom some control in odoo ? Or I shoupd put all values from excel to some table?

Mazhar Iqbal Rana
on 1/15/15, 6:44 AM


| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 1/15/15, 4:15 AM

Here is some comments... 
1. fields declaration is wrong:
excel_file= fields.Char('/home/mazhar/Desktop/Odoo project activity list.xlsx',size = 250), -> dont put actual value in field name... 
should be: 
excell_file = fields.Char('Path to file')  # size is not needed... values will contain actual path to file... 
hint: why not using field binary or attachment insted so you can upload file when needed ( put it in transient model if no need to keep old xls files..)

in action list.. 
the part with db connection string is also apsolutly not needed.. except if you try to connect to some other db.. 
this line : def action_list(self,cr,uid,ids,context=None):
states that you want db cursor ( or  cr  in odoo) to be passed to method... so why on earth you need to initiate it again?
yust use cr.execute(some_sql) 

try this , look what happens.. .

hope it helps

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: 1/15/15, 4:03 AM
Seen: 1083 times
Last updated: 3/16/15, 8:10 AM