Skip to content

Commit

Permalink
[18.0][MIG] base_tier_validation: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Nov 12, 2024
1 parent 6964060 commit a85f05c
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 131 deletions.
2 changes: 1 addition & 1 deletion base_tier_validation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Base Tier Validation",
"summary": "Implement a validation process based on tiers.",
"version": "18.0.1.0.1",
"version": "18.0.1.0.0",
"development_status": "Mature",
"maintainers": ["LoisRForgeFlow"],
"category": "Tools",
Expand Down
4 changes: 2 additions & 2 deletions base_tier_validation/models/tier_definition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import api, fields, models


class TierDefinition(models.Model):
Expand All @@ -10,7 +10,7 @@ class TierDefinition(models.Model):

@api.model
def _get_default_name(self):
return _("New Tier Validation")
return self.env._("New Tier Validation")

@api.model
def _get_tier_validation_model_names(self):
Expand Down
30 changes: 13 additions & 17 deletions base_tier_validation/models/tier_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import pytz

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError


class TierReview(models.Model):
_name = "tier.review"
_description = "Tier Review"

name = fields.Char(related="definition_id.name", readonly=True)
name = fields.Char(related="definition_id.name")
status = fields.Selection(
[
("waiting", "Waiting"),
Expand All @@ -28,14 +28,10 @@ class TierReview(models.Model):
related="definition_id.company_id",
store=True,
)
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_field_id = fields.Many2one(
related="definition_id.reviewer_field_id", readonly=True
)
review_type = fields.Selection(related="definition_id.review_type")
reviewer_id = fields.Many2one(related="definition_id.reviewer_id")
reviewer_group_id = fields.Many2one(related="definition_id.reviewer_group_id")
reviewer_field_id = fields.Many2one(related="definition_id.reviewer_field_id")
reviewer_ids = fields.Many2many(
string="Reviewers",
comodel_name="res.users",
Expand All @@ -51,19 +47,17 @@ class TierReview(models.Model):
reviewed_formated_date = fields.Char(
string="Validation Formated Date", compute="_compute_reviewed_formated_date"
)
has_comment = fields.Boolean(related="definition_id.has_comment", readonly=True)
has_comment = fields.Boolean(related="definition_id.has_comment")
comment = fields.Char(string="Comments")
can_review = fields.Boolean(
compute="_compute_can_review",
store=True,
help="""Can review will be marked if the review is pending and the
approve sequence has been achieved""",
)
approve_sequence = fields.Boolean(
related="definition_id.approve_sequence", readonly=True
)
approve_sequence = fields.Boolean(related="definition_id.approve_sequence")
approve_sequence_bypass = fields.Boolean(
related="definition_id.approve_sequence_bypass", readonly=True
related="definition_id.approve_sequence_bypass"
)

@api.depends("status")
Expand Down Expand Up @@ -136,7 +130,7 @@ def _compute_todo_by(self):
for rec in self:
todo_by = False
if rec.reviewer_group_id:
todo_by = _("Group %s") % rec.reviewer_group_id.name
todo_by = self.env._("Group %s") % rec.reviewer_group_id.name
else:
todo_by = ", ".join(rec.reviewer_ids[:num_show].mapped("display_name"))
num_users = len(rec.reviewer_ids)
Expand All @@ -152,7 +146,9 @@ def _get_reviewers(self):
resource = self.env[self.model].browse(self.res_id)
reviewer_field = getattr(resource, self.reviewer_field_id.name, False)
if not reviewer_field or not reviewer_field._name == "res.users":
raise ValidationError(_("There are no res.users in the selected field"))
raise ValidationError(

Check warning on line 149 in base_tier_validation/models/tier_review.py

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_review.py#L149

Added line #L149 was not covered by tests
self.env._("There are no res.users in the selected field")
)
return reviewer_field

def _notify_pending_status(self, review_ids):
Expand Down
89 changes: 47 additions & 42 deletions base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from lxml import etree
from psycopg2.extensions import AsIs

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import SQL
from odoo.tools.misc import frozendict

BASE_EXCEPTION_FIELDS = ["message_follower_ids", "access_token"]
Expand Down Expand Up @@ -163,21 +164,20 @@ def _get_to_validate_message_name(self):
return self._description

def _get_to_validate_message(self):
return (
"""<i class="fa fa-info-circle" /> %s"""
% _("This %s needs to be validated")
% self._get_to_validate_message_name()
msg_fragment = self.env._(
f"This {self._get_to_validate_message_name()} " f"needs to be validated"
)
return f"""<i class="fa fa-info-circle" /> {msg_fragment}"""

def _get_validated_message(self):
msg = """<i class="fa fa-thumbs-up" /> %s""" % _(
"""Operation has been <b>validated</b>!"""
msg = """<i class="fa fa-thumbs-up" /> {}""".format(
self.env._("""Operation has been <b>validated</b>!""")
)
return self.validated and msg or ""

def _get_rejected_message(self):
msg = """<i class="fa fa-thumbs-down" /> %s""" % _(
"""Operation has been <b>rejected</b>."""
msg = """<i class="fa fa-thumbs-down" /> {}""".format(
self.env._("""Operation has been <b>rejected</b>.""")
)
return self.rejected and msg or ""

Expand Down Expand Up @@ -215,7 +215,7 @@ def _compute_next_review(self):
review = rec.review_ids.sorted("sequence").filtered(
lambda x: x.status == "pending"
)[:1]
rec.next_review = review and _("Next: %s") % review.name or ""
rec.next_review = review and self.env._("Next: %s") % review.name or ""

def _compute_hide_reviews(self):
for rec in self:
Expand Down Expand Up @@ -347,11 +347,12 @@ def write(self, vals):
self._tier_validation_check_write_remove_reviews(vals)
return super().write(vals)

def _write(self, vals):
if self._tier_validation_state_field_is_computed:
self._tier_validation_check_state_on_write(vals)
self._tier_validation_check_write_remove_reviews(vals)
return super()._write(vals)
def _write_multi(self, vals_list):
for rec, vals in zip(self, vals_list, strict=False):
if rec._tier_validation_state_field_is_computed:
rec._tier_validation_check_state_on_write(vals)
rec._tier_validation_check_write_remove_reviews(vals)
return super()._write_multi(vals_list)

def _tier_validation_get_current_state_value(self):
"""Get the current value from the cache or the database.
Expand All @@ -362,12 +363,12 @@ def _tier_validation_get_current_state_value(self):
self.ensure_one()
if self._tier_validation_state_field_is_computed and isinstance(self.id, int):
self.env.cr.execute(
"select %(field)s from %(table)s where id = %(res_id)s",
{
"field": AsIs(self._state_field),
"table": AsIs(self._table),
"res_id": self.id,
},
SQL(
"select %(field)s from %(table)s where id = %(res_id)s",
field=AsIs(self._state_field),
table=AsIs(self._table),
res_id=self.id,
)
)
rows = self.env.cr.fetchall()
if rows:
Expand All @@ -383,14 +384,14 @@ def _tier_validation_check_state_on_write(self, vals):
rec._validate_tier(reviews)
if not self._calc_reviews_validated(reviews):
raise ValidationError(
_(
self.env._(
"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(
_(
self.env._(
"A validation process is still open for at least "
"one record."
)
Expand All @@ -414,15 +415,13 @@ def _tier_validation_check_write_allowed(self, vals):
vals, rec._get_under_validation_exceptions
)
raise ValidationError(
_(
self.env._(
"You are not allowed to write those fields under validation.\n"
"- %(not_allowed_fields)s\n\n"
"Only those fields can be modified:\n- %(allowed_fields)s"
"Only those fields can be modified:\n- %(allowed_fields)s",
not_allowed_fields="\n- ".join(not_allowed_fields),
allowed_fields="\n- ".join(allowed_fields),
)
% {
"not_allowed_fields": "\n- ".join(not_allowed_fields),
"allowed_fields": "\n- ".join(allowed_fields),
}
)

# Write after validation. Check only if Tier Validation Exception is created
Expand All @@ -441,7 +440,7 @@ def _tier_validation_check_write_allowed(self, vals):
vals, rec._get_after_validation_exceptions
)
raise ValidationError(
_(
self.env._(
"You are not allowed to write those fields after validation.\n"
"- %(not_allowed_fields)s\n\n"
"Only those fields can be modified:\n- %(allowed_fields)s"
Expand Down Expand Up @@ -552,13 +551,13 @@ def _notify_accepted_reviews_body(self):
)
if has_comment:
comment = has_comment.mapped("comment")[0]
return _("A review was accepted. (%s)") % comment
return _("A review was accepted")
return self.env._("A review was accepted. (%s)") % comment
return self.env._("A review was accepted")

def _add_comment(self, validate_reject, reviews):
wizard = self.env.ref("base_tier_validation.view_comment_wizard")
return {
"name": _("Comment"),
"name": self.env._("Comment"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "comment.wizard",
Expand Down Expand Up @@ -602,11 +601,12 @@ def _notify_rejected_review_body(self):
)
if has_comment:
comment = has_comment.mapped("comment")[0]
return _("A review was rejected by %(user)s. (%(comment)s)") % {
"user": self.env.user.name,
"comment": comment,
}
return _("A review was rejected by %s.") % (self.env.user.name)
return self.env._(
"A review was rejected by %(user)s. (%(comment)s)",
user=self.env.user.name,
comment=comment,
)
return self.env._("A review was rejected by %s.") % (self.env.user.name)

def _notify_rejected_review(self):
post = "message_post"
Expand Down Expand Up @@ -648,12 +648,12 @@ def _rejected_tier(self, tiers=False):
rec._notify_rejected_review()

def _notify_created_review_body(self):
return _("A record to be reviewed has been created by %s.") % (
return self.env._("A record to be reviewed has been created by %s.") % (
self.env.user.name
)

def _notify_requested_review_body(self):
return _("A review has been requested by %s.") % (self.env.user.name)
return self.env._("A review has been requested by %s.") % (self.env.user.name)

def _notify_review_requested(self, tier_reviews):
"""method to notify when tier validation is created"""
Expand Down Expand Up @@ -708,7 +708,7 @@ def request_validation(self):
return created_trs

def _notify_restarted_review_body(self):
return _("The review has been reset by %s.") % (self.env.user.name)
return self.env._("The review has been reset by %s.") % (self.env.user.name)

def _notify_restarted_review(self):
post = "message_post"
Expand Down Expand Up @@ -756,7 +756,12 @@ def _update_counter(self, review_counter):
notifications = []
channel = "base.tier.validation/updated"
notifications.append([self.env.user.partner_id, channel, review_counter])
self.env["bus.bus"]._sendmany(notifications)
self.env["bus.bus"]._sendone(
channel,
"inbox",
f"Base tier validation for partner "
f"{self.env.user.partner_id}, counter {review_counter}",
)

def unlink(self):
self.mapped("review_ids").unlink()
Expand Down
6 changes: 2 additions & 4 deletions base_tier_validation/models/tier_validation_exception.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Copyright 2024 Moduon Team (https://www.moduon.team)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, exceptions, fields, models
from odoo import api, exceptions, fields, models

from .tier_validation import BASE_EXCEPTION_FIELDS


class TierValidationException(models.Model):
_name = "tier.validation.exception"
_description = "Tier Validation Exceptions"
_rec_name = "name"

@api.model
def _get_tier_validation_model_names(self):
Expand All @@ -30,7 +29,6 @@ def _get_tier_validation_model_names(self):
related="model_id.model",
string="Model Name",
store=True,
readonly=True,
index=True,
)
field_ids = fields.Many2many(
Expand Down Expand Up @@ -85,7 +83,7 @@ def _check_allowed_to_write(self):
and not self.allowed_to_write_after_validation
):
raise exceptions.ValidationError(

Check warning on line 85 in base_tier_validation/models/tier_validation_exception.py

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_validation_exception.py#L85

Added line #L85 was not covered by tests
_(
self.env._(
"At least one of these fields must be checked! "
"Write under Validation, Write after Validation"
)
Expand Down
2 changes: 1 addition & 1 deletion base_tier_validation/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ access_tier_review,access.tier.review,model_tier_review,base.group_user,1,1,1,1
access_tier_definition_all,tier.definition.all,model_tier_definition,base.group_user,1,0,0,0
access_tier_definition_settings,tier.definition.settings,model_tier_definition,base.group_system,1,1,1,1
access_comment_wizard,access.comment.wizard,model_comment_wizard,base.group_user,1,1,1,1
access_tier_validation_exceptions_all,tier.validation.exceptions,model_tier_validation_exception,,1,0,0,0
access_tier_validation_exceptions_all,tier.validation.exceptions,model_tier_validation_exception,base.group_user,1,0,0,0
access_tier_validation_exceptions_settings,tier.validation.exceptions,model_tier_validation_exception,base.group_system,1,1,1,1
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/* @odoo-module */

import {Component, useState} from "@odoo/owl";
import {Dropdown} from "@web/core/dropdown/dropdown";
import {DropdownItem} from "@web/core/dropdown/dropdown_item";
import {registry} from "@web/core/registry";
import {useDiscussSystray} from "@mail/utils/common/hooks";
import {useService} from "@web/core/utils/hooks";

const {document} = globalThis;
const systrayRegistry = registry.category("systray");

export class TierReviewMenu extends Component {
setup() {
this.discussSystray = useDiscussSystray();
this.orm = useService("orm");
this.store = useState(useService("mail.store"));
this.state = useState({
tierReviewCounter: 0,
tierReviewGroups: [],
});
this.action = useService("action");
this.fetchSystrayReviewer();
}
Expand All @@ -23,8 +25,8 @@ export class TierReviewMenu extends Component {
for (const group of groups) {
total += group.pending_count || 0;
}
this.store.tierReviewCounter = total;
this.store.tierReviewGroups = groups;
this.state.tierReviewCounter = total;
this.state.tierReviewGroups = groups;
}
onBeforeOpen() {
this.fetchSystrayReviewer();
Expand Down
Loading

0 comments on commit a85f05c

Please sign in to comment.