diff --git a/partner_tier_validation/README.rst b/partner_tier_validation/README.rst new file mode 100644 index 00000000000..3d4b19e9da1 --- /dev/null +++ b/partner_tier_validation/README.rst @@ -0,0 +1,130 @@ +======================= +Partner Tier Validation +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/16.0/partner_tier_validation + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_tier_validation + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/partner-contact&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adds an approval workflow to Partners. +The default rule requires new company Contacts to be approved +before they can be used. + +The rule can be extended to new non-company contact, +but beware that may cause issues with automatically created new contacts, +such as the ones generated when processing incoming emails. + +If the 'Is Company' or 'Parent' field changes then the contact is Request +for approval. + +For this, the new Contact record is kept as "Archived" until it is approved. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on ``base_tier_validation``. You can find it at +`OCA/server-ux `_ + +Usage +===== + +Before using, check Contact Stages configuration, +to ensure that the default stage has the "Related State" field +set to "To Approve". +For example, having the "Draft" stage the default ensures this. + +A regular user creates a new Contact and sends it for approval: + +#. Create a Contact triggering at least one "Tier Definition". + The Contact will be in Draft state and marked as Archived until approved. +#. Click on *Request Validation* button. +#. In the *Reviews* section, at the bottom of the form, inspect the pending reviews and their status. + + +The approver reviews Contacts to approve: + +#. Navigate to the Contacts app, and select the filter "Needs my Approval" +#. Open the Contact form to approve. It will display a + "This Records needs to be validated" banner, with "Validate" and "Reject" options. +#. The approver can change the state to "Active". + This will automatically unarchive the record and make it available to be used. + + +The Approve/Reject actions do not automatically change the State. +This could be a future improvement. + +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 +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* `Open Source Integrators `_. + + * Antonio Yamuta + * Daniel Reis + * Urvisha Desai + +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-dreispt| image:: https://github.com/dreispt.png?size=40px + :target: https://github.com/dreispt + :alt: dreispt + +Current `maintainer `__: + +|maintainer-dreispt| + +This module is part of the `OCA/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_tier_validation/__init__.py b/partner_tier_validation/__init__.py new file mode 100644 index 00000000000..3275ac2adf3 --- /dev/null +++ b/partner_tier_validation/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/partner_tier_validation/__manifest__.py b/partner_tier_validation/__manifest__.py new file mode 100644 index 00000000000..d242d20626b --- /dev/null +++ b/partner_tier_validation/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Partner Tier Validation", + "summary": "Support a tier validation process for Contacts", + "version": "16.0.1.0.0", + "website": "https://github.com/OCA/partner-contact", + "category": "Contact", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["contacts", "base_tier_validation", "partner_stage"], + "data": [ + "data/tier_definition.xml", + "views/res_partner_view.xml", + ], + "maintainers": ["dreispt"], +} diff --git a/partner_tier_validation/data/tier_definition.xml b/partner_tier_validation/data/tier_definition.xml new file mode 100644 index 00000000000..c46c0e54adc --- /dev/null +++ b/partner_tier_validation/data/tier_definition.xml @@ -0,0 +1,11 @@ + + + Validate New Company + + group + + domain + + [["is_company","=",True]] + + diff --git a/partner_tier_validation/i18n/partner_tier_validation.pot b/partner_tier_validation/i18n/partner_tier_validation.pot new file mode 100644 index 00000000000..47604053c3e --- /dev/null +++ b/partner_tier_validation/i18n/partner_tier_validation.pot @@ -0,0 +1,112 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_tier_validation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__can_review +msgid "Can Review" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model,name:partner_tier_validation.model_res_partner +msgid "Contact" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__display_name +#: model:ir.model.fields,field_description:partner_tier_validation.field_tier_definition__display_name +msgid "Display Name" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__has_comment +msgid "Has Comment" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__id +#: model:ir.model.fields,field_description:partner_tier_validation.field_tier_definition__id +msgid "ID" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner____last_update +#: model:ir.model.fields,field_description:partner_tier_validation.field_tier_definition____last_update +msgid "Last Modified on" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__need_validation +msgid "Need Validation" +msgstr "" + +#. module: partner_tier_validation +#: model_terms:ir.ui.view,arch_db:partner_tier_validation.partner_form_tier_filter +msgid "Needs my Approval" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__next_review +msgid "Next Review" +msgstr "" + +#. module: partner_tier_validation +#: model_terms:ir.ui.view,arch_db:partner_tier_validation.partner_form_tier_filter +msgid "Partner(s) to Approve" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__rejected +msgid "Rejected" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__rejected_message +msgid "Rejected Message" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__reviewer_ids +msgid "Reviewers" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model,name:partner_tier_validation.model_tier_definition +msgid "Tier Definition" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__to_validate_message +msgid "To Validate Message" +msgstr "" + +#. module: partner_tier_validation +#: model:tier.definition,name:partner_tier_validation.partner_tier_definition_company_only +msgid "Validate New Company" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__validated +msgid "Validated" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__validated_message +msgid "Validated Message" +msgstr "" + +#. module: partner_tier_validation +#: model:ir.model.fields,field_description:partner_tier_validation.field_res_partner__review_ids +msgid "Validations" +msgstr "" diff --git a/partner_tier_validation/models/__init__.py b/partner_tier_validation/models/__init__.py new file mode 100644 index 00000000000..77a3f1dc96d --- /dev/null +++ b/partner_tier_validation/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_partner +from . import tier_definition diff --git a/partner_tier_validation/models/res_partner.py b/partner_tier_validation/models/res_partner.py new file mode 100644 index 00000000000..3b303bf4b4e --- /dev/null +++ b/partner_tier_validation/models/res_partner.py @@ -0,0 +1,50 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ResPartner(models.Model): + _name = "res.partner" + _inherit = ["res.partner", "tier.validation"] + + _tier_validation_buttons_xpath = "/form/header/field[@name='state']" + _state_from = ["draft", "cancel"] + _state_to = ["confirmed"] + _cancel_state = ["inactive"] + _tier_validation_manual_config = False + + @api.model + def _partner_tier_revalidation_fields(self, values): + """ + Changing some Partner fields forces Tier Validation to be reevaluated. + Out of the box these are is_company and parent_id. + Other can be added extending this method. + """ + # IDEA: make it a System Parameter? + return [ + "company_type", + "parent_id", + "vat", + "state_id", + "country_id", + "property_account_position_id", + "property_account_receivable_id", + "property_account_payable_id", + ] + + def write(self, vals): + # Changing certain fields requires a new validation process + revalidate_fields = self._partner_tier_revalidation_fields(vals) + if any(x in revalidate_fields for x in vals.keys()): + vals["stage_id"] = self._get_default_stage_id().id + # Tier Validation does not work with Stages, only States :-( + # Workaround is to signal state transition adding it to the write values + if "stage_id" in vals: + stage_id = vals.get("stage_id") + stage = self.env["res.partner.stage"].browse(stage_id) + vals["state"] = stage.state + res = super().write(vals) + if "stage_id" in vals and vals.get("stage_id") in self._state_from: + self.restart_validation() + return res diff --git a/partner_tier_validation/models/tier_definition.py b/partner_tier_validation/models/tier_definition.py new file mode 100644 index 00000000000..c159d95b3eb --- /dev/null +++ b/partner_tier_validation/models/tier_definition.py @@ -0,0 +1,14 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class TierDefinition(models.Model): + _inherit = "tier.definition" + + @api.model + def _get_tier_validation_model_names(self): + res = super(TierDefinition, self)._get_tier_validation_model_names() + res.append("res.partner") + return res diff --git a/partner_tier_validation/readme/CONFIGURATION.rst b/partner_tier_validation/readme/CONFIGURATION.rst new file mode 100644 index 00000000000..12f37af2d2f --- /dev/null +++ b/partner_tier_validation/readme/CONFIGURATION.rst @@ -0,0 +1,24 @@ +The approval rules can be configured to suit particular use cases. +A default validation rule is provided out of the box, +that can be used as a starting point fot this configuration. + +This configuration is done at +*Settings / Technical / Tier Validations / Tier Definition*. + +Also relevant is the configuration on the default Stage +for new Contacts/Partners. +This can be set at *Contacts / Configuration / Contact Stage*, +setting the "Default Sate" field on the appropriate Stage record. + +Changing some fields will trigger a new request for validation. +This list of fields can be customized extending ``_partner_tier_revalidation_fields``. +By default these fields are: + +- Company Type (Individual or Company) +- Parent Company +- Tax ID +- State +- Country +- Fiscal Position +- Account Receivable +- Account Payable diff --git a/partner_tier_validation/readme/CONTRIBUTORS.rst b/partner_tier_validation/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..f3a6bc52754 --- /dev/null +++ b/partner_tier_validation/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Open Source Integrators `_. + + * Antonio Yamuta + * Daniel Reis + * Urvisha Desai diff --git a/partner_tier_validation/readme/DESCRIPTION.rst b/partner_tier_validation/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..fe2b83fe66f --- /dev/null +++ b/partner_tier_validation/readme/DESCRIPTION.rst @@ -0,0 +1,12 @@ +Adds an approval workflow to Partners. +The default rule requires new company Contacts to be approved +before they can be used. + +The rule can be extended to new non-company contact, +but beware that may cause issues with automatically created new contacts, +such as the ones generated when processing incoming emails. + +If the 'Is Company' or 'Parent' field changes then the contact is Request +for approval. + +For this, the new Contact record is kept as "Archived" until it is approved. diff --git a/partner_tier_validation/readme/INSTALL.rst b/partner_tier_validation/readme/INSTALL.rst new file mode 100644 index 00000000000..638fbd2d688 --- /dev/null +++ b/partner_tier_validation/readme/INSTALL.rst @@ -0,0 +1,2 @@ +This module depends on ``base_tier_validation``. You can find it at +`OCA/server-ux `_ diff --git a/partner_tier_validation/readme/USAGE.rst b/partner_tier_validation/readme/USAGE.rst new file mode 100644 index 00000000000..fb81ae01d5c --- /dev/null +++ b/partner_tier_validation/readme/USAGE.rst @@ -0,0 +1,24 @@ +Before using, check Contact Stages configuration, +to ensure that the default stage has the "Related State" field +set to "To Approve". +For example, having the "Draft" stage the default ensures this. + +A regular user creates a new Contact and sends it for approval: + +#. Create a Contact triggering at least one "Tier Definition". + The Contact will be in Draft state and marked as Archived until approved. +#. Click on *Request Validation* button. +#. In the *Reviews* section, at the bottom of the form, inspect the pending reviews and their status. + + +The approver reviews Contacts to approve: + +#. Navigate to the Contacts app, and select the filter "Needs my Approval" +#. Open the Contact form to approve. It will display a + "This Records needs to be validated" banner, with "Validate" and "Reject" options. +#. The approver can change the state to "Active". + This will automatically unarchive the record and make it available to be used. + + +The Approve/Reject actions do not automatically change the State. +This could be a future improvement. diff --git a/partner_tier_validation/static/description/icon.png b/partner_tier_validation/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/partner_tier_validation/static/description/icon.png differ diff --git a/partner_tier_validation/static/description/index.html b/partner_tier_validation/static/description/index.html new file mode 100644 index 00000000000..969027956bf --- /dev/null +++ b/partner_tier_validation/static/description/index.html @@ -0,0 +1,464 @@ + + + + + + +Partner Tier Validation + + + +
+

