diff --git a/partner_tier_validation/__manifest__.py b/partner_tier_validation/__manifest__.py index c86cd1f14..cb932174d 100644 --- a/partner_tier_validation/__manifest__.py +++ b/partner_tier_validation/__manifest__.py @@ -2,17 +2,16 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Partner Tier Validation", - "summary": "Extends the functionality of Contacts to" - "support a tier validation process.", + "summary": "Support a tier validation process for Contacts", "version": "14.0.1.0.0", "website": "https://github.com/OCA/partner-contact", "category": "Contact", "author": "Open Source Integrators, Odoo Community Association (OCA)", "license": "AGPL-3", - "application": False, "installable": True, "depends": ["contacts", "base_tier_validation"], "data": [ + "data/tier_definition.xml", "views/res_partner_view.xml", ], } diff --git a/partner_tier_validation/data/tier_definition.xml b/partner_tier_validation/data/tier_definition.xml new file mode 100644 index 000000000..9d328db91 --- /dev/null +++ b/partner_tier_validation/data/tier_definition.xml @@ -0,0 +1,12 @@ + + + Partner Validation + + group + + domain + ["&",["parent_id","=",False],"|",["active","=",True],["active","=",False]] + + diff --git a/partner_tier_validation/models/__init__.py b/partner_tier_validation/models/__init__.py index a415f52e7..77a3f1dc9 100644 --- a/partner_tier_validation/models/__init__.py +++ b/partner_tier_validation/models/__init__.py @@ -2,4 +2,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import res_partner -from . import tier_validation +from . import tier_definition diff --git a/partner_tier_validation/models/res_partner.py b/partner_tier_validation/models/res_partner.py index df52d4b9f..79464e016 100644 --- a/partner_tier_validation/models/res_partner.py +++ b/partner_tier_validation/models/res_partner.py @@ -1,15 +1,32 @@ # Copyright 2019 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class ResPartner(models.Model): _name = "res.partner" - _inherit = ["res.partner", "tier.validation", "mail.activity.mixin"] - _state_from = ["new", "to approve"] - _state_to = ["approved"] + _inherit = ["res.partner", "tier.validation"] + _tier_validation_manual_config = False state = fields.Selection( - [("new", "New"), ("approved", "Approved")], string="Status", default="new" + [("draft", "Draft"), ("confirmed", "Active"), ("cancel", "Archived")], + string="Status", + default="draft", ) + + @api.model + def create(self, vals): + new = super().create(vals) + if new.need_validation and new.state != "confirmed": + new.active = False + return new + + def write(self, vals): + """ + Default `active` is False. + It is set to True when State changes to confirmed. + """ + if "state" in vals: + vals["active"] = vals["state"] == "confirmed" + return super().write(vals) diff --git a/partner_tier_validation/models/tier_definition.py b/partner_tier_validation/models/tier_definition.py new file mode 100644 index 000000000..c159d95b3 --- /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/models/tier_validation.py b/partner_tier_validation/models/tier_validation.py deleted file mode 100644 index a070e2ac1..000000000 --- a/partner_tier_validation/models/tier_validation.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2019 Open Source Integrators -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import api, models - - -class TierValidation(models.AbstractModel): - _inherit = "tier.validation" - - @api.model - def _get_under_validation_exceptions(self): - """Extend for more field exceptions.""" - res = super(TierValidation, self)._get_under_validation_exceptions() or [] - ex_fields = ["categ_id", "state", "customer", "supplier", "excise_tax"] - for val in ex_fields: - res.append(val) - return res - - def validate_tier(self): - super(TierValidation, self).validate_tier() - # make sure to only work with res.partner object. - if self._name != "res.partner": - return - for partner in self: - rec = self.env["tier.review"].search( - [("res_id", "=", partner.id), ("model", "=", "res.partner")] - ) - if rec and rec.status == "approved": - partner.state = "approved" - - # Need to override for Partner Tier Validation since can_review field - # is set to True based only - # if current user is a member of reviewer_ids. This can_review field - # is used to enable or disable the boolean - # field Is Customer / Is Vendor not only during the Validation process - # but even if it is in Approved State. - @api.depends("review_ids") - def _compute_reviewer_ids(self): - if str(self.__class__) == "": - for rec in self: - rec.reviewer_ids = rec.review_ids.filtered( - lambda r: r.status in ("pending", "approved") - ).mapped("reviewer_ids") - else: - for rec in self: - rec.reviewer_ids = rec.review_ids.filtered( - lambda r: r.status == "pending" - ).mapped("reviewer_ids") - - def request_validation(self): - res = super().request_validation() - for rec in self.filtered(lambda x: x._name == "res.partner"): - rec.message_subscribe( - partner_ids=[ - self.env.user.partner_id.id, - ] - ) - return res diff --git a/partner_tier_validation/readme/CONFIGURATION.rst b/partner_tier_validation/readme/CONFIGURATION.rst new file mode 100644 index 000000000..f2c56d72e --- /dev/null +++ b/partner_tier_validation/readme/CONFIGURATION.rst @@ -0,0 +1,10 @@ +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*. + +Note that, since Contacts start as archived records, +the *Definition Domain* must include ``"|",["active","=",True],["active","=",False]``. +Otherwise the validation rule won't apply correctly in new records. diff --git a/partner_tier_validation/readme/CONTRIBUTORS.rst b/partner_tier_validation/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3c78380fe --- /dev/null +++ b/partner_tier_validation/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Open Source Integrators `_. + + * Antonio Yamuta + * Daniel Reis diff --git a/partner_tier_validation/readme/DESCRIPTION.rst b/partner_tier_validation/readme/DESCRIPTION.rst new file mode 100644 index 000000000..3e383aee8 --- /dev/null +++ b/partner_tier_validation/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +Adds an approval workflow to Partners. +The default rule requires new parent Contacts to be approved +before they can be used. + +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 000000000..638fbd2d6 --- /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 000000000..40016f54a --- /dev/null +++ b/partner_tier_validation/readme/USAGE.rst @@ -0,0 +1,19 @@ +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/views/res_partner_view.xml b/partner_tier_validation/views/res_partner_view.xml index 053dbbb44..cc74dee53 100644 --- a/partner_tier_validation/views/res_partner_view.xml +++ b/partner_tier_validation/views/res_partner_view.xml @@ -1,4 +1,3 @@ - @@ -6,85 +5,18 @@ partner.form.tier res.partner - - - -
- -
-
+ + -
- - - - - - - -
- - + +
+ +
@@ -95,12 +27,12 @@ res.partner - +