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

How to implement sequences [Closed]

By
cdn
on 3/29/13, 4:34 PM 8,066 views

The Question has been closed

by
Sudhir Arya (SA)
on 04/18/2013 05:20:12

I'm new at openerp and a little bit confused about all.

I would like to add a sequence to automatically create customers ID. For that I need to create a xml file and implement this, right?

But I have no idea where I have to do this. Is there a manual for openerp, where this is explained?

Thank you

4

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 3/30/13, 10:42 AM

Create sequence.xml file and add it in data in __openerp__.py

Here is an example for sequence:

<record model="ir.sequence.type" id="seq_type_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
</record>
<record model="ir.sequence" id="seq_emp_id">
    <field name="name">Employee Number</field>
    <field name="code">hr.employee</field>
    <field name="prefix"></field>
    <field name="padding">3</field>
</record>

After creating sequence in xml, you can call that sequence from your code:

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

You can call this sequence either from create or from your own function or from _defaults.

Hope this will sort out your confusion.

Thanks

Thanks for your answer, but this manual do not help me. I don't know where to call the sequence and also do not know the structure of a module. Isn't there sth. like an overview ? Thanks for your replies

cdn
on 3/30/13, 1:36 PM

Hi Sudhir, in self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})

what is [picking.id]? and also how can i use my current id without 'ids' in the argument field of the ORM create method

Atchuthan
on 7/1/13, 3:57 AM

Add this in your create method:

vals['your_field_name'] = my_sequence
Sudhir Arya (SA)
on 7/1/13, 6:32 AM

yeah i tried... but this will provide the value after clicking on "SAVE" button.

Atchuthan
on 7/1/13, 6:41 AM

That is normal. When you create a new record and click on Save button, create method is called and then record is saved to database.

Sudhir Arya (SA)
on 7/1/13, 6:54 AM

my requirement is to display the sequence generated in the form. If I use _defaults to provide the value... the sequence generated are always even numbers like E002, E004, E006, etc...

So how can I show the sequence at the same time the value must not change after clicking on "SAVE" button

Atchuthan
on 7/1/13, 7:14 AM

If you are generating sequence code from _default, then make sure you have removed get sequence code from create method.

Sudhir Arya (SA)
on 7/1/13, 7:19 AM

If I use _default and display in the form, at the opening of the form the employee number is E001 and after adding values to other field. When "SAVE" button is clicked, the records employee number changes to E002.

Atchuthan
on 7/1/13, 7:27 AM

Did you remove code from create method for sequence?

Sudhir Arya (SA)
on 7/1/13, 9:07 AM

I already removed it in create

Atchuthan
on 7/1/13, 11:06 AM

About This Community

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

Question tools

2 follower(s)

Stats

Asked: 3/29/13, 4:34 PM
Seen: 8066 times
Last updated: 3/16/15, 8:10 AM