Python 每条线的Odoo 10报告表
下面是python代码:Python 每条线的Odoo 10报告表,python,xml,foreach,html-table,odoo-10,Python,Xml,Foreach,Html Table,Odoo 10,下面是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 =
@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;"/>
呈现编译AST时出错
AttributeError:“str”对象没有属性“\u字段”
模板:hr_module.sosyal_sigorta_报告文件
路径:/templates/t/t/div/div/div/div[11]/table/tbody/tr/td[1]/span
节点:
我将如何使用t-foreach?我正在尝试创建表列和表行。这部分将填充行,但我无法完成。通过t-esc改变t-field和t.sira通过t\u值改变
<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>
这是我的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>
编辑:我解决了这样的问题
<span t-esc="t['sira']" style=" font-size:13px;" />
感谢您的回复。感谢您的回复,但我如何获取数组项employee_data={'sira':str(count),'sigortano':str(employee.socialsecurityno)}例如,我想要“sira”和“sigortano”嗨,t是dict的键,t_值是值。例如:{'sira':1,'sigortano':'test'}t=1和t_value=test但我仍然不能做我想做的,它在1列上显示所有dict。我不能把“sira”列改为“sira”列,“sigortano”列改为“SIGORTA”列。这将在'sira'列中显示{'sira':1,'sigortano':'test'}。如果可以,您可以向我显示您的代码XML。我在上一个注释示例中遇到了一个错误:{'sira':1,'sigortano':'test'}t等于sira和t_值eq 1Please,这段python代码应该在这里。在模型文件夹或报告中?
<span t-esc="t['sira']" style=" font-size:13px;" />