auto increment - internal reference odoo9

本小妞迷上赌 提交于 2019-12-08 11:05:59

问题


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)

And the xml file:

      <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>


回答1:


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)


来源:https://stackoverflow.com/questions/39266106/auto-increment-internal-reference-odoo9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!