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

I have the following records:

name

date

amount

Peter

06/05/2019

10.00

Peter

06/05/2019

-5.00

Peter

06/06/2019

20.00

Peter

06/06/2019

10.00

How do i create a model function that returns recordsets that sum the amount fields and group by date.

e.g result :

Peter     06/05/2019 5.00

Peter    06/06/2019 30.00

i have found a read_group() function but how do i get a sum(amount) field in read_group() ? 

Avatar
Discard
Best Answer
groups = self.env['your_model'].read_group([], ['date', 'amount'], ['date'])
for group in groups:
    print('>>>>>>', group['date_count'], group['amount'])

odoo v12 support group by 'month', 'week', 'day' like
groups = self.env['your_model'].read_group([], ['date', 'amount'], ['date:day'])
for group in groups:
    print('>>>>>>', group['date:day'],group['date_count'], group['amount'])

 ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​    ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​     ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​    ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​    ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​     ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​    ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​   ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​  ​   ​    ​   ​     ​   ​    ​   ​      ​   ​    ​   ​     ​   ​    ​   ​


Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
940
1
Jun 24
3561
1
Oct 23
8587
1
Oct 23
97
1
Aug 23
2192