class data_migration(osv.osv):
_name = 'excel.product.tmp'
_description = 'Data Migration For Excel'
_columns = {
'db_name':fields.char('DB Name'),
'excel_file': fields.char('Excel File Path',size = 200),
'sheet_name':fields.char('Excel Sheet Name'),
}
def import_data(self,cr,uid,ids,context=None):
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='openerp' password='openpgpwd' 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:
product_id_from_excel =row[0].value
statement = "select id from product_template where LOWER(name)=LOWER('"+product_id_from_excel+"')"
cursor.execute(statement)
conn.commit()
product_id = cursor.fetchone()
if product_id == None:
list_price_from_excel = row[1].value
statement = "UPDATE product_template SET list_price='"+list_price_from_excel+"' WHERE id = '"+product_id+"'"
cursor.execute(statement)
conn.commit()
data_migration()
ошибки шоу из консоли, когда обновление от пути файла Excel заявления = "UPDATE product_template SET list_price = ' "+ list_price_from_excel +"' WHERE ID =«" + product_id + "'"обновления цен PRODCUT список с тем же списком имен из пути импорта файла Excel
TypeError: coercing to Unicode: need string or buffer, NoneType found
спасибо Я могу попробовать ответить, если product_id: –