Partner Tier Validation

+ + +

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

+

Adds an approval workflow to Partners. +The default rule requires new company Contacts to be approved +before they can be used.

+

The rule can be extended to new non-company contact, +but beware that may cause issues with automatically created new contacts, +such as the ones generated when processing incoming emails.

+

If the ‘Is Company’ or ‘Parent’ field changes then the contact is Request +for approval.

+

For this, the new Contact record is kept as “Archived” until it is approved.

+

Table of contents

+ +
+

Installation

+

This module depends on base_tier_validation. You can find it at +OCA/server-ux

+
+
+

Usage

+

Before using, check Contact Stages configuration, +to ensure that the default stage has the “Related State” field +set to “To Approve”. +For example, having the “Draft” stage the default ensures this.

+

A regular user creates a new Contact and sends it for approval:

+
    +
  1. Create a Contact triggering at least one “Tier Definition”. +The Contact will be in Draft state and marked as Archived until approved.
  2. +
  3. Click on Request Validation button.
  4. +
  5. In the Reviews section, at the bottom of the form, inspect the pending reviews and their status.
  6. +
+

The approver reviews Contacts to approve:

+
    +
  1. Navigate to the Contacts app, and select the filter “Needs my Approval”
  2. +
  3. Open the Contact form to approve. It will display a +“This Records needs to be validated” banner, with “Validate” and “Reject” options.
  4. +
  5. The approver can change the state to “Active”. +This will automatically unarchive the record and make it available to be used.
  6. +
