Browse Source

[FIX] partner_tier_validation: workflow was not working

14.0
Daniel Reis 3 years ago
parent
commit
61e29e5705
  1. 5
      partner_tier_validation/__manifest__.py
  2. 12
      partner_tier_validation/data/tier_definition.xml
  3. 2
      partner_tier_validation/models/__init__.py
  4. 27
      partner_tier_validation/models/res_partner.py
  5. 14
      partner_tier_validation/models/tier_definition.py
  6. 58
      partner_tier_validation/models/tier_validation.py
  7. 10
      partner_tier_validation/readme/CONFIGURATION.rst
  8. 4
      partner_tier_validation/readme/CONTRIBUTORS.rst
  9. 5
      partner_tier_validation/readme/DESCRIPTION.rst
  10. 2
      partner_tier_validation/readme/INSTALL.rst
  11. 19
      partner_tier_validation/readme/USAGE.rst
  12. 98
      partner_tier_validation/views/res_partner_view.xml

5
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",
],
}

12
partner_tier_validation/data/tier_definition.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"
>["&amp;",["parent_id","=",False],"|",["active","=",True],["active","=",False]]</field>
</record>
</odoo>

2
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

27
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)

14
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

58
partner_tier_validation/models/tier_validation.py

@ -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

10
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.

4
partner_tier_validation/readme/CONTRIBUTORS.rst

@ -0,0 +1,4 @@
* `Open Source Integrators <https://opensourceintegrators.com>`_.
* Antonio Yamuta <ayamuta@opensourceintegrators.com>
* Daniel Reis <dreis@opensourceintegrators.com>

5
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.

2
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 <https://github.com/OCA/server-ux>`_

19
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.

98
partner_tier_validation/views/res_partner_view.xml

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
@ -6,85 +5,18 @@
<record id="partner_form_tier" model="ir.ui.view">
<field name="name">partner.form.tier</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="/form/sheet" position="before">
<header>
<field name="state" widget="statusbar" statusbar_visible="new, approved" />
<button
name="request_validation"
string="Request Validation"
attrs="{'invisible': ['|','|',('need_validation', '!=', True),('rejected','=',True),('state','not in',['new','to approve'])]}"
type="object"
/>
<button
name="restart_validation"
string="Restart Validation"
attrs="{'invisible': ['|',('review_ids', '=', []),('state','not in',['new','to approve'])]}"
type="object"
/>
</header>
</xpath>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<header position="after">
<field name="need_validation" invisible="1" />
<field name="validated" invisible="1" />
<field name="rejected" invisible="1" />
<field name="reviewer_ids" invisible="1" />
<div
class="alert alert-warning"
role="alert"
attrs="{'invisible': ['|', '|', '|',
('validated', '=', True), ('state', 'not in', ['new','to approve']),
('rejected', '=', True), ('review_ids', '=', [])]}"
style="margin-bottom:0px;"
>
<p><i class="fa fa-info-circle" />This partner needs to be
approved before it can have transactions.
<field name="can_review" invisible="1" />
<button
name="validate_tier"
string="Validate"
attrs="{'invisible': [('can_review', '=', False)]}"
type="object"
class="oe_inline oe_button btn-success"
icon="fa-thumbs-up"
/>
<button
name="reject_tier"
string="Reject"
attrs="{'invisible': [('can_review', '=', False)]}"
type="object"
class="btn-icon btn-danger"
icon="fa-thumbs-down"
/>
</p>
</div>
<div
class="alert alert-success"
role="alert"
attrs="{'invisible': ['|', '|', ('validated', '!=', True), ('state', 'not in', ['new','to approve']), ('review_ids', '=', [])]}"
style="margin-bottom:0px;"
>
<p><i class="fa fa-thumbs-up" /> Partner has been <b
>approved and now can have transactions</b>!</p>
</div>
<div
class="alert alert-danger"
role="alert"
attrs="{'invisible': ['|', '|', ('rejected', '!=', True), ('state', 'not in', ['new','to approve']), ('review_ids', '=', [])]}"
style="margin-bottom:0px;"
>
<p><i class="fa fa-thumbs-down" /> Partner creation has been <b
>rejected</b>.</p>
</div>
</header>
<xpath expr="//form/div[hasclass('oe_chatter')]" position="before">
<field
name="review_ids"
widget="tier_validation"
attrs="{'invisible':[('review_ids', '=', [])]}"
/>
<xpath expr="/form/sheet" position="before">
<header>
<field
name="state"
widget="statusbar"
options="{'clickable': '1'}"
/>
<button name="dummy" invisible="True" />
</header>
</xpath>
</field>
@ -95,12 +27,12 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="type_person" position="before">
<filter name="inactive" position="before">
<filter
name="needs_review"
string="Needs my Review"
domain="[('reviewer_ids','in',uid), ('state', 'not in', ['approved','to approve'])]"
help="Partner(s) to review"
string="Needs my Approval"
domain="[('reviewer_ids','in',uid), ('state', '=', 'draft'), '|', ('active','=', True), ('active', '=', False)]"
help="Partner(s) to Approve"
/>
</filter>
</field>

Loading…
Cancel
Save