[REF] mrp: simplify the bom strucure report

Add `_get_extra_column_count` to extend and clean
extention for mrp_plm and mrp_subcontracting.

See enterprise commit.

task-2486811

Part-of: odoo/odoo#75041
This commit is contained in:
Rémy Voet (ryv)
2021-09-03 10:37:46 +00:00
parent 7d9a9574ce
commit 10c6f4e837
2 changed files with 26 additions and 1 deletions
@@ -62,6 +62,7 @@ class ReportBomStructure(models.AbstractModel):
'bom_id': bom_id,
'currency': self.env.company.currency_id,
'operations': lines,
'extra_column_count': self._get_extra_column_count()
}
return self.env.ref('mrp.report_mrp_operation_line')._render({'data': values})
@@ -99,7 +100,8 @@ class ReportBomStructure(models.AbstractModel):
'bom_uom_name': bom_uom_name,
'bom_qty': bom_quantity,
'is_variant_applied': self.env.user.user_has_groups('product.group_product_variant') and len(bom_product_variants) > 1,
'is_uom_applied': self.env.user.user_has_groups('uom.group_uom')
'is_uom_applied': self.env.user.user_has_groups('uom.group_uom'),
'extra_column_count': self._get_extra_column_count()
}
def _get_bom(self, bom_id=False, product_id=False, line_qty=False, line_id=False, level=False):
@@ -147,6 +149,7 @@ class ReportBomStructure(models.AbstractModel):
lines['bom_cost'] = lines['total'] * lines['cost_share']
lines['byproducts_cost'] = sum(byproduct['bom_cost'] for byproduct in byproducts)
lines['byproducts_total'] = sum(byproduct['product_qty'] for byproduct in byproducts)
lines['extra_column_count'] = self._get_extra_column_count()
return lines
def _get_bom_lines(self, bom, bom_quantity, product, line_id, level):
@@ -326,4 +329,8 @@ class ReportBomStructure(models.AbstractModel):
pdf_lines = get_sub_lines(bom, product_id, qty, False, 1)
data['components'] = []
data['lines'] = pdf_lines
data['extra_column_count'] = self._get_extra_column_count()
return data
def _get_extra_column_count(self):
return 0
@@ -62,6 +62,9 @@
<tfoot>
<tr t-if="data['report_structure'] != 'bom_structure'" class="o_mrp_prod_cost">
<td></td>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td name="td_mrp_bom_f" class="text-right">
<span><t t-if="data['byproducts']" t-esc="data['bom_prod_name']"/></span>
</td>
@@ -77,6 +80,9 @@
<t t-if="data['report_structure'] != 'bom_structure'" t-foreach="data['byproducts']" t-as="byproduct">
<tr class="o_mrp_bom_cost">
<td/>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td name="td_mrp_bom_byproducts_f" class="text-right">
<span><t t-esc="byproduct['product_name']"/></span>
</td>
@@ -150,6 +156,9 @@
<span class="o_mrp_bom_unfoldable fa fa-fw fa-caret-right" t-att-data-function="'get_operations'" role="img" aria-label="Unfold" title="Unfold"/>
Operations
</td>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td/>
<td class="text-right">
<span t-esc="data['operations_time']" t-options='{"widget": "float_time"}'/>
@@ -170,6 +179,9 @@
<span class="o_mrp_bom_unfoldable fa fa-fw fa-caret-right" t-att-data-function="'get_byproducts'" role="img" aria-label="Unfold" title="Unfold"/>
By-Products
</td>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td/>
<td class="text-right">
<span t-esc="data['byproducts_total']"/>
@@ -192,6 +204,9 @@
<span t-att-style="space_td"/>
<a href="#" t-att-data-res-id="op['operation'].id" t-att-data-model="'mrp.routing.workcenter'" class="o_mrp_bom_action"><t t-esc="op['name']"/></a>
</td>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td/>
<td class="text-right">
<span t-esc="op['duration_expected']" t-options='{"widget": "float_time"}'/>
@@ -215,6 +230,9 @@
<span t-att-style="space_td"/>
<a href="#" t-att-data-res-id="byproduct['product_id'].id" t-att-data-model="byproduct['product_id']._name" class="o_mrp_bom_action"><t t-esc="byproduct['product_name']"/></a>
</td>
<t t-foreach="range(data.get('extra_column_count', 0))" t-as="index">
<td/>
</t>
<td/>
<td class="text-right">
<span t-esc="byproduct['product_qty']"/>