This question has been flagged
2 Replies
5084 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!

Avatar
Discard

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

Best Answer

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

Avatar
Discard
Best Answer

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

 

Avatar
Discard