Hi,
I wish to enhance the product price list report by adding additional product fields to it.
My code to override _get_product_data is as follows but it doesn't seem to be called.
#-*- coding: utf-8 -*-
from odoo import models, fields, api
class x_pricelist(models.AbstractModel):
_inherit= 'report.product.report_pricelist'
def _get_product_data(self, is_product_tmpl, product, pricelist, quantities):
data = {
'id': product.id,
'name': is_product_tmpl and product.name or product.display_name,
'price': dict.fromkeys(quantities, 0.0),
'x_pricelist': product.x_pricelist,
'x_pricelist_desc': product.x_price_list_description,
'short_name': "sss"
}
for qty in quantities:
data['price'][qty] = pricelist.get_product_price(product, qty, False)
return data
super(report_product_pricelist,self)._get_product_data(is_product_tmpl, product, pricelist, quantities)
Any assistance would be appreciated.
To understand what I am trying to achieve, here is the view where the function is used.
<?xml version="1.0"?>
<t t-name="product.report_pricelist_page">
<div class="container bg-white p-4 my-4">
<div class="row my-3">
<div class="col-12">
<h2 t-if="is_html_type">
Pricelist:
<a href="#" class="o_action" data-model="product.pricelist" t-att-data-res-id="pricelist.id">
<t t-esc="pricelist.display_name"/>
</a>
</h2>
<h2 t-else="">
Pricelist: <t t-esc="pricelist.display_name"/>
</h2>
</div>
</div>
<div class="row">
<div class="col-12">
<table class="table table-sm">
<thead>
<tr>
<th>Products</th>
<t t-foreach="quantities" t-as="qty">
<th class="text-right"><t t-esc="qty"/> Units</th>
</t>
</tr>
</thead>
<tbody>
<t t-foreach="products" t-as="product">
<tr>
<td t-att-class="is_product_tmpl and 'font-weight-bold' or None">
<a t-if="is_html_type" href="#" class="o_action" t-att-data-model="is_product_tmpl and 'product.template' or 'product.product'" t-att-data-res-id="product['id']">
<t t-esc="product['name']"/>
</a>
<t t-else="">
<t t-esc="product['name']"/>
</t>
</td>
<t t-foreach="quantities" t-as="qty">
<td class="text-right">
<t t-esc="product['price'][qty]" t-options="{"widget": "monetary", "display_currency": pricelist.currency_id}"/>
</td>
</t>
</tr>
<t t-if="is_product_tmpl">
<tr t-foreach="product['variants']" t-as="variant">
<t t-set="xprice" t-value="variant['x_pricelist']"/>
<t t-if="xprice">
<td>
<a t-if="is_html_type" href="#" class="o_action ml-4" data-model="product.product" t-att-data-res-id="variant['id']">
<t t-esc="variant['short_name']"/>
</a>
<span t-else="" class="ml-4" t-esc="variant['id']"/>
</td>
<t t-foreach="quantities" t-as="qty">
<td class="text-right">
<t t-esc="variant['price'][qty]" t-options="{"widget": "monetary", "display_currency": pricelist.currency_id}"/>
</td>
</t>
</t>
</tr>
</t>
</t>
</tbody>
</table>
</div>
</div>
</div>
</t>