我正在尝试覆盖创建和复制方法,这样每当我执行任何此方法时,我的序列号自动递增,这里是create方法:
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
data_obj = self.pool.get('ir.model.data')
sequence_ids = data_obj.search(cr, uid, [('name','=','seq_tour_booking')], context=context)
sequence_id = data_obj.browse(cr, uid, sequence_ids[0], context=context).res_id
if vals.get('name','/') =='/':
code = self.pool.get('ir.sequence').get_id(cr, uid, sequence_id, 'id', context) or '/'
vals['name'] = code
return super(tour_booking, self).create(cr, uid, vals, context=context)
复制方法的任何想法? 谢谢。
答案 0 :(得分:1)
MAybe我错了,但您也不应该覆盖复制,因为它会调用创建:因此覆盖它就足够了。
答案 1 :(得分:0)
我试过这个并且有效:
def copy(self, cr, uid, id, default=None, context=None):
if default == None:
default = {}
default['name'] = self.pool.get('ir.sequence').get(cr, uid,'your.object.name')
return super(your_class_name, self).copy(cr, uid, id, default, context=context)