diff --git a/partner_tier_validation/README.rst b/partner_tier_validation/README.rst index b6e7f63e6..c197ce0b7 100644 --- a/partner_tier_validation/README.rst +++ b/partner_tier_validation/README.rst @@ -2,9 +2,9 @@ :target: https://www.gnu.org/licenses/agpl :alt: License: AGPL-3 -==================== +======================= Partner Tier Validation -==================== +======================= This module extends the functionality of Partner to support a tier validation process. diff --git a/partner_tier_validation/__manifest__.py b/partner_tier_validation/__manifest__.py index b3f724a7a..8aa407cac 100644 --- a/partner_tier_validation/__manifest__.py +++ b/partner_tier_validation/__manifest__.py @@ -1,19 +1,17 @@ -# Copyright 2019 Open Source Integrators +# Copyright 2021 Open Source Integrators # 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.", - "version": "12.0.1.0.0", + "support a tier validation process.", + "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", - ], + "depends": ["contacts", "base_tier_validation", "partner_autocomplete"], "data": [ "views/res_partner_view.xml", ], diff --git a/partner_tier_validation/models/__init__.py b/partner_tier_validation/models/__init__.py index a415f52e7..9253d4876 100644 --- a/partner_tier_validation/models/__init__.py +++ b/partner_tier_validation/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2019 Open Source Integrators +# Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import res_partner diff --git a/partner_tier_validation/models/res_partner.py b/partner_tier_validation/models/res_partner.py index 2085f2c19..aeea2870a 100644 --- a/partner_tier_validation/models/res_partner.py +++ b/partner_tier_validation/models/res_partner.py @@ -1,20 +1,15 @@ -# Copyright 2019 Open Source Integrators +# Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import fields, models -class ResPartner(models.Model): +class ResPartner11(models.Model): _name = "res.partner" - _inherit = ['res.partner', 'tier.validation'] - _state_from = ['new', 'to approve'] - _state_to = ['approved'] + _inherit = ["res.partner", "tier.validation", "mail.activity.mixin"] + _state_from = ["new", "to approve"] + _state_to = ["approved"] - # override core odoo to set default value to False - customer = fields.Boolean(string='Is a Customer', default=False, - help="Check this box if this contact is a customer. It can be selected in sales orders.") - - state = fields.Selection(selection=[('new','New'), - ('approved','Approved'),], - string='Status', - default='new' ) + state = fields.Selection( + [("new", "New"), ("approved", "Approved")], string="Status", default="new" + ) diff --git a/partner_tier_validation/models/tier_validation.py b/partner_tier_validation/models/tier_validation.py index 515e3549e..565cc1bb9 100644 --- a/partner_tier_validation/models/tier_validation.py +++ b/partner_tier_validation/models/tier_validation.py @@ -1,53 +1,58 @@ -# Copyright 2019 Open Source Integrators +# Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import api, models, _ -from odoo.exceptions import ValidationError +from odoo import api, models + class TierValidation(models.AbstractModel): _inherit = "tier.validation" @api.model def _get_under_validation_exceptions(self): - res = super(TierValidation, self)._get_under_validation_exceptions() or [] """Extend for more field exceptions.""" - ex_fields = ['categ_id','state', 'customer','supplier','excise_tax'] + 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 - @api.multi def validate_tier(self): super(TierValidation, self).validate_tier() # make sure to only work with res.partner object. - if self._name != 'res.partner': - return + 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': - if not (partner.customer or partner.supplier): - raise ValidationError(_('Cannot Validate. Please configure partner %s as a Customer or Vendor or Both.') % (partner.display_name)) - else: - partner.state = 'approved' + 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.multi - @api.depends('review_ids') + # 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__) == "": + 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') + 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') + lambda r: r.status == "pending" + ).mapped("reviewer_ids") - @api.multi 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,]) + 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/views/res_partner_view.xml b/partner_tier_validation/views/res_partner_view.xml index 81d72cbc3..f6675dc5b 100644 --- a/partner_tier_validation/views/res_partner_view.xml +++ b/partner_tier_validation/views/res_partner_view.xml @@ -1,96 +1,109 @@ - - partner.form.tier res.partner - - - - + + +
- -
-
- - - - -
- - - - {'readonly': [('can_review', '=', False)]} - - - {'readonly': [('can_review', '=', False)]} - - + +
+
- + partner.form.tier.filter res.partner - + - - - + + - +