Openerp在树视图中添加按钮以创建one2many字段

时间:2014-12-04 00:49:23

标签: forms button tree openerp

我在moudle1和mosule2之间有一个很好的关系。我想添加一个与one2emany相同的行为的按钮"添加元素"在module1树视图中。我做了如下:

  1. 在树状视图中添加带对象操作的按钮:

    <button string="Add Entry" icon="STOCK_ADD" name="action_add_entry" type="object"/>
    
  2. 在module1中定义动作处理程序:

    def action_add_entry(self, cr, uid, ids, context=None):
        '''
        This function opens a window to compose an meeting request
        '''
        assert len(ids) == 1, 'This option should only be used for a single id at a time.'
    
        ir_model_data = self.pool.get('ir.model.data')
        try:
            compose_form_id = ir_model_data.get_object_reference(cr, uid, 'module2', 'module2_form_view')[1]
        except ValueError:
            compose_form_id = False 
        ctx = dict(context)
        ctx.update({
            'default_model': 'module1',
            'default_module1_id': ids[0],
        })
        return {
            'type': 'ir.actions.act_window',
            'name':'Create Complaint',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'module2',
            'views': [(compose_form_id, 'form')],
            'view_id': False,
            'target': 'new',
            'flags': {'form': {'action_buttons': True}},
            'context': ctx,
            'nodestroy': True
        }
    
  3. 我成功获得弹出窗口中显示的表单视图,但我没有得到 Save&amp;关闭按钮或 Save&amp;新。我只得到保存按钮和取消(这不起作用)。

0 个答案:

没有答案
相关问题