diff --git a/beesdoo_easy_my_coop/__init__.py b/beesdoo_easy_my_coop/__init__.py index ada0b87be..e69de29bb 100644 --- a/beesdoo_easy_my_coop/__init__.py +++ b/beesdoo_easy_my_coop/__init__.py @@ -1,3 +0,0 @@ -from . import controllers -from . import models -from . import wizards diff --git a/beesdoo_easy_my_coop/__manifest__.py b/beesdoo_easy_my_coop/__manifest__.py index 81baa2a0e..f899c0a7d 100644 --- a/beesdoo_easy_my_coop/__manifest__.py +++ b/beesdoo_easy_my_coop/__manifest__.py @@ -6,23 +6,9 @@ "category": "Cooperative management", "version": "12.0.1.2.0", "depends": [ - "eater", - "beesdoo_shift", - "cooperator", - "cooperator_website", - "partner_contact_birthdate", - # fixme: the module itself does not depend on member_card, but its - # demo data and its tests do - "member_card", + "cooperator_worker", + "cooperator_eater", + "cooperator_info_session", ], - "data": [ - "views/res_company.xml", - "views/res_partner.xml", - "views/subscription_request.xml", - "views/subscription_templates.xml", - "views/product.xml", - ], - "demo": ["demo/product_share.xml"], - "auto_install": True, "license": "AGPL-3", } diff --git a/beesdoo_easy_my_coop/demo/product_share.xml b/beesdoo_easy_my_coop/demo/product_share.xml deleted file mode 100644 index 488310f89..000000000 --- a/beesdoo_easy_my_coop/demo/product_share.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - Acquisition de parts A de Beescoop scrl - share_a - - - - 3 - - - - Acquisition de parts B de Beescoop scrl - share_b - - - - 2 - - - - Acquisition de parts C de Beescoop scrl - share_c - - - - -1 - - - - - - - 2 - 2020-01-01 - - - - - - - share_a - - - - - 4 - 2020-01-01 - - - - - - - share_b - - - - - 6 - 2020-01-01 - - - - - - - share_c - - diff --git a/beesdoo_easy_my_coop/tests/__init__.py b/beesdoo_easy_my_coop/tests/__init__.py deleted file mode 100644 index d57d215f9..000000000 --- a/beesdoo_easy_my_coop/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import test_res_partner diff --git a/beesdoo_easy_my_coop/tests/test_res_partner.py b/beesdoo_easy_my_coop/tests/test_res_partner.py deleted file mode 100644 index 4d9c64154..000000000 --- a/beesdoo_easy_my_coop/tests/test_res_partner.py +++ /dev/null @@ -1,280 +0,0 @@ -# Copyright 2020 Coop IT Easy SC () -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from datetime import date - -from dateutil.relativedelta import relativedelta - -from odoo.exceptions import ValidationError -from odoo.tests.common import TransactionCase - - -class TestResPartner(TransactionCase): - def setUp(self): - super().setUp() - self.eater1 = self.env.ref("eater.eater1") - self.eater2 = self.env.ref("eater.eater2") - self.eater3 = self.env.ref("eater.eater3") - self.eater4 = self.env.ref("eater.eater4") - self.worker_share = self.env["product.template"].create( - { - "name": "Worker Share", - "is_share": True, - "eater": "worker_eater", - } - ) - self.eater_share = self.env["product.template"].create( - { - "name": "Eater Share", - "is_share": True, - "eater": "eater", - } - ) - - def test_max_eater_assignment_share_a(self): - """ - Test adding eater to a cooperator and raise when max is - reached. - """ - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - coop1.write({"child_eater_ids": [(4, self.eater1.id)]}) - self.assertEqual(len(coop1.child_eater_ids), 1) - coop1.write({"child_eater_ids": [(4, self.eater2.id)]}) - self.assertEqual(len(coop1.child_eater_ids), 2) - coop1.write({"child_eater_ids": [(4, self.eater3.id)]}) - self.assertEqual(len(coop1.child_eater_ids), 3) - with self.assertRaises(ValidationError) as econtext: - coop1.write({"child_eater_ids": [(4, self.eater4.id)]}) - self.assertIn("can only set", str(econtext.exception)) - # Reset - coop1.write({"child_eater_ids": [(5, None, None)]}) - self.assertEqual(len(coop1.child_eater_ids), 0) - # Test by editing parent_eater_id - self.eater1.write({"parent_eater_id": coop1.id}) - self.assertEqual(len(coop1.child_eater_ids), 1) - self.eater2.write({"parent_eater_id": coop1.id}) - self.assertEqual(len(coop1.child_eater_ids), 2) - self.eater3.write({"parent_eater_id": coop1.id}) - self.assertEqual(len(coop1.child_eater_ids), 3) - with self.assertRaises(ValidationError) as econtext: - self.eater4.write({"parent_eater_id": coop1.id}) - self.assertIn("can only set", str(econtext.exception)) - - def test_max_eater_assignment_share_b(self): - """ - Test adding eater to a cooperator and raise when max is - reached. - """ - coop2 = self.env.ref("member_card.res_partner_cooperator_2_demo") - coop2.write({"child_eater_ids": [(4, self.eater1.id)]}) - self.assertEqual(len(coop2.child_eater_ids), 1) - coop2.write({"child_eater_ids": [(4, self.eater2.id)]}) - self.assertEqual(len(coop2.child_eater_ids), 2) - with self.assertRaises(ValidationError) as econtext: - coop2.write({"child_eater_ids": [(4, self.eater3.id)]}) - self.assertIn("can only set", str(econtext.exception)) - # Reset - coop2.write({"child_eater_ids": [(5, None, None)]}) - self.assertEqual(len(coop2.child_eater_ids), 0) - # Test by editing parent_eater_id - self.eater1.write({"parent_eater_id": coop2.id}) - self.assertEqual(len(coop2.child_eater_ids), 1) - self.eater2.write({"parent_eater_id": coop2.id}) - self.assertEqual(len(coop2.child_eater_ids), 2) - with self.assertRaises(ValidationError) as econtext: - self.eater3.write({"parent_eater_id": coop2.id}) - self.assertIn("can only set", str(econtext.exception)) - - def test_unlimited_eater_assignment_share_c(self): - """ - Test that share_c can have an unlimited number of eater. - """ - coop3 = self.env.ref("member_card.res_partner_cooperator_3_demo") - coop3.write({"child_eater_ids": [(4, self.eater1.id)]}) - self.assertEqual(len(coop3.child_eater_ids), 1) - coop3.write({"child_eater_ids": [(4, self.eater2.id)]}) - self.assertEqual(len(coop3.child_eater_ids), 2) - coop3.write({"child_eater_ids": [(4, self.eater3.id)]}) - self.assertEqual(len(coop3.child_eater_ids), 3) - coop3.write({"child_eater_ids": [(4, self.eater4.id)]}) - self.assertEqual(len(coop3.child_eater_ids), 4) - - def test_share_with_no_eater_assignment_allowed(self): - """ - Test that share that doesn't allow eater assignment. - """ - share_c = self.env.ref("beesdoo_easy_my_coop.share_c") - share_c.max_nb_eater_allowed = 0 - coop3 = self.env.ref("member_card.res_partner_cooperator_3_demo") - with self.assertRaises(ValidationError) as econtext: - coop3.write({"child_eater_ids": [(4, self.eater3.id)]}) - self.assertIn("can only set", str(econtext.exception)) - with self.assertRaises(ValidationError) as econtext: - self.eater1.write({"parent_eater_id": coop3.id}) - self.assertIn("can only set", str(econtext.exception)) - - def test_multiple_eater_assignement_share_a(self): - """ - Test adding multiple eater in one write. - """ - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - coop1.write( - { - "child_eater_ids": [ - (4, self.eater1.id), - (4, self.eater2.id), - (4, self.eater3.id), - ] - } - ) - self.assertEqual(len(coop1.child_eater_ids), 3) - - def test_parent_assignement_to_eater(self): - """ - Test adding a parent to multiple eater in one write from the eater. - """ - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - eaters = self.eater1 - eaters |= self.eater2 - eaters |= self.eater3 - eaters.write({"parent_eater_id": coop1.id}) - self.assertEqual(len(coop1.child_eater_ids), 3) - - def test_is_worker_share_a(self): - """ - Test that a cooperator is a worker based on his share type. - """ - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - # Run computed field - coop1._compute_is_worker() - self.assertEqual(coop1.is_worker, True) - - def test_is_worker_share_b(self): - """ - Test that a cooperator is a worker based on his share type. - """ - coop2 = self.env.ref("member_card.res_partner_cooperator_2_demo") - # Run computed field - coop2._compute_is_worker() - self.assertEqual(coop2.is_worker, False) - - def test_search_worker(self): - """ - Test that the search function returns worker based on the - 'is_worker' field. - """ - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - coop2 = self.env.ref("member_card.res_partner_cooperator_2_demo") - # Run computed field - coop1._compute_is_worker() - coop2._compute_is_worker() - workers = self.env["res.partner"].search([("is_worker", "=", True)]) - self.assertIn(coop1, workers) - self.assertNotIn(coop2, workers) - workers = self.env["res.partner"].search([("is_worker", "=", False)]) - self.assertNotIn(coop1, workers) - self.assertIn(coop2, workers) - - def test_compute_can_shop_share_a(self): - """ - Test that a cooperator can shop based on his share type. - """ - # using self.env.ref("beesdoo_shift.res_partner_worker_1_demo") - # does not work because the is_worker field is overiden by - # beesdoo_easy_my_coop's `_compute_is_worker` - - coop1 = self.env.ref("member_card.res_partner_cooperator_1_demo") - coop1.cooperative_status_ids = self.env.ref( - "beesdoo_shift.cooperative_status_1_demo" - ) - # Run computed field - coop1._compute_can_shop() - self.assertEqual(coop1.can_shop, True) - # Now unsubscribe the coop - coop1.cooperative_status_ids.status = "resigning" - self.assertEqual(coop1.cooperative_status_ids.can_shop, False) - self.assertEqual(coop1.can_shop, False) - - def test_compute_can_shop_share_c(self): - """ - Test that a cooperator can shop based on his share type. - """ - coop3 = self.env.ref("member_card.res_partner_cooperator_3_demo") - # Run computed field - coop3._compute_can_shop() - self.assertEqual(coop3.can_shop, False) - - def test_get_eater_vals_returns_share_configuration(self): - partner = self.env["res.partner"].create( - { - "name": "Partner with birthdate set", - "birthdate_date": date.today() - relativedelta(years=30), - } - ) - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.worker_share - ) - self.assertEqual(vals["eater"], "worker_eater") - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.eater_share - ) - self.assertEqual(vals["eater"], "eater") - - def test_get_eater_vals_returns_worker_eater_for_unset_birthdate(self): - partner = self.env["res.partner"].create( - { - "name": "Partner without birthdate set", - } - ) - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.worker_share - ) - self.assertEqual(vals["eater"], "worker_eater") - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.eater_share - ) - self.assertEqual(vals["eater"], "eater") - - def test_get_eater_vals_returns_eater_for_youngsters(self): - partner = self.env["res.partner"].create( - { - "name": "Young Partner", - "birthdate_date": date.today() - relativedelta(years=15), - } - ) - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.worker_share - ) - self.assertEqual(vals["eater"], "eater") - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.eater_share - ) - self.assertEqual(vals["eater"], "eater") - - def test_get_eater_vals_returns_eater_for_newborns(self): - """ - Test that get_eater_vals() work correctly when the partner is 0 years - old. - """ - partner = self.env["res.partner"].create( - { - "name": "Newborn Partner", - "birthdate_date": date.today() - relativedelta(days=180), - } - ) - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.worker_share - ) - self.assertEqual(vals["eater"], "eater") - - vals = self.env["subscription.request"].get_eater_vals( - partner, self.eater_share - ) - self.assertEqual(vals["eater"], "eater") diff --git a/cooperator_eater/README.rst b/cooperator_eater/README.rst new file mode 100644 index 000000000..7180f3044 --- /dev/null +++ b/cooperator_eater/README.rst @@ -0,0 +1,59 @@ +=============================== +Beescoop link with easy my coop +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-beescoop%2Fobeesdoo-lightgray.png?logo=github + :target: https://github.com/beescoop/obeesdoo/tree/12.0/beesdoo_easy_my_coop + :alt: beescoop/obeesdoo + +|badge1| |badge2| |badge3| + +Link between beesdoo customization and easy_my_coop + +**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 +~~~~~~~ + +* BEES coop +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* BEES coop +* Coop IT Easy SC + +Maintainers +~~~~~~~~~~~ + +This module is part of the `beescoop/obeesdoo `_ project on GitHub. + +You are welcome to contribute. diff --git a/cooperator_eater/__init__.py b/cooperator_eater/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/cooperator_eater/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/cooperator_eater/__manifest__.py b/cooperator_eater/__manifest__.py new file mode 100644 index 000000000..f7b31a9cc --- /dev/null +++ b/cooperator_eater/__manifest__.py @@ -0,0 +1,19 @@ +{ + "name": "Cooperator Eater Configuration", + "summary": """Eater configuration based on Share product""", + "author": "BEES coop, Coop IT Easy SC", + "website": "https://github.com/beescoop/Obeesdoo", + "category": "Cooperative management", + "version": "12.0.1.0.2", + "depends": [ + "eater", + "cooperator", + "partner_contact_birthdate", + "cooperator_worker", + ], + "data": [ + "views/product_template_views.xml", + ], + "demo": ["demo/product_share.xml"], + "license": "AGPL-3", +} diff --git a/cooperator_eater/demo/product_share.xml b/cooperator_eater/demo/product_share.xml new file mode 100644 index 000000000..d1fe936ea --- /dev/null +++ b/cooperator_eater/demo/product_share.xml @@ -0,0 +1,14 @@ + + + + + 3 + + + 2 + + + -1 + + + diff --git a/cooperator_eater/i18n/cooperator_eater_configuration.pot b/cooperator_eater/i18n/cooperator_eater_configuration.pot new file mode 100644 index 000000000..12cb2b2e9 --- /dev/null +++ b/cooperator_eater/i18n/cooperator_eater_configuration.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cooperator_eater_configuration +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: cooperator_eater_configuration +#: model:ir.model,name:cooperator_eater_configuration.model_res_partner +msgid "Contact" +msgstr "" + +#. module: cooperator_eater_configuration +#: model:ir.model,name:cooperator_eater_configuration.model_product_template +msgid "Product Template" +msgstr "" + +#. module: cooperator_eater_configuration +#: model:ir.model,name:cooperator_eater_configuration.model_subscription_request +msgid "Subscription Request" +msgstr "" + diff --git a/beesdoo_easy_my_coop/models/__init__.py b/cooperator_eater/models/__init__.py similarity index 77% rename from beesdoo_easy_my_coop/models/__init__.py rename to cooperator_eater/models/__init__.py index 20c4ac16b..3be512244 100644 --- a/beesdoo_easy_my_coop/models/__init__.py +++ b/cooperator_eater/models/__init__.py @@ -1,4 +1,3 @@ from . import product_template -from . import res_company from . import res_partner from . import subscription_request diff --git a/beesdoo_easy_my_coop/models/product_template.py b/cooperator_eater/models/product_template.py similarity index 58% rename from beesdoo_easy_my_coop/models/product_template.py rename to cooperator_eater/models/product_template.py index 9b9ca57e4..38a03d8e2 100644 --- a/beesdoo_easy_my_coop/models/product_template.py +++ b/cooperator_eater/models/product_template.py @@ -12,17 +12,6 @@ class ProductTemplate(models.Model): "A negative value means no maximum." ), ) - allow_working = fields.Boolean( - string="Allow owner to work?", - help=( - "Owner of this type of share are allowed to participate to the " - "shift system." - ), - ) - allow_shopping = fields.Boolean( - string="Allow owner to shop?", - help="Owner of this type of share are allowed to shop.", - ) eater = fields.Selection( [("eater", "Eater"), ("worker_eater", "Worker and Eater")], string="Eater/Worker", diff --git a/cooperator_eater/models/res_partner.py b/cooperator_eater/models/res_partner.py new file mode 100644 index 000000000..af4fde973 --- /dev/null +++ b/cooperator_eater/models/res_partner.py @@ -0,0 +1,58 @@ +# Copyright 2019-2020 Coop IT Easy SC +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class Partner(models.Model): + _inherit = "res.partner" + + def _check_number_of_eaters(self): + """ + This function has been splitted into two functions: + - _check_max_parent_eaters() + - _check_max_child_eaters() + The purpose of this function is to overwrite the function + defined in beesdoo_base/models/partner.py. + """ + + @api.constrains("parent_eater_id") + def _check_max_parent_eaters(self): + """ + Check that the parent_eater_id in partner in self doesn't exceed + the maximum eater limit. + See also: _check_max_child_eaters() + """ + for rec in self: + if rec.parent_eater_id: + share_type = rec.parent_eater_id._cooperator_share_type() + if ( + share_type + and share_type.max_nb_eater_allowed >= 0 + and len(rec.parent_eater_id.child_eater_ids) + > share_type.max_nb_eater_allowed + ): + raise ValidationError( + _("You can only set %d additional eaters per worker") + % share_type.max_nb_eater_allowed + ) + + @api.constrains("child_eater_ids") + def _check_max_child_eaters(self): + """ + Check the maximum number of eaters that can be assigned to a + share owner. + See also: _check_max_parent_eaters() + """ + for rec in self: + share_type = rec._cooperator_share_type() + if ( + share_type + and share_type.max_nb_eater_allowed >= 0 + and len(rec.child_eater_ids) > share_type.max_nb_eater_allowed + ): + raise ValidationError( + _("You can only set %d additional eaters per worker") + % share_type.max_nb_eater_allowed + ) diff --git a/cooperator_eater/models/subscription_request.py b/cooperator_eater/models/subscription_request.py new file mode 100644 index 000000000..5282bcf9e --- /dev/null +++ b/cooperator_eater/models/subscription_request.py @@ -0,0 +1,29 @@ +from odoo import api, models + +_MAJORITY = 18 + + +class SubscriptionRequest(models.Model): + _inherit = "subscription.request" + + def get_eater_vals(self, partner, share_product_id): + eater = share_product_id.eater + + # if birthdate_date is not set, age is 0 and lower than _MAJORITY + # in that case, the configuration coming from the share product is kept + if partner.is_company or (partner.birthdate_date and partner.age < _MAJORITY): + eater = "eater" + + return {"eater": eater} + + @api.multi + def validate_subscription_request(self): + self.ensure_one() + + invoice = super().validate_subscription_request()[0] + partner = invoice.partner_id + + vals = self.get_eater_vals(partner, self.share_product_id) + partner.write(vals) + + return invoice diff --git a/cooperator_eater/readme/CONTRIBUTORS.rst b/cooperator_eater/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..cd83b682f --- /dev/null +++ b/cooperator_eater/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* BEES coop +* Coop IT Easy SC diff --git a/cooperator_eater/readme/DESCRIPTION.rst b/cooperator_eater/readme/DESCRIPTION.rst new file mode 100644 index 000000000..2cd516915 --- /dev/null +++ b/cooperator_eater/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +- Overwrite validation of subscription request to get eaters information +- Add constraint on eaters based on share configuration +- Add eater configuration on share product diff --git a/cooperator_eater/static/description/index.html b/cooperator_eater/static/description/index.html new file mode 100644 index 000000000..db3bace56 --- /dev/null +++ b/cooperator_eater/static/description/index.html @@ -0,0 +1,416 @@ + + + + + + +Beescoop link with easy my coop + + + + + + diff --git a/cooperator_eater/tests/__init__.py b/cooperator_eater/tests/__init__.py new file mode 100644 index 000000000..9037a9bd6 --- /dev/null +++ b/cooperator_eater/tests/__init__.py @@ -0,0 +1 @@ +from . import test_eaters diff --git a/cooperator_eater/tests/test_eaters.py b/cooperator_eater/tests/test_eaters.py new file mode 100644 index 000000000..93498adbe --- /dev/null +++ b/cooperator_eater/tests/test_eaters.py @@ -0,0 +1,191 @@ +# Copyright 2020 Coop IT Easy SC () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from datetime import date + +from dateutil.relativedelta import relativedelta + +from odoo.exceptions import ValidationError + +from odoo.addons.cooperator_worker.tests.test_base import TestWorkerBase + + +class TestEaters(TestWorkerBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + partner_obj = cls.env["res.partner"] + ptemplate_obj = cls.env["product.template"] + + cls.eater_1 = partner_obj.create( + {"name": "Eater 1", "customer": True, "eater": "eater"} + ) + cls.eater_2 = partner_obj.create( + {"name": "Eater 2", "customer": True, "eater": "eater"} + ) + cls.eater_3 = partner_obj.create( + {"name": "Eater 3", "customer": True, "eater": "eater"} + ) + cls.eater_4 = partner_obj.create( + {"name": "Eater 4", "customer": True, "eater": "eater"} + ) + + cls.worker_share = ptemplate_obj.create( + { + "name": "Worker Share", + "is_share": True, + "eater": "worker_eater", + } + ) + cls.eater_share = ptemplate_obj.create( + { + "name": "Eater Share", + "is_share": True, + "eater": "eater", + } + ) + + def test_max_eater_assignment_to_positive_integer(self): + """ + Test adding eater to a cooperator and raise when max is + reached. + """ + self.share_x.max_nb_eater_allowed = 3 + self.cooperator_x.write( + { + "child_eater_ids": [ + (6, 0, [self.eater_1.id, self.eater_2.id, self.eater_3.id]) + ] + } + ) + self.assertEqual(len(self.cooperator_x.child_eater_ids), 3) + + max_eater_error_msg = "You can only set 3 additional eaters per worker" + with self.assertRaisesRegex(ValidationError, max_eater_error_msg): + self.cooperator_x.write({"child_eater_ids": [(4, self.eater_4.id)]}) + + # Reset + self.cooperator_x.write({"child_eater_ids": [(5, None, None)]}) + self.assertEqual(len(self.cooperator_x.child_eater_ids), 0) + # Test by editing parent_eater_id + self.eater_1.parent_eater_id = self.cooperator_x.id + self.eater_2.parent_eater_id = self.cooperator_x.id + self.eater_3.parent_eater_id = self.cooperator_x.id + self.assertEqual(len(self.cooperator_x.child_eater_ids), 3) + + with self.assertRaisesRegex(ValidationError, max_eater_error_msg): + self.eater_4.write({"parent_eater_id": self.cooperator_x.id}) + + def test_unlimited_eater_assignment(self): + """ + Test that can have an unlimited number of eater. + """ + self.share_y.max_nb_eater_allowed = -1 + self.cooperator_y.write( + { + "child_eater_ids": [ + ( + 6, + 0, + [ + self.eater_1.id, + self.eater_2.id, + self.eater_3.id, + self.eater_4.id, + ], + ) + ] + } + ) + self.assertEqual(len(self.cooperator_y.child_eater_ids), 4) + + def test_share_with_no_eater_assignment_allowed(self): + """ + Test that share that doesn't allow eater assignment. + """ + self.share_z.max_nb_eater_allowed = 0 + + max_eater_error_msg = "You can only set 0 additional eaters per worker" + with self.assertRaisesRegex(ValidationError, max_eater_error_msg): + self.cooperator_z.write({"child_eater_ids": [(4, self.eater_1.id)]}) + + with self.assertRaisesRegex(ValidationError, max_eater_error_msg): + self.eater_1.write({"parent_eater_id": self.cooperator_z.id}) + + def test_get_eater_vals_returns_share_zonfiguration(self): + partner = self.env["res.partner"].create( + { + "name": "Partner with birthdate set", + "birthdate_date": date.today() - relativedelta(years=30), + } + ) + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.worker_share + ) + self.assertEqual(vals["eater"], "worker_eater") + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.eater_share + ) + self.assertEqual(vals["eater"], "eater") + + def test_get_eater_vals_returns_worker_eater_for_unset_birthdate(self): + partner = self.env["res.partner"].create( + { + "name": "Partner without birthdate set", + } + ) + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.worker_share + ) + self.assertEqual(vals["eater"], "worker_eater") + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.eater_share + ) + self.assertEqual(vals["eater"], "eater") + + def test_get_eater_vals_returns_eater_for_youngsters(self): + partner = self.env["res.partner"].create( + { + "name": "Young Partner", + "birthdate_date": date.today() - relativedelta(years=15), + } + ) + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.worker_share + ) + self.assertEqual(vals["eater"], "eater") + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.eater_share + ) + self.assertEqual(vals["eater"], "eater") + + def test_get_eater_vals_returns_eater_for_newborns(self): + """ + Test that get_eater_vals() work correctly when the partner is 0 years + old. + """ + partner = self.env["res.partner"].create( + { + "name": "Newborn Partner", + "birthdate_date": date.today() - relativedelta(days=180), + } + ) + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.worker_share + ) + self.assertEqual(vals["eater"], "eater") + + vals = self.env["subscription.request"].get_eater_vals( + partner, self.eater_share + ) + self.assertEqual(vals["eater"], "eater") diff --git a/beesdoo_easy_my_coop/views/product.xml b/cooperator_eater/views/product_template_views.xml similarity index 72% rename from beesdoo_easy_my_coop/views/product.xml rename to cooperator_eater/views/product_template_views.xml index 8714fdbb2..2b97a92d8 100644 --- a/beesdoo_easy_my_coop/views/product.xml +++ b/cooperator_eater/views/product_template_views.xml @@ -6,14 +6,6 @@ - - `_. +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 +~~~~~~~ + +* BEES coop +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* BEES coop +* Coop IT Easy SC + +Maintainers +~~~~~~~~~~~ + +This module is part of the `beescoop/obeesdoo `_ project on GitHub. + +You are welcome to contribute. diff --git a/cooperator_info_session/__init__.py b/cooperator_info_session/__init__.py new file mode 100644 index 000000000..ada0b87be --- /dev/null +++ b/cooperator_info_session/__init__.py @@ -0,0 +1,3 @@ +from . import controllers +from . import models +from . import wizards diff --git a/cooperator_info_session/__manifest__.py b/cooperator_info_session/__manifest__.py new file mode 100644 index 000000000..dc52a8cfd --- /dev/null +++ b/cooperator_info_session/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "Cooperator Info Session", + "summary": """Info session for getting share""", + "author": "BEES coop, Coop IT Easy SC", + "website": "https://github.com/beescoop/Obeesdoo", + "category": "Cooperative management", + "version": "12.0.1.0.2", + "depends": [ + "beesdoo_shift", + "cooperator", + "cooperator_website", + ], + "data": [ + "views/res_company.xml", + "views/res_partner.xml", + "views/subscription_request.xml", + "views/subscription_templates.xml", + ], + "license": "AGPL-3", +} diff --git a/beesdoo_easy_my_coop/controllers/__init__.py b/cooperator_info_session/controllers/__init__.py similarity index 100% rename from beesdoo_easy_my_coop/controllers/__init__.py rename to cooperator_info_session/controllers/__init__.py diff --git a/beesdoo_easy_my_coop/controllers/main.py b/cooperator_info_session/controllers/main.py similarity index 100% rename from beesdoo_easy_my_coop/controllers/main.py rename to cooperator_info_session/controllers/main.py diff --git a/cooperator_info_session/models/__init__.py b/cooperator_info_session/models/__init__.py new file mode 100644 index 000000000..39aa04d5d --- /dev/null +++ b/cooperator_info_session/models/__init__.py @@ -0,0 +1,3 @@ +from . import res_company +from . import res_partner +from . import subscription_request diff --git a/beesdoo_easy_my_coop/models/res_company.py b/cooperator_info_session/models/res_company.py similarity index 95% rename from beesdoo_easy_my_coop/models/res_company.py rename to cooperator_info_session/models/res_company.py index c95907c09..5aaa5a9b9 100644 --- a/beesdoo_easy_my_coop/models/res_company.py +++ b/cooperator_info_session/models/res_company.py @@ -20,7 +20,7 @@ class ResCompany(models.Model): ) @api.onchange("info_session_confirmation_required") - def onchange_info_session_confirmatio_required(self): + def onchange_info_session_confirmation_required(self): if self.info_session_confirmation_required: self.display_info_session_confirmation = True diff --git a/cooperator_info_session/models/res_partner.py b/cooperator_info_session/models/res_partner.py new file mode 100644 index 000000000..41523c494 --- /dev/null +++ b/cooperator_info_session/models/res_partner.py @@ -0,0 +1,12 @@ +# Copyright 2019-2020 Coop IT Easy SC +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Partner(models.Model): + _inherit = "res.partner" + + info_session_confirmed = fields.Boolean( + string="Confirmed presence to info session", default=False + ) diff --git a/beesdoo_easy_my_coop/models/subscription_request.py b/cooperator_info_session/models/subscription_request.py similarity index 52% rename from beesdoo_easy_my_coop/models/subscription_request.py rename to cooperator_info_session/models/subscription_request.py index 10fc000a9..ef20dabd4 100644 --- a/beesdoo_easy_my_coop/models/subscription_request.py +++ b/cooperator_info_session/models/subscription_request.py @@ -1,9 +1,7 @@ # Copyright 2019 Coop IT Easy SC # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models - -_MAJORITY = 18 +from odoo import fields, models class SubscriptionRequest(models.Model): @@ -24,25 +22,3 @@ def get_required_field(self): if company.info_session_confirmation_required: required_fields.append("info_session_confirmed") return required_fields - - def get_eater_vals(self, partner, share_product_id): - eater = share_product_id.eater - - # if birthdate_date is not set, age is 0 and lower than _MAJORITY - # in that case, the configuration coming from the share product is kept - if partner.is_company or (partner.birthdate_date and partner.age < _MAJORITY): - eater = "eater" - - return {"eater": eater} - - @api.multi - def validate_subscription_request(self): - self.ensure_one() - - invoice = super().validate_subscription_request()[0] - partner = invoice.partner_id - - vals = self.get_eater_vals(partner, self.share_product_id) - partner.write(vals) - - return invoice diff --git a/cooperator_info_session/readme/CONTRIBUTORS.rst b/cooperator_info_session/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..cd83b682f --- /dev/null +++ b/cooperator_info_session/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* BEES coop +* Coop IT Easy SC diff --git a/cooperator_info_session/readme/DESCRIPTION.rst b/cooperator_info_session/readme/DESCRIPTION.rst new file mode 100644 index 000000000..e6943c594 --- /dev/null +++ b/cooperator_info_session/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +Configuration for info session on website form for getting a cooperator share : + +- info session description and fields on the online form +- add info session text description on the company +- set if the attending an info session is required on the company diff --git a/cooperator_info_session/static/description/index.html b/cooperator_info_session/static/description/index.html new file mode 100644 index 000000000..db3bace56 --- /dev/null +++ b/cooperator_info_session/static/description/index.html @@ -0,0 +1,416 @@ + + + + + + +Beescoop link with easy my coop + + + + + + diff --git a/beesdoo_easy_my_coop/views/res_company.xml b/cooperator_info_session/views/res_company.xml similarity index 100% rename from beesdoo_easy_my_coop/views/res_company.xml rename to cooperator_info_session/views/res_company.xml diff --git a/beesdoo_easy_my_coop/views/res_partner.xml b/cooperator_info_session/views/res_partner.xml similarity index 100% rename from beesdoo_easy_my_coop/views/res_partner.xml rename to cooperator_info_session/views/res_partner.xml diff --git a/beesdoo_easy_my_coop/views/subscription_request.xml b/cooperator_info_session/views/subscription_request.xml similarity index 100% rename from beesdoo_easy_my_coop/views/subscription_request.xml rename to cooperator_info_session/views/subscription_request.xml diff --git a/beesdoo_easy_my_coop/views/subscription_templates.xml b/cooperator_info_session/views/subscription_templates.xml similarity index 91% rename from beesdoo_easy_my_coop/views/subscription_templates.xml rename to cooperator_info_session/views/subscription_templates.xml index 10e981bc5..ea6081656 100644 --- a/beesdoo_easy_my_coop/views/subscription_templates.xml +++ b/cooperator_info_session/views/subscription_templates.xml @@ -4,8 +4,8 @@