0

在我的情况下,当我打开表单时会显示 +1 序列号。但是当我保存记录时,它又增加了 1。这意味着我的序列号现在看起来像这样:

  • EMP0010
  • EMP0012
  • EMP0014

这是 openerp 的问题还是我的代码中缺少某些内容?

'register_no': fields.char('Register No', size=32, help='Register No', readonly=True),  # employer wise ,estate wise
        'employer_no': fields.char('Employer No', type='char', readonly=True),

_defaults = {
 'register_no': lambda obj, cr, uid, context: '/',
 'employer_no': lambda obj, cr, uid, context: '/',
 }

您可以在这里查看我的代码

我评论了

    def create(self, cr, uid, values, context=None):
        values['register_no'] = self.pool.get('ir.sequence').get(cr, uid, 'bpl.worker')
        values['employer_no'] = self.pool.get('ir.sequence').get(cr, uid, 'bpl.employer')
        return super(bpl_worker_registration, self).create(cr, uid, values, context=context)
4

1 回答 1

1

您已经调用了两次 ir.sequence 方法,一次来自 create

def create(self, cr, uid, values, context=None):

values['register_no'] = self.pool.get('ir.sequence').get(cr, uid, 'bpl.worker')
values['employer_no'] = self.pool.get('ir.sequence').get(cr, uid, 'bpl.employer')
return super(bpl_worker_registration, self).create(cr, uid, values, context=context)

第二个是默认值

_defaults = {

 'register_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'bpl.worker'),
 'employer_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'bpl.employer'),

 }

调用两次没有任何意义。仅从 _default 或从 create 方法进行调用

于 2013-03-26T08:29:39.290 回答