'布尔'对象没有属性' __ getitem __'在Odoo 8

时间:2017-11-06 06:18:01

标签: python python-2.7 odoo odoo-8 qweb

我试图根据用户选择显示报告,这是文件.py中的代码:

@api.multi
def render_html(self,data=None,context=None):

    if data['region_id']==True or data['location_id']==False or data['no_zero']==False:
        report=self.env['report']
        document=self._get_report_s_r(data)
        docss=self._get_report_s_r_detail(data)
        ctx=self._context.copy()
        object=self.env['report.wizard'].browse([ctx['active_id']])
        data={'o':object,'docs':document,'docss':docss}
        return report.render('report.report_s', data)

    elif data['region_id']==False or data['location_id']==True or data['no_zero']==False:
        report=self.env['report']
        document=self._get_report_s_false(data)
        docss=self._get_report_s_false_detail(data)
        ctx=self._context.copy()
        object=self.env['report.wizard'].browse([ctx['active_id']])
        data={'o':object,'docs':document,'docss':docss}
        return report.render('report.pos_report_sales', data)

    elif data['region_id']==False or data['location_id']==True or data['no_zero']==True:
        report=self.env['report']
        document=self._get_report_s(data)
        docss=self._get_report_s_detail(data)
        ctx=self._context.copy()
        object=self.env['report.wizard'].browse([ctx['active_id']])
        data={'o':object,'docs':document,'docss':docss}
        return report.render('report.pos_report_s', data)

    else:
        _logger.error('Required document not set in Report!')
  1. region_id = True,location_id = False,no_zero = False:正确
  2. region_id = False,location_id = True,no_zero = False:错误(' bool'对象没有属性' getitem ')
  3. region_id = False,location_id = True,no_zero = True:错误(显示应为2)
  4. region_id = True,location_id = True,no_zero = True:错误(显示应为3)
  5. 如果我改变了或者#39;使用'和',所有报告都是错误(空白)。
  6. 希望有人帮助我。三江源!

1 个答案:

答案 0 :(得分:0)

我命令True并使用此代码找到解决方案:

@api.multi
def render_html(self,data=None,context=None):

if data['region_id']==True or (data['location_id']==False and data['no_zero']==False):
    report=self.env['report']
    document=self._get_report_s_r(data)
    docss=self._get_report_s_r_detail(data)
    ctx=self._context.copy()
    object=self.env['report.wizard'].browse([ctx['active_id']])
    data={'o':object,'docs':document,'docss':docss}
    return report.render('report.report_s', data)

elif data['location_id']==True or (data['region_id']==False and data['no_zero']==False):
    report=self.env['report']
    document=self._get_report_s_false(data)
    docss=self._get_report_s_false_detail(data)
    ctx=self._context.copy()
    object=self.env['report.wizard'].browse([ctx['active_id']])
    data={'o':object,'docs':document,'docss':docss}
    return report.render('report.pos_report_sales', data)

elif (data['location_id']==True and data['no_zero']==True) or data['region_id']==False:
    report=self.env['report']
    document=self._get_report_s(data)
    docss=self._get_report_s_detail(data)
    ctx=self._context.copy()
    object=self.env['report.wizard'].browse([ctx['active_id']])
    data={'o':object,'docs':document,'docss':docss}
    return report.render('report.pos_report_s', data)

else:
    _logger.error('Required document not set in Report!')

但是,我不确定是否可以适用于所有情况。