2
votes

So I've been looking around the web, on a mission to find a way to create my own sequence for the new API for Odoo 9 that I am using. However, I wasn't able to find a satisfactory answer. As far as I've seen, sequences aren't very well documented in the Odoo Docs.

Here's what I know so far.

From this I know:

<openerp>
  <data noupdate="1">
    <record model="ir.sequence.type" id="seq_type_obj_id">
      <field name="name">obj_id_seq</field>
      <field name="code">seq.obj.name</field>
    </record>
    <record model="ir.sequence" id="seq_obj_id">
      <field name="name">obj_id_seq</field>
      <field name="code">seq.obj.name</field>
      <field name="prefix">prefix</field>
      <field name="padding">3</field>
    </record>
  </data>
</openerp>

But apparently ir.sequence.type is NOT a model that exists and I cannot use, so I removed that record and it compiles/updates without errors.

From previous source, I also know:

my_sequence = self.pool['ir.sequence'].get(cr, uid, seq_obj_name)
self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

But this is the old API, so I've changed it to:

# Correct me if I'm wrong here
my_sequence = self.env['ir.sequence'].get('seq.obj.name')

And have added it to the create function, which then writes to an arbitrary field to be stored.

So I've done all this without getting any error messages.

My problem is: The field I'm storing the sequence instance to is not changing. I checked in the sequence settings and the sequence is not being incremented when I create a new record either.

For the sake of clarity:

@api.model
def create(self, vals):
    for rec in self:
        rec.seq_id = self.env['ir.sequence'].get('seq.obj.name')
    return super(PurchaseOrder, self).create(vals)

If someone could give me a thorough explanation of where Odoo does the auto increment, maybe direct me to a proper source, or point out what is wrong with my code and how to fix it, I would much appreciate the effort.

1

1 Answers

0
votes

You code didn't update the directory variable. That's the reason of it.

Try with this code.

@api.model
def create(self, vals):
    if vals:
        vals.update({
            'seq_id': self.env['ir.sequence'].get('seq.obj.name')
        })
    return super(PurchaseOrder, self).create(vals)