-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
16 changed files
with
1,090 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
=============== | ||
Base Recurrence | ||
=============== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github | ||
:target: https://github.com/OCA/server-ux/tree/13.0/base_recurrence | ||
:alt: OCA/server-ux | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/server-ux-13-0/server-ux-13-0-base_recurrence | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/250/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This is a technical module that helps managing recurrence on Odoo models. | ||
|
||
It allows to define a recurring rule on a record and two helper methods: | ||
* One to get the recurring next date | ||
* One to set the recurring next date on the record | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
|
||
Supported intervals | ||
~~~~~~~~~~~~~~~~~~~ | ||
|
||
* Day | ||
* Month | ||
* End of Next Month | ||
* Quarter | ||
* Semester | ||
* Year | ||
|
||
|
||
|
||
Example | ||
~~~~~~~ | ||
|
||
.. code-block:: python | ||
from odoo import fields, models | ||
class RecurrenceModel(models.Model): | ||
_name = "recurrence.model" | ||
_inherit = ["recurrence.mixin"] | ||
_description = "A model that implements recurrence" | ||
_field_last_recurrency_date = "last_recurrency_date" | ||
_field_next_recurrency_date = "next_recurrency_date" | ||
last_recurrency_date = fields.Datetime() | ||
next_recurrency_date = fields.Datetime() | ||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20base_recurrence%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* ACSONE SA/NV | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Denis Roussel <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px | ||
:target: https://github.com/rousseldenis | ||
:alt: rousseldenis | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-rousseldenis| | ||
|
||
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/13.0/base_recurrence>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2021 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Base Recurrence", | ||
"summary": """ | ||
Allows to define base methods for recurrence computation""", | ||
"version": "15.0.1.0.0", | ||
"license": "AGPL-3", | ||
"maintainers": ["rousseldenis"], | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/server-ux", | ||
"depends": ["base"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_recurrence | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 13.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__daily | ||
msgid "Daily" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields,field_description:base_recurrence.field_recurrence_mixin__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields,field_description:base_recurrence.field_recurrence_mixin__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields,field_description:base_recurrence.field_recurrence_mixin____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__monthly | ||
msgid "Monthly" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__monthlylastday | ||
msgid "Monthly Last Day" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__quarterly | ||
msgid "Quarterly" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model,name:base_recurrence.model_recurrence_mixin | ||
msgid "Recurrence Mixin" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields,field_description:base_recurrence.field_recurrence_mixin__recurrence_type | ||
msgid "Recurrence Type" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__semesterly | ||
msgid "Semesterly" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__weekly | ||
msgid "Weekly" | ||
msgstr "" | ||
|
||
#. module: base_recurrence | ||
#: model:ir.model.fields.selection,name:base_recurrence.selection__recurrence_mixin__recurrence_type__yearly | ||
msgid "Yearly" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import recurrence_mixin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Copyright 2021 ACSONE SA/NV | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class RecurrenceMixin(models.AbstractModel): | ||
|
||
_name = "recurrence.mixin" | ||
_description = "Recurrence Mixin" | ||
_field_last_recurrency_date = None | ||
_field_next_recurrency_date = None | ||
|
||
# Scheduling | ||
recurrence_type = fields.Selection( | ||
[ | ||
("daily", "Daily"), | ||
("weekly", "Weekly"), | ||
("monthly", "Monthly"), | ||
("monthlylastday", "Monthly Last Day"), | ||
("quarterly", "Quarterly"), | ||
("semesterly", "Semesterly"), | ||
("yearly", "Yearly"), | ||
] | ||
) | ||
|
||
@api.model | ||
def get_relative_delta(self, recurring_rule_type, interval=1): | ||
"""Return a relativedelta for one period. | ||
When added to the first day of the period, | ||
it gives the first day of the next period. | ||
""" | ||
recurring_func = "_recurring_rule_type_" + recurring_rule_type | ||
if hasattr(self, recurring_func): | ||
return getattr(self, recurring_func)(interval=interval) | ||
else: | ||
raise NotImplementedError() | ||
|
||
# HELPER FUNCTIONS # | ||
@api.model | ||
def _recurring_rule_type_daily(self, interval): | ||
return relativedelta(days=interval) | ||
|
||
@api.model | ||
def _recurring_rule_type_weekly(self, interval): | ||
return relativedelta(weeks=interval) | ||
|
||
@api.model | ||
def _recurring_rule_type_monthly(self, interval): | ||
return relativedelta(months=interval) | ||
|
||
@api.model | ||
def _recurring_rule_type_monthlylastday(self, interval): | ||
return relativedelta(months=interval, day=31) | ||
|
||
@api.model | ||
def _recurring_rule_type_quarterly(self, interval): | ||
return relativedelta(months=3 * interval, day=1) | ||
|
||
@api.model | ||
def _recurring_rule_type_semesterly(self, interval): | ||
return relativedelta(months=6 * interval, day=1) | ||
|
||
@api.model | ||
def _recurring_rule_type_yearly(self, interval): | ||
return relativedelta(years=interval) | ||
|
||
def _get_next_recurrency_date(self): | ||
self.ensure_one() | ||
return self[self._field_last_recurrency_date] + self.get_relative_delta( | ||
self.recurrence_type | ||
) | ||
|
||
def _update_recurrency_date(self): | ||
""" | ||
Update the last recurrency date from the next recurrency date, | ||
then compute the new next recurrency date. | ||
""" | ||
for record in self: | ||
record.update( | ||
{ | ||
record._field_last_recurrency_date: record[ | ||
record._field_next_recurrency_date | ||
], | ||
} | ||
) | ||
record.update( | ||
{record._field_next_recurrency_date: record._get_next_recurrency_date()} | ||
) | ||
|
||
def _set_next_recurrency_date(self, from_now=False): | ||
""" | ||
Set the next recurrency date from the last recurrency field value. | ||
This method allows to reset that last recurrency date to now(). | ||
Usually, this is used to initialize the record first values. | ||
:param from_now: [description], defaults to False | ||
:type from_now: bool, optional | ||
""" | ||
if from_now: | ||
self.update({self._field_last_recurrency_date: fields.Datetime.now()}) | ||
for record in self: | ||
record[ | ||
record._field_next_recurrency_date | ||
] = record._get_next_recurrency_date() | ||
record[ | ||
record._field_next_recurrency_date | ||
] = record._get_next_recurrency_date() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Denis Roussel <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This is a technical module that helps managing recurrence on Odoo models. | ||
|
||
It allows to define a recurring rule on a record and two helper methods: | ||
* One to get the recurring next date | ||
* One to set the recurring next date on the record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
Supported intervals | ||
~~~~~~~~~~~~~~~~~~~ | ||
|
||
* Day | ||
* Month | ||
* End of Next Month | ||
* Quarter | ||
* Semester | ||
* Year | ||
|
||
|
||
|
||
Example | ||
~~~~~~~ | ||
|
||
.. code-block:: python | ||
from odoo import fields, models | ||
class RecurrenceModel(models.Model): | ||
_name = "recurrence.model" | ||
_inherit = ["recurrence.mixin"] | ||
_description = "A model that implements recurrence" | ||
_field_last_recurrency_date = "last_recurrency_date" | ||
_field_next_recurrency_date = "next_recurrency_date" | ||
last_recurrency_date = fields.Datetime() | ||
next_recurrency_date = fields.Datetime() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.