Freni-OSI
4 years ago
6 changed files with 127 additions and 116 deletions
-
4partner_tier_validation/README.rst
-
10partner_tier_validation/__manifest__.py
-
2partner_tier_validation/models/__init__.py
-
23partner_tier_validation/models/res_partner.py
-
51partner_tier_validation/models/tier_validation.py
-
75partner_tier_validation/views/res_partner_view.xml
@ -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). |
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
{ |
{ |
||||
"name": "Partner Tier Validation", |
"name": "Partner Tier Validation", |
||||
"summary": "Extends the functionality of Contacts to" |
"summary": "Extends the functionality of Contacts to" |
||||
"support a tier validation process.", |
"support a tier validation process.", |
||||
"version": "12.0.1.0.0", |
|
||||
|
"version": "14.0.1.0.0", |
||||
|
"website": "https://github.com/OCA/partner-contact", |
||||
"category": "Contact", |
"category": "Contact", |
||||
"author": "Open Source Integrators, Odoo Community Association (OCA)", |
"author": "Open Source Integrators, Odoo Community Association (OCA)", |
||||
"license": "AGPL-3", |
"license": "AGPL-3", |
||||
"application": False, |
"application": False, |
||||
"installable": True, |
"installable": True, |
||||
"depends": [ |
|
||||
"contacts", |
|
||||
"base_tier_validation", |
|
||||
], |
|
||||
|
"depends": ["contacts", "base_tier_validation", "partner_autocomplete"], |
||||
"data": [ |
"data": [ |
||||
"views/res_partner_view.xml", |
"views/res_partner_view.xml", |
||||
], |
], |
||||
|
@ -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). |
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
from . import res_partner |
from . import res_partner |
||||
|
@ -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). |
# 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" |
_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" |
||||
|
) |
@ -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). |
# 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): |
class TierValidation(models.AbstractModel): |
||||
_inherit = "tier.validation" |
_inherit = "tier.validation" |
||||
|
|
||||
@api.model |
@api.model |
||||
def _get_under_validation_exceptions(self): |
def _get_under_validation_exceptions(self): |
||||
res = super(TierValidation, self)._get_under_validation_exceptions() or [] |
|
||||
"""Extend for more field exceptions.""" |
"""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: |
for val in ex_fields: |
||||
res.append(val) |
res.append(val) |
||||
return res |
return res |
||||
|
|
||||
@api.multi |
|
||||
def validate_tier(self): |
def validate_tier(self): |
||||
super(TierValidation, self).validate_tier() |
super(TierValidation, self).validate_tier() |
||||
# make sure to only work with res.partner object. |
# make sure to only work with res.partner object. |
||||
if self._name != 'res.partner': |
|
||||
|
if self._name != "res.partner": |
||||
return |
return |
||||
for partner in self: |
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): |
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: |
for rec in self: |
||||
rec.reviewer_ids = rec.review_ids.filtered( |
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: |
else: |
||||
for rec in self: |
for rec in self: |
||||
rec.reviewer_ids = rec.review_ids.filtered( |
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): |
def request_validation(self): |
||||
res = super().request_validation() |
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 |
return res |
Write
Preview
Loading…
Cancel
Save
Reference in new issue