1

如何解决此错误 Odoo 在单击时会在 TreeView 第二行按钮上引发 MissingError 。第一条记录行有效,但我需要这样,对于树上的每条记录,下面的代码将能够传递上下文并打开适当的视图。请协助

这是按钮上调用的代码

@api.multi
def action_four_weeks_schedule_form(self):
    self.ensure_one()
    res = {}
    ids = self._ids
    cr = self._cr
    uid = self._uid
    context = self._context.copy()
    for id in self.browse(self.ids):
        print  'id  in  ++++ ' , id
        order_obj = self.pool.get('ratecard.multiple').browse(cr,uid,ids)[0]
        ratecard_multiple_id=order_obj.id  #int(order_obj.id)
        # self.copy(cr,uid, id,ids, {},context)
        print  '##############################################'
        print  'ratecard_multiple_id', ratecard_multiple_id
        print  'action_four_weeks_schedule_form ratecard_multiple_id ' , ratecard_multiple_id
        scheduled_for= order_obj.scheduled_for
        code= order_obj.code

        print  'order_obj.multiple_ratecard_id.code' ,[ x.code  for  x in  order_obj.multiple_ratecard_id[0]]

        print  '##################################################################'
        for  lineitems  in  order_obj.multiple_ratecard_id:
            print  'Ratecard Codes of  selected  ' , lineitems.code
            singular_code = [ x.code  for  x in  order_obj.multiple_ratecard_id[0]]
            for  ln  in  lineitems:
                print  '***************************************'
                print  'ratecard singular name' , ln.name
                print  'ratecard singular code' ,  ln.code
                print  '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
                # self.copy(cr,uid,id, ids , {},context)
                scheduled_for= order_obj.scheduled_for
                code= order_obj.code
                singular_code = [ x.code  for  x in  order_obj.multiple_ratecard_id[0]]
                print  '[ x.code  for  x in  order_obj.multiple_ratecard_id[0]]' , singular_code




        # for line in id:
        #     line_obj = self.pool.get('ratecard.multiple').browse(cr,uid,ids)[0]
        #     print  'line_obj contains' , line_obj
        #     print  '***************************************'
        #     print  'INNER  LOOP action_four_weeks_schedule_form   scheduled_for ' , line_obj.scheduled_for
        #     print  ' INNER LOOP action_four_weeks_schedule_form  code ' , line_obj.code
        #     print  'Can  i  get  code  of  selected   line_obj.multiple_ratecard_id.code  ' , line_obj.multiple_ratecard_id.code
        #     print  '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
        #     ratecard_multiple_id=line.id
        #     print  'inner line_obj  action_four_weeks_schedule_form ratecard_multiple_id ' , ratecard_multiple_id

        # scheduled_for= line_obj.scheduled_for
        # code= line_obj.code

    scheduled_for= order_obj.scheduled_for
    code= order_obj.code
    singular_code = [ x.code  for  x in  order_obj.multiple_ratecard_id[0]]


    print  'action_four_weeks_schedule_form   scheduled_for ' , scheduled_for
    print  'action_four_weeks_schedule_form  code ' , code
    print  'singular  ratecard  selected  is  ' , singular_code

    res = {}
    if scheduled_for == 2:
            view_id = self.env.ref('ragtimeorder.view_two_weeks_schedule_form').id
            form_id = self.env.ref('ragtimeorder.view_two_weeks_schedule_form').id
            tree_id = self.env.ref('ragtimeorder.view_two_weeks_schedule_tree').id
            res = {
                'name': _('TWO WEEKS SCHEDULE FOR  RATECARD'),
                'view_type': 'form',
                'view_mode': 'form',
                'views': [(view_id, 'form'), ],
                'res_model': 'two.weeks.schedule',
                #  'res_id':self.id,
                'type': 'ir.actions.act_window',
                'nodestroy': True,
                'target': 'new',
                'domain': '[]',
                'context':{'default_scheduled_for':scheduled_for,'default_code':code , 'default_singular_code':singular_code},
                'flags': {'form': {'action_buttons': True}}

            }
    elif scheduled_for == 3:
        view_id = self.env.ref('ragtimeorder.view_three_weeks_schedule_form').id
        form_id = self.env.ref('ragtimeorder.view_three_weeks_schedule_form').id
        tree_id = self.env.ref('ragtimeorder.view_three_weeks_schedule_tree').id
        res = {
            'name': _('THREE WEEKS SCHEDULE FOR  RATECARD'),
            'view_type': 'form',
            'view_mode': 'form',
            'views': [(view_id, 'form'), ],
            'res_model': 'three.weeks.schedule',
            #  'res_id':self.id,
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'domain': '[]',
            'context': context,
            'flags': {'form': {'action_buttons': True}}

        }
    elif scheduled_for == 4:
        view_id = self.env.ref('ragtimeorder.view_four_weeks_schedule_form').id
        form_id = self.env.ref('ragtimeorder.view_four_weeks_schedule_form').id
        tree_id = self.env.ref('ragtimeorder.view_four_weeks_schedule_tree').id
        res = {
            'name': _('FOUR WEEKS SCHEDULE FOR  RATECARD'),
            'view_type': 'form',
            'view_mode': 'form',
            'views': [(view_id, 'form'), ],
            'res_model': 'four.weeks.schedule',
            #  'res_id':self.id,
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'domain': '[]',
            'context':{'default_scheduled_for':scheduled_for,'default_code':code ,'default_singular_code':singular_code },
            'flags': {'form': {'action_buttons': True}}

        }
    elif scheduled_for == 1:
        view_id = self.env.ref('ragtimeorder.view_one_week_schedule_form').id
        form_id = self.env.ref('ragtimeorder.view_one_week_schedule_form').id
        tree_id = self.env.ref('ragtimeorder.view_one_week_schedule_tree').id
        res = {
            'name': _('ONE WEEK SCHEDULE FOR  RATECARD'),
            'view_type': 'form',
            'view_mode': 'form',
            'views': [(view_id, 'form'), ],
            'res_model': 'one.week.schedule',
            #  'res_id':self.id,
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'domain': '[]',
            'context':{'default_scheduled_for':scheduled_for,'default_code':code , 'default_singular_code':singular_code},
            'flags': {'form': {'action_buttons': True}}

        }
    else:

        view_obj = self.pool.get('ir.ui.view')
        view_id = view_obj.search(cr, uid, [('model', '=', self._name), \
                                            ('name', '=', self._name + '.view')])
        res = {
            'view_mode': 'form',
            'view_type': 'form',
            'view_id': view_id or False,
            'res_model': self._name,
            'context': context,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'flags': {'form': {'action_buttons': True}}


        }

    id.update({
        'radio_scheduled_for': scheduled_for,
        'update_code' : code,
        'singular_code' : singular_code ,
    })
    return res

这是按下按钮引发此错误的错误截图 在此处输入图像描述

4

0 回答 0