From 8d1991ea0fbf3ebfe2e440d539cb59bf9dc25990 Mon Sep 17 00:00:00 2001 From: Anjeel Haria Date: Mon, 16 Sep 2024 15:43:04 +0530 Subject: [PATCH] [ADD] membership_activity added missed out files added test scripts pre-commit fixes --- membership_activity/README.rst | 92 ++++ membership_activity/__init__.py | 1 + membership_activity/__manifest__.py | 18 + .../data/reconcile_partner_cron.xml | 18 + membership_activity/menuitems.xml | 17 + membership_activity/models/__init__.py | 4 + .../models/membership_activity.py | 37 ++ .../models/membership_activity_type.py | 21 + membership_activity/models/project_project.py | 49 ++ membership_activity/models/res_partner.py | 42 ++ membership_activity/readme/CONFIGURE.rst | 4 + membership_activity/readme/CONTRIBUTORS.rst | 1 + membership_activity/readme/DESCRIPTION.rst | 1 + membership_activity/readme/USAGE.rst | 4 + .../security/ir_model_access.xml | 22 + .../static/description/index.html | 441 ++++++++++++++++++ membership_activity/tests/__init__.py | 1 + .../tests/test_membership_activity.py | 45 ++ .../views/membership_activity_type_view.xml | 34 ++ .../views/membership_activity_view.xml | 103 ++++ .../views/res_partner_view.xml | 47 ++ .../odoo/addons/membership_activity | 1 + setup/membership_activity/setup.py | 6 + 23 files changed, 1009 insertions(+) create mode 100644 membership_activity/README.rst create mode 100644 membership_activity/__init__.py create mode 100644 membership_activity/__manifest__.py create mode 100644 membership_activity/data/reconcile_partner_cron.xml create mode 100644 membership_activity/menuitems.xml create mode 100644 membership_activity/models/__init__.py create mode 100644 membership_activity/models/membership_activity.py create mode 100644 membership_activity/models/membership_activity_type.py create mode 100644 membership_activity/models/project_project.py create mode 100644 membership_activity/models/res_partner.py create mode 100644 membership_activity/readme/CONFIGURE.rst create mode 100644 membership_activity/readme/CONTRIBUTORS.rst create mode 100644 membership_activity/readme/DESCRIPTION.rst create mode 100644 membership_activity/readme/USAGE.rst create mode 100644 membership_activity/security/ir_model_access.xml create mode 100644 membership_activity/static/description/index.html create mode 100644 membership_activity/tests/__init__.py create mode 100644 membership_activity/tests/test_membership_activity.py create mode 100644 membership_activity/views/membership_activity_type_view.xml create mode 100644 membership_activity/views/membership_activity_view.xml create mode 100644 membership_activity/views/res_partner_view.xml create mode 120000 setup/membership_activity/odoo/addons/membership_activity create mode 100644 setup/membership_activity/setup.py diff --git a/membership_activity/README.rst b/membership_activity/README.rst new file mode 100644 index 000000000..a81d0a14c --- /dev/null +++ b/membership_activity/README.rst @@ -0,0 +1,92 @@ +=================== +Membership Activity +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6891f99197610e0eca1d1728218ce6b197ae75351c4ef2bd0e50de2745a0dbd9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fvertical--association-lightgray.png?logo=github + :target: https://github.com/OCA/vertical-association/tree/16.0/membership_activity + :alt: OCA/vertical-association +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/vertical-association-16-0/vertical-association-16-0-membership_activity + :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/vertical-association&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to track activities of members.This is a base module that allows to define some basic membership activities + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +#. Go to *Members > Configuration > Activity Types*. +#. Create different activity types as you want for Membership Activity model. + +Usage +===== + +To use this module, you need to: + +#. Create Activity Types as needed. +#. Create Membership Activities defining the project, activity type, date of activity and url(possibly defining url for commits,PRs etc). + +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 +~~~~~~~ + +* Onestein + +Contributors +~~~~~~~~~~~~ + +* `Onestein `_ + +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/vertical-association `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/membership_activity/__init__.py b/membership_activity/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/membership_activity/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/membership_activity/__manifest__.py b/membership_activity/__manifest__.py new file mode 100644 index 000000000..9161c6573 --- /dev/null +++ b/membership_activity/__manifest__.py @@ -0,0 +1,18 @@ +{ + "name": "Membership Activity", + "summary": "Track activity of members", + "category": "Membership", + "version": "16.0.1.0.0", + "author": "Onestein, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/vertical-association", + "license": "AGPL-3", + "depends": ["membership", "project"], + "data": [ + "data/reconcile_partner_cron.xml", + "security/ir_model_access.xml", + "views/res_partner_view.xml", + "views/membership_activity_view.xml", + "views/membership_activity_type_view.xml", + "menuitems.xml", + ], +} diff --git a/membership_activity/data/reconcile_partner_cron.xml b/membership_activity/data/reconcile_partner_cron.xml new file mode 100644 index 000000000..42b38aa0c --- /dev/null +++ b/membership_activity/data/reconcile_partner_cron.xml @@ -0,0 +1,18 @@ + + + + + Set partner on membership activities + + + code + model.reconcile_partner() + 1 + days + -1 + + + diff --git a/membership_activity/menuitems.xml b/membership_activity/menuitems.xml new file mode 100644 index 000000000..18865b826 --- /dev/null +++ b/membership_activity/menuitems.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/membership_activity/models/__init__.py b/membership_activity/models/__init__.py new file mode 100644 index 000000000..de725fef5 --- /dev/null +++ b/membership_activity/models/__init__.py @@ -0,0 +1,4 @@ +from . import membership_activity +from . import membership_activity_type +from . import res_partner +from . import project_project diff --git a/membership_activity/models/membership_activity.py b/membership_activity/models/membership_activity.py new file mode 100644 index 000000000..69801575c --- /dev/null +++ b/membership_activity/models/membership_activity.py @@ -0,0 +1,37 @@ +from odoo import fields, models + + +class MembershipActivity(models.Model): + _name = "membership.activity" + _description = "Member Activity" + + partner_id = fields.Many2one( + comodel_name="res.partner", + string="Member", + ondelete="cascade", + store=True, + compute="_compute_partner_id", + ) + project_id = fields.Many2one( + comodel_name="project.project", string="Related Project", ondelete="cascade" + ) + date = fields.Datetime(required=True) + url = fields.Char() + type_id = fields.Many2one( + comodel_name="membership.activity.type", string="Activity Type" + ) + + def name_get(self): + res = [] + for activity in self: + res.append((activity.id, activity.partner_id.display_name)) + return res + + def _compute_partner_id(self): + # To be implemented by other modules + # For example for CDE activity, the activity can be created before the member + # is created in the system + pass + + def reconcile_partner(self): + self.search([("partner_id", "=", False)])._compute_partner_id() diff --git a/membership_activity/models/membership_activity_type.py b/membership_activity/models/membership_activity_type.py new file mode 100644 index 000000000..76f697635 --- /dev/null +++ b/membership_activity/models/membership_activity_type.py @@ -0,0 +1,21 @@ +from odoo import fields, models + + +class MembershipActivityType(models.Model): + _name = "membership.activity.type" + _description = "Member Activity Type" + _parent_store = True + _parent_name = "parent_id" + + name = fields.Char() + parent_id = fields.Many2one( + comodel_name="membership.activity.type", + string="Parent Activity Type", + index=True, + ) + child_ids = fields.One2many( + comodel_name="membership.activity.type", + inverse_name="parent_id", + string="Sub Activity Types", + ) + parent_path = fields.Char(index=True, unaccent=False) diff --git a/membership_activity/models/project_project.py b/membership_activity/models/project_project.py new file mode 100644 index 000000000..17f6307ff --- /dev/null +++ b/membership_activity/models/project_project.py @@ -0,0 +1,49 @@ +from datetime import datetime + +from odoo import api, fields, models + + +class Project(models.Model): + _inherit = "project.project" + + membership_activity_ids = fields.One2many( + comodel_name="membership.activity", + inverse_name="project_id", + string="Member Activities", + ) + membership_activity_count = fields.Integer( + string="# of Activities", + compute="_compute_membership_activity_count", + store=True, + ) + last_membership_activity_date = fields.Date( + string="Last Activity Date", + compute="_compute_last_membership_activity_date", + store=True, + copy=False, + ) + + @api.depends("membership_activity_ids") + def _compute_membership_activity_count(self): + for project in self: + project.membership_activity_count = len(project.membership_activity_ids) + + @api.depends("membership_activity_ids") + def _compute_last_membership_activity_date(self): + for project in self: + project.last_membership_activity_date = ( + project.membership_activity_ids + and max(project.membership_activity_ids.mapped("date")) + ) + + def get_last_membership_activity_date_by_type(self, type_id_or_xml_id): + self.ensure_one() + activity_type_id = type_id_or_xml_id + if type(type_id_or_xml_id) == str: + activity_type_id = self.env.ref(type_id_or_xml_id).id + matching_activities = self.membership_activity_ids.filtered( + lambda a: a.type_id.id == activity_type_id + ).mapped("date") + if not matching_activities: + return datetime.min + return max(matching_activities) diff --git a/membership_activity/models/res_partner.py b/membership_activity/models/res_partner.py new file mode 100644 index 000000000..aa6c919c6 --- /dev/null +++ b/membership_activity/models/res_partner.py @@ -0,0 +1,42 @@ +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + membership_activity_ids = fields.One2many( + comodel_name="membership.activity", + inverse_name="partner_id", + string="Member Activities", + ) + membership_activity_count = fields.Integer( + string="# of Activities", + compute="_compute_membership_activity_count", + store=True, + ) + last_membership_activity_date = fields.Date( + string="Last Activity Date", + compute="_compute_last_membership_activity_date", + store=True, + copy=False, + ) + + @api.depends("membership_activity_ids") + def _compute_membership_activity_count(self): + for partner in self: + partner.membership_activity_count = len(partner.membership_activity_ids) + + @api.depends("membership_activity_ids") + def _compute_last_membership_activity_date(self): + for partner in self: + partner.last_membership_activity_date = ( + partner.membership_activity_ids + and max(partner.membership_activity_ids.mapped("date")) + ) + + def open_membership_activity(self): + action = self.env["ir.actions.act_window"]._for_xml_id( + "membership_activity.membership_activity_action" + ) + action["domain"] = [("partner_id", "in", self.ids)] + return action diff --git a/membership_activity/readme/CONFIGURE.rst b/membership_activity/readme/CONFIGURE.rst new file mode 100644 index 000000000..583ad0a4f --- /dev/null +++ b/membership_activity/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module, you need to: + +#. Go to *Members > Configuration > Activity Types*. +#. Create different activity types as you want for Membership Activity model. diff --git a/membership_activity/readme/CONTRIBUTORS.rst b/membership_activity/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..85125abb2 --- /dev/null +++ b/membership_activity/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* `Onestein `_ diff --git a/membership_activity/readme/DESCRIPTION.rst b/membership_activity/readme/DESCRIPTION.rst new file mode 100644 index 000000000..2042d38b9 --- /dev/null +++ b/membership_activity/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to track activities of members.This is a base module that allows to define some basic membership activities diff --git a/membership_activity/readme/USAGE.rst b/membership_activity/readme/USAGE.rst new file mode 100644 index 000000000..db7438d76 --- /dev/null +++ b/membership_activity/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, you need to: + +#. Create Activity Types as needed. +#. Create Membership Activities defining the project, activity type, date of activity and url(possibly defining url for commits,PRs etc). diff --git a/membership_activity/security/ir_model_access.xml b/membership_activity/security/ir_model_access.xml new file mode 100644 index 000000000..201d4b8d8 --- /dev/null +++ b/membership_activity/security/ir_model_access.xml @@ -0,0 +1,22 @@ + + + + membership_activity_access + + + + + + + + + + membership_activity_type_access + + + + + + + + diff --git a/membership_activity/static/description/index.html b/membership_activity/static/description/index.html new file mode 100644 index 000000000..62c0a3e62 --- /dev/null +++ b/membership_activity/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Membership Activity + + + +
+

