Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions date_range/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Date Range
|badge1| |badge2| |badge3| |badge4| |badge5|

This module lets you define global date ranges that can be used to
filter your values in tree views.
filter your values in list views.

It also provides a mixin model for developers that extends the model's
search view so that date ranges can be search as any relational field.
Expand Down Expand Up @@ -79,50 +79,49 @@ Usage

To configure this module, you need to:

- Go to Settings > Technical > Date ranges > Date Range Types where you
can create types of date ranges.
- Go to Settings > Technical > Date ranges > Date Range Types where you
can create types of date ranges.

|image1|
|image1|

- Go to Settings > Technical > Date ranges > Date Ranges where you can
create date ranges.
- Go to Settings > Technical > Date ranges > Date Ranges where you can
create date ranges.

|image2|
|image2|

It's also possible to launch a wizard from the 'Generate Date Ranges'
menu.
It's also possible to launch a wizard from the 'Generate Date Ranges'
menu.

|image3|
|image3|

The wizard is useful to generate recurring periods. Set an end date
or enter the number of ranges to create.
The wizard is useful to generate recurring periods. Set an end date or
enter the number of ranges to create.

|image4|
|image4|

- Your date ranges are now available in the search filter for any date
or datetime fields
- Your date ranges are now available in the search filter for any date
or datetime fields

Date range types are proposed as a filter operator
Date range types are proposed as a filter operator

|image5|
|image5|

Once a type is selected, date ranges of this type are porposed as a
filter value
Once a type is selected, date ranges of this type are porposed as a
filter value

|image6|
|image6|

And the dates specified into the date range are used to filter your
result.
And the dates specified into the date range are used to filter your
result.

|image7|
|image7|

- You can configure date range types with default values for the
generation wizard on the Generation tab. In the same tab you can also
configure date range types for auto-generation. New ranges for types
configured for this are generated by a scheduled task that runs
daily.
- You can configure date range types with default values for the
generation wizard on the Generation tab. In the same tab you can also
configure date range types for auto-generation. New ranges for types
configured for this are generated by a scheduled task that runs daily.

|image8|
|image8|

.. |image1| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_create.png
.. |image2| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_create.png
Expand Down Expand Up @@ -154,14 +153,16 @@ Authors
Contributors
------------

- Laurent Mignon <[email protected]>
- Alexis de Lattre <[email protected]>
- Miquel Raïch <[email protected]>
- Andrea Stirpe <[email protected]>
- Stefan Rijnhart <[email protected]>
- David Ramia <<@ramiadavid>>
- Son Ho <[email protected]>
- Bert Van Groenendael <[email protected]>
- Laurent Mignon <[email protected]>
- Alexis de Lattre <[email protected]>
- Miquel Raïch <[email protected]>
- Andrea Stirpe <[email protected]>
- Stefan Rijnhart <[email protected]>
- David Ramia <<@ramiadavid>>
- Son Ho <[email protected]>
- Bert Van Groenendael <[email protected]>
- Andrii Kompaniiets <[email protected]>
- Rafael Blasco <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion date_range/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Date Range",
"summary": "Manage all kind of date range",
"version": "18.0.1.0.0",
"version": "18.0.2.0.0",
"category": "Uncategorized",
"website": "https://github.com/OCA/server-ux",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
Expand Down
18 changes: 18 additions & 0 deletions date_range/migrations/18.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.delete_sql_constraint_safely(
env, "date_range", "date_range", "date_range_uniq"
)
openupgrade.m2o_to_x2m(
env.cr, env["date.range"], "date_range", "company_ids", "company_id"
)
env.cr.execute(
"UPDATE ir_rule SET domain_force = %s WHERE name = %s",
(
"['|',('company_ids', 'in', company_ids),('company_ids','=',False)]",
"Date Range multi-company",
),
)
37 changes: 21 additions & 16 deletions date_range/models/date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError


class DateRange(models.Model):
Expand All @@ -26,10 +26,9 @@ def _default_company(self):
ondelete="restrict",
check_company=True,
)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
index=True,
company_ids = fields.Many2many(
"res.company",
string="Companies",
default=_default_company,
)
active = fields.Boolean(
Expand All @@ -40,14 +39,6 @@ def _default_company(self):
store=True,
)

_sql_constraints = [
(
"date_range_uniq",
"unique (name,type_id, company_id)",
"A date range must be unique per company !",
)
]

@api.depends("type_id.active")
def _compute_active(self):
for date in self:
Expand All @@ -56,7 +47,7 @@ def _compute_active(self):
else:
date.active = False

