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

Adding Date To Sales Order Number

By
Alex Gallien
on 6/16/14, 3:06 PM 729 views

I am trying to change the naming scheme of Sales Orders to incorprate the date, in the format SOyymmdd###, where yy is the year, mm is the month, dd is the day, and ### is the padding for the orders created that day. I think I have found the code that creates the names in /addons/sales/sale_sequence.xml:

        <record id="seq_sale_order" model="ir.sequence">

            <field name="name">Sales Order</field>

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

            <field name="prefix">SO</field>

            <field name="padding">3</field>

            <field name="company_id" eval="False"/>

        </record>

 

Is it posible to add a dynamic name based on the date here? Or would it be somewhere in sale.py? Or is there an easier way to customize this? Thanks!

On sale.py you can find the 'name' field default in copy method.

klacus
on 6/17/14, 12:33 AM
1
Eva Pinter
On 6/16/14, 7:11 PM

Hi Alex

There is no need to change the code to do it. It is preferable to go to the settings ->Sequence and identifiers->Sequence. There you can choose sales.order and define what you want to see there.

Good luck

1
klacus
On 6/17/14, 12:31 AM

I think much better if you inherit the sale_order create def.

import datetime # must put this your import section

    def create(self, cr, uid, vals, context=None):
            if vals['name'] <> '':

                pad_s = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') # get seq. like : 'SO111'

                pad_s = pad_s..replace('SO','') # remove the 'SO' from the seq number

                your_new_so_name = 'SO' + str(today.strftime("%y/%m/%d")) +'-' + str(pad_s)

                # >target is 'SO'SO14/06/17-001
                vals.update({'name': your_new_so_name})
        return super(sale_order, self).create(cr, uid, vals, context=context)

Please note I don't test it.. (print varaible for the check..)

I am sure you need to modify the copy method also, if somebody duplicate the SO the name must be prepare.

Bye

P.m.: for inheriting a model you can find a lot of good tutorial:

https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/object_inherit.html/

http://anybox.fr/blog/inside-openerp-inheritance

http://forum.openerp.com/forum/topic34747.html

and so on...

 

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: 6/16/14, 3:06 PM
Seen: 729 times
Last updated: 3/16/15, 8:10 AM