Browse Source
Merge pull request #52 from versada/12.0-mig-base-tier-validation
Merge pull request #52 from versada/12.0-mig-base-tier-validation
[12.0] base_tier_validation: port to v12pull/69/head
Pedro M. Baeza
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 1471 additions and 0 deletions
-
103base_tier_validation/README.rst
-
3base_tier_validation/__init__.py
-
23base_tier_validation/__manifest__.py
-
270base_tier_validation/i18n/base_tier_validation.pot
-
5base_tier_validation/models/__init__.py
-
54base_tier_validation/models/tier_definition.py
-
47base_tier_validation/models/tier_review.py
-
201base_tier_validation/models/tier_validation.py
-
5base_tier_validation/readme/CONFIGURE.rst
-
2base_tier_validation/readme/CONTRIBUTORS.rst
-
9base_tier_validation/readme/DESCRIPTION.rst
-
1base_tier_validation/readme/ROADMAP.rst
-
4base_tier_validation/security/ir.model.access.csv
-
443base_tier_validation/static/description/index.html
-
4base_tier_validation/tests/__init__.py
-
13base_tier_validation/tests/common.py
-
150base_tier_validation/tests/test_tier_validation.py
-
21base_tier_validation/tests/tier_validation_tester.py
-
89base_tier_validation/views/tier_definition_view.xml
-
24base_tier_validation/views/tier_review_view.xml
@ -0,0 +1,103 @@ |
|||||
|
==================== |
||||
|
Base Tier Validation |
||||
|
==================== |
||||
|
|
||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
|
||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png |
||||
|
:target: https://odoo-community.org/page/development-status |
||||
|
:alt: Mature |
||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github |
||||
|
:target: https://github.com/OCA/server-ux/tree/11.0/base_tier_validation |
||||
|
:alt: OCA/server-ux |
||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
||||
|
:target: https://translation.odoo-community.org/projects/server-ux-11-0/server-ux-11-0-base_tier_validation |
||||
|
:alt: Translate me on Weblate |
||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png |
||||
|
:target: https://runbot.odoo-community.org/runbot/250/11.0 |
||||
|
:alt: Try me on Runbot |
||||
|
|
||||
|
|badge1| |badge2| |badge3| |badge4| |badge5| |
||||
|
|
||||
|
This module does not provide a functionality by itself but an abstract model |
||||
|
to implement a validation process based on tiers on other models (e.g. |
||||
|
purchase orders, sales orders...). |
||||
|
|
||||
|
**Note:** To be able to use this module in a new model you will need some |
||||
|
development. |
||||
|
|
||||
|
See `purchase_tier_validation <https://github |
||||
|
.com/OCA/purchase-workflow>`_ as an example of implementation. |
||||
|
|
||||
|
**Table of contents** |
||||
|
|
||||
|
.. contents:: |
||||
|
:local: |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
|
||||
|
To configure this module, you need to: |
||||
|
|
||||
|
#. Go to *Settings > Technical > Tier Validations > Tier Definition*. |
||||
|
#. Create as many tiers as you want for any model having tier validation |
||||
|
functionality. |
||||
|
|
||||
|
Known issues / Roadmap |
||||
|
====================== |
||||
|
|
||||
|
* In odoo v11 it would be interesting to try to take advantage of ``mail.activity.mixin``. |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20base_tier_validation%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
Do not contact contributors directly about support or help with technical issues. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Authors |
||||
|
~~~~~~~ |
||||
|
|
||||
|
* Eficent |
||||
|
|
||||
|
Contributors |
||||
|
~~~~~~~~~~~~ |
||||
|
|
||||
|
* Lois Rilo <lois.rilo@eficent.com> |
||||
|
|
||||
|
Maintainers |
||||
|
~~~~~~~~~~~ |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
.. |maintainer-lreficent| image:: https://github.com/lreficent.png?size=40px |
||||
|
:target: https://github.com/lreficent |
||||
|
:alt: lreficent |
||||
|
|
||||
|
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: |
||||
|
|
||||
|
|maintainer-lreficent| |
||||
|
|
||||
|
This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/11.0/base_tier_validation>`_ project on GitHub. |
||||
|
|
||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
@ -0,0 +1,3 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import models |
@ -0,0 +1,23 @@ |
|||||
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
{ |
||||
|
"name": "Base Tier Validation", |
||||
|
"summary": "Implement a validation process based on tiers.", |
||||
|
"version": "12.0.1.0.0", |
||||
|
"development_status": "Mature", |
||||
|
"maintainers": ['lreficent'], |
||||
|
"category": "Tools", |
||||
|
"website": "https://github.com/OCA/server-ux", |
||||
|
"author": "Eficent, Odoo Community Association (OCA)", |
||||
|
"license": "AGPL-3", |
||||
|
"application": False, |
||||
|
"installable": True, |
||||
|
"depends": [ |
||||
|
"base", |
||||
|
], |
||||
|
"data": [ |
||||
|
"security/ir.model.access.csv", |
||||
|
"views/tier_definition_view.xml", |
||||
|
"views/tier_review_view.xml", |
||||
|
], |
||||
|
} |
@ -0,0 +1,270 @@ |
|||||
|
# Translation of Odoo Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * base_tier_validation |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Odoo Server 11.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"Last-Translator: <>\n" |
||||
|
"Language-Team: \n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: \n" |
||||
|
"Plural-Forms: \n" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: code:addons/base_tier_validation/models/tier_validation.py:132 |
||||
|
#, python-format |
||||
|
msgid "A validation process is still open for at least one record." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_active |
||||
|
msgid "Active" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_definition_view_search |
||||
|
msgid "All" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: selection:tier.definition,review_type:0 |
||||
|
msgid "Any user in a specific group." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: selection:tier.review,status:0 |
||||
|
msgid "Approved" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_can_review |
||||
|
msgid "Can Review" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_company_id |
||||
|
msgid "Company" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_create_uid |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_create_uid |
||||
|
msgid "Created by" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_create_date |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_create_date |
||||
|
msgid "Created on" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_definition_id |
||||
|
msgid "Definition" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_display_name |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_display_name |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_display_name |
||||
|
msgid "Display Name" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_done_by |
||||
|
msgid "Done By" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: code:addons/base_tier_validation/models/tier_validation.py:99 |
||||
|
#, python-format |
||||
|
msgid "Error evaluating tier validation conditions.\n" |
||||
|
" %s" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_definition_view_search |
||||
|
msgid "Group By" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_id |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_id |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_id |
||||
|
msgid "ID" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition___last_update |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review___last_update |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation___last_update |
||||
|
msgid "Last Modified on" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_write_uid |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_write_uid |
||||
|
msgid "Last Updated by" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_write_date |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_write_date |
||||
|
msgid "Last Updated on" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_model |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_definition_view_search |
||||
|
msgid "Model" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_need_validation |
||||
|
msgid "Need Validation" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: selection:tier.review,status:0 |
||||
|
msgid "Pending" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_model_id |
||||
|
msgid "Referenced Model" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_rejected |
||||
|
#: selection:tier.review,status:0 |
||||
|
msgid "Rejected" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_res_id |
||||
|
msgid "Related Document ID" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_model |
||||
|
msgid "Related Document Model" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_requested_by |
||||
|
msgid "Requested By" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_reviewer_id |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_reviewer_id |
||||
|
msgid "Reviewer" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_reviewer_group_id |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_reviewer_group_id |
||||
|
msgid "Reviewer group" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_reviewer_ids |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_reviewer_ids |
||||
|
msgid "Reviewers" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_sequence |
||||
|
msgid "Sequence" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: selection:tier.definition,review_type:0 |
||||
|
msgid "Specific user" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_status |
||||
|
msgid "Status" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: code:addons/base_tier_validation/models/tier_validation.py:139 |
||||
|
#, python-format |
||||
|
msgid "The operation is under validation." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: code:addons/base_tier_validation/models/tier_validation.py:128 |
||||
|
#, python-format |
||||
|
msgid "This action needs to be validated for at least one record. \n" |
||||
|
"Please request a validation." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_sequence |
||||
|
msgid "Tier" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.actions.act_window,name:base_tier_validation.tier_definition_action |
||||
|
#: model:ir.ui.menu,name:base_tier_validation.menu_tier_definition |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_definition_view_form |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_definition_view_tree |
||||
|
msgid "Tier Definition" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_python_code |
||||
|
msgid "Tier Definition Expression" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.ui.view,arch_db:base_tier_validation.tier_review_view_tree |
||||
|
msgid "Tier Review" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.ui.menu,name:base_tier_validation.menu_tier_confirmation |
||||
|
msgid "Tier Validations" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_validated |
||||
|
msgid "Validated" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_definition_review_type |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_review_review_type |
||||
|
msgid "Validated by" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,field_description:base_tier_validation.field_tier_validation_review_ids |
||||
|
msgid "Validations" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model.fields,help:base_tier_validation.field_tier_definition_python_code |
||||
|
msgid "Write Python code that defines when this tier confirmation will be needed. The result of executing the expresion must be a boolean." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model,name:base_tier_validation.model_tier_definition |
||||
|
msgid "tier.definition" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model,name:base_tier_validation.model_tier_review |
||||
|
msgid "tier.review" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: base_tier_validation |
||||
|
#: model:ir.model,name:base_tier_validation.model_tier_validation |
||||
|
msgid "tier.validation" |
||||
|
msgstr "" |
||||
|
|
@ -0,0 +1,5 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import tier_definition |
||||
|
from . import tier_review |
||||
|
from . import tier_validation |
@ -0,0 +1,54 @@ |
|||||
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class TierDefinition(models.Model): |
||||
|
_name = "tier.definition" |
||||
|
_description = "Tier Definition" |
||||
|
_rec_name = "model_id" |
||||
|
|
||||
|
@api.model |
||||
|
def _get_tier_validation_model_names(self): |
||||
|
res = [] |
||||
|
return res |
||||
|
|
||||
|
model_id = fields.Many2one( |
||||
|
comodel_name="ir.model", |
||||
|
string="Referenced Model", |
||||
|
) |
||||
|
model = fields.Char( |
||||
|
related='model_id.model', index=True, store=True, |
||||
|
) |
||||
|
review_type = fields.Selection( |
||||
|
string="Validated by", default="individual", |
||||
|
selection=[("individual", "Specific user"), |
||||
|
("group", "Any user in a specific group.")] |
||||
|
) |
||||
|
reviewer_id = fields.Many2one( |
||||
|
comodel_name="res.users", string="Reviewer", |
||||
|
) |
||||
|
reviewer_group_id = fields.Many2one( |
||||
|
comodel_name="res.groups", string="Reviewer group", |
||||
|
) |
||||
|
python_code = fields.Text( |
||||
|
string='Tier Definition Expression', |
||||
|
help="Write Python code that defines when this tier confirmation " |
||||
|
"will be needed. The result of executing the expresion must be " |
||||
|
"a boolean.", |
||||
|
default="""# Available locals:\n# - rec: current record""", |
||||
|
) |
||||
|
active = fields.Boolean(default=True) |
||||
|
sequence = fields.Integer(default=30) |
||||
|
company_id = fields.Many2one( |
||||
|
comodel_name="res.company", string="Company", |
||||
|
default=lambda self: self.env["res.company"]._company_default_get( |
||||
|
"tier.definition"), |
||||
|
) |
||||
|
|
||||
|
@api.onchange('model_id') |
||||
|
def onchange_model_id(self): |
||||
|
return {'domain': { |
||||
|
'model_id': [ |
||||
|
('model', 'in', self._get_tier_validation_model_names())]}} |
@ -0,0 +1,47 @@ |
|||||
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class TierReview(models.Model): |
||||
|
_name = "tier.review" |
||||
|
_description = "Tier Review" |
||||
|
|
||||
|
status = fields.Selection( |
||||
|
selection=[("pending", "Pending"), |
||||
|
("rejected", "Rejected"), |
||||
|
("approved", "Approved")], |
||||
|
default="pending", |
||||
|
) |
||||
|
model = fields.Char(string='Related Document Model', index=True) |
||||
|
res_id = fields.Integer(string='Related Document ID', index=True) |
||||
|
definition_id = fields.Many2one( |
||||
|
comodel_name="tier.definition", |
||||
|
) |
||||
|
review_type = fields.Selection( |
||||
|
related="definition_id.review_type", readonly=True, |
||||
|
) |
||||
|
reviewer_id = fields.Many2one( |
||||
|
related="definition_id.reviewer_id", readonly=True, |
||||
|
) |
||||
|
reviewer_group_id = fields.Many2one( |
||||
|
related="definition_id.reviewer_group_id", readonly=True, |
||||
|
) |
||||
|
reviewer_ids = fields.Many2many( |
||||
|
string="Reviewers", comodel_name="res.users", |
||||
|
compute="_compute_reviewer_ids", store=True, |
||||
|
) |
||||
|
sequence = fields.Integer(string="Tier") |
||||
|
done_by = fields.Many2one( |
||||
|
comodel_name="res.users", |
||||
|
) |
||||
|
requested_by = fields.Many2one( |
||||
|
comodel_name="res.users", |
||||
|
) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('reviewer_id', 'reviewer_group_id', 'reviewer_group_id.users') |
||||
|
def _compute_reviewer_ids(self): |
||||
|
for rec in self: |
||||
|
rec.reviewer_ids = rec.reviewer_id + rec.reviewer_group_id.users |
@ -0,0 +1,201 @@ |
|||||
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models, _ |
||||
|
from odoo.exceptions import ValidationError, UserError |
||||
|
from odoo.tools.safe_eval import safe_eval |
||||
|
|
||||
|
|
||||
|
class TierValidation(models.AbstractModel): |
||||
|
_name = "tier.validation" |
||||
|
_description = "Tier Validation (abstract)" |
||||
|
|
||||
|
_state_field = 'state' |
||||
|
_state_from = ['draft'] |
||||
|
_state_to = ['confirmed'] |
||||
|
_cancel_state = 'cancel' |
||||
|
|
||||
|
# TODO: step by step validation? |
||||
|
|
||||
|
review_ids = fields.One2many( |
||||
|
comodel_name='tier.review', inverse_name='res_id', |
||||
|
string='Validations', |
||||
|
domain=lambda self: [('model', '=', self._name)], |
||||
|
auto_join=True, |
||||
|
) |
||||
|
validated = fields.Boolean( |
||||
|
compute="_compute_validated_rejected", |
||||
|
search="_search_validated", |
||||
|
) |
||||
|
need_validation = fields.Boolean(compute="_compute_need_validation") |
||||
|
rejected = fields.Boolean(compute="_compute_validated_rejected") |
||||
|
reviewer_ids = fields.Many2many( |
||||
|
string="Reviewers", comodel_name="res.users", |
||||
|
compute="_compute_reviewer_ids", |
||||
|
search="_search_reviewer_ids", |
||||
|
) |
||||
|
can_review = fields.Boolean(compute="_compute_can_review") |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_can_review(self): |
||||
|
for rec in self: |
||||
|
rec.can_review = self.env.user in rec.reviewer_ids |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('review_ids') |
||||
|
def _compute_reviewer_ids(self): |
||||
|
for rec in self: |
||||
|
rec.reviewer_ids = rec.review_ids.filtered( |
||||
|
lambda r: r.status == 'pending').mapped('reviewer_ids') |
||||
|
|
||||
|
@api.model |
||||
|
def _search_validated(self, operator, value): |
||||
|
assert operator in ('=', '!='), 'Invalid domain operator' |
||||
|
assert value in (True, False), 'Invalid domain value' |
||||
|
pos = self.search([ |
||||
|
(self._state_field, 'in', self._state_from)]).filtered( |
||||
|
lambda r: r.review_ids and r.validated == value) |
||||
|
return [('id', 'in', pos.ids)] |
||||
|
|
||||
|
@api.model |
||||
|
def _search_reviewer_ids(self, operator, value): |
||||
|
reviews = self.env['tier.review'].search([ |
||||
|
('model', '=', self._name), |
||||
|
('reviewer_ids', operator, value), |
||||
|
('status', '=', 'pending')]) |
||||
|
return [('id', 'in', list(set(reviews.mapped('res_id'))))] |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_validated_rejected(self): |
||||
|
for rec in self: |
||||
|
rec.validated = self._calc_reviews_validated(rec.review_ids) |
||||
|
rec.rejected = self._calc_reviews_rejected(rec.review_ids) |
||||
|
|
||||
|
@api.model |
||||
|
def _calc_reviews_validated(self, reviews): |
||||
|
"""Override for different validation policy.""" |
||||
|
if not reviews: |
||||
|
return False |
||||
|
return not any([s != 'approved' for s in reviews.mapped('status')]) |
||||
|
|
||||
|
@api.model |
||||
|
def _calc_reviews_rejected(self, reviews): |
||||
|
"""Override for different rejection policy.""" |
||||
|
return any([s == 'rejected' for s in reviews.mapped('status')]) |
||||
|
|
||||
|
@api.multi |
||||
|
def _compute_need_validation(self): |
||||
|
for rec in self: |
||||
|
tiers = self.env[ |
||||
|
'tier.definition'].search([('model', '=', self._name)]) |
||||
|
valid_tiers = any([self.evaluate_tier(tier) for tier in tiers]) |
||||
|
rec.need_validation = not rec.review_ids and valid_tiers and \ |
||||
|
getattr(rec, self._state_field) in self._state_from |
||||
|
|
||||
|
@api.multi |
||||
|
def evaluate_tier(self, tier): |
||||
|
try: |
||||
|
res = safe_eval(tier.python_code, globals_dict={'rec': self}) |
||||
|
except Exception as error: |
||||
|
raise UserError(_( |
||||
|
"Error evaluating tier validation conditions.\n %s") % error) |
||||
|
return res |
||||
|
|
||||
|
@api.model |
||||
|
def _get_under_validation_exceptions(self): |
||||
|
"""Extend for more field exceptions.""" |
||||
|
return ['message_follower_ids'] |
||||
|
|
||||
|
@api.multi |
||||
|
def _check_allow_write_under_validation(self, vals): |
||||
|
"""Allow to add exceptions for fields that are allowed to be written |
||||
|
even when the record is under validation.""" |
||||
|
exceptions = self._get_under_validation_exceptions() |
||||
|
for val in vals: |
||||
|
if val not in exceptions: |
||||
|
return False |
||||
|
return True |
||||
|
|
||||
|
@api.multi |
||||
|
def write(self, vals): |
||||
|
for rec in self: |
||||
|
if (getattr(rec, self._state_field) in self._state_from and |
||||
|
vals.get(self._state_field) in self._state_to): |
||||
|
if rec.need_validation: |
||||
|
# try to validate operation |
||||
|
reviews = rec.request_validation() |
||||
|
rec._validate_tier(reviews) |
||||
|
if not self._calc_reviews_validated(reviews): |
||||
|
raise ValidationError(_( |
||||
|
"This action needs to be validated for at least " |
||||
|
"one record. \nPlease request a validation.")) |
||||
|
if rec.review_ids and not rec.validated: |
||||
|
raise ValidationError(_( |
||||
|
"A validation process is still open for at least " |
||||
|
"one record.")) |
||||
|
if (rec.review_ids and getattr(rec, self._state_field) in |
||||
|
self._state_from and not vals.get(self._state_field) in |
||||
|
(self._state_to + [self._cancel_state]) and not |
||||
|
self._check_allow_write_under_validation(vals)): |
||||
|
raise ValidationError(_("The operation is under validation.")) |
||||
|
if vals.get(self._state_field) in self._state_from: |
||||
|
self.mapped('review_ids').unlink() |
||||
|
return super(TierValidation, self).write(vals) |
||||
|
|
||||
|
def _validate_tier(self, tiers=False): |
||||
|
self.ensure_one() |
||||
|
tier_reviews = tiers or self.review_ids |
||||
|
user_reviews = tier_reviews.filtered( |
||||
|
lambda r: r.status in ('pending', 'rejected') and |
||||
|
(r.reviewer_id == self.env.user or |
||||
|
r.reviewer_group_id in self.env.user.groups_id)) |
||||
|
user_reviews.write({ |
||||
|
'status': 'approved', |
||||
|
'done_by': self.env.user.id, |
||||
|
}) |
||||
|
|
||||
|
@api.multi |
||||
|
def validate_tier(self): |
||||
|
for rec in self: |
||||
|
rec._validate_tier() |
||||
|
|
||||
|
@api.multi |
||||
|
def reject_tier(self): |
||||
|
for rec in self: |
||||
|
user_reviews = rec.review_ids.filtered( |
||||
|
lambda r: r.status in ('pending', 'approved') and |
||||
|
(r.reviewer_id == self.env.user or |
||||
|
r.reviewer_group_id in self.env.user.groups_id)) |
||||
|
user_reviews.write({ |
||||
|
'status': 'rejected', |
||||
|
'done_by': self.env.user.id, |
||||
|
}) |
||||
|
|
||||
|
@api.multi |
||||
|
def request_validation(self): |
||||
|
td_obj = self.env['tier.definition'] |
||||
|
tr_obj = created_trs = self.env['tier.review'] |
||||
|
for rec in self: |
||||
|
if getattr(rec, self._state_field) in self._state_from: |
||||
|
if rec.need_validation: |
||||
|
tier_definitions = td_obj.search([ |
||||
|
('model', '=', self._name)], order="sequence desc") |
||||
|
sequence = 0 |
||||
|
for td in tier_definitions: |
||||
|
if self.evaluate_tier(td): |
||||
|
sequence += 1 |
||||
|
created_trs += tr_obj.create({ |
||||
|
'model': self._name, |
||||
|
'res_id': rec.id, |
||||
|
'definition_id': td.id, |
||||
|
'sequence': sequence, |
||||
|
'requested_by': self.env.uid, |
||||
|
}) |
||||
|
# TODO: notify? post some msg in chatter? |
||||
|
return created_trs |
||||
|
|
||||
|
@api.multi |
||||
|
def restart_validation(self): |
||||
|
for rec in self: |
||||
|
if getattr(rec, self._state_field) in self._state_from: |
||||
|
rec.mapped('review_ids').unlink() |
@ -0,0 +1,5 @@ |
|||||
|
To configure this module, you need to: |
||||
|
|
||||
|
#. Go to *Settings > Technical > Tier Validations > Tier Definition*. |
||||
|
#. Create as many tiers as you want for any model having tier validation |
||||
|
functionality. |
@ -0,0 +1,2 @@ |
|||||
|
* Lois Rilo <lois.rilo@eficent.com> |
||||
|
* Naglis Jonaitis <naglis@versada.eu> |
@ -0,0 +1,9 @@ |
|||||
|
This module does not provide a functionality by itself but an abstract model |
||||
|
to implement a validation process based on tiers on other models (e.g. |
||||
|
purchase orders, sales orders...). |
||||
|
|
||||
|
**Note:** To be able to use this module in a new model you will need some |
||||
|
development. |
||||
|
|
||||
|
See `purchase_tier_validation <https://github |
||||
|
.com/OCA/purchase-workflow>`_ as an example of implementation. |
@ -0,0 +1 @@ |
|||||
|
* Starting with Odoo v11 it would be interesting to try to take advantage of ``mail.activity.mixin``. |
@ -0,0 +1,4 @@ |
|||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink |
||||
|
access_tier_review,access.tier.review,model_tier_review,,1,1,1,1 |
||||
|
access_tier_definition_all,tier.definition.all,model_tier_definition,,1,0,0,0 |
||||
|
access_tier_definition_settings,tier.definition.settings,model_tier_definition,base.group_system,1,1,1,1 |
@ -0,0 +1,443 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
|
<head> |
||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
||||
|
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" /> |
||||
|
<title>Base Tier Validation</title> |
||||
|
<style type="text/css"> |
||||
|
|
||||
|
/* |
||||
|
:Author: David Goodger (goodger@python.org) |
||||
|
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $ |
||||
|
:Copyright: This stylesheet has been placed in the public domain. |
||||
|
|
||||
|
Default cascading style sheet for the HTML output of Docutils. |
||||
|
|
||||
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to |
||||
|
customize this style sheet. |
||||
|
*/ |
||||
|
|
||||
|
/* used to remove borders from tables and images */ |
||||
|
.borderless, table.borderless td, table.borderless th { |
||||
|
border: 0 } |
||||
|
|
||||
|
table.borderless td, table.borderless th { |
||||
|
/* Override padding for "table.docutils td" with "! important". |
||||
|
The right padding separates the table cells. */ |
||||
|
padding: 0 0.5em 0 0 ! important } |
||||
|
|
||||
|
.first { |
||||
|
/* Override more specific margin styles with "! important". */ |
||||
|
margin-top: 0 ! important } |
||||
|
|
||||
|
.last, .with-subtitle { |
||||
|
margin-bottom: 0 ! important } |
||||
|
|
||||
|
.hidden { |
||||
|
display: none } |
||||
|
|
||||
|
.subscript { |
||||
|
vertical-align: sub; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
.superscript { |
||||
|
vertical-align: super; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
a.toc-backref { |
||||
|
text-decoration: none ; |
||||
|
color: black } |
||||
|
|
||||
|
blockquote.epigraph { |
||||
|
margin: 2em 5em ; } |
||||
|
|
||||
|
dl.docutils dd { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] { |
||||
|
overflow: hidden; |
||||
|
} |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms |
||||
|
dl.docutils dt { |
||||
|
font-weight: bold } |
||||
|
*/ |
||||
|
|
||||
|
div.abstract { |
||||
|
margin: 2em 5em } |
||||
|
|
||||
|
div.abstract p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
text-align: center } |
||||
|
|
||||
|
div.admonition, div.attention, div.caution, div.danger, div.error, |
||||
|
div.hint, div.important, div.note, div.tip, div.warning { |
||||
|
margin: 2em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.admonition p.admonition-title, div.hint p.admonition-title, |
||||
|
div.important p.admonition-title, div.note p.admonition-title, |
||||
|
div.tip p.admonition-title { |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
div.attention p.admonition-title, div.caution p.admonition-title, |
||||
|
div.danger p.admonition-title, div.error p.admonition-title, |
||||
|
div.warning p.admonition-title, .code .error { |
||||
|
color: red ; |
||||
|
font-weight: bold ; |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
/* Uncomment (and remove this text!) to get reduced vertical space in |
||||
|
compound paragraphs. |
||||
|
div.compound .compound-first, div.compound .compound-middle { |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
div.compound .compound-last, div.compound .compound-middle { |
||||
|
margin-top: 0.5em } |
||||
|
*/ |
||||
|
|
||||
|
div.dedication { |
||||
|
margin: 2em 5em ; |
||||
|
text-align: center ; |
||||
|
font-style: italic } |
||||
|
|
||||
|
div.dedication p.topic-title { |
||||
|
font-weight: bold ; |
||||
|
font-style: normal } |
||||
|
|
||||
|
div.figure { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
div.footer, div.header { |
||||
|
clear: both; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
div.line-block { |
||||
|
display: block ; |
||||
|
margin-top: 1em ; |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
div.line-block div.line-block { |
||||
|
margin-top: 0 ; |
||||
|
margin-bottom: 0 ; |
||||
|
margin-left: 1.5em } |
||||
|
|
||||
|
div.sidebar { |
||||
|
margin: 0 0 0.5em 1em ; |
||||
|
border: medium outset ; |
||||
|
padding: 1em ; |
||||
|
background-color: #ffffee ; |
||||
|
width: 40% ; |
||||
|
float: right ; |
||||
|
clear: right } |
||||
|
|
||||
|
div.sidebar p.rubric { |
||||
|
font-family: sans-serif ; |
||||
|
font-size: medium } |
||||
|
|
||||
|
div.system-messages { |
||||
|
margin: 5em } |
||||
|
|
||||
|
div.system-messages h1 { |
||||
|
color: red } |
||||
|
|
||||
|
div.system-message { |
||||
|
border: medium outset ; |
||||
|
padding: 1em } |
||||
|
|
||||
|
div.system-message p.system-message-title { |
||||
|
color: red ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
div.topic { |
||||
|
margin: 2em } |
||||
|
|
||||
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, |
||||
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { |
||||
|
margin-top: 0.4em } |
||||
|
|
||||
|
h1.title { |
||||
|
text-align: center } |
||||
|
|
||||
|
h2.subtitle { |
||||
|
text-align: center } |
||||
|
|
||||
|
hr.docutils { |
||||
|
width: 75% } |
||||
|
|
||||
|
img.align-left, .figure.align-left, object.align-left, table.align-left { |
||||
|
clear: left ; |
||||
|
float: left ; |
||||
|
margin-right: 1em } |
||||
|
|
||||
|
img.align-right, .figure.align-right, object.align-right, table.align-right { |
||||
|
clear: right ; |
||||
|
float: right ; |
||||
|
margin-left: 1em } |
||||
|
|
||||
|
img.align-center, .figure.align-center, object.align-center { |
||||
|
display: block; |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
table.align-center { |
||||
|
margin-left: auto; |
||||
|
margin-right: auto; |
||||
|
} |
||||
|
|
||||
|
.align-left { |
||||
|
text-align: left } |
||||
|
|
||||
|
.align-center { |
||||
|
clear: both ; |
||||
|
text-align: center } |
||||
|
|
||||
|
.align-right { |
||||
|
text-align: right } |
||||
|
|
||||
|
/* reset inner alignment in figures */ |
||||
|
div.align-right { |
||||
|
text-align: inherit } |
||||
|
|
||||
|
/* div.align-center * { */ |
||||
|
/* text-align: left } */ |
||||
|
|
||||
|
.align-top { |
||||
|
vertical-align: top } |
||||
|
|
||||
|
.align-middle { |
||||
|
vertical-align: middle } |
||||
|
|
||||
|
.align-bottom { |
||||
|
vertical-align: bottom } |
||||
|
|
||||
|
ol.simple, ul.simple { |
||||
|
margin-bottom: 1em } |
||||
|
|
||||
|
ol.arabic { |
||||
|
list-style: decimal } |
||||
|
|
||||
|
ol.loweralpha { |
||||
|
list-style: lower-alpha } |
||||
|
|
||||
|
ol.upperalpha { |
||||
|
list-style: upper-alpha } |
||||
|
|
||||
|
ol.lowerroman { |
||||
|
list-style: lower-roman } |
||||
|
|
||||
|
ol.upperroman { |
||||
|
list-style: upper-roman } |
||||
|
|
||||
|
p.attribution { |
||||
|
text-align: right ; |
||||
|
margin-left: 50% } |
||||
|
|
||||
|
p.caption { |
||||
|
font-style: italic } |
||||
|
|
||||
|
p.credits { |
||||
|
font-style: italic ; |
||||
|
font-size: smaller } |
||||
|
|
||||
|
p.label { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
p.rubric { |
||||
|
font-weight: bold ; |
||||
|
font-size: larger ; |
||||
|
color: maroon ; |
||||
|
text-align: center } |
||||
|
|
||||
|
p.sidebar-title { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold ; |
||||
|
font-size: larger } |
||||
|
|
||||
|
p.sidebar-subtitle { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
p.topic-title { |
||||
|
font-weight: bold } |
||||
|
|
||||
|
pre.address { |
||||
|
margin-bottom: 0 ; |
||||
|
margin-top: 0 ; |
||||
|
font: inherit } |
||||
|
|
||||
|
pre.literal-block, pre.doctest-block, pre.math, pre.code { |
||||
|
margin-left: 2em ; |
||||
|
margin-right: 2em } |
||||
|
|
||||
|
pre.code .ln { color: grey; } /* line numbers */ |
||||
|
pre.code, code { background-color: #eeeeee } |
||||
|
pre.code .comment, code .comment { color: #5C6576 } |
||||
|
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } |
||||
|
pre.code .literal.string, code .literal.string { color: #0C5404 } |
||||
|
pre.code .name.builtin, code .name.builtin { color: #352B84 } |
||||
|
pre.code .deleted, code .deleted { background-color: #DEB0A1} |
||||
|
pre.code .inserted, code .inserted { background-color: #A3D289} |
||||
|
|
||||
|
span.classifier { |
||||
|
font-family: sans-serif ; |
||||
|
font-style: oblique } |
||||
|
|
||||
|
span.classifier-delimiter { |
||||
|
font-family: sans-serif ; |
||||
|
font-weight: bold } |
||||
|
|
||||
|
span.interpreted { |
||||
|
font-family: sans-serif } |
||||
|
|
||||
|
span.option { |
||||
|
white-space: nowrap } |
||||
|
|
||||
|
span.pre { |
||||
|
white-space: pre } |
||||
|
|
||||
|
span.problematic { |
||||
|
color: red } |
||||
|
|
||||
|
span.section-subtitle { |
||||
|
/* font-size relative to parent (h1..h6 element) */ |
||||
|
font-size: 80% } |
||||
|
|
||||
|
table.citation { |
||||
|
border-left: solid 1px gray; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docinfo { |
||||
|
margin: 2em 4em } |
||||
|
|
||||
|
table.docutils { |
||||
|
margin-top: 0.5em ; |
||||
|
margin-bottom: 0.5em } |
||||
|
|
||||
|
table.footnote { |
||||
|
border-left: solid 1px black; |
||||
|
margin-left: 1px } |
||||
|
|
||||
|
table.docutils td, table.docutils th, |
||||
|
table.docinfo td, table.docinfo th { |
||||
|
padding-left: 0.5em ; |
||||
|
padding-right: 0.5em ; |
||||
|
vertical-align: top } |
||||
|
|
||||
|
table.docutils th.field-name, table.docinfo th.docinfo-name { |
||||
|
font-weight: bold ; |
||||
|
text-align: left ; |
||||
|
white-space: nowrap ; |
||||
|
padding-left: 0 } |
||||
|
|
||||
|
/* "booktabs" style (no vertical lines) */ |
||||
|
table.docutils.booktabs { |
||||
|
border: 0px; |
||||
|
border-top: 2px solid; |
||||
|
border-bottom: 2px solid; |
||||
|
border-collapse: collapse; |
||||
|
} |
||||
|
table.docutils.booktabs * { |
||||
|
border: 0px; |
||||
|
} |
||||
|
table.docutils.booktabs th { |
||||
|
border-bottom: thin solid; |
||||
|
text-align: left; |
||||
|
} |
||||
|
|
||||
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, |
||||
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { |
||||
|
font-size: 100% } |
||||
|
|
||||
|
ul.auto-toc { |
||||
|
list-style-type: none } |
||||
|
|
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="document" id="base-tier-validation"> |
||||
|
<h1 class="title">Base Tier Validation</h1> |
||||
|
|
||||
|
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
||||
|
!! This file is generated by oca-gen-addon-readme !! |
||||
|
!! changes will be overwritten. !! |
||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> |
||||
|
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-ux/tree/11.0/base_tier_validation"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-ux-11-0/server-ux-11-0-base_tier_validation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/250/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> |
||||
|
<p>This module does not provide a functionality by itself but an abstract model |
||||
|
to implement a validation process based on tiers on other models (e.g. |
||||
|
purchase orders, sales orders…).</p> |
||||
|
<p><strong>Note:</strong> To be able to use this module in a new model you will need some |
||||
|
development.</p> |
||||
|
<p>See <a class="reference external" href="https://github.com/OCA/purchase-workflow">purchase_tier_validation</a> as an example of implementation.</p> |
||||
|
<p><strong>Table of contents</strong></p> |
||||
|
<div class="contents local topic" id="contents"> |
||||
|
<ul class="simple"> |
||||
|
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li> |
||||
|
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li> |
||||
|
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li> |
||||
|
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul> |
||||
|
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li> |
||||
|
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li> |
||||
|
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li> |
||||
|
</ul> |
||||
|
</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="configuration"> |
||||
|
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> |
||||
|
<p>To configure this module, you need to:</p> |
||||
|
<ol class="arabic simple"> |
||||
|
<li>Go to <em>Settings > Technical > Tier Validations > Tier Definition</em>.</li> |
||||
|
<li>Create as many tiers as you want for any model having tier validation |
||||
|
functionality.</li> |
||||
|
</ol> |
||||
|
</div> |
||||
|
<div class="section" id="known-issues-roadmap"> |
||||
|
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1> |
||||
|
<ul class="simple"> |
||||
|
<li>In odoo v11 it would be interesting to try to take advantage of <tt class="docutils literal">mail.activity.mixin</tt>.</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="bug-tracker"> |
||||
|
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1> |
||||
|
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-ux/issues">GitHub Issues</a>. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed |
||||
|
<a class="reference external" href="https://github.com/OCA/server-ux/issues/new?body=module:%20base_tier_validation%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> |
||||
|
<p>Do not contact contributors directly about support or help with technical issues.</p> |
||||
|
</div> |
||||
|
<div class="section" id="credits"> |
||||
|
<h1><a class="toc-backref" href="#id4">Credits</a></h1> |
||||
|
<div class="section" id="authors"> |
||||
|
<h2><a class="toc-backref" href="#id5">Authors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Eficent</li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="contributors"> |
||||
|
<h2><a class="toc-backref" href="#id6">Contributors</a></h2> |
||||
|
<ul class="simple"> |
||||
|
<li>Lois Rilo <<a class="reference external" href="mailto:lois.rilo@eficent.com">lois.rilo@eficent.com</a>></li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="section" id="maintainers"> |
||||
|
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2> |
||||
|
<p>This module is maintained by the OCA.</p> |
||||
|
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> |
||||
|
<p>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.</p> |
||||
|
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p> |
||||
|
<p><a class="reference external" href="https://github.com/lreficent"><img alt="lreficent" src="https://github.com/lreficent.png?size=40px" /></a></p> |
||||
|
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-ux/tree/11.0/base_tier_validation">OCA/server-ux</a> project on GitHub.</p> |
||||
|
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,4 @@ |
|||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import common |
||||
|
from . import test_tier_validation |
@ -0,0 +1,13 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
|
||||
|
def setup_test_model(env, model_clses): |
||||
|
for model_cls in model_clses: |
||||
|
model_cls._build_model(env.registry, env.cr) |
||||
|
|
||||
|
env.registry.setup_models(env.cr) |
||||
|
env.registry.init_models( |
||||
|
env.cr, [model_cls._name for model_cls in model_clses], |
||||
|
dict(env.context, update_custom_fields=True) |
||||
|
) |
@ -0,0 +1,150 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
||||
|
|
||||
|
from odoo.tests import common |
||||
|
from odoo.exceptions import ValidationError, UserError |
||||
|
from .common import setup_test_model |
||||
|
from .tier_validation_tester import TierValidationTester |
||||
|
|
||||
|
|
||||
|
@common.at_install(False) |
||||
|
@common.post_install(True) |
||||
|
class TierTierValidation(common.SavepointCase): |
||||
|
|
||||
|
@classmethod |
||||
|
def setUpClass(cls): |
||||
|
super(TierTierValidation, cls).setUpClass() |
||||
|
|
||||
|
setup_test_model(cls.env, [TierValidationTester]) |
||||
|
|
||||
|
cls.test_model = cls.env[TierValidationTester._name] |
||||
|
|
||||
|
cls.tester_model = cls.env['ir.model'].search([ |
||||
|
('model', '=', 'tier.validation.tester')]) |
||||
|
|
||||
|
# Access record: |
||||
|
cls.env["ir.model.access"].create({ |
||||
|
'name': "access.tester", |
||||
|
'model_id': cls.tester_model.id, |
||||
|
'perm_read': 1, |
||||
|
'perm_write': 1, |
||||
|
'perm_create': 1, |
||||
|
'perm_unlink': 1, |
||||
|
}) |
||||
|
|
||||
|
# Create users: |
||||
|
group_ids = cls.env.ref('base.group_system').ids |
||||
|
cls.test_user_1 = cls.env['res.users'].create({ |
||||
|
'name': 'John', |
||||
|
'login': 'test1', |
||||
|
'groups_id': [(6, 0, group_ids)], |
||||
|
}) |
||||
|
cls.test_user_2 = cls.env['res.users'].create({ |
||||
|
'name': 'Mike', |
||||
|
'login': 'test2', |
||||
|
}) |
||||
|
|
||||
|
# Create tier definition: |
||||
|
cls.tier_def_obj = cls.env['tier.definition'] |
||||
|
cls.tier_def_obj.create({ |
||||
|
'model_id': cls.tester_model.id, |
||||
|
'review_type': 'individual', |
||||
|
'reviewer_id': cls.test_user_1.id, |
||||
|
'python_code': 'rec.test_field > 1.0', |
||||
|
}) |
||||
|
|
||||
|
cls.test_record = cls.test_model.create({ |
||||
|
'test_field': 2.5, |
||||
|
}) |
||||
|
|
||||
|
def test_01_auto_validation(self): |
||||
|
"""When the user can validate all future reviews, it is not needed |
||||
|
to request a validation, the action can be done straight forward.""" |
||||
|
self.test_record.sudo(self.test_user_1.id).action_confirm() |
||||
|
self.assertEqual(self.test_record.state, 'confirmed') |
||||
|
|
||||
|
def test_02_no_auto_validation(self): |
||||
|
"""User with no right to validate future reviews must request a |
||||
|
validation.""" |
||||
|
with self.assertRaises(ValidationError): |
||||
|
self.test_record.sudo(self.test_user_2.id).action_confirm() |
||||
|
|
||||
|
def test_03_request_validation_approved(self): |
||||
|
"""User 2 request a validation and user 1 approves it.""" |
||||
|
self.assertFalse(self.test_record.review_ids) |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_2.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
record.validate_tier() |
||||
|
self.assertTrue(record.validated) |
||||
|
|
||||
|
def test_04_request_validation_rejected(self): |
||||
|
"""Request validation, rejection and reset.""" |
||||
|
self.assertFalse(self.test_record.review_ids) |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_2.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
record.reject_tier() |
||||
|
self.assertTrue(record.review_ids) |
||||
|
self.assertTrue(record.rejected) |
||||
|
record.restart_validation() |
||||
|
self.assertFalse(record.review_ids) |
||||
|
|
||||
|
def test_05_under_validation(self): |
||||
|
"""Write is forbidden in a record under validation.""" |
||||
|
self.assertFalse(self.test_record.review_ids) |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_2.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
with self.assertRaises(ValidationError): |
||||
|
record.write({'test_field': 0.5}) |
||||
|
|
||||
|
def test_06_validation_process_open(self): |
||||
|
"""Operation forbidden while a validation process is open.""" |
||||
|
self.assertFalse(self.test_record.review_ids) |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_2.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
with self.assertRaises(ValidationError): |
||||
|
record.action_confirm() |
||||
|
|
||||
|
def test_07_search_reviewers(self): |
||||
|
"""Test search methods.""" |
||||
|
reviews = self.test_record.sudo( |
||||
|
self.test_user_2.id).request_validation() |
||||
|
self.assertTrue(reviews) |
||||
|
record = self.test_record.sudo(self.test_user_1.id) |
||||
|
self.assertIn(self.test_user_1, record.reviewer_ids) |
||||
|
res = self.test_model.search( |
||||
|
[('reviewer_ids', 'in', self.test_user_1.id)]) |
||||
|
self.assertTrue(res) |
||||
|
|
||||
|
def test_08_search_validated(self): |
||||
|
"""Test for the validated search method.""" |
||||
|
self.test_record.sudo(self.test_user_2.id).request_validation() |
||||
|
res = self.test_model.sudo(self.test_user_1.id).search( |
||||
|
[('validated', '=', False)]) |
||||
|
self.assertTrue(res) |
||||
|
|
||||
|
def test_09_wrong_tier_definition(self): |
||||
|
"""Error should raise with incorrect python expresions on |
||||
|
tier definitions.""" |
||||
|
self.tier_def_obj.create({ |
||||
|
'model_id': self.tester_model.id, |
||||
|
'review_type': 'individual', |
||||
|
'reviewer_id': self.test_user_1.id, |
||||
|
'python_code': 'rec.not_existing_field > 1.0', |
||||
|
}) |
||||
|
with self.assertRaises(UserError): |
||||
|
self.test_record.sudo(self.test_user_1.id).action_confirm() |
||||
|
|
||||
|
def test_10_dummy_tier_definition(self): |
||||
|
"""Test tier.definition methods.""" |
||||
|
res = self.tier_def_obj._get_tier_validation_model_names() |
||||
|
self.assertEqual(res, []) |
||||
|
res = self.tier_def_obj.onchange_model_id() |
||||
|
self.assertTrue(res) |
@ -0,0 +1,21 @@ |
|||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L. |
||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class TierValidationTester(models.Model): |
||||
|
_name = 'tier.validation.tester' |
||||
|
_inherit = ['tier.validation'] |
||||
|
|
||||
|
state = fields.Selection( |
||||
|
selection=[('draft', 'Draft'), |
||||
|
('confirmed', 'Confirmed'), |
||||
|
('cancel', 'Cancel')], |
||||
|
default='draft', |
||||
|
) |
||||
|
test_field = fields.Float() |
||||
|
|
||||
|
@api.multi |
||||
|
def action_confirm(self): |
||||
|
self.write({'state': 'confirmed'}) |
@ -0,0 +1,89 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> |
||||
|
<odoo> |
||||
|
|
||||
|
<record id="tier_definition_view_tree" model="ir.ui.view"> |
||||
|
<field name="name">tier.definition.tree</field> |
||||
|
<field name="model">tier.definition</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree string="Tier Definition"> |
||||
|
<field name="model_id"/> |
||||
|
<field name="review_type"/> |
||||
|
<field name="reviewer_id"/> |
||||
|
<field name="reviewer_group_id"/> |
||||
|
<field name="sequence"/> |
||||
|
<field name="company_id" groups="base.group_multi_company"/> |
||||
|
<field name="active"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="tier_definition_view_form" model="ir.ui.view"> |
||||
|
<field name="name">tier.definition.form</field> |
||||
|
<field name="model">tier.definition</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Tier Definition"> |
||||
|
<sheet> |
||||
|
<div class="oe_button_box" name="button_box"> |
||||
|
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive"> |
||||
|
<field name="active" widget="boolean_button"/> |
||||
|
</button> |
||||
|
</div> |
||||
|
<group> |
||||
|
<group name="left"> |
||||
|
<field name="model_id" options="{'no_create': True}"/> |
||||
|
<field name="review_type"/> |
||||
|
<field name="reviewer_id" |
||||
|
attrs="{'invisible': [('review_type', '!=', 'individual')]}"/> |
||||
|
<field name="reviewer_group_id" |
||||
|
attrs="{'invisible': [('review_type', '!=', 'group')]}"/> |
||||
|
</group> |
||||
|
<group name="right"> |
||||
|
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/> |
||||
|
<field name="sequence"/> |
||||
|
</group> |
||||
|
</group> |
||||
|
<group col="4" name="bottom"> |
||||
|
<field name="python_code" colspan="4"/> |
||||
|
</group> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="tier_definition_view_search" model="ir.ui.view"> |
||||
|
<field name="name">tier.definition.search</field> |
||||
|
<field name="model">tier.definition</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<search> |
||||
|
<field name="model_id"/> |
||||
|
<field name="reviewer_id"/> |
||||
|
<field name="reviewer_group_id"/> |
||||
|
<field name="active"/> |
||||
|
<separator/> |
||||
|
<filter string="All" name="all" domain="['|', ('active', '=', False), ('active', '=', True)]" /> |
||||
|
<group expand="0" string="Group By"> |
||||
|
<filter string="Model" name="model_id" domain="[]" context="{'group_by':'model_id'}"/> |
||||
|
</group> |
||||
|
</search> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="tier_definition_action" model="ir.actions.act_window"> |
||||
|
<field name="name">Tier Definition</field> |
||||
|
<field name="type">ir.actions.act_window</field> |
||||
|
<field name="res_model">tier.definition</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">tree,form</field> |
||||
|
<field name="context">{'search_default_all': 1}</field> |
||||
|
</record> |
||||
|
|
||||
|
<menuitem id="menu_tier_confirmation" |
||||
|
name="Tier Validations" |
||||
|
parent="base.menu_custom"/> |
||||
|
<menuitem id="menu_tier_definition" |
||||
|
parent="menu_tier_confirmation" |
||||
|
action="tier_definition_action"/> |
||||
|
|
||||
|
</odoo> |
@ -0,0 +1,24 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L. |
||||
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> |
||||
|
<odoo> |
||||
|
|
||||
|
<record id="tier_review_view_tree" model="ir.ui.view"> |
||||
|
<field name="name">tier.review.tree</field> |
||||
|
<field name="model">tier.review</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree string="Tier Review" |
||||
|
decoration-danger="status=='rejected'" |
||||
|
decoration-success="status=='approved'"> |
||||
|
<field name="sequence"/> |
||||
|
<field name="requested_by"/> |
||||
|
<field name="review_type"/> |
||||
|
<field name="reviewer_id"/> |
||||
|
<field name="reviewer_group_id"/> |
||||
|
<field name="status"/> |
||||
|
<field name="done_by"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue