I want to generate sequence number in purchase.requisition.line. Below is my code. Can anyone please correct me?
class purchase_requisition(osv.osv):
_inherit = 'purchase.requisition'
def update_seq(self, cr, uid, ids, line_ids, context=None):
print "line_ids",line_ids
new_order_line = []
counter = 1
x = {}
for line in line_ids:
if line[0] in [1,4]:
line[0] = 1
if type(line[2]) == type({}):
line[2].update({'serial_no':counter})
print "counter1",counter
#x = counter
else:
line[2] = {'serial_no':counter}
print "counter2",counter
#x = counter
counter = counter + 1
print "counter",counter
x = new_order_line.append(line)
print "new_order_line",new_order_line
return {'value': {'line_ids': x} }
class purchase_requisition_line(osv.osv):
_inherit = 'purchase.requisition.line'
def update_seq(self, cr, uid, ids, line_ids, context=None):
print "line_ids",line_ids
new_order_line = []
counter = 1
for line in line_ids:
if line[0] in [1,4]:
line[0] = 1
if type(line[2]) == type({}):
line[2].update({'serial_no':counter})
print "counter1",counter
else:
line[2] = {'serial_no':counter}
print "counter2",counter
counter = counter + 1
print "counter",counter
new_order_line.append(line)
print "new_order_line",new_order_line
return {'value': {'serial_no': new_order_line} }
_columns={
'serial_no':fields.integer('Serial No'),
}
_order = 'serial_no desc, serial_no, id'
_defaults = {'serial_no': 1,
}
purchase_requisition_line()
I didnt get the output.
i didnt get step 1 and step 2. can you please explain?
Its already explained. you need to pass onem2any field in context. for example your one2many field name is line_ids than Than override the name_get method i mean use the code which i have posted to your one2many model. it will work for your sequence.
i tried but its not working. i will try again
you can do that using context: http://learnopenerp.blogspot.com/2018/01/get-parent-form-value-in-one2many-form.html