Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5745 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
nov 19
5305
3
set 22
7976
2
ago 20
72
2
ago 20
52
1
lug 25
1038