diff --git a/calendar_export_ics/README.rst b/calendar_export_ics/README.rst new file mode 100644 index 00000000..154be733 --- /dev/null +++ b/calendar_export_ics/README.rst @@ -0,0 +1,93 @@ +===================== +Calendar - Export ics +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:89e22508ece2c84daa64b8426a0ae4e4a2fe63905d721af87c1e7273240a91a4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fcalendar-lightgray.png?logo=github + :target: https://github.com/OCA/calendar/tree/15.0/calendar_export_ics + :alt: OCA/calendar +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/calendar-15-0/calendar-15-0-calendar_export_ics + :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/calendar&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a new wizard that allows you to export odoo calendar into an .ics file. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, follow these steps: + +#. Navigate to the Calendar App. +#. Go to Configuration. +#. Select Export to ICS File. + +When exporting, you have two options: + +* Specify the maximum date of the calendar you want to export. +* Leave the date field empty to export all events from your calendar. + +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 +~~~~~~~ + +* ForgeFlow S.L. + +Contributors +~~~~~~~~~~~~ + +* Arnau Cruz + + +Do not contact contributors directly about support or help with technical issues. + +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/calendar `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/calendar_export_ics/__init__.py b/calendar_export_ics/__init__.py new file mode 100644 index 00000000..5cb1c491 --- /dev/null +++ b/calendar_export_ics/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/calendar_export_ics/__manifest__.py b/calendar_export_ics/__manifest__.py new file mode 100644 index 00000000..da99dd10 --- /dev/null +++ b/calendar_export_ics/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2024 - ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Calendar - Export ics", + "summary": "Allow exporting odoo calendar to an ics file", + "version": "15.0.1.0.1", + "author": "ForgeFlow S.L.,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/calendar", + "license": "AGPL-3", + "depends": ["calendar", "calendar_import_ics"], + "data": [ + "security/calendar_export_security.xml", + "security/ir.model.access.csv", + "wizards/wizard_export_ics.xml", + ], +} diff --git a/calendar_export_ics/readme/CONTRIBUTORS.rst b/calendar_export_ics/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..42206acc --- /dev/null +++ b/calendar_export_ics/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Arnau Cruz + + +Do not contact contributors directly about support or help with technical issues. diff --git a/calendar_export_ics/readme/DESCRIPTION.rst b/calendar_export_ics/readme/DESCRIPTION.rst new file mode 100644 index 00000000..6627ab0a --- /dev/null +++ b/calendar_export_ics/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds a new wizard that allows you to export odoo calendar into an .ics file. diff --git a/calendar_export_ics/readme/USAGE.rst b/calendar_export_ics/readme/USAGE.rst new file mode 100644 index 00000000..1c96861c --- /dev/null +++ b/calendar_export_ics/readme/USAGE.rst @@ -0,0 +1,10 @@ +To use this module, follow these steps: + +#. Navigate to the Calendar App. +#. Go to Configuration. +#. Select Export to ICS File. + +When exporting, you have two options: + +* Specify the maximum date of the calendar you want to export. +* Leave the date field empty to export all events from your calendar. diff --git a/calendar_export_ics/security/calendar_export_security.xml b/calendar_export_ics/security/calendar_export_security.xml new file mode 100644 index 00000000..043d6e2a --- /dev/null +++ b/calendar_export_ics/security/calendar_export_security.xml @@ -0,0 +1,7 @@ + + + + Calendar Export Ics + + + diff --git a/calendar_export_ics/security/ir.model.access.csv b/calendar_export_ics/security/ir.model.access.csv new file mode 100644 index 00000000..8cfc913a --- /dev/null +++ b/calendar_export_ics/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wizard_calendar_export_ics,access_wizard_calendar_export_ics,model_calendar_export_ics,calendar_export_ics.group_calendar_export,1,1,1,1 diff --git a/calendar_export_ics/static/description/index.html b/calendar_export_ics/static/description/index.html new file mode 100644 index 00000000..8300dd63 --- /dev/null +++ b/calendar_export_ics/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Calendar - Export ics + + + +
+

