This question has been flagged
2 Replies
6699 Views

Odoo 11 Enterprise

We have tried to make the internal reference automatically filled using the sequences settings. Technical>>sequences and identifiers>>sequences but cant seem to get it to work.


Avatar
Discard
Best Answer

https://www.odoo.com/apps/modules/11.0/product_sequence/

This module allows you to associate a sequence to the product reference. The reference (default code) is unique (SQL constraint is used to enforce this) and mandatory.  You can also optionally specify different sequences for different product categories.

Avatar
Discard
Best Answer

You can make it in your own custom module (add-on):

1. define sequence in xml file

<odoo>

<data>

<record id="<your_sequence_id>" model="ir.sequence">

<field name="name"><your_sequence_name></field>

<field name="code"><your_sequence_code></field>

<field name="prefix"><your_sequence_prefix></field>

<field name="suffix"><your_sequence_suffix></field>

<field name="padding">3</field>

<field name="number_increment">1</field>

</record>

</data>

</odoo>

there:

sequence format := <your_sequence_prefix><next_seq_number><your_sequence_suffix>

<next_seq_number> := <previous_seq_number> + <number_increment> ( 1 in this case)

<previous_seq_number> := { 0 | <previous_seq_number>}

<previous_seq_number> := <next_seq_number> - <number_increment> ( 1 in this case)

<your_sequence_prefix> := prefix format according to the legend you can find in every sequence form in ODOO,

for example PRODUCT-%(range_year)s-%(month)s-%(day)s-

<your_sequence_suffix> := suffix format according to the legend you can find in every sequence form, usually I leave it empty

<your_sequence_code> := the sequence code you will use to call it from python code,

for example myproduct.name.sequence

2. overwrite create method

@api.model

def create (self, vals):

vals['default_code'] = self.env['ir.sequence'].next_by_code('myproduct.name.sequence')

result = super ( ProductTemplate, self).create(vals)

return result

there:

myproduct.name.sequence := <your_sequence_code> defined in xml file

don't forget make default_code field read only in the form to avoid manual changes

Note: after your custom module installation this sequence will appear in ODOO sequences list


Avatar
Discard