@api.constrains("type_id", "date_start", "date_end", "company_id")
@api.constrains("type_id", "date_start", "date_end", "company_ids")
def _validate_range(self):
for this in self:
if this.date_start > this.date_end:
Expand All @@ -73,6 +64,18 @@ def _validate_range(self):
)
if this.type_id.allow_overlap:
continue
if bool(
this.type_id.company_id
and this.type_id.company_id not in this.company_ids
):
raise UserError(
self.env._(
"The Date Range Type %(drt_name)s assigned to other "
"company, you can't change the company in "
"Date Range %(dt_name)s"
)
% {"drt_name": this.type_id.name, "dt_name": this.name}
)
# here we use a plain SQL query to benefit of the daterange
# function available in PostgresSQL
# (http://www.postgresql.org/docs/current/static/rangetypes.html)
Expand All @@ -81,20 +84,22 @@ def _validate_range(self):
id
FROM
date_range dt
INNER JOIN date_range_res_company_rel as rc
ON dt.id = rc.date_range_id
WHERE
DATERANGE(dt.date_start, dt.date_end, '[]') &&
DATERANGE(%s::date, %s::date, '[]')
AND dt.id != %s
AND dt.active
AND dt.company_id = %s
AND rc.res_company_id IN %s
AND dt.type_id=%s;"""
self.env.cr.execute(
SQL,
(
this.date_start,
this.date_end,
this.id,
this.company_id.id or None,
tuple(this.company_ids.ids) or (None,),
this.type_id.id,
),
)
Expand Down
4 changes: 2 additions & 2 deletions date_range/models/date_range_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def _check_company_id(self):
continue
if bool(
rec.date_range_ids.filtered(
lambda r, drt=rec: r.company_id
and r.company_id != drt.company_id
lambda r, drt=rec: r.company_ids
and drt.company_id not in r.company_ids
)
):
raise ValidationError(
Expand Down
2 changes: 2 additions & 0 deletions date_range/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- David Ramia \<<@ramiadavid>\>
- Son Ho \<<[email protected]>\>
- Bert Van Groenendael \<<[email protected]>\>
- Andrii Kompaniiets \<<[email protected]>\>
- Rafael Blasco \<<[email protected]>\>
2 changes: 1 addition & 1 deletion date_range/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This module lets you define global date ranges that can be used to
filter your values in tree views.
filter your values in list views.

It also provides a mixin model for developers that extends the model's
search view so that date ranges can be search as any relational field.
2 changes: 1 addition & 1 deletion date_range/security/date_range_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="name">Date Range multi-company</field>
<field name="model_id" ref="model_date_range" />
<field name="domain_force">
['|',('company_id', 'in', company_ids),('company_id','=',False)]
['|',('company_ids', 'in', company_ids),('company_ids','=',False)]
</field>
</record>
</odoo>
11 changes: 6 additions & 5 deletions date_range/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ <h1 class="title">Date Range</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-ux/tree/18.0/date_range"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-18-0/server-ux-18-0-date_range"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-ux&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module lets you define global date ranges that can be used to
filter your values in tree views.</p>
filter your values in list views.</p>
<p>It also provides a mixin model for developers that extends the model’s
search view so that date ranges can be search as any relational field.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -429,8 +429,8 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<p>It’s also possible to launch a wizard from the ‘Generate Date Ranges’
menu.</p>
<p><img alt="image3" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard.png" /></p>
<p>The wizard is useful to generate recurring periods. Set an end date
or enter the number of ranges to create.</p>
<p>The wizard is useful to generate recurring periods. Set an end date or
enter the number of ranges to create.</p>
<p><img alt="image4" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard_result.png" /></p>
</li>
<li><p class="first">Your date ranges are now available in the search filter for any date
Expand All @@ -447,8 +447,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<li><p class="first">You can configure date range types with default values for the
generation wizard on the Generation tab. In the same tab you can also
configure date range types for auto-generation. New ranges for types
configured for this are generated by a scheduled task that runs
daily.</p>
configured for this are generated by a scheduled task that runs daily.</p>
<p><img alt="image8" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_autogeneration.png" /></p>
</li>
</ul>
Expand Down Expand Up @@ -480,6 +479,8 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>David Ramia &lt;&lt;&#64;ramiadavid&gt;&gt;</li>
<li>Son Ho &lt;<a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a>&gt;</li>
<li>Bert Van Groenendael &lt;<a class="reference external" href="mailto:bert.vangroenendael&#64;dynapps.eu">bert.vangroenendael&#64;dynapps.eu</a>&gt;</li>
<li>Andrii Kompaniiets &lt;<a class="reference external" href="mailto:andrii&#64;moduon.team">andrii&#64;moduon.team</a>&gt;</li>
<li>Rafael Blasco &lt;<a class="reference external" href="mailto:rblasco&#64;moduon.team">rblasco&#64;moduon.team</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
11 changes: 6 additions & 5 deletions date_range/tests/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import datetime

from odoo import Command
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase

Expand Down Expand Up @@ -36,18 +37,18 @@ def test_default_company(self):
"type_id": self.type.id,
}
)
self.assertTrue(dr.company_id)
self.assertTrue(dr.company_ids)
# you can specify company_id to False
dr = self.date_range.create(
{
"name": "FS2016_NO_COMPANY",
"date_start": "2015-01-01",
"date_end": "2016-12-31",
"type_id": self.type.id,
"company_id": False,
"company_ids": False,
}
)
self.assertFalse(dr.company_id)
self.assertFalse(dr.company_ids)

def test_empty_company(self):
dr = self.date_range.create(
Expand All @@ -56,7 +57,7 @@ def test_empty_company(self):
"date_start": "2015-01-01",
"date_end": "2016-12-31",
"type_id": self.type.id,
"company_id": None,
"company_ids": None,
}
)
self.assertEqual(dr.name, "FS2016")
Expand Down Expand Up @@ -135,6 +136,6 @@ def test_date_range_multicompany_1(self):
"date_start": "2015-01-01",
"date_end": "2016-12-31",
"type_id": self.typeB.id,
"company_id": self.company_2.id,
"company_ids": [Command.set(self.company_2.ids)],
}
)
6 changes: 3 additions & 3 deletions date_range/tests/test_date_range_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dateutil.rrule import MONTHLY, YEARLY
from psycopg2 import IntegrityError

from odoo import fields
from odoo import Command, fields
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
Expand Down Expand Up @@ -55,12 +55,12 @@ def test_type_multicompany(self):
"date_start": "2015-01-01",
"date_end": "2016-12-31",
"type_id": drt.id,
"company_id": self.company.id,
"company_ids": [Command.set(self.company.ids)],
}
)
drt.company_id = self.company.id
with self.assertRaises(UserError):
dr.company_id = self.company_2
dr.company_ids = self.company_2.ids

def test_autogeneration(self):
"""Ranges are autogenerated for types configured for that"""
Expand Down
Loading