我正在尝试执行一个函数来填充新的树视图。我需要执行该功能并重定向到仅由一个按钮完成的树视图。请帮我做。
我的功能是
def populate_values(self, cr, uid, ids, context={}):
result = {'value': {}}
today = datetime.datetime.now()
tt=today.date()
emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
if emps:
#...
#...
#...
return {
'name':_("leave.score.card.tree"),
'view_mode': 'tree',
'view_id': '%(open_leave_score_card_tree)d',
'views': [('tree'),('graph')],
'view_type': 'graph',
'res_id' : '%(open_leave_score_card)d',
'res_model': 'leave.score.card',
'type': 'ir.actions.act_window',
'target': 'new',
}
使用按钮
的表单视图<record model="ir.ui.view" id="edit_leave_score_card_form">
<field name="name">leave.score.card.form</field>
<field name="model">leave.score.card</field>
<field name="arch" type="xml">
<form string="Leave Score Card" create="false" edit="false" version="7.0">
<sheet>
<button string="Generate" type="object" name="populate_values" class="oe_highlight"/>
</sheet>
</form>
</field>
</record>
我需要重定向的树视图
<record model="ir.ui.view" id="view_leave_score_card_tree">
<field name="name">leave.score.card.tree</field>
<field name="model">leave.score.card</field>
<field name="arch" type="xml">
<tree string="Leave Score Card To the Date" create="false" edit="false" colors="red:available_medical < 0.0; red:available_casual < 0.0">
<field name="employee_id" />
<field name="category_id" />
<field name="taken_medical" />
<field name="taken_casual" />
<field name="taken_annual" />
<field name="taken_spc" />
<field name="available_medical" />
<field name="available_casual" />
<field name="available_annual" />
<field name="available_spc" />
<field name="sec_id" invisible="1" />
</tree>
</field>
</record>
操作窗口
<record id="open_leave_score_card" model="ir.actions.act_window">
<field name="name">Leave Score Card Form</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<record id="open_leave_score_card_tree" model="ir.actions.act_window">
<field name="name">Leave Score Card Tree</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="view_id" eval="view_leave_score_card_tree"/>
<field name="search_view_id" ref="view_leave_score_card_search"/>
</record>
请让我知道我在哪里做错了,因为按钮调用完全没有重定向
答案 0 :(得分:1)
无需为此编写任何功能。我知道你想在点击按钮时打印员工的记分卡。
更新记分卡的操作如下。
<record id="open_leave_score_card_tree" model="ir.actions.act_window">
<field name="name">Leave Score Card Tree</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="view_id" eval="view_leave_score_card_tree"/>
<field name="search_view_id" ref="view_leave_score_card_search"/>
<field name="context">{
'search_default_employee_id': [active_id],
'default_employee_id': active_id,
'active_test': False,}
</field>
</record>
然后在xml中更改按钮代码,如下所示。
<button string="Generate" type="action" name="%(open_leave_score_card_tree)d" class="oe_highlight"/>
删除功能不需要它。如果你想在不改变任何内容的情况下使用现有代码,那么在动态操作中设置domain,你将从函数返回。
在你的函数中你写错了 view_type ,如果你想返回列表视图,它应该是form不是图形。
def populate_values(self, cr, uid, ids, context={}):
today = datetime.datetime.now()
tt=today.date()
emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
if emps:
return {
'name':_("leave.score.card.tree"),
'view_mode': 'tree',
'view_id': '%(open_leave_score_card_tree)d',
'views': [('tree'),('graph')],
'view_type': 'form',
'res_id' : '%(open_leave_score_card)d',
'res_model': 'leave.score.card',
'type': 'ir.actions.act_window',
'domain' : [('employee_id','in', ids)],
'target': 'new',
}
return True