Odoo Help


How to make new sequence

on 12/16/14, 9:44 PM 1,772 views

Hi, everyone,,

i want to question ,

i will add sequence 'KODE CABANG' in Purchase Order (PO) Sequence, with format  PO like


i have code 'KODE CABANG' like MML, HHO, ULZ, DBB ...

so, code 'KODE CABANG' show in field prefix or suffix in sequence form ..

eg :


what i do ?

@Heru As per your requirement you have different "Kode Cabang", so I think you will have to create those many sequence to to identify as per different "codes". Then while in create method you will have to identify the appropriate sequence and call it for the record creation.

Emipro Technologies Pvt. Ltd.
on 12/17/14, 12:47 AM

I dont know.. but some said ir.sequence will help you.. check about it...

on 12/17/14, 12:49 AM
On 12/17/14, 4:22 AM

If your requirement is very specific to PO (not to other sequences), then I would advise that you don't touch the ir.sequence.  Make the sequence of PO to supply 2 DIGIT YEAR+2 DIGIT MONTH+5 DIGIT SEQUENCE.  Then in the code where PO name is applied (it is during create method in v7.0, see odoo/addons/purchase/purchase.py), put the "PO"+KODE CABANG as a prefix to the already provided string.

If you need the KODE CABANG to be applicable for more than one sequences, then maybe it is worth considering to inherit ir.sequence and enhance it's _next method (see odoo/openerp/addons/base/ir/ir_sequence.py).  The challange is how would you provide the information for KODE CABANG.  Some models actually called _next in their default_get, which is called even before the model instance is created.

Note that when the PO has been created, I presume the field for KODE CABANG will still be editable until a certain state. You may need to make the assignment of PO number later in the process (not in create) if you want to get the most up to date KODE CABANG.

on 12/17/14, 5:01 AM
On 12/17/14, 9:20 PM

ok thanks ,

@Emipro Technologies, @Anand, @Ivan, @Ben Bernard  ... for your solutions, 

it works, with add method create, like :

def create(self, cr, uid, vals, context=None):
        seq = self.pool.get('res.partner').browse(cr, uid, vals['partner_id'])
        vals['name'] = self.pool.get('ir.sequence').get(cr, uid, seq.kd_sequence.code)
        return super(purchase_order, self).create(cr, uid, vals, context=context)

so ir.sequence helped you na.. :) :P

on 12/18/14, 12:42 AM
yes , right Anad

On Thu, Dec 18, 2014 at 12:42 PM, Anand <anand.k@mitosistech.com> wrote:

so ir.sequence helped you na.. :) :P

Sent by Odoo S.A. using Odoo about Forum Post False
on 12/18/14, 12:49 AM

you can also put it in _defaults{ 'rep_id':lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'report.model'), }

on 12/18/14, 1:47 AM
Ben Bernard
On 12/17/14, 4:03 AM

As @Anand said, you can do it via ir.sequence (Configuration / Sequences). There should be already default value for purchase order and you can try to modify it.

To make it more dynamic, I think you should add some code to detect required 'KODE CABANG''.

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

4 follower(s)


Asked: 12/16/14, 9:44 PM
Seen: 1772 times
Last updated: 3/16/15, 8:10 AM