繁体   English   中英

如果表单是通过OPENERP中的特定按钮定向的,则显示表单按钮

[英]Show form button if the form is directed through specific button in OPENERP

我想知道是否有可能根据如何调用表单来设置表单按钮的可见性。 就像有两种形式“ A”和“ B”一样。 现在,表格“ A”上的按钮称为表格“ B”。 我只想显示通过特定表单“ A”按钮调用的“ B”按钮。 我不知道这将如何实现,但是我认为我必须在表单B的按钮上设置属性。但是如何检查是否单击了表单A按钮。 那就是我被困住的地方。 我需要一些指导,希望能对您有所帮助。 调用表单“ b”的代码:

def edits(self,cr,uid,ids,context=None):
    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
        my_id=int(deg_obj.my_products)

    return{
          'view_type': 'form',
          'view_mode': 'form',  
          'res_model': 'product.product',
          'res_id':my_id,
          'type': 'ir.actions.act_window',
          'nodestroy':False,
          'target': 'inline',          
          }

我希望仅当我通过“编辑”按钮将其打开时才显示“ b”按钮。

要从形式“ A”打开形式“ B”,您需要在对象中定义一个方法以调用形式“ B”。 在此方法上,您可以设置上下文,例如,

def edits(self,cr,uid,ids,context=None):
    if context is None:
        context = {}

    for id in ids:
        deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
        my_id=int(deg_obj.my_products)

    context['from_edits'] = True

    return{
      'view_type': 'form',
      'view_mode': 'form',  
      'res_model': 'product.product',
      'res_id':my_id,
      'type': 'ir.actions.act_window',
      'nodestroy':False,
      'target': 'inline',       
      'context': context,   
      }

在表格B的XML声明中,您可以尝试

<button string="To form A" type="object" name="to_form_a" invisible="context.get('from_edits')" />

只需更改按钮声明中的小东西

<button name="saves" string="SAVE" type="object" invisible="context.get('product_product',False)" />

并确保您在上下文中设置了适当的值

context['product_product'] = True

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM