Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] base: read_group date part number granularity #159528

Conversation

VincentSchippefilt
Copy link
Contributor
@VincentSchippefilt VincentSchippefilt commented Mar 27, 2024

When doing reporting, especially in spreadsheet, it is usefull to be able
to group dates by different granularities.
Today, Odoo supports Year, Quarter, Month, Week and Day. Those granularities are
"absolute" in the sence that b.e. Quarter will return "Q1 2021"

In this commit, I introduce new granularities.
These granularities will span different years and collect the all dates with specific month, quarter or week:
"month_number", will return the month of the year of all dates: a number between 1 and 12;
"quarter_number", will return the quarter of the year: a number between 1 and 4;
"week_number", will return the week of the year, according to ISO 8601: a number between 1 and 53

Usage:
In read_group or _read_group, the group_by and order by can now be ['date_field:month_number'].
In a domain, you can write [('date_field.month_number','=',2)].
Note that read_group will return a __domain containing the correct relative granularity.

Example:

self.env["my_model"].create(({"value": "1", "date": "2021-02-09"},
		             {"value": "2", "date": "2021-06-01"},
                	     {"value": "3", "date": "2022-02-01"}))
self.env["my_model"].read_group([],fields=['date', 'value'],groupby=['date:month_number'])
-->
[
    {
        'date:month_number': 2.0,
        'date_count': 2,
        'value': 4,
        '__domain': [('date.month_number', '=', 2.0)]
    }, {
        'date:month_number': 6.0,
        'date_count': 1,
        'value': 2,
        '__domain': [('date.month_number', '=', 6.0)]
    }
])

documentation PR: odoo/documentation#8447
Task: 3836802


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor
robodoo commented Mar 27, 2024

Pull request status dashboard.

@C3POdoo C3POdoo added the RD research & development, internal work label Mar 27, 2024
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch 3 times, most recently from 2de9fd5 to d0804a5 Compare March 28, 2024 14:12
@VincentSchippefilt VincentSchippefilt changed the title Master real granularity read group vsc [IMP] base: read_group relative granularity Mar 28, 2024
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch from d0804a5 to f592a58 Compare March 28, 2024 14:18
Copy link
Contributor
@ryv-odoo ryv-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @VincentSchippefilt
It looks very promising, I already left some comments.

odoo/models.py Outdated Show resolved Hide resolved
odoo/osv/expression.py Outdated Show resolved Hide resolved
odoo/addons/test_read_group/tests/test_date_range.py Outdated Show resolved Hide resolved
odoo/addons/test_read_group/tests/test_date_range.py Outdated Show resolved Hide resolved
odoo/addons/test_read_group/tests/test_empty.py Outdated Show resolved Hide resolved
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch 2 times, most recently from 340b80a to 6a28ede Compare March 29, 2024 13:57
@VincentSchippefilt VincentSchippefilt marked this pull request as ready for review March 29, 2024 13:57
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch from 6a28ede to 128ab4b Compare March 29, 2024 14:01
@C3POdoo C3POdoo requested review from a team, rco-odoo and sleepy-monax and removed request for a team March 29, 2024 14:03
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch from 128ab4b to f01cb3e Compare March 29, 2024 15:28
@VincentSchippefilt
Copy link
Contributor Author

Hello @odoo/rd-security, I wouldn't mind a good review as I add a "new" SQL operation, using date_part.

Copy link
Collaborator
@xmo-odoo xmo-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a naming perspective I'm not sure about "relative", my first thought reading the PR title was that it was going to be a sliding window (increments relative to now).

SQL seems fine.

odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/osv/expression.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Outdated Show resolved Hide resolved
odoo/models.py Show resolved Hide resolved
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch 3 times, most recently from ba1f330 to 917f40d Compare April 3, 2024 13:24
@VincentSchippefilt
Copy link
Contributor Author

robodoo r+

@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch from fdd1169 to 5cc028d Compare April 25, 2024 12:06
When doing reporting, especially in spreadsheet, it is usefull to be able
to group dates by different granularities.
Today, Odoo supports Year, Quarter, Month, Week and Day. Those granularities are
"absolute" in the sence that b.e. Quarter will return "Q1 2021"

In this commit, I introduce new granularities.
These granularities will span different years and collect the all dates with specific month, quarter or week:
"month_number", will return  the month of the year of all dates: a number between 1 and 12;
"quarter_number", will return the quarter of the year: a number between 1 and 4;
"iso_week_number", will return the week of the year, according to ISO 8601: a number between 1 and 53,
etc.

Usage:
In read_group or _read_group, the group_by and order by can now be ['date_field:month_number'].
In a domain, you can write [('date_field.month_number','=',2)].
Note that read_group will return a __domain containing the correct relative granularity.

Example:
self.env["my_model"].create(({"value": "1", "date": "2021-02-09"},
		             {"value": "2", "date": "2021-06-01"},
                	     {"value": "3", "date": "2022-02-01"}))
self.env["my_model"].read_group([],fields=['date', 'value'],groupby=['date:month_number'])
-->
[
    {
        'date:month_number': 2.0,
        'date_count': 2,
        'value': 4,
        '__domain': [('date.month_number', '=', 2.0)]
    }, {
        'date:month_number': 6.0,
        'date_count': 1,
        'value': 2,
        '__domain': [('date.month_number', '=', 6.0)]
    }
])

Task: 3836802
@VincentSchippefilt VincentSchippefilt force-pushed the master-real_granularity_read_group-vsc branch from 5cc028d to d8fe54d Compare April 25, 2024 12:39
@VincentSchippefilt
Copy link
Contributor Author

robodoo r+

robodoo pushed a commit that referenced this pull request Apr 25, 2024
when asking for a non-existent field in read_group,
the error message was referring to the groupby field instead of the selection field

Task: 3836802
Part-of: #159528
robodoo pushed a commit that referenced this pull request Apr 25, 2024
fix a bunch of typos

Task: 3836802
Part-of: #159528
robodoo pushed a commit that referenced this pull request Apr 25, 2024
When doing reporting, especially in spreadsheet, it is usefull to be able
to group dates by different granularities.
Today, Odoo supports Year, Quarter, Month, Week and Day. Those granularities are
"absolute" in the sence that b.e. Quarter will return "Q1 2021"

In this commit, I introduce new granularities.
These granularities will span different years and collect the all dates with specific month, quarter or week:
"month_number", will return  the month of the year of all dates: a number between 1 and 12;
"quarter_number", will return the quarter of the year: a number between 1 and 4;
"iso_week_number", will return the week of the year, according to ISO 8601: a number between 1 and 53,
etc.

Usage:
In read_group or _read_group, the group_by and order by can now be ['date_field:month_number'].
In a domain, you can write [('date_field.month_number','=',2)].
Note that read_group will return a __domain containing the correct relative granularity.

Example:
self.env["my_model"].create(({"value": "1", "date": "2021-02-09"},
		             {"value": "2", "date": "2021-06-01"},
                	     {"value": "3", "date": "2022-02-01"}))
self.env["my_model"].read_group([],fields=['date', 'value'],groupby=['date:month_number'])
-->
[
    {
        'date:month_number': 2.0,
        'date_count': 2,
        'value': 4,
        '__domain': [('date.month_number', '=', 2.0)]
    }, {
        'date:month_number': 6.0,
        'date_count': 1,
        'value': 2,
        '__domain': [('date.month_number', '=', 6.0)]
    }
])

closes #159528

Task: 3836802
Related: odoo/documentation#8447
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
robodoo pushed a commit to odoo/documentation that referenced this pull request Apr 25, 2024
references odoo/odoo#159528

closes #8447

Task: 3836802
Related: odoo/odoo#159528
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
@robodoo robodoo added the 17.3 label Apr 25, 2024
@robodoo robodoo closed this Apr 25, 2024
@fw-bot fw-bot deleted the master-real_granularity_read_group-vsc branch May 9, 2024 18:46
pro-odoo added a commit to odoo-dev/odoo that referenced this pull request Jul 8, 2024
This commit adds the support for the new granularities added in odoo#159528.

Task: 3899604
pro-odoo added a commit to odoo-dev/odoo that referenced this pull request Jul 8, 2024
This commit adds the support for the new granularities added in odoo#159528.

Task: 3899604
robodoo pushed a commit that referenced this pull request Jul 8, 2024
This commit adds the support for the new granularities added in #159528.

Task: 3899604
Part-of: #172202
Related: odoo/enterprise#66209
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
17.3 RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants