Odoo Help


generate a random value for an invoice

Maarten Ureel
on 4/1/15, 4:06 AM 1,663 views

I want to generate a random value for every invoice I create, to use it as an access key for online payment of the invoice.

How can I accomplish the creation of this random value? The online payment part, displaying it on the invoice, and creating the payment I will be able to do just fine.


Baiju KS

--Baiju KS--
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju KS
On 4/1/15, 6:22 AM


You can use sequence for this purpose. Here is more details.

First you have to define "sequence type" and "sequence" as follows in xml file (better define a new xml file for sequence) :-


<data noupdate="1">

<!-- Sequences for purchase.order -->

<record id="seq_type_brand" model="ir.sequence.type">

<field name="name">Brand</field>

<field name="code">product.brand</field> # name of type


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

<field name="name">Brand</field>

<field name="code">product.brand</field> # name of type

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

<field name="number_next">50000</field> # first number

<field name="number_increment">1</field> # increment by




->here in "ir.sequence" you can use attribute like 'prefix' and 'suffix' if needed (number_next is starting number)

Then you can use get method (of ir.sequence) in defaults of field you want to generate sequence :-

Eg : test = fields.Char('Test', default = lambda obj: obj.env['ir.sequence'].get('product.brand') or '/') 

or if you want to only generate the sequence when a record is saved, you can override the create function.

Hope this helps........

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/1/15, 4:06 AM
Seen: 1663 times
Last updated: 4/1/15, 2:54 PM