【发布时间】:2015-07-14 14:57:43
【问题描述】:
我们如何将上下文值传递给 qweb 报告,以便我可以控制表格的可见性。我有一个包含很多表格的 qweb 报告。根据选择列表,我想控制 qweb 报告中这些表格的视图。所以我的选择是使用上下文来控制。但是没有找到任何方法来传递上下文。如果有其他意见,欢迎分享。
【问题讨论】:
标签: odoo odoo-8 openerp-8 qwebpage qweb
我们如何将上下文值传递给 qweb 报告,以便我可以控制表格的可见性。我有一个包含很多表格的 qweb 报告。根据选择列表,我想控制 qweb 报告中这些表格的视图。所以我的选择是使用上下文来控制。但是没有找到任何方法来传递上下文。如果有其他意见,欢迎分享。
【问题讨论】:
标签: odoo odoo-8 openerp-8 qwebpage qweb
先创建解析器类
import time
from openerp.osv import osv
from openerp.report import report_sxw
class sale_quotation_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(sale_quotation_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
‘key’: value,
‘function_name’: self.function_name,
})
def function_name(self):
### add some code if required..
然后定义另一个类
class report_saleorderqweb(osv.AbstractModel):
_name = ‘module_name.report_sale_order_qweb’
_inherit = ‘report.abstract_report’
_template = ‘module_name.report_sale_order_qweb’
_wrapped_report_class = sale_quotation_report
那么就可以这样调用localcontext方法了
<span t-esc=”function_name(parameter)”/>
请参阅我们的博客Qweb report
【讨论】:
你的问题不是很清楚你到底想要什么。例如,我不知道“取决于选择列表”是什么意思,所以我假设您有一个向导,提示用户选择一些选项。如果是这种情况,您可以在打印函数的返回语句中传递数据字典中的选择变量。
def print_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
datas = {'ids': context.get('active_ids', [])}
res = self.read(cr, uid, ids, ['date_start', 'date_end', 'user_ids'], context=context)
res = res and res[0] or {}
datas['form'] = res
if res.get('id',False):
datas['ids']=[res['id']]
return self.pool['report'].get_action(cr, uid, [], 'point_of_sale.report_detailsofsales', data=datas, context=context)
这会传递 data['form'] 下的用户选择。然后,您可以在 qweb 中以 data['form']['date_start']
的形式访问选择【讨论】: