python - 使用python动态创建和更新odoo qweb报告中的表行和列
问题描述
我将上面的这张表作为我的 qweb 报告的最终输出。该表应该是动态生成的。
您需要什么样的数据结构来表示这些数据,以便当前为零的表格单元格的值等于拆分变量后的值。
我想要这样,如果你有一个变量m-x = 20
,表格单元格在col m
,row x
将等于20
等等。如果没有这样的组合,则表格单元格等于 0。
请让我知道这是否有意义以及可能的任何澄清。谢谢!
这就是我现在正在做的事情。不确定我的方向是否正确。正在从制造模型打印报告。尽管产品在库存中移动,但我会搜索其来源或参考与制造订单名称匹配的所有移动。
然后我取 lot_id 的名称,加入字典中的键并检查它们是否匹配,然后更新值。
size = {
'u/s': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0}
'w': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0}
'bhl': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0}
}
for output in self.env['stock.move.line'].search(['|', ('origin', '=', docs.name), ('reference', '=', docs.name)]):
lot_id = output.lot_id.name
for i in size:
for j in size[i]:
if (j+'-'+i) == lot_id:
i[j] = output.qty_done
解决方案
我通过使用字典来完成这项工作。
Python代码:
size = {
'u/s': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'w': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'bhl': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'bhp': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'rhl': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'rhp': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'yhl': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'yhp': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
'stains': {'mp/sup': 0, 'tr': 0, 'd2':0,'v':0,'v1':0,'d/rej':0},
}
for output in self.env['stock.move.line'].search(['|', ('origin', '=', docs.name), ('reference', '=', docs.name)]):
lot_id = output.lot_id.name
if lot_id:
for i in size:
for j in size[i]:
if (f"{j}-{i}") == lot_id.lower():
size[i][j] = output.qty_done
xml代码:
<thead>
<tr>
<th>SIZE</th>
<th>MP/SUP</th>
<th>TR</th>
<th>D2</th>
<th>V</th>
<th>V1</th>
<th>D/REJ</th>
<th>TOTAL</th>
<th>PERCENTAGE (%)</th>
</tr>
</thead>
<tbody>
<t t-foreach="size" t-as="i">
<tr>
<th>
<t t-esc="i.upper()" />
</th>
<t t-foreach="size[i]" t-as="j">
<td>
<t t-esc="size[i][j]" />
</td>
</t>
</tr>
</t>
</tbody>
附言。Pandas 似乎是一种快速完成工作的方法。
推荐阅读
- android - 如果获取的字符串数据为空,如何在位置 0 设置微调器
- mysql - 使用sequelize插入mysql中的两个依赖表
- python - 在函数中处理 Python 错误的最佳方法
- paypal - Paypal 拒绝付款激活请求
- linux-kernel - 为什么 ov5640_mipi_v3 模块中的子设备为 NULL?
- string - 突出显示所有匹配词 TypeScript
- angular - 我不能使用 chrome 与角度扩展进行通信
- javascript - 数据表js默认日期格式
- python - Python - 计算二叉树的分支和
- zapier - 如何在 Zapier 集成中的应用程序中使用/读取来自应用程序的示例输出数据到 webhook?