Browse Source

[14.0][MIG]partner_tier_validation

14.0
Freni-OSI 4 years ago
parent
commit
9ce6257b26
  1. 4
      partner_tier_validation/README.rst
  2. 12
      partner_tier_validation/__manifest__.py
  3. 2
      partner_tier_validation/models/__init__.py
  4. 23
      partner_tier_validation/models/res_partner.py
  5. 55
      partner_tier_validation/models/tier_validation.py
  6. 147
      partner_tier_validation/views/res_partner_view.xml

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

12
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",
],

2
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

23
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"
)

55
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__) == "<class 'odoo.api.res.partner'>":
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')
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

147
partner_tier_validation/views/res_partner_view.xml

@ -1,96 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 Open Source Integrators
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Open Source Integrators
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<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="inherit_id" ref="product.product_template_form_view"/>-->
<field name="arch" type="xml">
<xpath expr="/form/sheet" position="before">
<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"/>
<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>
<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': ['|', '|', '|',
<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
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"/>
<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
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
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>
<xpath expr="//group[@name='sale']/field[@name='customer']" position="attributes">
<attribute name="attrs">{'readonly': [('can_review', '=', False)]}</attribute>
</xpath>
<xpath expr="//group[@name='purchase']/field[@name='supplier']" position="attributes">
<attribute name="attrs">{'readonly': [('can_review', '=', False)]}</attribute>
</xpath>
<field
name="review_ids"
widget="tier_validation"
attrs="{'invisible':[('review_ids', '=', [])]}"
/>
</xpath>
</field>
</record>
<record id="partner_form_tier_filter" model="ir.ui.view">
<field name="name">partner.form.tier.filter</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="inherit_id" ref="base.view_res_partner_filter" />
<field name="arch" type="xml">
<filter name="customer" 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"/>
<!--<filter name="tier_validated" string="Validated"
domain="[('validated', '=', True)]"
help="Partners validated or Approved"/>-->
<filter name="type_person" 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"
/>
</filter>
</field>
</record>
</odoo>
Loading…
Cancel
Save