From c50de6c99178bd8ef091b1e37d30f770a0bc3007 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Wed, 21 Sep 2022 16:33:03 +0200 Subject: [PATCH] [ADD] membership_custom_date This module is needed for memberships that have a custom date range for every individual. The normal workflow when clicking on 'Buy Membership' does not involve specifying the start and end dates. Rather, those dates are calculated from the membership product. This calculation happens _after_ clicking on 'Invoice Membership' in the wizard UI. If we want to include the dates in the wizard UI, we disrupt this workflow, and override the default behaviour of using the dates configured in the membership product. We circumvent this by only breaking the workflow for membership products of type 'custom', which would be expected. We keep the workflow for other types. An alternative method is to calculate the dates from the product selected in the wizard (onchange), but this is UX-wise incompatible with the a downstream (non-OCA) requirement that the dates be changed to the dates specified on another model (also onchange). So depending on which field you changed last (product or project); that's the dates you get. This is strange and unexpected behaviour. Signed-off-by: Carmen Bianca BAKKER --- membership_custom_date/README.rst | 87 ++++ membership_custom_date/__init__.py | 6 + membership_custom_date/__manifest__.py | 27 ++ membership_custom_date/i18n/fr.po | 51 +++ .../i18n/membership_custom_date.pot | 24 + membership_custom_date/models/__init__.py | 5 + .../models/product_template.py | 23 + .../readme/CONTRIBUTORS.rst | 3 + membership_custom_date/readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 427 ++++++++++++++++++ membership_custom_date/wizard/__init__.py | 5 + .../wizard/membership_invoice.py | 34 ++ .../wizard/membership_invoice_views.xml | 21 + .../odoo/addons/membership_custom_date | 1 + setup/membership_custom_date/setup.py | 6 + 15 files changed, 722 insertions(+) create mode 100644 membership_custom_date/README.rst create mode 100644 membership_custom_date/__init__.py create mode 100644 membership_custom_date/__manifest__.py create mode 100644 membership_custom_date/i18n/fr.po create mode 100644 membership_custom_date/i18n/membership_custom_date.pot create mode 100644 membership_custom_date/models/__init__.py create mode 100644 membership_custom_date/models/product_template.py create mode 100644 membership_custom_date/readme/CONTRIBUTORS.rst create mode 100644 membership_custom_date/readme/DESCRIPTION.rst create mode 100644 membership_custom_date/static/description/index.html create mode 100644 membership_custom_date/wizard/__init__.py create mode 100644 membership_custom_date/wizard/membership_invoice.py create mode 100644 membership_custom_date/wizard/membership_invoice_views.xml create mode 120000 setup/membership_custom_date/odoo/addons/membership_custom_date create mode 100644 setup/membership_custom_date/setup.py diff --git a/membership_custom_date/README.rst b/membership_custom_date/README.rst new file mode 100644 index 000000000..4f44a2084 --- /dev/null +++ b/membership_custom_date/README.rst @@ -0,0 +1,87 @@ +=========================== +Custom date for memberships +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1408ca166babe4521d36b67e7ebf366a2d53122b83aec7ca454397aed5a3163d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_custom_date + :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_custom_date + :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| + +Memberships with custom dates have their dates specified on a +subscription-by-subscription basis. + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Coop IT Easy SC `_: + + * Carmen Bianca Bakker + +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. + +.. |maintainer-carmenbianca| image:: https://github.com/carmenbianca.png?size=40px + :target: https://github.com/carmenbianca + :alt: carmenbianca + +Current `maintainer `__: + +|maintainer-carmenbianca| + +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_custom_date/__init__.py b/membership_custom_date/__init__.py new file mode 100644 index 000000000..7bf9c9c03 --- /dev/null +++ b/membership_custom_date/__init__.py @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import models +from . import wizard diff --git a/membership_custom_date/__manifest__.py b/membership_custom_date/__manifest__.py new file mode 100644 index 000000000..31e832541 --- /dev/null +++ b/membership_custom_date/__manifest__.py @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Custom date for memberships", + "summary": """ + Memberships with custom dates have their dates specified on a + subscription-by-subscription basis.""", + "version": "16.0.1.0.0", + "category": "Association", + "website": "https://github.com/OCA/vertical-association", + "author": "Coop IT Easy SC, Odoo Community Association (OCA)", + "maintainers": ["carmenbianca"], + "license": "AGPL-3", + "application": False, + "depends": [ + "membership_extension", + "membership_type", + ], + "excludes": [], + "data": [ + "wizard/membership_invoice_views.xml", + ], + "demo": [], + "qweb": [], +} diff --git a/membership_custom_date/i18n/fr.po b/membership_custom_date/i18n/fr.po new file mode 100644 index 000000000..501bcfe66 --- /dev/null +++ b/membership_custom_date/i18n/fr.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * membership_custom_date +# Carmen Bianca Bakker , 2022. +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0beta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2022-10-04 14:34+0200\n" +"Last-Translator: Carmen Bianca Bakker \n" +"Language-Team: French \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: Poedit 3.0.1\n" + +#. module: membership_custom_date +#: model:ir.model.fields.selection,name:membership_custom_date.selection__product_template__membership_type__custom +msgid "Custom dates" +msgstr "Dates personnalisées" + +#. module: membership_custom_date +#: model:ir.model.fields,field_description:membership_custom_date.field_membership_invoice__date_to +msgid "End Date" +msgstr "Date de fin" + +#. module: membership_custom_date +#: model:ir.model,name:membership_custom_date.model_membership_invoice +msgid "Membership Invoice" +msgstr "Facture d'adhésion" + +#. module: membership_custom_date +#: model:ir.model.fields,field_description:membership_custom_date.field_membership_invoice__product_id_type +#: model:ir.model.fields,field_description:membership_custom_date.field_product_product__membership_type +#: model:ir.model.fields,field_description:membership_custom_date.field_product_template__membership_type +msgid "Membership Type" +msgstr "Type d'adhésion" + +#. module: membership_custom_date +#: model:ir.model,name:membership_custom_date.model_product_template +msgid "Product" +msgstr "Produit" + +#. module: membership_custom_date +#: model:ir.model.fields,field_description:membership_custom_date.field_membership_invoice__date_from +msgid "Start Date" +msgstr "Date de début" diff --git a/membership_custom_date/i18n/membership_custom_date.pot b/membership_custom_date/i18n/membership_custom_date.pot new file mode 100644 index 000000000..39e295435 --- /dev/null +++ b/membership_custom_date/i18n/membership_custom_date.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * membership_custom_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: membership_custom_date +#: model:ir.model,name:membership_custom_date.model_membership_invoice +msgid "Membership Invoice" +msgstr "" + +#. module: membership_custom_date +#: model:ir.model,name:membership_custom_date.model_product_template +msgid "Product" +msgstr "" diff --git a/membership_custom_date/models/__init__.py b/membership_custom_date/models/__init__.py new file mode 100644 index 000000000..8afbbed9b --- /dev/null +++ b/membership_custom_date/models/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import product_template diff --git a/membership_custom_date/models/product_template.py b/membership_custom_date/models/product_template.py new file mode 100644 index 000000000..41edd977f --- /dev/null +++ b/membership_custom_date/models/product_template.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + membership_type = fields.Selection( + selection_add=[ + ("custom", "Custom dates"), + ], + ondelete={"custom": "set default"}, + ) + + @api.model + def _correct_vals_membership_type(self, vals): + vals = super()._correct_vals_membership_type(vals) + if vals.get("membership_type") == "custom": + vals["membership_date_from"] = vals["membership_date_to"] = False + return vals diff --git a/membership_custom_date/readme/CONTRIBUTORS.rst b/membership_custom_date/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..d64451edc --- /dev/null +++ b/membership_custom_date/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SC `_: + + * Carmen Bianca Bakker diff --git a/membership_custom_date/readme/DESCRIPTION.rst b/membership_custom_date/readme/DESCRIPTION.rst new file mode 100644 index 000000000..79abf42f8 --- /dev/null +++ b/membership_custom_date/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Memberships with custom dates have their dates specified on a +subscription-by-subscription basis. diff --git a/membership_custom_date/static/description/index.html b/membership_custom_date/static/description/index.html new file mode 100644 index 000000000..39da68088 --- /dev/null +++ b/membership_custom_date/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +Custom date for memberships + + + +
+

