This question has been flagged
3 Replies
6431 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 ?

Avatar
Discard

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

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

Best Answer

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

Avatar
Discard
Author Best Answer

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)

Avatar
Discard

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

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

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

Best Answer

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.

Avatar
Discard

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.