Skip to Content
Menu
This question has been flagged
1 Reply
4608 Views

Hello,

I need to automate the task of generating a report of the POS statistics. 

The same as described here: https://www.odoo.com/documentation/user/9.0/point_of_sale/analyze/statistics.html

So I was trying to generate the totals based on some criteria without doing the entire process of getting orders, then getting the order lines, read the products and sum the totals and more... 

I found that the model report.pos.order retrieves the data I need but I needed to group it by some fields. 

Example:

$models = ripcord::client("$url/xmlrpc/2/object");
$report = $models->execute_kw($db, $uid, $password, 'report.pos.order', 'search', array(array()));

But i found that the method read_group allows me to group the report.pos.order by specified fields .

Based on: https://www.odoo.com/documentation/9.0/reference/orm.html

$fields = [];
$groupby = ['product_id','config_id'];
$criteria = [['date', '>=', '2019-11-01 00:00:00']];
$data = $models->execute_kw($db, $uid, $password, 'report.pos.order', 'read_group', array($criteria), array('fields'=>$fields, 'groupby'=>$groupby));

This is better because I can get the final values of the actual report based on criteria and groups. But it only groups by the first field declared (product_id) in this case because the last one on $groupby doesn't make any change.

But in the Pivot view of POS Analysis you can set multiple groups and it will retrieve a full list.

How is this possible through API?


I would appreciate any help!

Thank you!


Technical Details:

- PHP 7.1

- Odoo 9.0c

- Ripcord: https://github.com/DarkaOnLine/Ripcord


 


Avatar
Discard
Best Answer

Hi. You have to set lazy to false

The documentation says, "if true, the results are only grouped by the first groupby and the remaining groupbys are put in the __context key. If false, all the groupbys are done in one call." - This is about the lazy argument

Example code of python is

search = models.execute_kw(db, uid, password, 'modelName', 'read_group', [[['filter1', '=', True], ['filter2', '=', 14052683]], ['fieldsToInclude1', 'fieldsToInclude2', 'fieldsToInclude3'], ['fieldsToGroupBy1', 'fieldsToGroupBy1', 'fieldsToGroupBy1'], [], [], [], False])


The last argument 'False' is the argument for lazy

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 19
4157
3
Sep 22
6322
2
Aug 20
72
2
Aug 20
52
0
Aug 24
106