html - 如何在odoo报告上添加静态字段而不循环?

标签 html css report odoo qweb

enter image description here我需要为每个员工打印一份时间表报告,并且需要在标题处而不是列单元格上显示员工姓名,因为它将在每一行中重复,而我不需要这样做

我尝试使用 < t-foreach > 但它显示的名称过多

 <template id="19011.employee">
     <t t-call="web.html_container">
         <t t-call="web.external_layout">
             <div class="page">
                 <div class="text-center">
                     <h2> <strong>TIME SHEET</strong>
                     </h2>
                     <h2>
                         <tr t-foreach="docs" t-as="o">
                             <span t-field="o.employee_id" />
                         </tr>
                     </h2>
                 </div>
                 <table class="table table-condensed" bgcolor="#875A7B">
                     <tr>
                         <th> check in</th>
                         <th> check out</th>
                         <th> Total</th>
                     </tr>
                     <tr t-foreach="docs" t-as="o">
                         <td>
                             <t t-esc="o.check_in" />
                         </td>
                         <td>
                             <t t-esc="o.check_out" />
                         </td>
                         <td>
                             <t t-esc="o.total" />
                         </td>
                     </tr>
                     <tr bgcolor="#875A7B">
                         <td align="center"> <strong> Total Hours</strong></td>
                         <td></td>
                         <td>
                             <strong t-esc="sum([o.total for o in docs])" />
                         </td>
                     </tr>
                 </table>
             </div>
         </t>
     </t>
 </template>

最佳答案

好吧,让我们尝试一个简单的解决方案,如果所有考勤表都是针对一名员工的,您可以通过访问第一条记录来显示其姓名。

        <div class="text-center">
             <h2> <strong>TIME SHEET</strong>
             </h2>
             <h2>
                   <t t-if="docs">
                     <!-- in case employee don't have any attending records you dont want to get index error -->
                     <span t-field="docs[0].employee_id" />
                   </t>
             </h2>
         </div>

如果考勤表有不止一名员工,则需要比这更多的工作,并且也有多种解决方案。

我不知道通过index访问第一条记录是否会导致t-field出现问题(如果它确实尝试设置)一个变量

            <t t-set="first_record" t-value="docs[0]"/>
            <span t-field="first_record.employee_id" />

关于html - 如何在odoo报告上添加静态字段而不循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510570/

相关文章:

java - 如何在 Apache OFBiz 中调用 java 类方法返回 excel 文件?

html - 将固定的 css 问题转换为流动的 css 问题

html - 更改打印的 CSS 边距

javascript - 修复 IE 的 div 宽度 @media 修复

javascript - 使用 jQuery 启动和停止 css3 动画

javascript - 如何使用 javascript 从 textarea 中删除我的数据?

php - HTML5 和神秘的字符集

javascript - 无法获取 jquery 中单选按钮的值 : 'Syntax error, unrecognized expression'

c# - 免费报表设计器(生成器),如 Crystal Report、Fast Report 等

odoo - 如何在 odoo 10 中添加“起始日期”到“截止日期”以打印报告中的一组记录?