继承产品保存方法
Inherit product save method
我想 运行 保存(添加或更新)产品时的脚本。
根据 this thread 答案的建议,我创建并安装了一个模块并尝试重写 product.product 的保存方法,如下所示:
# -*- coding: utf-8 -*-
from openerp.osv import osv
class lcd_update(osv.osv):
_inherit = 'product.product'
def save(self, **args):
self.log()
value = super(lcd_update, self).save(self, **args)
return value
def log():
f = open('log.txt', 'w')
f.write('test\n')
f.close()
说实话,我不知道lcd_update
这里说的对不对。我从文档中遵循了这一点。
这段代码有什么问题?它什么也没做。
尝试在 return 语句之前添加您的自定义代码,或者在某处捕获 super 的结果并在此之后添加您的代码和 return 更改后的结果,不要忘记 return 来自方法。
from openerp.osv import osv
class lcd_update(osv.osv):
_inherit = 'product.product'
def create(self, cr, uid, vals, context=None):
return super(lcd_update,self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
return super(lcd_update,self).write(cr, uid, ids, vals, context=context)
希望对您有所帮助。
我想 运行 保存(添加或更新)产品时的脚本。
根据 this thread 答案的建议,我创建并安装了一个模块并尝试重写 product.product 的保存方法,如下所示:
# -*- coding: utf-8 -*-
from openerp.osv import osv
class lcd_update(osv.osv):
_inherit = 'product.product'
def save(self, **args):
self.log()
value = super(lcd_update, self).save(self, **args)
return value
def log():
f = open('log.txt', 'w')
f.write('test\n')
f.close()
说实话,我不知道lcd_update
这里说的对不对。我从文档中遵循了这一点。
这段代码有什么问题?它什么也没做。
尝试在 return 语句之前添加您的自定义代码,或者在某处捕获 super 的结果并在此之后添加您的代码和 return 更改后的结果,不要忘记 return 来自方法。
from openerp.osv import osv
class lcd_update(osv.osv):
_inherit = 'product.product'
def create(self, cr, uid, vals, context=None):
return super(lcd_update,self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
return super(lcd_update,self).write(cr, uid, ids, vals, context=context)
希望对您有所帮助。