Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] base_tier_validation_waiting #638

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def _notify_review_requested(self, tier_reviews):
subscribe = "message_subscribe"
post = "message_post"
if hasattr(self, post) and hasattr(self, subscribe):
for rec in self:
for rec in self.sudo():
users_to_notify = tier_reviews.filtered(
lambda r: r.definition_id.notify_on_create and r.res_id == rec.id
).mapped("reviewer_ids")
Expand Down
9 changes: 7 additions & 2 deletions base_tier_validation/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ def setUpClass(cls):
# 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)]}
{
"name": "John",
"login": "test1",
"email": "john@yourcompany.example.com",
"groups_id": [(6, 0, group_ids)],
}
)
cls.test_user_2 = cls.env["res.users"].create(
{"name": "Mike", "login": "test2"}
{"name": "Mike", "login": "test2", "email": "mike@yourcompany.example.com"}
)

# Create tier definitions:
Expand Down
4 changes: 2 additions & 2 deletions base_tier_validation/tests/tier_validation_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TierValidationTester(models.Model):
_name = "tier.validation.tester"
_description = "Tier Validation Tester"
_inherit = ["tier.validation"]
_inherit = ["tier.validation", "mail.thread"]
_tier_validation_manual_config = True

state = fields.Selection(
Expand All @@ -28,7 +28,7 @@ def action_confirm(self):
class TierValidationTester2(models.Model):
_name = "tier.validation.tester2"
_description = "Tier Validation Tester 2"
_inherit = ["tier.validation"]
_inherit = ["tier.validation", "mail.thread"]
_tier_validation_manual_config = False

state = fields.Selection(
Expand Down
13 changes: 10 additions & 3 deletions base_tier_validation_formula/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ def setUpClass(cls):
# 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)]}
{
"name": "John",
"login": "test1",
"groups_id": [(6, 0, group_ids)],
"email": "john@yourcompany.example.com",
}
)
cls.test_user_2 = cls.env["res.users"].create(
{"name": "Mike", "login": "test2"}
{"name": "Mike", "login": "test2", "email": "mike@yourcompany.example.com"}
)
cls.test_user_3 = cls.env["res.users"].create(
{"name": "Mary", "login": "test3"}
{"name": "Mary", "login": "test3", "email": "mary@yourcompany.example.com"}
)

# Create tier definitions:
Expand Down Expand Up @@ -103,6 +108,8 @@ def test_01_reviewer_from_python_expression(self):
record = self.test_record.with_user(self.test_user_1.id)
self.test_record.invalidate_cache()
record.invalidate_cache()
record.review_ids[0]._compute_can_review()
record.review_ids[1]._compute_can_review()
self.assertIn(self.test_user_1, record.reviewer_ids)
self.assertIn(self.test_user_2, record.reviewer_ids)
res = self.test_model.search([("reviewer_ids", "in", self.test_user_2.id)])
Expand Down
16 changes: 12 additions & 4 deletions base_tier_validation_forward/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class TierTierValidation(TransactionCase):
@classmethod
def setUpClass(cls):
super(TierTierValidation, cls).setUpClass()

cls.env = cls.env(
context=dict(cls.env.context, tracking_disable=True, no_reset_password=True)
)
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from odoo.addons.base_tier_validation.tests.tier_validation_tester import (
Expand Down Expand Up @@ -45,13 +47,18 @@ def setUpClass(cls):
# 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)]}
{
"name": "John",
"login": "test1",
"groups_id": [(6, 0, group_ids)],
"email": "john@yourcompany.example.com",
}
)
cls.test_user_2 = cls.env["res.users"].create(
{"name": "Mike", "login": "test2"}
{"name": "Mike", "login": "test2", "email": "mike@yourcompany.example.com"}
)
cls.test_user_3 = cls.env["res.users"].create(
{"name": "Mary", "login": "test3"}
{"name": "Mary", "login": "test3", "email": "mary@yourcompany.example.com"}
)

# Create tier definitions:
Expand Down Expand Up @@ -91,6 +98,7 @@ def test_01_forward_tier(self):
self.assertTrue(review)
record = test_record.with_user(self.test_user_1.id)
record.invalidate_cache()
record.review_ids[0]._compute_can_review()
record.validate_tier()
self.assertFalse(record.can_forward)
# User 2 forward to user 1
Expand Down
82 changes: 82 additions & 0 deletions base_tier_validation_waiting/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
=====================================
Base Tier Validation - Waiting status
=====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4346475efe4ef480f0be92477f55cec22180d4b9cc084696826c6ae8a532cf7f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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/15.0/base_tier_validation_waiting
: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-15-0/server-ux-15-0-base_tier_validation_waiting
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends base_tier_validation to add an initial **"waiting"** status to tier reviews.
It also auto moves next review to pending status when needed and handles notification if set.

**Table of contents**

.. contents::
:local:

Configuration
=============

Set "Notify reviewers on reaching pending" if you want to send a notification when pending status is reached

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20base_tier_validation_waiting%0Aversion:%2015.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
~~~~~~~

* brain-tec AG

Contributors
~~~~~~~~~~~~

* Javier Colmeiro <javier.colmeiro@braintec.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.

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/15.0/base_tier_validation_waiting>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions base_tier_validation_waiting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2022 brain-tec AG (https://braintec.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
21 changes: 21 additions & 0 deletions base_tier_validation_waiting/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2022 brain-tec AG (https://braintec.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Base Tier Validation - Waiting status",
"summary": "Base Tier Validation Extension to add waiting status",
"category": "Tools",
"version": "15.0.1.0.0",
"author": "brain-tec AG, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-ux",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"base_tier_validation",
],
"data": [
"security/ir.model.access.csv",
"views/tier_definition_views.xml",
],
"qweb": ["static/src/xml/tier_review_template.xml"],
}
72 changes: 72 additions & 0 deletions base_tier_validation_waiting/i18n/base_tier_validation_waiting.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_tier_validation_waiting
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.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_waiting
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_definition__display_name
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_review__display_name
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_validation__display_name
msgid "Display Name"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_definition__id
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_review__id
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_validation__id
msgid "ID"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields,help:base_tier_validation_waiting.field_tier_definition__notify_on_pending
msgid ""
"If set, all possible reviewers will be notified by email when this "
"definition is triggered."
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_definition____last_update
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_review____last_update
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_validation____last_update
msgid "Last Modified on"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_definition__notify_on_pending
msgid "Notify Reviewers on reaching Pending"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields,field_description:base_tier_validation_waiting.field_tier_review__status
msgid "Status"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model,name:base_tier_validation_waiting.model_tier_definition
msgid "Tier Definition"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model,name:base_tier_validation_waiting.model_tier_review
msgid "Tier Review"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model,name:base_tier_validation_waiting.model_tier_validation
msgid "Tier Validation (abstract)"
msgstr ""

#. module: base_tier_validation_waiting
#: model:ir.model.fields.selection,name:base_tier_validation_waiting.selection__tier_review__status__waiting
msgid "Waiting"
msgstr ""
6 changes: 6 additions & 0 deletions base_tier_validation_waiting/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2022 brain-tec AG (https://braintec.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import tier_definition
from . import tier_review
from . import tier_validation
14 changes: 14 additions & 0 deletions base_tier_validation_waiting/models/tier_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2022 brain-tec AG (https://braintec.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class TierDefinition(models.Model):
_inherit = "tier.definition"

notify_on_pending = fields.Boolean(
string="Notify Reviewers on reaching Pending",
help="If set, all possible reviewers will be notified by email when "
"this definition is triggered.",
)
56 changes: 56 additions & 0 deletions base_tier_validation_waiting/models/tier_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2022 brain-tec AG (https://braintec.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.tools import config


class TierReview(models.Model):
_inherit = "tier.review"

def _default_status(self):
if (
not config["test_enable"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this specific check for tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, without this commit, it would mean that we need to patch a lot of depending modules, to fix their tests.

Another solution I've evaluated is using seperate tests. That might solve the problem with the CI tests here on github.
But it would simply transfer the problem to the persons running an custom CI like odoo.sh.

The method here is not really clean. But it's the least dirty solution.
(Discussed this test issue with a couple of oca contributors at the OXP)
Maybe you have another insight to solve this problem?

or config["test_enable"]
and self.env.context.get("testing_base_tier_validation_waiting")
):
return "waiting"
else:
return "pending"

status = fields.Selection(
selection_add=[("waiting", "Waiting")],
default=_default_status,
Copy link
Contributor

@simahawk simahawk Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use lambda to not reference the method object directly

ondelete={"waiting": "set default"},
)

def _notify_pending_status(self, review_ids):
"""Method to call and reuse abstract notification method"""
resource = self.env[self.model].browse(self.res_id)
resource._notify_review_available(review_ids)

@api.depends("definition_id.approve_sequence")
def _compute_can_review(self):
"""inherit base module to push forward waiting reviews"""
reviews = self.filtered(
lambda rev: rev.status in ["waiting", "pending", "rejected"]
)
if reviews:
# get minimum sequence of all to prevent jumps
next_seq = min(reviews.mapped("sequence"))
for record in reviews:
# if not in waiting, nothing to do
if record.status != "waiting":
continue
# if approve by sequence, check sequence has been reached
if record.approve_sequence:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I get this IF block: in any case you set "pending" -> can't you have 1 single check?

if record.sequence == next_seq:
record.status = "pending"
# if there is no approval sequence go directly to pending state
elif not record.approve_sequence:
record.status = "pending"
# notify if state has changed
if record.status == "pending":
if record.definition_id.notify_on_pending:
record._notify_pending_status(record)
return super(TierReview, self)._compute_can_review()
Loading