Odoo Help


Add Serial No. in Sale Order line Odoo

Rahul Shendge
on 5/22/15, 12:59 AM 3,352 views

Hello Friends,

I am new in Odoo 8. I want to add Sr.No. sales order line. While adding items in sale order Sr.no. should auto increment from 1.

Plz Give Solution for it.

thanks in advanced



--Odoo --

| 5 2 5
--Odoo --

Working in Odoo TEchnologies

On 5/22/15, 5:14 AM

Try Below code ...

class sale_order_line(osv.Model):


  def _get_line_numbers(self, cr, uid, ids, fields, arg, context=None):

"""Assign sequential numbers to line items, starting at 1"""

if context is None: context = {}

res = {}

line_num = 1

# Take the first line in the order, find the root PO, then iterate through all

# PO line items to sequence them properly


  first_line_rec = self.browse(cr, uid, ids, context=context)[0]

for line_rec in first_line_rec.order_id.order_line:

res[line_rec.id] = line_num

line_num += 1

return res


'sequence': fields.integer('Sequence'),

# TODO: Consider making this a stored field to save on read time

'line_no': fields.function(_get_line_numbers, type='integer', string='Line Number'),


<record id="view_order_form_double_validation" model="ir.ui.view">

            <field name="name">sale.order.form</field>

            <field name="model">sale.order</field>

            <field name="inherit_id" ref="sale.view_order_form"/>

                   <field name="arch" type="xml">



<xpath expr="//field[@name='order_line']/tree/field[@name='product_id']" position="before">


                       <field name="sequence" widget="handle"/> 

            <field name="line_no" string="Line No"/>



Please upvote   my answer if resolved your issue          

Thanks Dep

on 12/24/15, 8:00 AM

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 5/22/15, 2:06 AM

You should consider using the sequence in SO line. You need to create a sequence and sequence code.Go through the following links:




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: 5/22/15, 12:59 AM
Seen: 3352 times
Last updated: 5/22/15, 5:14 AM