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.

0

increment sale order line sequence by 10

By
Wided
on 1/9/15, 4:07 AM 2,852 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'),    
            }

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

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.

Wided
on 1/9/15, 4:53 AM
2

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
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.

https://www.odoo.com/forum/help-1/question/how-to-generate-automatic-sequence-number-in-one2many-field-67834#answer-67880

Regards,

Anil.

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.

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

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

Wided
on 1/13/15, 3:51 AM

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

3 follower(s)

Stats

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