This question has been flagged
3 Replies
3272 Views

How to make a sequence number increment by 10 in Openenerp

For Example: In POLine have added new colum Line NO , When Adding an item Line no value should be set as increment by 10.

PO001
   LineNo   Product    Quantity
   10           Pdt1          10
   20           Pdt2          10
   30           Pdt3          10
PO002
   LineNo   Product    Quantity
   10           Pdt1          10
   20           Pdt2          10

My Code:

'line_no':fields.integer('Line No'),
_defaults = {
    'line_no':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order.line'),    
}

sequence.xml

<record id="seq_type_purchase_order_line" model="ir.sequence.type">
     <field name="name">Purchase Order Line</field>
     <field name="code">purchase.order.line</field>
</record>
<record id="seq_purchase_order_line" model="ir.sequence">
     <field name="name">Purchase Order Line</field>
     <field name="code">purchase.order.line</field>            
     <field name="padding">4</field>
     <field name="number_increment">10</field>
 </record>

I got the below error:

Error: [_.sprintf] expecting number but found string

Any advice would be appreciated.

Avatar
Discard
Best Answer

0 down vote

what you have done, it is correct , you have done one single mistake,

you have to define 'line_no' as char type field not as interger

define like this: 'line_no':fields.char('Line No'),

ir.sequence return string and your line_no is integer

what increment next number is return by get method is combile of prefix field,

interpolated_prefix + '%%0%sd' % seq['padding'] % seq['number_next'] + interpolated_suffix

so it is a string type sequence return from get method

Hope this help

Avatar
Discard
Best Answer

Hello I think you should have try onchange method this method is perfectly working for me

def onchange_line(self, cr, uid, ids, lines,context=None):
result = {}
result['value'] = {}
#do the proper checking
count_dict = {}
count = 10
had_seq = 0
for index,line in enumerate(lines):
    if line[0] == 0:
        count_dict[index] = count
        count +=10
    else:
        had_seq +=1
#seqnece_no is the new sequence field defined
for k in count_dict:
    if had_seq:
        lines[k][2]['sequence_no'] = had_seq*10 + count_dict[k]
    else:
        lines[k][2]['sequence_no'] = count_dict[k]
result['value'].update({'order_line':lines})
return result

and call the onchange method in purchase order line

Avatar
Discard
Best Answer

Hello,

You can do it by giving number_increment as 10 in your sequence file.

For example: <field name="padding">4</field> <field name="number_increment">10</field>

Avatar
Discard
Author

Created Sequence with number_increment as 10 ,Im getting Error: [_.sprintf] expecting number but found string

Author

As same as i written please check my updated post

Author

Error Exist

Author

@nehal@ updated in post

Replace your line_no field with 'line_no':fields.char('Line No'),