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.

2

How to make new sequence

By
heru
on 12/16/14, 9:44 PM 1,169 views

Hi, everyone,,

i want to question ,

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

PO+'KODE CABANG'+2 DIGIT YEAR+2 DIGIT MONTH+5 DIGIT SEQUENCE ...

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

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

eg :

POMML141200001

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

Anand
on 12/17/14, 12:49 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
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.

Ivan
on 12/17/14, 5:01 AM
0
heru
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

Anand
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

--
Anand
Sent by Odoo S.A. using Odoo about Forum Post False
heru
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'), }

Anand
on 12/18/14, 1:47 AM
0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
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''.

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

4 follower(s)

Stats

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