Odoo Help


Openerpv7: Numbering in Purchase Requisition OrderLine? But python code is not working properly.

on 10/31/14, 8:31 AM 669 views

class purchase_requisition_line(osv.osv):
      _inherit = 'purchase.requisition.line'
      def _default_sequence(self, cr, uid, ids, context=None):
            if not context:
            context = {}
            max_sequence = 0
            print "order_id",context.get('requisition_id')
            if context.get('requisition_id'):
               order_line = self.search(cr, uid, [('requisition_id', '=', context['requisition_id'])])
              if order_line:
                 max_sequence = max([line['serial_no'] for line in self.read(cr, uid, order_line, ['serial_no'])])
            return max_sequence + 1

            'serial_no':fields.integer('Serial No'),

      _defaults = {
             'serial_no': _default_sequence


But i doesnt get the context.get('requisition_id') value. so function always return value 1.


I refer the above link. In that link, it also contains another code. But no output. I changed field name corresponding purchase_requisition_line.

Did i want to again add below field line_ids again in my custom module?


<field name="line_ids" 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

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/31/14, 8:31 AM
Seen: 669 times
Last updated: 3/16/15, 8:10 AM