Membership Activity

+ + +

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

+

This module allows to track activities of members.This is a base module that allows to define some basic membership activities

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to Members > Configuration > Activity Types.
  2. +
  3. Create different activity types as you want for Membership Activity model.
  4. +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Create Activity Types as needed.
  2. +
  3. Create Membership Activities defining the project, activity type, date of activity and url(possibly defining url for commits,PRs etc).
  4. +
+
+
+

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

+
    +
  • Onestein
  • +
+
+ +
+

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

+

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

+
+
+
+ + diff --git a/membership_activity/tests/__init__.py b/membership_activity/tests/__init__.py new file mode 100644 index 000000000..2c08f0010 --- /dev/null +++ b/membership_activity/tests/__init__.py @@ -0,0 +1 @@ +from . import test_membership_activity diff --git a/membership_activity/tests/test_membership_activity.py b/membership_activity/tests/test_membership_activity.py new file mode 100644 index 000000000..ee57a77e3 --- /dev/null +++ b/membership_activity/tests/test_membership_activity.py @@ -0,0 +1,45 @@ +# Copyright 2024 Onestein +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import datetime + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestMembershipActivity(TransactionCase): + def setUp(self): + super().setUp() + self.partner = self.env["res.partner"].create({"name": "Test Member"}) + self.project = self.env["project.project"].create({"name": "Test project"}) + self.membership_activity_type = self.env["membership.activity.type"].create( + {"name": "Testing"} + ) + self.membership_activity = self.env["membership.activity"].create( + { + "partner_id": self.partner.id, + "project_id": self.project.id, + "date": fields.Date.today(), + "type_id": self.membership_activity_type.id, + } + ) + + def test_name_get(self): + self.assertTrue(self.membership_activity.name_get()) + + def test_reconcile_partner(self): + self.membership_activity.partner_id = False + self.membership_activity.reconcile_partner() + + def test_get_last_membership_activity_date_by_type(self): + membership_activity = self.project.get_last_membership_activity_date_by_type( + False + ) + self.assertEqual(membership_activity, datetime.min) + membership_activity = self.project.get_last_membership_activity_date_by_type( + self.membership_activity_type.id + ) + self.assertEqual(membership_activity, self.membership_activity.date) + + def test_open_membership_activity(self): + action = self.partner.open_membership_activity() + self.assertEqual(action["domain"], [("partner_id", "in", self.partner.ids)]) diff --git a/membership_activity/views/membership_activity_type_view.xml b/membership_activity/views/membership_activity_type_view.xml new file mode 100644 index 000000000..41f2121a2 --- /dev/null +++ b/membership_activity/views/membership_activity_type_view.xml @@ -0,0 +1,34 @@ + + + + membership.activity.type + + + + + + + + + + membership.activity.type + +
+ + + + + + + +
+
+
+ + + Activity Types + ir.actions.act_window + membership.activity.type + tree,form + +
diff --git a/membership_activity/views/membership_activity_view.xml b/membership_activity/views/membership_activity_view.xml new file mode 100644 index 000000000..4d0e199e6 --- /dev/null +++ b/membership_activity/views/membership_activity_view.xml @@ -0,0 +1,103 @@ + + + + membership.activity + + + + + + + + + + + + + membership.activity + +
+ + + + + + + + + +
+
+
+ + + membership.activity + + + + + + + + + + membership.activity + + + + + + + + + + membership.activity + + + + + + + + + + + + + + + + + Activities + ir.actions.act_window + membership.activity + graph,pivot,tree,form + + + + + Reconcile Activity with Members + + + code + + records.reconcile_partner() + + +
diff --git a/membership_activity/views/res_partner_view.xml b/membership_activity/views/res_partner_view.xml new file mode 100644 index 000000000..82f3c8a79 --- /dev/null +++ b/membership_activity/views/res_partner_view.xml @@ -0,0 +1,47 @@ + + + + res.partner + + + + + + + + + + res.partner + + + + + + + + + + res.partner + + + + + + + + diff --git a/setup/membership_activity/odoo/addons/membership_activity b/setup/membership_activity/odoo/addons/membership_activity new file mode 120000 index 000000000..69fd5d0fb --- /dev/null +++ b/setup/membership_activity/odoo/addons/membership_activity @@ -0,0 +1 @@ +../../../../membership_activity \ No newline at end of file diff --git a/setup/membership_activity/setup.py b/setup/membership_activity/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/membership_activity/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)