Custom date for memberships

+ + +

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

+

Memberships with custom dates have their dates specified on a +subscription-by-subscription basis.

+

Table of contents

+ +
+

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

+
    +
  • Coop IT Easy SC
  • +
+
+
+

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.

+

Current maintainer:

+

carmenbianca

+

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_custom_date/wizard/__init__.py b/membership_custom_date/wizard/__init__.py new file mode 100644 index 000000000..ce5e00bd4 --- /dev/null +++ b/membership_custom_date/wizard/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import membership_invoice diff --git a/membership_custom_date/wizard/membership_invoice.py b/membership_custom_date/wizard/membership_invoice.py new file mode 100644 index 000000000..e49ec1fc9 --- /dev/null +++ b/membership_custom_date/wizard/membership_invoice.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import fields, models + + +class MembershipInvoice(models.TransientModel): + _inherit = "membership.invoice" + + date_from = fields.Date(string="Start Date", default=fields.Datetime.now) + date_to = fields.Date(string="End Date") + + product_id_type = fields.Selection( + string="Membership Type", + related="product_id.membership_type", + ) + + def membership_invoice(self): + res = super().membership_invoice() + + account_moves = self.env["account.move"].search(res["domain"]) + membership_lines = account_moves.mapped( + "invoice_line_ids.membership_lines" + ).filtered(lambda line: line.membership_id.membership_type == "custom") + + membership_lines.write( + { + "date_from": self.date_from, + "date_to": self.date_to, + } + ) + + return res diff --git a/membership_custom_date/wizard/membership_invoice_views.xml b/membership_custom_date/wizard/membership_invoice_views.xml new file mode 100644 index 000000000..7cfae3c74 --- /dev/null +++ b/membership_custom_date/wizard/membership_invoice_views.xml @@ -0,0 +1,21 @@ + + + + membership.invoice.view.form + membership.invoice + + + + + + + + + + diff --git a/setup/membership_custom_date/odoo/addons/membership_custom_date b/setup/membership_custom_date/odoo/addons/membership_custom_date new file mode 120000 index 000000000..a081e479e --- /dev/null +++ b/setup/membership_custom_date/odoo/addons/membership_custom_date @@ -0,0 +1 @@ +../../../../membership_custom_date \ No newline at end of file diff --git a/setup/membership_custom_date/setup.py b/setup/membership_custom_date/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/membership_custom_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)