Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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'),
#wbk = xlwt.Workbook()
#sheet1 = wbk.add_sheet('my sheet')
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:
statement = "select task_name from activity_track where LOWER(name)=LOWER('"+task_name_from_excel+"')"
task_name = cursor.fetchone()
Pleae need your sincere guidance
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...
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
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 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
|Asked: 1/15/15, 4:03 AM|
|Seen: 922 times|
|Last updated: 3/16/15, 8:10 AM|