diff --git a/partner_tier_validation/README.rst b/partner_tier_validation/README.rst new file mode 100644 index 000000000..c197ce0b7 --- /dev/null +++ b/partner_tier_validation/README.rst @@ -0,0 +1,92 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :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. + +Installation +============ + +This module depends on ``base_tier_validation``. You can find it at +`OCA/server-ux `_ + + +Configuration +============= + +To configure this module, you need to: + +#. Go to *Settings > Technical > Tier Validations > Tier Definition*. +#. Create as many tiers as you want for Contact model. +#. Example: + Definition Formula + Tier Definition Expression + # Available locals: + # - rec: current record + + [rec.state == New] + +Usage +===== + +To use this module, you need to: + +#. Create a Contact triggering at least one "Tier Definition". +#. Click on *Request Validation* button. +#. Under the tab *Reviews* have a look to pending reviews and their statuses. +#. Validator has to update Is Customer or Is Supplier or Both for this Contact to be usable on SO/PO. + +Additional features: + +* You can filter the Invoices requesting your review through the filter *Needs my + Review*. +* User with rights to confirm the Vendor Bill (validate all tiers that would + be generated) can directly do the operation, this is, there is no need for + her/him to request a validation. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/142/11.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Antonio Yamuta + +Do not contact contributors directly about support or help with technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/partner_tier_validation/__init__.py b/partner_tier_validation/__init__.py new file mode 100644 index 000000000..31660d6a9 --- /dev/null +++ b/partner_tier_validation/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/partner_tier_validation/__manifest__.py b/partner_tier_validation/__manifest__.py new file mode 100644 index 000000000..c86cd1f14 --- /dev/null +++ b/partner_tier_validation/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2019 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": "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": [ + "views/res_partner_view.xml", + ], +} diff --git a/partner_tier_validation/models/__init__.py b/partner_tier_validation/models/__init__.py new file mode 100644 index 000000000..a415f52e7 --- /dev/null +++ b/partner_tier_validation/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_partner +from . import tier_validation diff --git a/partner_tier_validation/models/res_partner.py b/partner_tier_validation/models/res_partner.py new file mode 100644 index 000000000..df52d4b9f --- /dev/null +++ b/partner_tier_validation/models/res_partner.py @@ -0,0 +1,15 @@ +# Copyright 2019 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import 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"] + + 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 new file mode 100644 index 000000000..a070e2ac1 --- /dev/null +++ b/partner_tier_validation/models/tier_validation.py @@ -0,0 +1,58 @@ +# 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__) == "": + 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 diff --git a/partner_tier_validation/static/description/icon.png b/partner_tier_validation/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/partner_tier_validation/static/description/icon.png differ diff --git a/partner_tier_validation/views/res_partner_view.xml b/partner_tier_validation/views/res_partner_view.xml new file mode 100644 index 000000000..053dbbb44 --- /dev/null +++ b/partner_tier_validation/views/res_partner_view.xml @@ -0,0 +1,109 @@ + + + + + + partner.form.tier + res.partner + + + +
+ +
+
+ +
+ + + + + + + +
+ + + + +
+
+ + + partner.form.tier.filter + res.partner + + + + + + + + +
diff --git a/setup/partner_tier_validation/odoo/addons/partner_tier_validation b/setup/partner_tier_validation/odoo/addons/partner_tier_validation new file mode 120000 index 000000000..f818463a8 --- /dev/null +++ b/setup/partner_tier_validation/odoo/addons/partner_tier_validation @@ -0,0 +1 @@ +../../../../partner_tier_validation \ No newline at end of file diff --git a/setup/partner_tier_validation/setup.py b/setup/partner_tier_validation/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/partner_tier_validation/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)