OCA-git-bot
4 years ago
12 changed files with 106 additions and 150 deletions
-
5partner_tier_validation/__manifest__.py
-
12partner_tier_validation/data/tier_definition.xml
-
2partner_tier_validation/models/__init__.py
-
27partner_tier_validation/models/res_partner.py
-
14partner_tier_validation/models/tier_definition.py
-
58partner_tier_validation/models/tier_validation.py
-
10partner_tier_validation/readme/CONFIGURATION.rst
-
4partner_tier_validation/readme/CONTRIBUTORS.rst
-
5partner_tier_validation/readme/DESCRIPTION.rst
-
2partner_tier_validation/readme/INSTALL.rst
-
19partner_tier_validation/readme/USAGE.rst
-
98partner_tier_validation/views/res_partner_view.xml
@ -0,0 +1,12 @@ |
|||||
|
<odoo noupdate="1"> |
||||
|
<record id="partner_tier_definition" model="tier.definition"> |
||||
|
<field name="name">Partner Validation</field> |
||||
|
<field name="model_id" ref="base.model_res_partner" /> |
||||
|
<field name="review_type">group</field> |
||||
|
<field name="reviewer_group_id" ref="base.group_user" /> |
||||
|
<field name="definition_type">domain</field> |
||||
|
<field |
||||
|
name="definition_domain" |
||||
|
>["&",["parent_id","=",False],"|",["active","=",True],["active","=",False]]</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -1,15 +1,32 @@ |
|||||
# Copyright 2019 Open Source Integrators |
# Copyright 2019 Open Source Integrators |
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
# 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): |
class ResPartner(models.Model): |
||||
_name = "res.partner" |
_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( |
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) |
@ -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 |
@ -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__) == "<class 'odoo.api.res.partner'>": |
|
||||
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 |
|
@ -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. |
@ -0,0 +1,4 @@ |
|||||
|
* `Open Source Integrators <https://opensourceintegrators.com>`_. |
||||
|
|
||||
|
* Antonio Yamuta <ayamuta@opensourceintegrators.com> |
||||
|
* Daniel Reis <dreis@opensourceintegrators.com> |
@ -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. |
@ -0,0 +1,2 @@ |
|||||
|
This module depends on ``base_tier_validation``. You can find it at |
||||
|
`OCA/server-ux <https://github.com/OCA/server-ux>`_ |
@ -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. |
Write
Preview
Loading…
Cancel
Save
Reference in new issue