Created
May 7, 2022 03:31
-
-
Save altela/a08811d0ba04f30e759c26441ed01a4e to your computer and use it in GitHub Desktop.
Odoo Create Sequence Number Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First you need to define a create method for the sequence number | |
class ExampleClass(models.Model): | |
_rec_name = 'sequence_number' | |
@api.model | |
def create(self, vals): | |
if vals.get('sequence_number', 'New') == 'New': | |
vals['sequence_number'] = self.env['ir.sequence'].next_by_code('mysequence.model') or 'New' | |
result = super(ExampleClass, self).create(vals) | |
return result | |
# after that, this .xml will hold the configuration on how the sequence are generated every | |
# once a form is created | |
<data noupdate="1"> | |
<record id="my_sequence_record_id" model="ir.sequence"> # rename the id | |
<field name="name">My Sequence</field> # rename my sequence | |
<field name="code">mysequence.model</field> # add your sequence model | |
<field name="prefix">SEC.</field> # the static prefix | |
<field name="padding">5</field> # the digits after prefix | |
<field name="number_next">1</field> # addition on each new record created | |
<field name="number_increment">1</field> # addition on each new record created | |
</record> | |
</data> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment