Chart in qweb pdf report - odoo 14 - odoo

Is there a way to print a bar chart within a qweb report?
I'm trying to use the t-raw property, but this doesn't seem to run javascript (I'm trying to embed Char.js)
This is what I did, but it just prints it, it doesn't run the javascript before rendering the report:
<div id="prueba">
Este texto no ha sido remplazado
</div>
<t t-set="meses"/>
<t t-raw="datos">
document.getElementById('prueba').innerHTML = '<h1>Remplazado!</h1>';
</t>
How can I achieve this?

Is there a way to print a bar chart within a qweb report?
I guess there are multiple ways.
Unfortunately, I can't understand your code example or why it is related to printing charts in qweb reports. But let me answer that question since most people are going to land here because they want to do exactly that.
Like you, I was trying to realize it by using Chart.js and Odoo's built in chart rendering. While this is probably possible, I gave up early because it might be very complicated to get Odoo to render the chart into an image inside qweb.
The easiest solution is probably to send the chart data to a chart creating API such as quickchart. You find all the information in their doucmentation.
Here an example how to have a chart on the invoice that shows the customer's monthly revenue for the current year split up in months:
Inside the qweb view add an img tag with a t-att-src attribute
<img style="width: 100%;" t-att-src="doc.chart_img()"/>
The t-att-src attribute here calls the chart_img() method on account.move model which returns an url and looks like following:
def chart_img():
partner = self.partner_id.id
orders_this_year = self.env['sale.order'].read_group(
['&', '&',
('partner_id', '=', partner),
('date_order', '>=', datetime(datetime.today().year, 1, 1)),
('date_order', '<=', datetime(datetime.today().year, 12, 31))],
['amount_untaxed'],
['date_order:month']
)
months = [order['date_order:month'] for order in orders_this_year]
rev_values = [order['amount_untaxed'] for order in orders_this_year]
data = {
'type': 'bar',
'data': {
'labels': months,
'datasets': [
{
'label': datetime.today().year,
'data': rev_values
},
]
},
}
return f"https://quickchart.io/chart?c={json.dumps(data)}"
It first gets all orders of the partner in the current year grouped by month by calling read_group() method. Then the data is converted into a query string for quickchart. The retrieved chart shows directly as an image in your qweb report. Note that by setting up the data using python and styling the chart using quickchart features you can likely create any chart that Odoo creates on the frontend using chart.js.

Related

In Opencart 3 under PHP 8 how do I call module to show in another page

I have seen on this site the post re calling a module on needed page. I have tried to use this code to solve a problem. This code does not appear to work for me.
What I have is a module that places a label over each product depending on its status. It works well on products throughout site. However I have a module which calls all products on to one page. I want the label to appear on the products on this all products page.
Banner on product
The code I used in catalog/controller for the all product extension from previous post here was (382 is the label module number):
$this->load->model('382');
$my_variable = $this->model_setting_module->getModule('382');
$data['any_variable'] = $my_variable['any_variable'];
On Template page:
{{ any_variable }}
How can I get the module to be apply the label to the custom all products page?
As always help appreciated
Create new module with name: "my_module" and you can call it in your "another_module" controller file:
$data['my_module'] = $this->load->controller('extension/module/my_module');
and in corresponding "another_module" template file you can retrieve it:
{{ my_module }}

Odoo access ir.config_paramter in report

I want to access and print a config parameter in a report.
I have tried this
<div t-if="ir.config_paramter">
<span t-field="ir.config_paramter.mymodule.myhtmlfield"/>
</div>
But I get an error saying it does not know 'ir'
The report I am trying to edit is account.report_invoice_document
What do I need to do to correctly print the field on the report?
You can pass the value of your ir_config_parameter via data argument in get_report function, or include it via a computed field in your report related method.
For example:
ir_parameter_value = fields.Char(compute="_compute_ir_parameter_value")
def _compute_ir_parameter_value(self):
for record in self:
record.ir_parameter_value = self.env['ir.config_parameter'].get_parameter("parameter_key")
config_paramter
is it a typo?
have do you include dependencies in manifest.py?

How to center td tags in odoo QWeb

How i can center a value in table , the table contain a column that contain the same value in each raw, i need to print only one value in all the raw and not print the value for each raw.
I try to customize print rapport in odoo sale module.
Vertical alignment is a pain in the butt in html, it is not very odoo related, take a look at this answer. If you could do what you want in HTML, then style the odoo form respectfully. But beware, changing default rendering of forms is not a good idea at all!

Keen IO Chart Labels

I'm trying to figure out how to adjust the labels on an Area Chart visualization of my Keen IO data. I've looked through the available configuration options, but I'm not seeing what option would do this. Currently my chart just lists "null" on the legend on the right side of the chart, and on the hover tooltips when you hover over a particular peak. Just looking to switch it to list "Hits" instead of "null."
Does anyone know how/where I would configure those labels?
You can use labelMappingfor that. Something like:
client.draw(funnel, document.getElementById("chart"), {
library: "google",
chartType: "columnchart",
labelMapping: {
null: "Hits"
}
});

Dojo datagrid with date and time

Could someone here please, for the love of God!, post an example of an working dojox.grid.DataGrid using a dojox.data.JsonRestStore, with 2 columns, date and time?
I have tried the following :
<th field="startdate" cellType="dojox.grid.cells._Widget" widgetClass="dijit.form.DateTextBox" editable="true" formatter="formatDate"></code></pre> and
<th field="starttime" cellType="dojox.grid.cells._Widget" widgetClass="dijit.form.TimeTextBox" editable="true" formatter="formatDate">
Also :
<th field="startdate" cellType="dojox.grid.cells.DateTextBox" editable="true" formatter="formatDate"></code></pre> and
<th field="starttime" cellType="dojox.grid.cells._Widget" widgetClass="dijit.form.TimeTextBox" editable="true" formatter="formatDate">
but nothing seems to work. It's been two days now and I've been reading tons of documentation and reports but I couldn't find a working example anywhere.
EDIT :
I am now facing the weirdest issue in my programmer's career : the grid is now working fine with DateTextBox and TimeTextBox (this case works in Firefox 3.6.6 and in 3.6.14pre, Internet Explorer 8 and Google Chrome.), except for the following :
In Firefox 3.6.13, with an even number of items in the grid, when I try editing the time or date of one element the widget box appears in the top left corner, the date isn't selected properly and the browser crashes with the CPU going to 100%.
However, if the number of items is odd the editing of date and time works just fine. I have absolutely no idea of what to do so please bounce some ideas.
you can keep the values in the grid to be date type but with your customized format....the grid will take care of sorting.....no need to write customized sorting for some simple field like Date....
......
var yourLayout = [[
{ 'name': 'Date', 'field': 'dateCol', 'width': '15%', 'formatter': this.formatDate}
]];
..............
formatDate: function(dateValue) {
return dojoLocale.format(dateValue, { selector: 'date', formatLength: 'long' });
}
......
There is an example of what you are trying to do in the dojo test suite. It's not actually using the JsonRestStore but that doesn't matter.
http://archive.dojotoolkit.org/nightly/checkout/dojox/grid/tests/test_edit_dijit.html
The best dojo documentation around are the tests.
If it helps, Oliver has added some examples of how to format dates in a grid, with and without editable dijit widgets. This still needs to be incorporated into the main documentation.