Calendar - Export ics

+ + +

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

+

This module adds a new wizard that allows you to export odoo calendar into an .ics file.

+

Table of contents

+ +
+

Usage

+

To use this module, follow these steps:

+
    +
  1. Navigate to the Calendar App.
  2. +
  3. Go to Configuration.
  4. +
  5. Select Export to ICS File.
  6. +
+

When exporting, you have two options:

+
    +
  • Specify the maximum date of the calendar you want to export.
  • +
  • Leave the date field empty to export all events from your calendar.
  • +
+
+
+

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

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

Contributors

+ +

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

+
+
+

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/calendar project on GitHub.

+

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

+
+
+
+ + diff --git a/calendar_export_ics/tests/__init__.py b/calendar_export_ics/tests/__init__.py new file mode 100644 index 00000000..93616580 --- /dev/null +++ b/calendar_export_ics/tests/__init__.py @@ -0,0 +1 @@ +from . import test_calendar_export_ics diff --git a/calendar_export_ics/tests/test_calendar_export_ics.py b/calendar_export_ics/tests/test_calendar_export_ics.py new file mode 100644 index 00000000..a543bb49 --- /dev/null +++ b/calendar_export_ics/tests/test_calendar_export_ics.py @@ -0,0 +1,83 @@ +# Copyright (C) 2024 - ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import base64 +from datetime import datetime + +from freezegun import freeze_time + +from odoo.tests.common import TransactionCase + + +class TestExportIcs(TransactionCase): + def setUp(self): + super(TestExportIcs, self).setUp() + self.event_model = self.env["calendar.event"] + self.partner_model = self.env["res.partner"] + self.export_wiz = self.env["calendar.export.ics"] + + self.partner_1 = self.partner_model.create({"name": "Partner 1"}) + self.partner_2 = self.partner_model.create({"name": "Partner 2"}) + self.event_1 = self.event_model.create( + { + "name": "Event 1", + "start": datetime(2024, 5, 22, 20, 00, 00), + "stop": datetime(2024, 5, 22, 21, 00, 00), + "partner_ids": [(4, self.partner_1.id)], + } + ) + self.event_2 = self.event_model.create( + { + "name": "Event 2", + "start": datetime(2024, 5, 22, 18, 00, 00), + "stop": datetime(2024, 5, 22, 18, 30, 00), + "partner_ids": [(4, self.partner_1.id)], + } + ) + self.event_3 = self.event_model.create( + { + "name": "Event 3", + "start": datetime(2024, 5, 19, 21, 00, 00), + "stop": datetime(2024, 5, 19, 22, 00, 00), + "partner_ids": [(4, self.partner_1.id)], + } + ) + self.event_4 = self.event_model.create( + { + "name": "Event 4", + "start": datetime(2024, 5, 23, 15, 00, 00), + "stop": datetime(2024, 5, 23, 17, 00, 00), + "partner_ids": [(4, self.partner_1.id)], + } + ) + self.event_5 = self.event_model.create( + { + "name": "Event 5", + "start": datetime(2024, 5, 24, 15, 00, 00), + "stop": datetime(2024, 5, 24, 17, 00, 00), + "partner_ids": [(4, self.partner_2.id)], + } + ) + + @freeze_time("2024-05-21") + def test_export_ics(self): + wiz = self.export_wiz.create({"partner_id": self.partner_1.id}) + wiz.button_export() + file_content = wiz.export_ics_file + decoded_content = base64.b64decode(file_content) + ics_content = decoded_content.decode() + # Check that events 1,2,4 are exported + self.assertIn( + "BEGIN:VEVENT\nSUMMARY:Event 1\nDTSTART:20240522T200000Z\nDTEND:20240522T210000Z", + ics_content, + ) + self.assertIn( + "BEGIN:VEVENT\nSUMMARY:Event 2\nDTSTART:20240522T180000Z\nDTEND:20240522T183000Z", + ics_content, + ) + self.assertIn( + "BEGIN:VEVENT\nSUMMARY:Event 4\nDTSTART:20240523T150000Z\nDTEND:20240523T170000Z", + ics_content, + ) + self.assertNotIn("SUMMARY:Event 3", ics_content) + self.assertNotIn("SUMMARY:Event 5", ics_content) diff --git a/calendar_export_ics/wizards/__init__.py b/calendar_export_ics/wizards/__init__.py new file mode 100644 index 00000000..b4642113 --- /dev/null +++ b/calendar_export_ics/wizards/__init__.py @@ -0,0 +1 @@ +from . import wizard_export_ics diff --git a/calendar_export_ics/wizards/wizard_export_ics.py b/calendar_export_ics/wizards/wizard_export_ics.py new file mode 100644 index 00000000..4d71f89b --- /dev/null +++ b/calendar_export_ics/wizards/wizard_export_ics.py @@ -0,0 +1,64 @@ +# Copyright (C) 2024 - ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +import base64 +from datetime import date + +from odoo import api, fields, models + + +class CalendarExportIcs(models.TransientModel): + """ + This wizard is used to export odoo calendar to ics file + """ + + _name = "calendar.export.ics" + _description = "Calendar Export Ics" + + export_ics_file = fields.Binary("Ics Exported File") + export_ics_filename = fields.Char(readonly=True) + export_end_date = fields.Date("End Export Date") + partner_id = fields.Many2one("res.partner", string="Partner") + + @api.model + def default_get(self, fields): + defaults = super(CalendarExportIcs, self).default_get(fields) + user = self.env.user + if user.partner_id: + defaults["partner_id"] = user.partner_id.id + return defaults + + def button_export(self): + today_date = date.today() + self.export_ics_filename = today_date.strftime("%Y-%m-%d") + "_calendar.ics" + self.export_ics_file = self.generate_ics_content() + + return { + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "calendar.export.ics", + "name": "Export to Ics File", + "target": "new", + "res_id": self.id, + } + + def generate_ics_content(self): + domain = [] + if self.export_end_date: + domain.append(("start", "<=", self.export_end_date)) + domain.append(("start", ">=", date.today())) + domain.append(("partner_ids", "in", [self.partner_id.id])) + events = self.env["calendar.event"].search(domain) + ics_content = "BEGIN:VCALENDAR\n" + for event in events: + ics_content += "BEGIN:VEVENT\n" + ics_content += f"SUMMARY:{event.name}\n" + ics_content += f"DTSTART:{event.start.strftime('%Y%m%dT%H%M%SZ')}\n" + ics_content += f"DTEND:{event.stop.strftime('%Y%m%dT%H%M%SZ')}\n" + if not event.event_identifier: + event.write({"event_identifier": event.id}) + ics_content += f"UID:{event.event_identifier}\n" + ics_content += "END:VEVENT\n" + ics_content += "END:VCALENDAR\n" + return base64.b64encode(ics_content.encode()) diff --git a/calendar_export_ics/wizards/wizard_export_ics.xml b/calendar_export_ics/wizards/wizard_export_ics.xml new file mode 100644 index 00000000..ecfe51b0 --- /dev/null +++ b/calendar_export_ics/wizards/wizard_export_ics.xml @@ -0,0 +1,45 @@ + + + + calendar.export.ics.form + calendar.export.ics + +
+ + + + + + +
+
+
+
+
+ + Export to Ics File + calendar.export.ics + form + new + + +
diff --git a/setup/calendar_export_ics/odoo/addons/calendar_export_ics b/setup/calendar_export_ics/odoo/addons/calendar_export_ics new file mode 120000 index 00000000..59a43cae --- /dev/null +++ b/setup/calendar_export_ics/odoo/addons/calendar_export_ics @@ -0,0 +1 @@ +../../../../calendar_export_ics \ No newline at end of file diff --git a/setup/calendar_export_ics/setup.py b/setup/calendar_export_ics/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/calendar_export_ics/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)