如何从SQL查询中提取数据并将其分配给Odoo类列?

前端之家收集整理的这篇文章主要介绍了如何从SQL查询中提取数据并将其分配给Odoo类列?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试从.mdb数据库提取数据并将其放入Odoo 8类列中.

这是我的.py文件

@H_403_4@class attendance_biometric(osv.Model): _name="attendance.biometric" _rec_name='name' _columns={ 'fdate':fields.datetime('From Date'),'tdate':fields.datetime('To Date'),'code':fields.integer('Code'),'name':fields.many2one('res.users','Employee Name',readonly=True),'ref': fields.one2many('bio.data','bio_ref','Data'),} _defaults = { 'name': lambda obj,cr,uid,context: uid,} def confirm_submit(self,ids,context=None): result=[] DBfile = '/home/administrator/test.mdb' conn = pyodbc.connect('DRIVER=MDBtools;DBQ='+DBfile) cr = conn.cursor() sql = ''' select InTime,OutTime,OutDeviceId,Duration from AttendanceLogs ''' cr.execute(sql) rows = cr.fetchall() for row in enumerate(rows): result.append(row) raise osv.except_osv(_('Info'),_('Data : %s\n' % (result)))

现在,当我点击提交按钮进行一些重新工作后,数据显示如下图所示

有人可以提供宝贵的意见吗?比如如何将这些值放入Odoo类列(我的意思是分配给类的字段)以及如何从两个表中获取列.

解决方法

你需要了解odoo中的fetch类型. @H_403_4@- cr.dictfetchall() It will returns the list of dictionary. Example: [{'column1':'value_column1',},{'column2':'value_column2',}] - cr.dictfetchone() It will return dictionary (Single record) Example: {'column1':'value_column1',} - cr.fetchall() It will returns the list of tuple. Example: [('value_column1'),('value_column2'),]. - cr.fetchone() It will returns the list of tuple. Example: ('value_column1')

所以更新你的代码,

@H_403_4@res = cr.dictfetchall() result['sname'] = res and res[0]['sname']

Whatever the values you want to set,all those must be returned by query.

但是,这是一个示例,您可能需要根据您的具体情况进行更新.

原文链接:https://www.f2er.com/mssql/76720.html

猜你在找的MsSQL相关文章