您的位置:首页 > 运维架构

Openerp7.0报表显示selection类型不正确问题

2014-10-18 21:05 148 查看
首先是引用:http://www.sandwych.com/Blog/161

写这篇文章的原因是该文只给了一个说明,对于一般的开发者还需要不少的时间摸索。反正我花了2,3个小时进行尝试,并测试

我使用的是rml生成pdf的打印方式。使用的系统默认的rml_parse。

所以需要做的内容是:

修改report_sxw文件rml_parse。

在__init__函数中增加两行。如下。使用原文的方式会报错。

self.localcontext['get_selection_item'] = self._get_selection_items('item')

self.localcontext['get_selection_items'] = self._get_selection_items()

另外是函数需要修改一下,把self.context修改为self.localcontext。因为rml_parse本身没有context成员对象

def _get_selection_items(self, kind='items'):
		def get_selection_item(obj, field, value=None):
			
			try:
				if isinstance(obj, browse_record_list):
					obj = obj[0]
				if isinstance(obj, (str,unicode)):
					model = obj
					field_val = value
				else:
					model = obj._table_name
					field_val = getattr(obj, field)
				if kind=='item':
					if field_val:
						return dict(self.pool.get(model).fields_get(self.cr, self.uid, allfields=[field], context=self.localcontext)[field]['selection'])[field_val]
				elif kind=='items':
					return self.pool.get(model).fields_get(self.cr, self.uid, allfields=[field], context=self.localcontext)[field]['selection']
				return ''
			except Exception:
				return ''
		return get_selection_item


最后需要跟文章中描述的一样,把rml中的数据引用修改为get_selection_item(rml定义对象名, 具体字段名)的方式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: