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 22, 2024
1 parent a399fe7 commit 75dfad8
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 177 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
3 changes: 1 addition & 2 deletions date_range/models/date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def _default_company(self):
comodel_name="res.company", string="Company", index=1, default=_default_company
)
active = fields.Boolean(
help="The active field allows you to hide the date range without "
"removing it.",
help="The active field allows you to hide the date range without " "removing it.",
compute="_compute_active",
readonly=False,
store=True,
Expand Down
6 changes: 4 additions & 2 deletions date_range/models/date_range_search_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions date_range/models/date_range_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def _default_company(self):
help="If set, date ranges of same type must not overlap.", default=False
)
active = fields.Boolean(
help="The active field allows you to hide the date range type "
"without removing it.",
help="The active field allows you to hide the date range type " "without removing it.",
default=True,
)
company_id = fields.Many2one(
Expand Down Expand Up @@ -84,8 +83,7 @@ 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_id and r.company_id != drt.company_id
)
):
raise ValidationError(
Expand Down Expand Up @@ -145,6 +143,5 @@ def autogenerate_ranges(self):
wizard.action_apply(batch=True)
except Exception as e:
logger.warning(
"Error autogenerating ranges for date range type "
f"{dr_type.name}: {e}"
"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
20 changes: 8 additions & 12 deletions date_range/static/src/js/domain_selector.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 +43,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 +95,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 75dfad8

Please sign in to comment.