-
-
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 hbrunn
- Loading branch information
Showing
15 changed files
with
683 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,91 @@ | ||
================= | ||
Base Archive Date | ||
================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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_archive_date | ||
: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_archive_date | ||
: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 module adds an archive timestamp and the user who did the archiving to all models having the `active` field. | ||
|
||
Whenever a record is archived, the latest archived date is timestamped on the record. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
#. Archive a record and the timestamp of the moment that the record has been archived is | ||
saved on the record on the `archive_date` technical field, also the user doing the archiving is saved under the `archive_uid` field. | ||
|
||
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_archive_date%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 | ||
~~~~~~~ | ||
|
||
* ForgeFlow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `ForgeFlow S.L. <https://www.forgeflow.com>`_: | ||
|
||
* Guillem Casassas <[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-GuillemCForgeFlow| image:: https://github.com/GuillemCForgeFlow.png?size=40px | ||
:target: https://github.com/GuillemCForgeFlow | ||
:alt: GuillemCForgeFlow | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-GuillemCForgeFlow| | ||
|
||
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/13.0/base_archive_date>`_ 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,17 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Base Archive Date", | ||
"summary": """ | ||
Adds an archive timestamp and user doing the archiving to all models. | ||
""", | ||
"version": "14.0.1.0.0", | ||
"category": "Usability", | ||
"license": "AGPL-3", | ||
"website": "https://github.com/OCA/server-ux", | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"depends": ["base"], | ||
"maintainers": ["GuillemCForgeFlow"], | ||
"installable": True, | ||
"application": False, | ||
} |
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,19 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_archive_date | ||
# | ||
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_archive_date | ||
#: model:ir.model,name:base_archive_date.model_base | ||
msgid "Base" | ||
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 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 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, fields, models | ||
|
||
LOG_ARCHIVE_DATE = "archive_date" | ||
LOG_ARCHIVE_UID = "archive_uid" | ||
|
||
|
||
class Base(models.AbstractModel): | ||
""" | ||
The base model is inherited by all models. | ||
Whenever a record has the active field, we save the latest date in which the record | ||
has been archived, False otherwise. We also save which user did the archiving. | ||
""" | ||
|
||
_inherit = "base" | ||
|
||
@api.model | ||
def _get_now_date(self): | ||
""" | ||
:return: datetime.datetime: actual time formated in the way Odoo saves dates | ||
for base fields, such as write_date or create_date | ||
""" | ||
now = fields.Datetime.context_timestamp(self, fields.Datetime.now()) | ||
return now.replace(tzinfo=None) | ||
|
||
@api.model | ||
def _add_magic_fields(self): | ||
result = super(Base, self)._add_magic_fields() | ||
if self._log_access and "active" in self._fields: | ||
self._add_field( | ||
LOG_ARCHIVE_DATE, | ||
fields.Datetime( | ||
string="Last Archived on", automatic=True, readonly=True | ||
), | ||
) | ||
self._add_field( | ||
LOG_ARCHIVE_UID, | ||
fields.Many2one( | ||
comodel_name="res.users", | ||
string="Last Archived by", | ||
automatic=True, | ||
readonly=True, | ||
), | ||
) | ||
return result | ||
|
||
@api.model_create_multi | ||
@api.returns("self", lambda value: value.id) | ||
def create(self, vals_list): | ||
if self._log_access: | ||
for vals in vals_list: | ||
if "active" in vals: | ||
archive_date = ( | ||
False if vals.get("active", False) else self._get_now_date() | ||
) | ||
archive_uid = self.env.user.id if archive_date else False | ||
vals.update( | ||
{LOG_ARCHIVE_DATE: archive_date, LOG_ARCHIVE_UID: archive_uid} | ||
) | ||
return super(Base, self).create(vals_list) | ||
|
||
def write(self, vals): | ||
if ( | ||
self._log_access | ||
and LOG_ARCHIVE_DATE not in vals | ||
and "active" in vals | ||
and not vals.get("active", True) | ||
): | ||
now = self._get_now_date() | ||
user_id = self.env.user.id | ||
vals.update({LOG_ARCHIVE_DATE: now, LOG_ARCHIVE_UID: user_id}) | ||
return super(Base, self).write(vals) |
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,3 @@ | ||
* `ForgeFlow S.L. <https://www.forgeflow.com>`_: | ||
|
||
* Guillem Casassas <[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,3 @@ | ||
This module adds an archive timestamp and the user who did the archiving to all models having the `active` field. | ||
|
||
Whenever a record is archived, the latest archived date is timestamped 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,2 @@ | ||
#. Archive a record and the timestamp of the moment that the record has been archived is | ||
saved on the record on the `archive_date` technical field, also the user doing the archiving is saved under the `archive_uid` field. |
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.