Reputation: 55
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.
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.
Upvotes: 1
Views: 3304
Reputation: 3207
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 integer
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
Upvotes: 2
Reputation: 1055
check this code and you need to create one field for sequence No.
<field name="order_line" on_change="onchange_line(order_line)">
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
hope this will help you
thanks @Odedra
Upvotes: -1
Reputation: 16733
In xml you need to replace
<field name="number_increment">10</field>
by
<field eval="10" name="number_increment"/>
Upvotes: 0