diff --git a/setup/sms_no_automatic_delete/odoo/addons/sms_no_automatic_delete b/setup/sms_no_automatic_delete/odoo/addons/sms_no_automatic_delete new file mode 120000 index 000000000..cf5c2653f --- /dev/null +++ b/setup/sms_no_automatic_delete/odoo/addons/sms_no_automatic_delete @@ -0,0 +1 @@ +../../../../sms_no_automatic_delete \ No newline at end of file diff --git a/setup/sms_no_automatic_delete/setup.py b/setup/sms_no_automatic_delete/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sms_no_automatic_delete/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/sms_no_automatic_delete/README.rst b/sms_no_automatic_delete/README.rst new file mode 100644 index 000000000..28f24823b --- /dev/null +++ b/sms_no_automatic_delete/README.rst @@ -0,0 +1,84 @@ +============================ +No automatic deletion of SMS +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0a5f4deed06afe5abaef59e4918f990556f36249dba50f5ad45ed26016ca8106 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fconnector--telephony-lightgray.png?logo=github + :target: https://github.com/OCA/connector-telephony/tree/16.0/sms_no_automatic_delete + :alt: OCA/connector-telephony +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/connector-telephony-16-0/connector-telephony-16-0-sms_no_automatic_delete + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to save sent sms and to delete them after a delay (in days). +In addition, the sms state is update as "sent" when they are sent and saved. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To delete sent sms, the cron "SMS: SMS Purge" is used in order to choice the maximum days a sms will be saved (by default : days = 90). + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Kévin Roche +* Sébastien Beau +* Bernat Puig + +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. + +This module is part of the `OCA/connector-telephony `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sms_no_automatic_delete/__init__.py b/sms_no_automatic_delete/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sms_no_automatic_delete/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sms_no_automatic_delete/__manifest__.py b/sms_no_automatic_delete/__manifest__.py new file mode 100644 index 000000000..e6f5e31d8 --- /dev/null +++ b/sms_no_automatic_delete/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2021 Akretion (http://www.akretion.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "No automatic deletion of SMS", + "summary": "Avoid automatic delete of sended sms", + "author": "Akretion,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/connector-telephony", + "license": "AGPL-3", + "category": "", + "version": "16.0.1.0.0", + "depends": ["sms"], + "data": [ + "data/ir_cron_data.xml", + ], + "application": False, + "installable": True, +} diff --git a/sms_no_automatic_delete/data/ir_cron_data.xml b/sms_no_automatic_delete/data/ir_cron_data.xml new file mode 100644 index 000000000..e8944891a --- /dev/null +++ b/sms_no_automatic_delete/data/ir_cron_data.xml @@ -0,0 +1,14 @@ + + + + SMS: SMS Purge + + code + model._purge(days=90) + + 1 + days + -1 + + + diff --git a/sms_no_automatic_delete/i18n/es.po b/sms_no_automatic_delete/i18n/es.po new file mode 100644 index 000000000..8c82b5a91 --- /dev/null +++ b/sms_no_automatic_delete/i18n/es.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sms_no_automatic_delete +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-20 19:33+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms__id +msgid "ID" +msgstr "ID" + +#. module: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: sms_no_automatic_delete +#: model:ir.model,name:sms_no_automatic_delete.model_sms_sms +msgid "Outgoing SMS" +msgstr "SMS Salientes" + +#. module: sms_no_automatic_delete +#: model:ir.actions.server,name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete_ir_actions_server +#: model:ir.cron,cron_name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete +#: model:ir.cron,name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete +msgid "SMS: SMS Purge" +msgstr "SMS: Purga de SMS" diff --git a/sms_no_automatic_delete/i18n/sms_no_automatic_delete.pot b/sms_no_automatic_delete/i18n/sms_no_automatic_delete.pot new file mode 100644 index 000000000..b819870c7 --- /dev/null +++ b/sms_no_automatic_delete/i18n/sms_no_automatic_delete.pot @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sms_no_automatic_delete +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms__display_name +msgid "Display Name" +msgstr "" + +#. module: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms__id +msgid "ID" +msgstr "" + +#. module: sms_no_automatic_delete +#: model:ir.model.fields,field_description:sms_no_automatic_delete.field_sms_sms____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sms_no_automatic_delete +#: model:ir.model,name:sms_no_automatic_delete.model_sms_sms +msgid "Outgoing SMS" +msgstr "" + +#. module: sms_no_automatic_delete +#: model:ir.actions.server,name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete_ir_actions_server +#: model:ir.cron,cron_name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete +#: model:ir.cron,name:sms_no_automatic_delete.ir_cron_sms_no_automatic_delete +msgid "SMS: SMS Purge" +msgstr "" diff --git a/sms_no_automatic_delete/models/__init__.py b/sms_no_automatic_delete/models/__init__.py new file mode 100644 index 000000000..d302db28a --- /dev/null +++ b/sms_no_automatic_delete/models/__init__.py @@ -0,0 +1 @@ +from . import sms_sms diff --git a/sms_no_automatic_delete/models/sms_sms.py b/sms_no_automatic_delete/models/sms_sms.py new file mode 100644 index 000000000..6304d21bf --- /dev/null +++ b/sms_no_automatic_delete/models/sms_sms.py @@ -0,0 +1,37 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime, timedelta + +from odoo import api, models + + +class SmsSms(models.Model): + _inherit = "sms.sms" + + @api.model + def _postprocess_iap_sent_sms( + self, iap_results, failure_reason=None, unlink_failed=False, unlink_sent=True + ): + # Update state of the sms as "sent" when they are sent. + ids = [item["res_id"] for item in iap_results if item["state"] == "success"] + self.browse(ids).write({"state": "sent"}) + return super()._postprocess_iap_sent_sms( + iap_results, + failure_reason=failure_reason, + unlink_failed=unlink_failed, + unlink_sent=unlink_sent, + ) + + @api.model + def _purge(self, days): + sms = self.env["sms.sms"].search( + [("write_date", "<=", datetime.now() - timedelta(days=days))] + ) + sms.with_context(force_unlink=True).unlink() + + def unlink(self): + if self._context.get("force_unlink"): + return super().unlink() + else: + return True diff --git a/sms_no_automatic_delete/readme/CONTRIBUTORS.rst b/sms_no_automatic_delete/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..50194a7ec --- /dev/null +++ b/sms_no_automatic_delete/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Kévin Roche +* Sébastien Beau +* Bernat Puig diff --git a/sms_no_automatic_delete/readme/DESCRIPTION.rst b/sms_no_automatic_delete/readme/DESCRIPTION.rst new file mode 100644 index 000000000..956b7b792 --- /dev/null +++ b/sms_no_automatic_delete/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to save sent sms and to delete them after a delay (in days). +In addition, the sms state is update as "sent" when they are sent and saved. diff --git a/sms_no_automatic_delete/readme/USAGE.rst b/sms_no_automatic_delete/readme/USAGE.rst new file mode 100644 index 000000000..439622cfb --- /dev/null +++ b/sms_no_automatic_delete/readme/USAGE.rst @@ -0,0 +1 @@ +To delete sent sms, the cron "SMS: SMS Purge" is used in order to choice the maximum days a sms will be saved (by default : days = 90). diff --git a/sms_no_automatic_delete/static/description/icon.png b/sms_no_automatic_delete/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sms_no_automatic_delete/static/description/icon.png differ diff --git a/sms_no_automatic_delete/static/description/index.html b/sms_no_automatic_delete/static/description/index.html new file mode 100644 index 000000000..e3066257f --- /dev/null +++ b/sms_no_automatic_delete/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +No automatic deletion of SMS + + + +
+

