【问题标题】:How to open a new window on a new model when clicking a button?单击按钮时如何在新模型上打开新窗口?
【发布时间】:2017-03-19 15:23:16
【问题描述】:

我在 product.template 看板视图上创建了一个新按钮。该按钮正确显示在看板视图的每个产品下方。

当用户单击其中一个按钮时,我想要一个新窗口,在表单视图中,产品变体(product.product 型号)ID 为 1362。

上下文很好地传递给动作。我已经用日志信息进行了验证。但是新窗口没有打开。当我单击一个按钮时,我在日志中看到触发了操作,但没有出现新窗口。没有错误。

按钮的 XML :

<record id="product_template_kanban_view_inherited" model="ir.ui.view">
    <field name="name">Product.template.kanban.view.inherited</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_kanban_view" />
    <field name="arch" type="xml">
        <xpath expr="//div[@name='tags']" position="after"> 
            <button name="open_product_variant" string="test" context="{'res_id': 1362}" type="object" />
        </xpath>
    </field>
</record>

用于操作的 Python:

from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)

class product_template(models.Model):
    _inherit = "product.template"

    @api.one
    def open_product_variant(self):
        _logger.error("open_product_variant")

        resid = self._context.get('res_id')
        _logger.error("    resid :: %s", str(resid))

        res = {
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'view_type': 'form',
            'res_model': 'product.product',
            'target': 'current',
            'res_id': resid,
            'view_id': False,
            'domain': False,
        }

        return res

按钮图片:

【问题讨论】:

    标签: model window action odoo-8


    【解决方案1】:

    我尝试在旧的 api 中重新定义我的 python 方法,并且它在第一枪中就起作用了! 我知道原来的product.template类继承了odoo 8中的osv.osv。对我来说,这意味着这个类是用旧的api编写的。 有时我会设法用新的 api 覆盖一些旧类,但这一次,我会忘记它。 我总是喜欢使用新的 api。

    如果有人设法更正了我上面的代码(新 api),我会改用它。

    我的 Python 代码

    import logging
    _logger = logging.getLogger(__name__)
    
    from openerp.osv import osv
    
    
    class product_template(osv.osv):
        _inherit = "product.template"
        
        def test(self, cr, uid, ids, context=None):
            _logger.error("open_product_variant")
    
            resid = context.get('res_id')
            _logger.error("    resid :: %s", str(resid))
            
            res = {
                'type': 'ir.actions.act_window',
                'view_mode': 'form',
                'view_type': 'form',
                'res_model': 'product.product',
                'target': 'current',
                'res_id': resid,
                'view_id': False,
                'domain': False,  
            }
    
            return res
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      相关资源
      最近更新 更多