自动递增-内部参考odoo9 [英] auto increment - internal reference odoo9

查看:91
本文介绍了自动递增-内部参考odoo9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字段"ref"(内部参考)的类型更改为自动递增(例如,每次创建新联系人时,我的内部参考都应增加1).因此,第一个联系人应该具有内部参考1,第二个2,第二个3,依此类推...

I want to change the type of the field 'ref' (Internal Reference) to be auto incremented (for example every time I create a new contact my Internal Reference should increase by 1). So first contact should have Internal Reference 1, the second 2, the third 3 and so on...

没有错误,但参考字段仍然为空.我错过了一些额外的代码吗?有人可以帮我吗?

There are no errors but still the reference field is empty. Have I missed some additional code? Can someone help me?

@api.model
def create(self, vals):
    if vals.get('ref', 'New') == 'New':
        vals['ref'] = self.env['ir.sequence'].next_by_code(
            'res.debt') or 'New'
    return super(Partner, self).create(vals)

和xml文件:

      <record id="your_sequence_id" model="ir.sequence">
          <field name="name">Reference</field>
          <field name="padding">3</field>
          <field name="code">res.debt</field>
      </record>

推荐答案

您不需要不必要的if语句,因为正如您在问题中所述,您希望引用在每次创建新用户时自动递增.用户无法从表单中更改字段,这就是您在odoo中获得下一个引用的方式.

You don't need the unnecessary if statement, because as you stated in your question you want the reference to autoincrement every time a new user is created. the users can't change the field from the form, this is how you get the next reference in odoo.

@api.model
def create(self, vals):
    vals['ref'] = self.env['ir.sequence'].get('res.debt')
    return super(Partner, self).create(vals)

这篇关于自动递增-内部参考odoo9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