Skip to content

Commit

Permalink
[18.0][MIG] date_range: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BertVGroenendael committed Oct 24, 2024
1 parent a399fe7 commit 3e9ec2f
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 181 deletions.
19 changes: 10 additions & 9 deletions date_range/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ model:

_date_range_search_field = "invoice_date"

.. |search_view| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_many2one_search_field.png
.. |search_view| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_many2one_search_field.png

Usage
=====
Expand Down Expand Up @@ -124,14 +124,14 @@ To configure this module, you need to:

|image8|

.. |image1| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_create.png
.. |image2| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_create.png
.. |image3| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_wizard.png
.. |image4| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_wizard_result.png
.. |image5| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_as_filter.png
.. |image6| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter.png
.. |image7| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter_result.png
.. |image8| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_autogeneration.png
.. |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
.. |image3| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard.png
.. |image4| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard_result.png
.. |image5| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_as_filter.png
.. |image6| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter.png
.. |image7| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter_result.png
.. |image8| image:: https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_autogeneration.png

Bug Tracker
===========
Expand Down Expand Up @@ -161,6 +161,7 @@ Contributors
- Stefan Rijnhart <[email protected]>
- David Ramia <<@ramiadavid>>
- Son Ho <[email protected]>
- Bert Van Groenendael <[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": "17.0.1.2.1",
"version": "18.0.1.0.0",
"category": "Uncategorized",
"website": "https://github.com/OCA/server-ux",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
Expand Down
2 changes: 0 additions & 2 deletions date_range/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<field name="name">Auto-generate date ranges</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="active">True</field>
<field name="doall" eval="False" />
<field name="model_id" ref="model_date_range_type" />
<field name="state">code</field>
<field name="code">model.autogenerate_ranges()</field>
Expand Down
9 changes: 6 additions & 3 deletions date_range/models/date_range.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

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


Expand Down Expand Up @@ -59,7 +59,10 @@ def _validate_range(self):
for this in self:
if this.date_start > this.date_end:
raise ValidationError(
_("%(name)s is not a valid range (%(date_start)s > %(date_end)s)")
self.env._(
"%(name)s is not a valid range "
"(%(date_start)s > %(date_end)s)"
)
% {
"name": this.name,
"date_start": this.date_start,
Expand Down Expand Up @@ -97,7 +100,7 @@ def _validate_range(self):
if res:
dt = self.browse(res[0][0])
raise ValidationError(
_("%(thisname)s overlaps %(dtname)s")
self.env._("%(thisname)s overlaps %(dtname)s")
% {"thisname": this.name, "dtname": dt.name}
)

Expand Down
10 changes: 6 additions & 4 deletions date_range/models/date_range_search_mixin.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 lxml import etree

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.osv.expression import FALSE_DOMAIN, NEGATIVE_TERM_OPERATORS, TRUE_DOMAIN


Expand Down Expand Up @@ -75,7 +75,7 @@ def get_view(self, view_id=None, view_type="form", **options):
"field",
attrib={
"name": "date_range_search_id",
"string": _("Period"),
"string": self.env._("Period"),
},
)
groups = root.xpath("/search/group")
Expand All @@ -97,6 +97,8 @@ def get_views(self, views, options=None):
fields list (while still showing up in the Export widget)
"""
result = super().get_views(views, options=options)
if "date_range_search_id" in result["models"][self._name]:
result["models"][self._name]["date_range_search_id"]["string"] = _("Period")
if "date_range_search_id" in result["models"][self._name]["fields"]:
result["models"][self._name]["fields"]["date_range_search_id"]["string"] = (
self.env._("Period")
)
return result
6 changes: 3 additions & 3 deletions date_range/models/date_range_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dateutil.relativedelta import relativedelta
from dateutil.rrule import DAILY, MONTHLY, WEEKLY, YEARLY

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


Expand Down Expand Up @@ -89,7 +89,7 @@ def _check_company_id(self):
)
):
raise ValidationError(
_(
self.env._(
"You cannot change the company, as this "
"Date Range Type is assigned to Date Range '%s'."
)
Expand Down Expand Up @@ -145,6 +145,6 @@ def autogenerate_ranges(self):
wizard.action_apply(batch=True)
except Exception as e:
logger.warning(
"Error autogenerating ranges for date range type "
f"Error autogenerating ranges for date range type "
f"{dr_type.name}: {e}"
)
6 changes: 3 additions & 3 deletions date_range/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ functionality to developers.
To configure a model to use the Many2one style search field, make the
model inherit from \`date.range.search.mixin\`:

```
```
class AccountMove(models.Model):
_name = "account.move"
_inherit = ["account.move", "date.range.search.mixin"]
```

This will make a Period field show up in the search view:

> ![search_view](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_many2one_search_field.png)
> ![search_view](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_many2one_search_field.png)
By default, the mixin works on the date field. If you want the mixin to
work on a field with a different name, you can set a property on your
model:

```
```
_date_range_search_field = "invoice_date"
```
1 change: 1 addition & 0 deletions date_range/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Stefan Rijnhart \<<[email protected]>\>
- David Ramia \<<@ramiadavid>\>
- Son Ho \<<[email protected]>\>
- Bert Van Groenendael \<<[email protected]>\>
16 changes: 8 additions & 8 deletions date_range/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ To configure this module, you need to:
- Go to Settings \> Technical \> Date ranges \> Date Range Types where
you can create types of date ranges.

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_create.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_create.png)

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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_create.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_create.png)

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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_wizard.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard.png)

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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_wizard_result.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_wizard_result.png)

- 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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_as_filter.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_as_filter.png)

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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter.png)

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

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter_result.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter_result.png)

- 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.

![](https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_autogeneration.png)
![](https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_autogeneration.png)
19 changes: 10 additions & 9 deletions date_range/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
</pre>
<p>This will make a Period field show up in the search view:</p>
<blockquote>
<img alt="search_view" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_many2one_search_field.png" /></blockquote>
<img alt="search_view" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_many2one_search_field.png" /></blockquote>
<p>By default, the mixin works on the date field. If you want the mixin to
work on a field with a different name, you can set a property on your
model:</p>
Expand All @@ -421,35 +421,35 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<ul>
<li><p class="first">Go to Settings &gt; Technical &gt; Date ranges &gt; Date Range Types where you
can create types of date ranges.</p>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_create.png" /></p>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_create.png" /></p>
</li>
<li><p class="first">Go to Settings &gt; Technical &gt; Date ranges &gt; Date Ranges where you can
create date ranges.</p>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_create.png" /></p>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_create.png" /></p>
<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-tools/17.0/date_range/static/description/date_range_wizard.png" /></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><img alt="image4" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_wizard_result.png" /></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
or datetime fields</p>
<p>Date range types are proposed as a filter operator</p>
<p><img alt="image5" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_as_filter.png" /></p>
<p><img alt="image5" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_type_as_filter.png" /></p>
<p>Once a type is selected, date ranges of this type are porposed as a
filter value</p>
<p><img alt="image6" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter.png" /></p>
<p><img alt="image6" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter.png" /></p>
<p>And the dates specified into the date range are used to filter your
result.</p>
<p><img alt="image7" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_as_filter_result.png" /></p>
<p><img alt="image7" src="https://raw.githubusercontent.com/OCA/server-ux/18.0/date_range/static/description/date_range_as_filter_result.png" /></p>
</li>
<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>
<p><img alt="image8" src="https://raw.githubusercontent.com/OCA/server-tools/17.0/date_range/static/description/date_range_type_autogeneration.png" /></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>
</div>
Expand Down Expand Up @@ -479,6 +479,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Stefan Rijnhart &lt;<a class="reference external" href="mailto:stefan&#64;opener.amsterdam">stefan&#64;opener.amsterdam</a>&gt;</li>
<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>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
2 changes: 1 addition & 1 deletion date_range/static/src/js/condition_tree.esm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @odoo-module **/
/* global document */
import {
condition,
connector,
Expand Down
21 changes: 8 additions & 13 deletions date_range/static/src/js/domain_selector.esm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @odoo-module **/
import {domainFromTreeDateRange, treeFromDomainDateRange} from "./condition_tree.esm";
import {onWillStart, useChildSubEnv} from "@odoo/owl";
import {Domain} from "@web/core/domain";
import {DomainSelector} from "@web/core/domain_selector/domain_selector";
import {patch} from "@web/core/utils/patch";
import {treeFromDomain} from "@web/core/tree_editor/condition_tree";
import {useService} from "@web/core/utils/hooks";

const ARCHIVED_DOMAIN = `[("active", "in", [True, False])]`;
Expand Down Expand Up @@ -42,14 +42,17 @@ patch(DomainSelector.prototype, {
this.includeArchived = false;
return;
}

const tree = treeFromDomain(domain);
const getFieldDef = await this.makeGetFieldDef(p.resModel, tree, ["active"]);

this.tree = treeFromDomainDateRange(domain, {
getFieldDef: this.getFieldDef.bind(this),
getFieldDef: getFieldDef,
distributeNot: !p.isDebugMode,
});
},
getOperatorEditorInfo(node) {
const info = super.getOperatorEditorInfo(node);
const fieldDef = this.getFieldDef(node.path);
getOperatorEditorInfo(fieldDef) {
const info = super.getOperatorEditorInfo(fieldDef);
const dateRanges = this.dateRanges;
const dateRangeTypes = this.dateRangeTypes.filter((dt) => dt.date_ranges_exist);
patch(info, {
Expand Down Expand Up @@ -91,14 +94,6 @@ patch(DomainSelector.prototype, {

return props;
},
isSupported([operator]) {
if (node.operator.includes("daterange")) {
return (
typeof operator === "string" && operator.includes("daterange")
);
}
return super.isSupported.apply(this, arguments);
},
});
return info;
},
Expand Down
Loading

0 comments on commit 3e9ec2f

Please sign in to comment.