Odoo 会计报告返回 IndexError:列表索引超出范围

问题描述

我正在为 odoo Enterprise 开发自定义会计报告。这是我第一次尝试做这种报告,所以我有很多疑问在网上没有解决

基于本地报告,我到目前为止:

class BudgetaryPositionCompanyReport(models.AbstractModel):
    _name = "budgetary.position.report"
    _inherit = "account.report"

    filter_date = {'date_from': '','date_to': '','filter': 'this_month'}
    filter_unfold_all = False

    def _get_columns_name(self,options):
        return [{'name': _('Budget Item')},{'name': _('Column1')},{'name': _('Column2')},{'name': _('%')}]

    @api.model
    def _get_lines(self,options,line_id=None):
        context = dict(self._context or {})
        date_from = context.get('date_from')
        date_to = context.get('date_to')
        lines = []

        sql_parents = """
        SELECT abp.name "name",sum(cbl.planned_amount) planned_amount,sum(cbl.r_practical_amount) r_practical_amount,sum(cbl.r_percentage) r_percentage
        FROM crossovered_budget_lines cbl
        JOIN account_budget_post abp ON (cbl.general_budget_id = abp.id)
        GROUP BY abp.id;
        """
        self.env.cr.execute(sql_parents)
        results_parents = self.env.cr.dictfetchall()

        for parent in results_parents:
            lines.append({
                    'id': parent.get('id'),'name': parent.get('name'),'level': 1,'unfoldable': True,'unfolded': True,'colspan': 4,'columns': [
                        {'name': parent.get('name') and parent.get('name')},{'name': parent.get('planned_amount') and self.format_value(parent.get('planned_amount'))},{'name': parent.get('r_practical_amount') and self.format_value(parent.get('r_practical_amount'))},{'name': parent.get('r_percentage') and self.format_value(parent.get('r_percentage'))}
                    ],})
        print(lines)
        return lines

    def _get_report_name(self):
        return _('Budgetary Positions (per company)')

    def _get_templates(self):
        templates = super(BudgetaryPositionCompanyReport,self)._get_templates()
        return templates

问题是当我尝试访问此报告时,我收到以下信息:

Error to render compiling AST
IndexError: list index out of range
Template: account_reports.line_template
Path: /templates/t/t/tr/t[2]/td
Node: <td t-att-class="'o_account_report_line ' + (column.get('class',lines.get('columns_header')[-1][column_index+line.get('colspan',1)].get('class','')) + (line.get('unfoldable') and ' o_foldable_total' or '')) + ('' if hierarchies_enabled else ' o_account_report_line_indent')" t-att-style="column.get('style',1)].get('style',''))">
                    <span class="o_account_report_column_value" t-att-title="column.get('title')">
                        <t t-esc="column.get('name')"/>
                    </span>
                </td>

我错过了什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)