【问题标题】:Odoo 10 report table foreach lineOdoo 10 报表每行
【发布时间】:2023-04-03 06:17:01
【问题描述】:

这里是python代码:

@api.depends('employee_id')
    def create_employee_report(self):
        count = 0
        employee_data = {}
        for employee in self.env['hr.employee'].search([]):
            if employee.socialsecurityno:
                count = count + 1
                employee_data ={'sira':str(count),'sigortano':str(employee.socialsecurityno)}
        return employee_data

和 view.xml

    <tbody>
    <tr t-foreach="o.create_employee_report()" t-as="t">
      <td class="td-lrbotborder">
        <span t-field="t.sira" style=" font-size:13px;" />
      </td>
    <tr>

这里是错误信息:

Error to render compiling AST
AttributeError: 'str' object has no attribute '_fields'
Template: hr_module.sosyal_sigorta_report_document
Path: /templates/t/t/div/div/div/div[11]/table/tbody/tr/td[1]/span
Node: <span t-field="t.sira" style=" font-size:13px;"/>

我将如何使用 t-foreach?我正在尝试创建表格列和行。这部分会填满线条,但我做不到。

【问题讨论】:

    标签: python xml foreach html-table odoo-10


    【解决方案1】:

    将 t-field 更改为 t-esc 和 t.sira 更改为 t_value 示例:

     <tr t-foreach="o.create_employee_report()" t-as="t">
      <td class="td-lrbotborder">
          <span t-esc="t_value" style=" font-size:13px;" />
      </td>
    </tr>
    

    【讨论】:

    • 感谢您的回复,但我将如何获取数组项 employee_data ={'sira':str(count),'sigortano':str(employee.socialsecurityno)} 例如我想要“sira”和“西戈塔诺”
    • hi , t 是您的 dict 的键, t_value 是值。例:{'sira':1,'sigortano':'test'} t = 1 and t_value= test
    • 但我仍然无法做我想做的事,它在 1 列上显示所有 dict。我无法将 'sira' 设为 'SIRA' 列,将 'sigortano' 设为 'SIGORTA' 列。这会在 'SIRA' 列中显示 {'sira':1,'sigortano':'test'}。
    • 如果可以的话,您可以向我展示您的代码 XML。我在上一个评论示例中有一个错误: {'sira':1,'sigortano':'test'} t is equal a sira and t_value eq 1
    【解决方案2】:

    这是我的xml;

    <table class="table table-condensed" style="width: 100%; border-collapse: collapse;">
            <thead>
                <tr>
                    <th class="td-allborder" style="width:30px; font-size:11px;">Sıra</th>
                    <th class="td-topbotborder" style="width:75px; font-size:10px;">Sigortalı No.</th>
                </tr>
            </thead>
            <tbody>
                <tr t-foreach="o.create_employee_report()" t-as="t">
                    <td class="td-lrbotborder">
                        <span t-esc="t_value" style=" font-size:13px;" />
                    </td>
                    <td class="td-botborder">
                        <span t-esc="t_value" style=" font-size:13px;" />
                </tr>
            </tbody>
        </table>
    

    这里是python文件;

    @api.depends('employee_id')
        def create_employee_report(self):
            count = 0
            employee_list = []
            employee_data = {}
            for employee in self.env['hr.employee'].search([]):
                if employee.socialsecurityno:
                    employee_data ={'sira':str(count),
                                    'sigortano':str(employee.socialsecurityno),
                                    'kimlikno':str(employee.personelno),
                                    'isim':employee.name}
                    count = count + 1
                    employee_list.append(employee_data)
            print employee_list
            return employee_list
    

    编辑:我解决了这样的问题;

    <span t-esc="t['sira']" style=" font-size:13px;" />
    

    感谢您的回复。

    【讨论】:

    • 拜托,这段python代码应该在哪里。在模型文件夹或报告中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多