[IMP] product: improve for the pricelist report

PURPOSE
------
In the new pricelist report, showing the resulting price of a product in the
situation of a pricelist or another, for certain quantities, the specified
quantities are shown as "X Units".

This can be misleading when using multiple Unit of Measure, because
the quantites are expressed in the products unit of measures, thus
not always in "Units".

We should probably either group the products by UoM, to display
adequates column titles, or we should update the display to make sure the user
understands clearly that the prices are /unit in the product uom.

users should be able to 'hide' pricelist name on the PDF.

TaskID-2360597
This commit is contained in:
Shweta Goltar
2021-08-23 09:31:54 +00:00
committed by Yannick Tivisse
parent cfd5837a24
commit 1ad72def2a
5 changed files with 43 additions and 7 deletions
@@ -9,22 +9,24 @@ class report_product_pricelist(models.AbstractModel):
_description = 'Pricelist Report'
def _get_report_values(self, docids, data):
is_visible_title = data['is_visible_title'] and bool(data['is_visible_title']) or False
product_ids = [int(i) for i in data['active_ids'].split(',')]
pricelist_id = data['pricelist_id'] and int(data['pricelist_id']) or None
quantities = [int(i) for i in data['quantities'].split(',')] or [1]
return self._get_report_data(data['active_model'], product_ids, pricelist_id, quantities, 'pdf')
return self._get_report_data(data['active_model'], product_ids, is_visible_title, pricelist_id, quantities, 'pdf')
@api.model
def get_html(self):
render_values = self._get_report_data(
self.env.context.get('active_model'),
self.env.context.get('active_ids'),
self.env.context.get('is_visible_title'),
self.env.context.get('pricelist_id'),
self.env.context.get('quantities') or [1]
)
return self.env.ref('product.report_pricelist_page')._render(render_values)
def _get_report_data(self, active_model, active_ids, pricelist_id, quantities, report_type='html'):
def _get_report_data(self, active_model, active_ids, is_visible_title, pricelist_id, quantities, report_type='html'):
products = []
is_product_tmpl = active_model == 'product.template'
@@ -55,6 +57,7 @@ class report_product_pricelist(models.AbstractModel):
'quantities': quantities,
'is_product_tmpl': is_product_tmpl,
'is_html_type': report_type == 'html',
'is_visible_title': is_visible_title,
}
def _get_product_data(self, is_product_tmpl, product, pricelist, quantities):
@@ -62,6 +65,7 @@ class report_product_pricelist(models.AbstractModel):
'id': product.id,
'name': is_product_tmpl and product.name or product.display_name,
'price': dict.fromkeys(quantities, 0.0),
'uom': product.uom_id.name,
}
for qty in quantities:
data['price'][qty] = pricelist.get_product_price(product, qty, False)
@@ -4,7 +4,7 @@
<template id="report_pricelist_page">
<div class="container bg-white p-4 my-4">
<div class="row my-3">
<div class="col-12">
<div class="col-12" t-if="is_visible_title">
<h2 t-if="is_html_type">
Pricelist:
<a href="#" class="o_action" data-model="product.pricelist" t-att-data-res-id="pricelist.id">
@@ -16,14 +16,20 @@
</h2>
</div>
</div>
<div class="row">
<div t-att-class="'text-center' + (' offset-8' if is_html_type else ' offset-7')">
<strong>Sales Order Line Quantities (price per unit)</strong>
</div>
</div>
<div class="row">
<div class="col-12">
<table class="table table-sm">
<thead>
<tr>
<th>Products</th>
<th groups="uom.group_uom">UoM</th>
<t t-foreach="quantities" t-as="qty">
<th class="text-right"><t t-esc="qty"/> Units</th>
<th class="text-right"><t t-esc="qty"/></th>
</t>
</tr>
</thead>
@@ -38,6 +44,9 @@
<t t-esc="product['name']"/>
</t>
</td>
<td groups="uom.group_uom">
<t t-esc="product['uom']"/>
</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}'/>
@@ -52,6 +61,9 @@
</a>
<span t-else="" class="ml-4" t-esc="variant['name']"/>
</td>
<td groups="uom.group_uom">
<t t-esc="product['uom']"/>
</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}'/>
@@ -147,6 +147,8 @@ var GeneratePriceList = AbstractAction.extend(StandaloneFieldManagerMixin, {
*/
start: function () {
this.controlPanelProps.cp_content = this._renderComponent();
const $content = this.controlPanelProps.cp_content;
$content["$searchview"][0].querySelector('.o_is_visible_title').addEventListener('click', this._onClickVisibleTitle.bind(this));
return this._super.apply(this, arguments).then(() => {
this.$('.o_content').html(this.reportHtml);
});
@@ -218,6 +220,17 @@ var GeneratePriceList = AbstractAction.extend(StandaloneFieldManagerMixin, {
// Handlers
//--------------------------------------------------------------------------
/**
* Checkbox is checked, the report title will show.
*
* @private
* @param {Event} ev
*/
_onClickVisibleTitle(ev) {
this.context.is_visible_title = ev.currentTarget.checked;
this._reload();
},
/**
* Open form view of particular record when link clicked.
*
@@ -240,9 +253,10 @@ var GeneratePriceList = AbstractAction.extend(StandaloneFieldManagerMixin, {
* @private
*/
_onClickPrint: function () {
const reportName = _.str.sprintf('product.report_pricelist?active_model=%s&active_ids=%s&pricelist_id=%s&quantities=%s',
const reportName = _.str.sprintf('product.report_pricelist?active_model=%s&active_ids=%s&is_visible_title=%s&pricelist_id=%s&quantities=%s',
this.context.active_model,
this.context.active_ids,
this.context.is_visible_title || '',
this.context.pricelist_id || '',
this.context.quantities.toString() || '1',
);
@@ -29,13 +29,19 @@
</div>
</div>
<div class="form-group">
<label class="font-weight-bold" for="qty_to_add">Quantities:</label>
<label class="font-weight-bold mb-4" for="qty_to_add">Quantities:</label>
<div class="row">
<div class="col">
<span class="o_product_qty"/>
</div>
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input o_is_visible_title ml-2" type="checkbox"/>
<label class="form-check-label">Display Pricelist</label>
</div>
</div>
</form>
</t>
@@ -150,7 +150,7 @@
</record>
<record id="action_product_template_price_list_report" model="ir.actions.server">
<field name="name">Generate Pricelist</field>
<field name="name">Generate Pricelist Report</field>
<field name="groups_id" eval="[(4, ref('product.group_product_pricelist'))]"/>
<field name="model_id" ref="product.model_product_template"/>
<field name="binding_model_id" ref="product.model_product_template"/>