No automatic deletion of SMS

+ + +

Beta License: AGPL-3 OCA/connector-telephony Translate me on Weblate Try me on Runboat

+

This module allows to save sent sms and to delete them after a delay (in days). +In addition, the sms state is update as “sent” when they are sent and saved.

+

Table of contents

+ +
+

Usage

+

To delete sent sms, the cron “SMS: SMS Purge” is used in order to choice the maximum days a sms will be saved (by default : days = 90).

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

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.

+

This module is part of the OCA/connector-telephony project on GitHub.

+

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

+
+
+
+ + diff --git a/sms_no_automatic_delete/tests/__init__.py b/sms_no_automatic_delete/tests/__init__.py new file mode 100644 index 000000000..d5d5460e8 --- /dev/null +++ b/sms_no_automatic_delete/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purge_and_unlink_sms diff --git a/sms_no_automatic_delete/tests/test_purge_and_unlink_sms.py b/sms_no_automatic_delete/tests/test_purge_and_unlink_sms.py new file mode 100644 index 000000000..b1828dde6 --- /dev/null +++ b/sms_no_automatic_delete/tests/test_purge_and_unlink_sms.py @@ -0,0 +1,63 @@ +# Copyright 2021 Akretion (https://www.akretion.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime, timedelta + +from odoo.tests.common import TransactionCase + +from odoo.addons.sms.tests.common import MockSMS + + +class TestSmsPurgeAndUnlink(TransactionCase, MockSMS): + def setUp(self): + super(TestSmsPurgeAndUnlink, self).setUp() + self.sms_sms = self.env["sms.sms"] + self.sms1 = self.sms_sms.create( + { + "state": "outgoing", + "write_date": datetime.now() - timedelta(days=30), + } + ) + self.sms2 = self.sms_sms.create( + { + "state": "outgoing", + "write_date": datetime.now() - timedelta(days=61), + } + ) + self.sms3 = self.sms_sms.create( + { + "state": "outgoing", + "write_date": datetime.now() - timedelta(days=91), + } + ) + + def test_sms_state_as_sent(self): + with self.mockSMSGateway(): + self.sms1.send() + self.assertEqual(self.sms1.state, "sent") + self.assertEqual(self.sms2.state, "outgoing") + + with self.mockSMSGateway(): + self.sms2.send() + self.assertEqual(self.sms2.state, "sent") + + def test_sms_unlink(self): + # force_unlink=False by default + self.sms1.unlink() + self.assertTrue(self.sms1.exists()) + # force_unlink=True + self.sms1.with_context(force_unlink=True).unlink() + self.assertFalse(self.sms1.exists()) + + def test_sms_purge(self): + self.sms_sms._purge(120) + self.assertEqual(len(self.sms_sms.search([])), 3) + + self.sms_sms._purge(90) + self.assertEqual(len(self.sms_sms.search([])), 2) + + self.sms_sms._purge(60) + self.assertEqual(len(self.sms_sms.search([])), 1) + + self.sms_sms._purge(0) + self.assertEqual(len(self.sms_sms.search([])), 0)