跳至內容
選單
此問題已被標幟
1 回覆
3604 瀏覽次數

I'm trying to show report based on user choice, this is code in file .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!')



!. region_id = True, location_id = False, no_zero = False : Correct

2. region_id = False, location_id = True, no_zero = False : Error ('bool' object has no attribute '__getitem__')

3. region_id = False, location_id = True, no_zero = True : Wrong (Show that should be number 2)

4. region_id = True, location_id = True, no_zero = True : Wrong (Show that should be number 3)

5. If I change 'or' with 'and', all report is error (blank).


Hope someone helps me. Thankyou!

頭像
捨棄
作者 最佳答案

I order the True and found the solution with this code:

@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!')

But, I'm not sure can work for all case.


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
2月 17
6
0
3月 25
1925
4
4月 24
175079
0
1月 24
1942
0
1月 24
1681