+

The Approve/Reject actions do not automatically change the State. +This could be a future improvement.

+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+ +
+

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:

+

dreispt

+

This module is part of the OCA/partner-contact project on GitHub.

+

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

+
+
+
+ + diff --git a/partner_tier_validation/test-requirements.txt b/partner_tier_validation/test-requirements.txt new file mode 100644 index 00000000000..3044a912bf8 --- /dev/null +++ b/partner_tier_validation/test-requirements.txt @@ -0,0 +1 @@ +git+https://github.com/OCA/partner-contact/pull/1339/head#subdirectory=setup/partner_stage diff --git a/partner_tier_validation/tests/__init__.py b/partner_tier_validation/tests/__init__.py new file mode 100644 index 00000000000..f39596410e7 --- /dev/null +++ b/partner_tier_validation/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_tier_validation diff --git a/partner_tier_validation/tests/test_tier_validation.py b/partner_tier_validation/tests/test_tier_validation.py new file mode 100644 index 00000000000..f9c348b8a95 --- /dev/null +++ b/partner_tier_validation/tests/test_tier_validation.py @@ -0,0 +1,96 @@ +# Copyright 2021 Patrick Wilson +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo.exceptions import ValidationError +from odoo.tests import common, tagged + + +@tagged("-at_install", "post_install") +class TestPartnerTierValidation(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Create users + group_user = cls.env.ref("base.group_user") + group_contacts = cls.env.ref("base.group_partner_manager") + group_approver = cls.env.ref("base.group_no_one") + User = cls.env["res.users"] + cls.user_employee = User.create( + { + "name": "Employee", + "login": "empl1", + "email": "empl1@example.com", + "groups_id": (group_user | group_contacts).ids, + } + ) + cls.user_approver = User.create( + { + "name": "Approver", + "login": "aprov1", + "email": "approv1@example.com", + "groups_id": (group_user | group_contacts | group_approver).ids, + } + ) + + # Create tier definition: example where only Company needs validation + cls.TierDefinition = cls.env["tier.definition"] + cls.TierDefinition.create( + { + "model_id": cls.env.ref("base.model_res_partner").id, + "review_type": "individual", + "reviewer_id": cls.user_approver.id, + "definition_domain": "[('is_company','=',True)]", + } + ) + + # Setup Contact Stages: draft is the default + Stage = cls.env["res.partner.stage"] + Stage.search([("is_default", "=", True)]).write({"is_default": False}) + cls.stage_draft = Stage.search([("state", "=", "draft")], limit=1) + cls.stage_draft.is_default = True + cls.stage_confirmed = Stage.search([("state", "=", "confirmed")], limit=1) + + def test_tier_validation_model_name(self): + self.assertIn( + "res.partner", self.TierDefinition._get_tier_validation_model_names() + ) + + def test_validation_res_partner(self): + """ + Case where new Contact requires validation + """ + Partner = self.env["res.partner"] + contact_vals = {"name": "Company for test", "company_type": "company"} + contact = Partner.with_user(self.user_employee).create(contact_vals) + self.assertEqual(contact.state, "draft") + + # Assert an error shows if trying to make it active + with self.assertRaises(ValidationError): + contact.write({"stage_id": self.stage_confirmed.id}) + + # Request and validate partner + contact.request_validation() + contact.invalidate_cache() + contact.with_user(self.user_approver).validate_tier() + contact.with_user(self.user_approver).write( + {"stage_id": self.stage_confirmed.id} + ) + self.assertEqual(contact.state, "confirmed") + + # Change company type to retrigger validation + contact.write({"company_type": "person"}) + self.assertEqual( + contact.state, "draft", "Change company type sets back to draft" + ) + + def test_no_validation_res_partner(self): + """ + Case where new Contact does not require validation + """ + Partner = self.env["res.partner"] + contact_vals = {"name": "Company for test", "company_type": "person"} + contact = Partner.with_user(self.user_employee).create(contact_vals) + self.assertEqual(contact.state, "draft") + # Can move to confirmed state without approval + contact.write({"stage_id": self.stage_confirmed.id}) + self.assertEqual(contact.state, "confirmed") diff --git a/partner_tier_validation/views/res_partner_view.xml b/partner_tier_validation/views/res_partner_view.xml new file mode 100644 index 00000000000..29cbd0a62be --- /dev/null +++ b/partner_tier_validation/views/res_partner_view.xml @@ -0,0 +1,35 @@ + + + + + partner.form.tier + res.partner + + + + + + + + + + + + + partner.form.tier.filter + res.partner + + + + + + + + + diff --git a/setup/partner_tier_validation/odoo/addons/partner_tier_validation b/setup/partner_tier_validation/odoo/addons/partner_tier_validation new file mode 120000 index 00000000000..f818463a863 --- /dev/null +++ b/setup/partner_tier_validation/odoo/addons/partner_tier_validation @@ -0,0 +1 @@ +../../../../partner_tier_validation \ No newline at end of file diff --git a/setup/partner_tier_validation/setup.py b/setup/partner_tier_validation/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/partner_tier_validation/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)