我想扩展sale.order.line模型的onchange_product_id方法。我尝试用新的和旧的api风格做,但没有任何效果。以下是我的尝试:
老pi:import logging
from openerp.osv import fields, osv
_logger = logging.getLogger(__name__)
class sale_order_line(osv.osv):
_inherit = 'sale.order.line'
def onchange_product_id(self, cr, uid, ids, product_id, context=None):
_logger.debug('product_id has changed')
return {}
新api:
from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)
class sale_order_line(models.Model):
_inherit = 'sale.order.line'
@api.onchange('product_id')
def onchange_product_id(self):
_logger.debug('product_id has changed')
return True
答案 0 :(得分:2)
尝试这种方式(我还没试过,但它应该有效)
from openerp.osv import fields, osv
class CustomSaleOrderLine(osv.osv):
_inherit = 'sale.order.line'
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
# some operations
return super(CustomSaleOrderLine, self).product_id_change(cr, uid, ids, pricelist, product, qty,
uom, qty_uos, uos, name, partner_id,
lang, update_tax, date_order, packaging, fiscal_position, flag, context)