diff --git a/base_archive_date/README.rst b/base_archive_date/README.rst new file mode 100644 index 0000000000..090b750afa --- /dev/null +++ b/base_archive_date/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow S.L. `_: + + * Guillem Casassas + +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 `__: + +|maintainer-GuillemCForgeFlow| + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_archive_date/__init__.py b/base_archive_date/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/base_archive_date/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_archive_date/__manifest__.py b/base_archive_date/__manifest__.py new file mode 100644 index 0000000000..70592e783c --- /dev/null +++ b/base_archive_date/__manifest__.py @@ -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, +} diff --git a/base_archive_date/i18n/base_archive_date.pot b/base_archive_date/i18n/base_archive_date.pot new file mode 100644 index 0000000000..2e295d9a0f --- /dev/null +++ b/base_archive_date/i18n/base_archive_date.pot @@ -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 "" diff --git a/base_archive_date/models/__init__.py b/base_archive_date/models/__init__.py new file mode 100644 index 0000000000..0e44449338 --- /dev/null +++ b/base_archive_date/models/__init__.py @@ -0,0 +1 @@ +from . import base diff --git a/base_archive_date/models/base.py b/base_archive_date/models/base.py new file mode 100644 index 0000000000..f58c9c5161 --- /dev/null +++ b/base_archive_date/models/base.py @@ -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) diff --git a/base_archive_date/readme/CONTRIBUTORS.rst b/base_archive_date/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a502d31e5b --- /dev/null +++ b/base_archive_date/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow S.L. `_: + + * Guillem Casassas diff --git a/base_archive_date/readme/DESCRIPTION.rst b/base_archive_date/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..dff2fb72d8 --- /dev/null +++ b/base_archive_date/readme/DESCRIPTION.rst @@ -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. diff --git a/base_archive_date/readme/USAGE.rst b/base_archive_date/readme/USAGE.rst new file mode 100644 index 0000000000..3d92d9610b --- /dev/null +++ b/base_archive_date/readme/USAGE.rst @@ -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. diff --git a/base_archive_date/static/description/icon.png b/base_archive_date/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/base_archive_date/static/description/icon.png differ diff --git a/base_archive_date/static/description/index.html b/base_archive_date/static/description/index.html new file mode 100644 index 0000000000..c5b4b3f1fe --- /dev/null +++ b/base_archive_date/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +Base Archive Date + + + +
+

Base Archive Date

+ + +

Beta License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runbot

+

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

+ +
+

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

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

GuillemCForgeFlow

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_archive_date/tests/__init__.py b/base_archive_date/tests/__init__.py new file mode 100644 index 0000000000..0165a0fd7f --- /dev/null +++ b/base_archive_date/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_archive_date diff --git a/base_archive_date/tests/test_base_archive_date.py b/base_archive_date/tests/test_base_archive_date.py new file mode 100644 index 0000000000..5225724691 --- /dev/null +++ b/base_archive_date/tests/test_base_archive_date.py @@ -0,0 +1,33 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields +from odoo.tests.common import SavepointCase + + +class TestBaseArchiveDate(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + # Models + cls.partner_model = cls.env["res.partner"] + + # Instances + cls.partner = cls.partner_model.create({"name": "Test Partner"}) + + def test_01_archive_partner_timestamp(self): + """ + Check that the technical field exists and check for the timestamp once the + partner is archived. + """ + self.assertTrue(self.partner.active) + self.assertTrue("archive_date" in self.partner._fields) + self.partner.toggle_active() + now = fields.Datetime.context_timestamp( + self.partner, fields.Datetime.now() + ).replace(tzinfo=None) + self.assertEqual( + self.partner.archive_date, now, "Archive Date should be equal to now." + ) diff --git a/setup/base_archive_date/odoo/addons/base_archive_date b/setup/base_archive_date/odoo/addons/base_archive_date new file mode 120000 index 0000000000..ef26ac7e6e --- /dev/null +++ b/setup/base_archive_date/odoo/addons/base_archive_date @@ -0,0 +1 @@ +../../../../base_archive_date \ No newline at end of file diff --git a/setup/base_archive_date/setup.py b/setup/base_archive_date/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/base_archive_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)