Odoo Help

Welcome!

This community 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.

1

generate a random value for an invoice

By
Maarten Ureel
on 4/1/15, 4:06 AM 797 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.

0

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        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
On 4/1/15, 6:22 AM

Hi,

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

<openerp>

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

<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

</record>

</data>

</openerp>

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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