我想扩展sale.order.line模型的onchange_product_id方法。我尝试以新的和旧的api风格进行操作,但是没有任何效果。这是我的尝试:
旧API:
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
最佳答案
尝试这种方式(我还没有尝试过,但是应该可以)
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)