Odoo Help


increment sale order line sequence by 10

on 1/9/15, 4:07 AM 4,456 views

I'd like that every time, I add an item in a sale order, the sequence field is automatically incremented by 10.

What I did:

class sale_order_line(osv.osv):

    _inherit = 'sale.order.line'

    _columns = {
       'sequence': fields.char('Sequence', help="Gives the sequence order when displaying a list of sales order lines."),

    _defaults = {
       'sequence':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'sale.order.line'),    


 <record id="seq_type_sale_order_line" model="ir.sequence.type">
     <field name="name">Sale Order Line</field>
     <field name="code">sale.order.line</field>
<record id="seq_sale_order_line" model="ir.sequence">
     <field name="name">Sale Order Line</field>
     <field name="code">sale.order.line</field>            
     <field name="padding">3</field>
     <field name="number_increment">10</field>
     <field name="number_next">10</field>

The sequence is incremented, but when I create a new sale order, it doesn't reset to 10. If I have SO1 with 3 sale lines, I have sequences 010, 020 and 030. But in SO2, I have 040 and 050, instead of 010 and 020.

How can I modify my code?

It doesn't reset automatically. It will continuously increases everytime you fetch the record. Why do you need to start from '10' everytime?

Emipro Technologies Pvt. Ltd.
on 1/9/15, 4:20 AM

You can use functional field in sales order line for creating a sequence as '010' instead using ir.sequence. Else you can reset sequence every time when a sales order created.

Kalpana Hemnani
on 1/9/15, 4:26 AM

Thanks for your answers. I need to start from '10' everytime because it's clearer, if I have many sales orders with many lines increasing everytime, I would attend numbers like 653240, and it would be difficult to distinguish which line has the lowest sequence. I tried using an onchange method, but I cannot call it in xml file because I should call it in sale.order model () but the onchange method is defined in sale.order model.

on 1/9/15, 4:53 AM

Anil R. Kesariya

--Anil R. Kesariya--
| 7 6 8
Rajkot, India
--Anil R. Kesariya--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya
On 1/9/15, 5:41 AM

Hello Wided,

Here you don't need to create ir.sequence record ,because it will always incremented.

better solution is to override default_get method of sale order line.

I have already given answer for this. Have a look on this answer it will help you.




Thanks Anil Kesariya, I've tried your code, but I always have 10 in my field "sequence", after debugging, I found that the line: if len(context.get('order_line')) > 0 is not executed, because context.get('order_line')=[], so len ( context.get('order_line')) is always 0. I don't understand context in openerp very well, I don't know how to change the code to work.

on 1/12/15, 3:33 AM

you need to pass your one2many field on context. whatever fields name is for eg. if sale order line than pass . you need to inherit the sale view and add context on sale order line field than it will work. so our default get method will get the line value. if any line added in your current sale order record.

Anil R. Kesariya
on 1/12/15, 4:13 AM

I did that: But I still get always 10 in sequence field.

on 1/12/15, 7:47 AM

I've found that the function is working when I use "add an item", but it's not working when I use "save and create". I'm trying to make it work when using "save and create".

on 1/13/15, 3:51 AM

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

3 follower(s)


Asked: 1/9/15, 4:07 AM
Seen: 4456 times
Last updated: 3/16/15, 8:10 AM