python - 如何在 qweb 报告中创建显示产品变型组合的表格?
问题描述
我想根据产品的变体在表格中显示我的产品。如果一个产品有两个属性,我希望它显示在一个表中,其中值(具有最少值的属性)作为列标题,其他属性值标题作为行标题。如果产品有一个或没有属性,那么属性值应该是行标题。如果一个产品有两个以上的属性,其余的属性应该形成一个与原始表格相邻的单独表格。
我设法使行标题正常工作,但无法使列标题和每个产品变体的价格正常工作。这是我的代码:
<?xml version="1.0"?>
<t t-name="product.report_menu">
<t t-call="web.html_container">
<t t-call="web.internal_layout">
<div class="page" style="height: 28cm; width: 21cm; font-family: Patrick Hand;">
<table style="width: 100%; padding-top: 30px">
<tbody>
<tr>
<td valign="top" style="width: 75%; border: solid 2px orange;padding-left: 20px;padding-right: 20px;">
<div style="min-height: 29.5cm;">
<!-- setting default groupings to nil-->
<t t-set="product_category" t-value="[]" />
<t t-set="attribute_category" t-value="[]" />
<t t-set="name_category" t-value="[]" />
<t t-set="attribute_value_name_category" t-value="[]" />
<t t-set="price" t-value="[]" />
<t t-set="pricf" t-value="[]" />
<!-- setting default groupings to nil-->
<t t-foreach="docs" t-as="mpl">
<!-- setting grouping to the value of the product-->
<t t-set="product_category" t-value="product_category+[mpl.categ_id]" />
</t>
<!-- lines associated for grouping individual products based on category, i.e Cookies and all its variants -->
<t t-foreach="set(product_category)" t-as="category">
<!-- product category name -->
<strong>
<h3 t-esc="category.name" /> </strong>
<!-- setting grouping to the value of the product-->
<t t-foreach="docs" t-as="mpl">
<t t-set="name_category" t-value="name_category+[mpl.name]" />
<t t-set="price" t-value="price+[mpl.lst_price]" />
<t t-foreach="mpl.attribute_value_ids" t-as="attrib_value">
<t t-set="pricf" t-value="pricf+[mpl.lst_price]" />
<t t-set="attribute_category" t-value="attribute_category+[attrib_value.attribute_id]" />
<t t-set="attribute_value_name_category" t-value="attribute_value_name_category+[attrib_value]" />
</t>
<!-- <t t-foreach="mpl.attribute_value_ids" t-as="attrib_value"> -->
</t>
<t t-foreach="set(name_category)" t-as="namecate">
<strong>
<h4 t-esc="namecate" /></strong>
<!-- if the products have attributes such as Size, create a size layout table -->
<table style="width: 50%; margin-bottom: 15px;">
<thead>
<th>Whatever...</th>
<th>att 1</th>
<th>att 2</th>
<th>att 4</th>
</thead>
<tbody>
<!-- setting grouping to the value of the product-->
<t t-foreach="set(attribute_category)" t-as="attric">
<t t-set="attribute_category" t-value="[]" />
<t t-if="not attric.name == 'Size'">
<strong>
<h5 style="color: gray;" t-esc="'Comes in %ss of:' % (attric.name)" />
</strong>
<t t-foreach="set(attribute_value_name_category)" t-as="avnc">
<t t-if="avnc.attribute_id.name == attric.name">
<t t-set="attribute_category" t-value="[]" />
<tr>
<td>
<p t-esc="avnc.name" />
</td>
<t t-foreach="set(price)" t-as="pricee">
<t t-if="not pricee == 0">
<td>
<span t-esc="'%s' % (pricee)" />
</td>
</t>
</t>
</tr>
</t>
</t>
</t>
</t>
</tbody>
</table>
</t>
</t>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
这是产品及其属性的列表: 产品及其属性
这是生成的报告:我目前得到的报告
这是我的目标:我想要做什么
我可以请一些帮助,我不知道如何继续。
谢谢
解决方案
我认为您最好使用自定义报告解析器来创建信息组以将其提供给报告模板,以便仅迭代自定义数据结构以将先前准备的数据打印到所需的表和报告输出中。
这似乎是一个非常复杂的报告,要针对如此多的关系字段构建,这将导致 qweb 级别的如此多的迭代和样板代码。
推荐阅读
- amazon-sqs - 并非所有消息都从 GetStream.io 转发到 SQS
- javascript - 强制 HTML5 画布使用软件渲染
- typescript - 财产的打字员
- c# - 尝试将模拟数据库“播种”到模拟 dbContext 时出错
- reactjs - 为什么在 Rebass Box 组件上使用 prop.children 会在 Chrome 中输出 console.error?
- java - 如何在 Java 中实现检查构建器模式
- optimization - 为什么梯度 descnet 不后退以避免振荡
- c++ - 为什么允许 C++ 引用构造函数中的临时变量?
- shacl - 如何验证 rdf:engine.validateNodesAgainstShape 中的类型
- mysql - 如何使用 Node/Express JS 在 MySQL 表中插入动态信息