openerp在不影响基数的情况下覆盖onchange行为 [英] openerp override onchange behavior without affecting base

查看:71
本文介绍了openerp在不影响基数的情况下覆盖onchange行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了purchase.order.line.我添加了很多相关领域.它们都通过order_line中的product_id与product.product中的字段相关.

I have inherited from purchase.order.line. I have added a bunch of related fields. They are all related to fields in product.product via product_id in order_line.

我要实现的是,当用户在采购订单行形式中选择或更改产品时,相关字段应使用所选产品的值进行刷新/更新/填充.

What I want to achieve is that when a user selects or changes a product in the purchase order line form, the related fields should get refreshed/updated/populated with values of the selected product.

我已经为此编写了onchange方法,但不确定如何从继承的视图中调用它? product_id字段已经在(父)order_line视图中存在,并且已经定义了onchange.如何让系统也使用我的onchange?

I have written the onchange method for this but I'm not sure how to invoke it from the inherited view? The product_id field was already there in the (parent) order_line view and it already has an onchange defined. How do I get the system to use my onchange as well?

我不想打扰Purchase.order.line中已经存在的onchange_productid方法.因此,无论是在我的onchange之前还是之后,它都应该继续其标准功能.

I don't want to disturb the onchange_productid method that is already there in purchase.order.line. So either before my onchange or after it, it should continue with its standard functioning.

谢谢

编辑:最新版本(任何相关的many2one或选择字段具有值时都会出错).

EDIT: latest version (getting errors when any of the related many2one or selection fields has a value).

class purchase_order_line_custom(osv.osv):
    _name = 'purchase.order.line'
    _inherit = 'purchase.order.line'

    def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, context=None):
    values = super(purchase_order_line_custom, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order, fiscal_position_id, date_planned,name, price_unit, context=context)
    if product_id:
        product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
        values['value'].update({
                                'qualified_name':product.qualified_name,
                                'product_type' : product.product_type or None,
                                'product_subtype' : product.product_subtype,
                                'count_id':product.count_id or None 
        })
    return values   

_columns={
          'product_type': fields.related('product_id','product_type',type='selection', string='Product Type', selection=[('X','X'),('Y','Y'),('Z','Z')]),
          'product_subtype': fields.related('product_id','product_subtype',type='char', size=64, string='Sub-Type'),
          'qualified_name': fields.related('product_id','qualified_name',type='char', size=64, string='Qualified Name'),
          'count_id': fields.related('product_id','count_id',type='many2one',relation='product.mycount',string='Count')
          }

purchase_order_line_custom() 

推荐答案

您需要为字段"product_id"覆盖onchange函数(可以使用super())并更新结果. 例如

you need to overide the onchange function(you can use super() ) for the field 'product_id' and update the result. for example

def onchange_product(self,cr,uid,ids,product_id,context=None):
    values = super(<your_class_name>,self).onchange_product(cr, uid,ids,product_id,context=context)
    # values will be a dictionary containing 'value' as a key.
    # You need to add all the newly added related fields and other fields to the values['value']. 
    # if 'aaa' is the newly added field, then values['value'].update({'aaa':<value for aaa>})
    # then return values
    return values

在更改以下内容时修改您

modify you onchange to the following

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
    partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
    name=False, price_unit=False, context=None):
    values = super(purchase_order_line_custom, self).onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order, fiscal_position_id, date_planned,name, price_unit, context=context)
    if product_id:
        product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
        values['value'].update({
            'product_type' : product.product_type,
            'product_subtype' : product.product_subtype,
            'qualified_name' : product.qualified_name,
            'count_id' : product.count_id                 
        })
    return values 

这篇关于openerp在不影响基数的情况下覆盖onchange行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