From bf3aac7c1a38e672f91e1f0245fe1186c5ec7ddb Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 29 Oct 2019 10:54:33 +0100 Subject: [PATCH] [12.0][ADD] - add a link between project tasks and calendar events --- calendar_event_link_base/README.rst | 97 ++++ calendar_event_link_base/__init__.py | 1 + calendar_event_link_base/__manifest__.py | 15 + calendar_event_link_base/models/__init__.py | 1 + .../models/calendar_event_link_mixin.py | 42 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + calendar_event_link_base/readme/USAGE.rst | 20 + .../static/description/index.html | 443 ++++++++++++++++++ calendar_event_link_project_task/README.rst | 73 +++ calendar_event_link_project_task/__init__.py | 2 + .../__manifest__.py | 16 + .../models/__init__.py | 1 + .../models/project_task.py | 9 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 419 +++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_calendar_event_link.py | 29 ++ .../views/project_task.xml | 24 + .../odoo/addons/calendar_event_link_base | 1 + setup/calendar_event_link_base/setup.py | 6 + .../addons/calendar_event_link_project_task | 1 + .../calendar_event_link_project_task/setup.py | 6 + 24 files changed, 1211 insertions(+) create mode 100644 calendar_event_link_base/README.rst create mode 100644 calendar_event_link_base/__init__.py create mode 100644 calendar_event_link_base/__manifest__.py create mode 100644 calendar_event_link_base/models/__init__.py create mode 100644 calendar_event_link_base/models/calendar_event_link_mixin.py create mode 100644 calendar_event_link_base/readme/CONTRIBUTORS.rst create mode 100644 calendar_event_link_base/readme/DESCRIPTION.rst create mode 100644 calendar_event_link_base/readme/USAGE.rst create mode 100644 calendar_event_link_base/static/description/index.html create mode 100644 calendar_event_link_project_task/README.rst create mode 100644 calendar_event_link_project_task/__init__.py create mode 100644 calendar_event_link_project_task/__manifest__.py create mode 100644 calendar_event_link_project_task/models/__init__.py create mode 100644 calendar_event_link_project_task/models/project_task.py create mode 100644 calendar_event_link_project_task/readme/CONTRIBUTORS.rst create mode 100644 calendar_event_link_project_task/readme/DESCRIPTION.rst create mode 100644 calendar_event_link_project_task/static/description/index.html create mode 100644 calendar_event_link_project_task/tests/__init__.py create mode 100644 calendar_event_link_project_task/tests/test_calendar_event_link.py create mode 100644 calendar_event_link_project_task/views/project_task.xml create mode 120000 setup/calendar_event_link_base/odoo/addons/calendar_event_link_base create mode 100644 setup/calendar_event_link_base/setup.py create mode 120000 setup/calendar_event_link_project_task/odoo/addons/calendar_event_link_project_task create mode 100644 setup/calendar_event_link_project_task/setup.py diff --git a/calendar_event_link_base/README.rst b/calendar_event_link_base/README.rst new file mode 100644 index 00000000..4bd239ea --- /dev/null +++ b/calendar_event_link_base/README.rst @@ -0,0 +1,97 @@ +======================== +Calendar Event Link Base +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fcalendar-lightgray.png?logo=github + :target: https://github.com/OCA/calendar/tree/12.0/calendar_event_link_base + :alt: OCA/calendar +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/calendar-12-0/calendar-12-0-calendar_event_link_base + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/279/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add an abstract model that provide an action to link any model to calendar events. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Inherit the `calendar.event.link.mixin` to the model you want to extend + +.. code-block:: python + + class YourModel(models.Model): + _name = 'your.model' + _inherit = ['your.model', 'calendar.event.link.mixin'] + +* Inherit the form view of your model and add this button to the `button_box` `div` + +.. code-block:: xml + + + + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +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_event_link_base/__init__.py b/calendar_event_link_base/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/calendar_event_link_base/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/calendar_event_link_base/__manifest__.py b/calendar_event_link_base/__manifest__.py new file mode 100644 index 00000000..bd4beb05 --- /dev/null +++ b/calendar_event_link_base/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Calendar Event Link Base", + "summary": """ + This module add an abstract model that provide an action to link + any model to calendar events""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/calendar", + "depends": ["calendar"], +} diff --git a/calendar_event_link_base/models/__init__.py b/calendar_event_link_base/models/__init__.py new file mode 100644 index 00000000..7cc92933 --- /dev/null +++ b/calendar_event_link_base/models/__init__.py @@ -0,0 +1 @@ +from . import calendar_event_link_mixin diff --git a/calendar_event_link_base/models/calendar_event_link_mixin.py b/calendar_event_link_base/models/calendar_event_link_mixin.py new file mode 100644 index 00000000..1ee4f8a0 --- /dev/null +++ b/calendar_event_link_base/models/calendar_event_link_mixin.py @@ -0,0 +1,42 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class CalendarEventLinkMixin(models.AbstractModel): + + _name = "calendar.event.link.mixin" + _description = "Calendar Event Link Mixin" + + event_count = fields.Integer(compute="_compute_event_count") + + @api.multi + def _compute_event_count(self): + for x in self.env["calendar.event"].read_group( + [("res_model", "=", self._name), ("res_id", "in", self.ids)], + ["id"], + ["res_id"], + ): + self.browse(x["res_id"]).update({"event_count": x["res_id_count"]}) + + @api.multi + def action_show_events(self): + self.ensure_one() + context = { + "default_res_id": self.id, + "default_res_model": self._name, + "default_name": self.name if "name" in self._fields else "", + } + context.update(self.env.context) + return { + "type": "ir.actions.act_window", + "name": _("Calendar"), + "res_model": "calendar.event", + "domain": [ + ("res_model", "=", self._name), + ("res_id", "=", self.id), + ], + "view_mode": "calendar,tree,form", + "context": context, + } diff --git a/calendar_event_link_base/readme/CONTRIBUTORS.rst b/calendar_event_link_base/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..50e6298d --- /dev/null +++ b/calendar_event_link_base/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/calendar_event_link_base/readme/DESCRIPTION.rst b/calendar_event_link_base/readme/DESCRIPTION.rst new file mode 100644 index 00000000..8815b199 --- /dev/null +++ b/calendar_event_link_base/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add an abstract model that provide an action to link any model to calendar events. diff --git a/calendar_event_link_base/readme/USAGE.rst b/calendar_event_link_base/readme/USAGE.rst new file mode 100644 index 00000000..3b74646f --- /dev/null +++ b/calendar_event_link_base/readme/USAGE.rst @@ -0,0 +1,20 @@ +* Inherit the `calendar.event.link.mixin` to the model you want to extend + +.. code-block:: python + + class YourModel(models.Model): + _name = 'your.model' + _inherit = ['your.model', 'calendar.event.link.mixin'] + +* Inherit the form view of your model and add this button to the `button_box` `div` + +.. code-block:: xml + + + diff --git a/calendar_event_link_base/static/description/index.html b/calendar_event_link_base/static/description/index.html new file mode 100644 index 00000000..b55789c3 --- /dev/null +++ b/calendar_event_link_base/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Calendar Event Link Base + + + + + + diff --git a/calendar_event_link_project_task/README.rst b/calendar_event_link_project_task/README.rst new file mode 100644 index 00000000..16378468 --- /dev/null +++ b/calendar_event_link_project_task/README.rst @@ -0,0 +1,73 @@ +=================================== +Calendar Event Link To Project Task +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fcalendar-lightgray.png?logo=github + :target: https://github.com/OCA/calendar/tree/12.0/calendar_event_link_project_task + :alt: OCA/calendar +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/calendar-12-0/calendar-12-0-calendar_event_link_project_task + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/279/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add a link between project tasks and calendar events + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +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_event_link_project_task/__init__.py b/calendar_event_link_project_task/__init__.py new file mode 100644 index 00000000..0ee8b507 --- /dev/null +++ b/calendar_event_link_project_task/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/calendar_event_link_project_task/__manifest__.py b/calendar_event_link_project_task/__manifest__.py new file mode 100644 index 00000000..00f2d9dc --- /dev/null +++ b/calendar_event_link_project_task/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Calendar Event Link To Project Task", + "summary": """ + This module add a link between project tasks and calendar events""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/calendar", + "depends": ["project", "calendar_event_link_base"], + "data": ["views/project_task.xml"], + "demo": [], +} diff --git a/calendar_event_link_project_task/models/__init__.py b/calendar_event_link_project_task/models/__init__.py new file mode 100644 index 00000000..edf2d36b --- /dev/null +++ b/calendar_event_link_project_task/models/__init__.py @@ -0,0 +1 @@ +from . import project_task diff --git a/calendar_event_link_project_task/models/project_task.py b/calendar_event_link_project_task/models/project_task.py new file mode 100644 index 00000000..e995c883 --- /dev/null +++ b/calendar_event_link_project_task/models/project_task.py @@ -0,0 +1,9 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProjectTask(models.Model): + _name = "project.task" + _inherit = ["project.task", "calendar.event.link.mixin"] diff --git a/calendar_event_link_project_task/readme/CONTRIBUTORS.rst b/calendar_event_link_project_task/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..50e6298d --- /dev/null +++ b/calendar_event_link_project_task/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/calendar_event_link_project_task/readme/DESCRIPTION.rst b/calendar_event_link_project_task/readme/DESCRIPTION.rst new file mode 100644 index 00000000..d3ddf319 --- /dev/null +++ b/calendar_event_link_project_task/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add a link between project tasks and calendar events diff --git a/calendar_event_link_project_task/static/description/index.html b/calendar_event_link_project_task/static/description/index.html new file mode 100644 index 00000000..fed93a5d --- /dev/null +++ b/calendar_event_link_project_task/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Calendar Event Link To Project Task + + + + + + diff --git a/calendar_event_link_project_task/tests/__init__.py b/calendar_event_link_project_task/tests/__init__.py new file mode 100644 index 00000000..73f92135 --- /dev/null +++ b/calendar_event_link_project_task/tests/__init__.py @@ -0,0 +1 @@ +from . import test_calendar_event_link diff --git a/calendar_event_link_project_task/tests/test_calendar_event_link.py b/calendar_event_link_project_task/tests/test_calendar_event_link.py new file mode 100644 index 00000000..c3bf2295 --- /dev/null +++ b/calendar_event_link_project_task/tests/test_calendar_event_link.py @@ -0,0 +1,29 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestCalendarEventLink(TransactionCase): + def setUp(self): + super(TestCalendarEventLink, self).setUp() + self.task = self.env["project.task"].search([], limit=1) + + def test_calendar_event_link(self): + calendar_event_link_action = self.task.action_show_events() + event = ( + self.env["calendar.event"] + .with_context(calendar_event_link_action["context"]) + .create( + { + "name": "event", + "start": "2019-10-29 10:00:00", + "stop": "2019-10-29 11:00:00", + } + ) + ) + self.assertEqual(self.task.event_count, 1) + self.assertEqual( + self.env["calendar.event"].search(calendar_event_link_action["domain"]), + event, + ) diff --git a/calendar_event_link_project_task/views/project_task.xml b/calendar_event_link_project_task/views/project_task.xml new file mode 100644 index 00000000..ecb03276 --- /dev/null +++ b/calendar_event_link_project_task/views/project_task.xml @@ -0,0 +1,24 @@ + + + + + + + project.task + + + + + + + + + + diff --git a/setup/calendar_event_link_base/odoo/addons/calendar_event_link_base b/setup/calendar_event_link_base/odoo/addons/calendar_event_link_base new file mode 120000 index 00000000..9e9cd28a --- /dev/null +++ b/setup/calendar_event_link_base/odoo/addons/calendar_event_link_base @@ -0,0 +1 @@ +../../../../calendar_event_link_base \ No newline at end of file diff --git a/setup/calendar_event_link_base/setup.py b/setup/calendar_event_link_base/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/calendar_event_link_base/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/calendar_event_link_project_task/odoo/addons/calendar_event_link_project_task b/setup/calendar_event_link_project_task/odoo/addons/calendar_event_link_project_task new file mode 120000 index 00000000..8f456ea0 --- /dev/null +++ b/setup/calendar_event_link_project_task/odoo/addons/calendar_event_link_project_task @@ -0,0 +1 @@ +../../../../calendar_event_link_project_task \ No newline at end of file diff --git a/setup/calendar_event_link_project_task/setup.py b/setup/calendar_event_link_project_task/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/calendar_event_link_project_task/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)