Skip to content

Commit

Permalink
[MIG] base_tier_validation: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rven authored and celm1990 committed Jan 9, 2024
1 parent 16ed501 commit 3c26247
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 706 deletions.
1 change: 1 addition & 0 deletions base_tier_validation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ Contributors
- Pedro Gonzalez <[email protected]>
- Kitti U. <[email protected]>
- Saran Lim. <[email protected]>
- Carlos Lopez <[email protected]>

Maintainers
-----------
Expand Down
20 changes: 7 additions & 13 deletions 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": "16.0.1.3.3",
"version": "17.0.1.0.0",
"development_status": "Mature",
"maintainers": ["LoisRForgeFlow"],
"category": "Tools",
Expand All @@ -25,18 +25,12 @@
],
"assets": {
"web.assets_backend": [
"/base_tier_validation/static/src/scss/systray.scss",
"/base_tier_validation/static/src/scss/review.scss",
"/base_tier_validation/static/src/js/main.esm.js",
"/base_tier_validation/static/src/js/ir_model.esm.js",
"/base_tier_validation/static/src/js/systray_service.esm.js",
"/base_tier_validation/static/src/js/systray.esm.js",
"/base_tier_validation/static/src/js/review_groups.esm.js",
"/base_tier_validation/static/src/js/reviewer_menu_view.esm.js",
"/base_tier_validation/static/src/js/tier_review_widget.esm.js",
"/base_tier_validation/static/src/js/review_group_view.esm.js",
"/base_tier_validation/static/src/js/reviewer_menu_container.esm.js",
"/base_tier_validation/static/src/js/review_notification_handler.esm.js",
"/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.esm.js",
"/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.xml",
"/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.esm.js",
"/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.scss",
"/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.xml",
"/base_tier_validation/static/src/js/services/tier_review_service.esm.js",
"/base_tier_validation/static/src/xml/**/*",
],
},
Expand Down
6 changes: 3 additions & 3 deletions base_tier_validation/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

# Activate me back when modules are migrated

module_base_tier_validation_formula = fields.Boolean(string="Tier Formula")
module_base_tier_validation_forward = fields.Boolean("Tier Forward & Backward")
# module_base_tier_validation_formula = fields.Boolean(string="Tier Formula")
# module_base_tier_validation_forward = fields.Boolean("Tier Forward & Backward")
# module_base_tier_validation_server_action = fields.Boolean("Tier Server Action")
# module_base_tier_validation_report = fields.Boolean("Tier Reports")
1 change: 0 additions & 1 deletion base_tier_validation/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def review_user_count(self):
records = records.filtered(
lambda x: x[x._state_field] != x._cancel_state
)
# if len(records):
for rec in records:
record = self.env[model]
user_reviews[model] = {
Expand Down
21 changes: 11 additions & 10 deletions base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TierValidation(models.AbstractModel):
)
has_comment = fields.Boolean(compute="_compute_has_comment")
next_review = fields.Char(compute="_compute_next_review")
hide_reviews = fields.Boolean(compute="_compute_hide_reviews")

def _compute_has_comment(self):
for rec in self:
Expand Down Expand Up @@ -197,10 +198,14 @@ def _compute_validation_status(self):
def _compute_next_review(self):
for rec in self:
review = rec.review_ids.sorted("sequence").filtered(
lambda l: l.status == "pending"
lambda x: x.status == "pending"
)[:1]
rec.next_review = review and _("Next: %s") % review.name or ""

def _compute_hide_reviews(self):
for rec in self:
rec.hide_reviews = rec[self._state_field] not in self._state_from

@api.model
def _calc_reviews_validated(self, reviews):
"""Override for different validation policy."""
Expand Down Expand Up @@ -282,7 +287,7 @@ def write(self, vals):
raise ValidationError(_("The operation is under validation."))
if rec._allow_to_remove_reviews(vals):
rec.mapped("review_ids").unlink()
return super(TierValidation, self).write(vals)
return super().write(vals)

def _allow_to_remove_reviews(self, values):
"""Method for deciding whether the elimination of revisions is necessary."""
Expand Down Expand Up @@ -381,7 +386,7 @@ def validate_tier(self):
self.ensure_one()
sequences = self._get_sequences_to_approve(self.env.user)
reviews = self.review_ids.filtered(
lambda l: l.sequence in sequences or l.approve_sequence_bypass
lambda x: x.sequence in sequences or x.approve_sequence_bypass
)
if self.has_comment:
return self._add_comment("validate", reviews)
Expand All @@ -391,7 +396,7 @@ def validate_tier(self):
def reject_tier(self):
self.ensure_one()
sequences = self._get_sequences_to_approve(self.env.user)
reviews = self.review_ids.filtered(lambda l: l.sequence in sequences)
reviews = self.review_ids.filtered(lambda x: x.sequence in sequences)
if self.has_comment:
return self._add_comment("reject", reviews)
self._rejected_tier(reviews)
Expand Down Expand Up @@ -444,7 +449,7 @@ def _notify_review_requested(self, tier_reviews):
if hasattr(self, post) and hasattr(self, subscribe):
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
lambda r: r.definition_id.notify_on_create and r.res_id == rec.id # noqa: B023
).mapped("reviewer_ids")
# Subscribe reviewers and notify
getattr(rec, subscribe)(
Expand Down Expand Up @@ -555,11 +560,7 @@ def get_view(self, view_id=None, view_type="form", **options):
View = View.with_context(base_model_name=res["base_model"])
if view_type == "form" and not self._tier_validation_manual_config:
doc = etree.XML(res["arch"])
params = {
"state_field": self._state_field,
"state_operator": "not in",
"state_value": self._state_from,
}
params = {}
all_models = res["models"].copy()
for node in doc.xpath(self._tier_validation_buttons_xpath):
# By default, after the last button of the header
Expand Down
1 change: 1 addition & 0 deletions base_tier_validation/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Pedro Gonzalez \<<[email protected]>\>
- Kitti U. \<<[email protected]>\>
- Saran Lim. \<<[email protected]>\>
- Carlos Lopez \<<[email protected]>\>
1 change: 1 addition & 0 deletions base_tier_validation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ <h2><a class="toc-backref" href="#toc-entry-21">Contributors</a></h2>
<li>Pedro Gonzalez &lt;<a class="reference external" href="mailto:pedro.gonzalez&#64;pesol.es">pedro.gonzalez&#64;pesol.es</a>&gt;</li>
<li>Kitti U. &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
<li>Saran Lim. &lt;<a class="reference external" href="mailto:saranl&#64;ecosoft.co.th">saranl&#64;ecosoft.co.th</a>&gt;</li>
<li>Carlos Lopez &lt;<a class="reference external" href="mailto:celm1990&#64;gmail.com">celm1990&#64;gmail.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* @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 systrayRegistry = registry.category("systray");

export class TierReviewMenu extends Component {
setup() {
this.discussSystray = useDiscussSystray();
this.orm = useService("orm");
this.store = useState(useService("mail.store"));
this.action = useService("action");
this.fetchSystrayReviewer();
}
async fetchSystrayReviewer() {
const groups = await this.orm.call("res.users", "review_user_count");
let total = 0;
for (const group of groups) {
total += group.pending_count || 0;
}
this.store.tierReviewCounter = total;
this.store.tierReviewGroups = groups;
}
onBeforeOpen() {
this.fetchSystrayReviewer();
}
availableViews() {
return [
[false, "kanban"],
[false, "list"],
[false, "form"],
[false, "activity"],
];
}
openReviewGroup(group) {
document.body.click(); // Hack to close dropdown
const context = {};
var domain = [["can_review", "=", true]];
if (group.active_field) {
domain.push(["active", "in", [true, false]]);
}
const views = this.availableViews();

this.action.doAction(
{
context,
domain,
name: group.name,
res_model: group.model,
search_view_id: [false],
type: "ir.actions.act_window",
views,
},
{
clearBreadcrumbs: true,
}
);
}
}

TierReviewMenu.template = "base_tier_validation.TierReviewMenu";
TierReviewMenu.components = {Dropdown, DropdownItem};
TierReviewMenu.props = [];

export const systrayItem = {Component: TierReviewMenu};

systrayRegistry.add("base_tier_validation.ReviewerMenu", systrayItem, {sequence: 99});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="base_tier_validation.TierReviewMenu">
<Dropdown
position="'bottom-end'"
beforeOpen.bind="onBeforeOpen"
autoOpen="false"
menuClass="discussSystray.menuClass"
class="discussSystray.class"
>
<t t-set-slot="toggler">
<i class="fa fa-pencil-square-o" role="img" aria-label="Reviews" />
<span
t-if="store.tierReviewCounter > 0"
class="o-mail-ActivityMenu-counter badge rounded-pill"
t-out="store.tierReviewCounter"
/>
</t>
<t t-set-slot="default">
<div t-att-class="`${discussSystray.contentClass} o-mail-ActivityMenu`">
<div
t-if="store.tierReviewCounter === 0"
class="o-mail-ActivityMenu-empty align-items-center text-muted p-2 opacity-50 d-flex justify-content-center"
>
<span>No reviews to do.</span>
</div>
<div class="d-flex flex-column list-group-flush" name="activityGroups">
<t
t-foreach="store.tierReviewGroups"
t-as="group"
t-key="group_index"
name="activityGroupLoop"
>
<div
class="o-mail-ActivityGroup list-group-item list-group-item-action d-flex p-2 cursor-pointer"
t-att-data-model_name="group.model"
t-on-click="() => this.openReviewGroup(group)"
>
<img alt="Activity" t-att-src="group.icon" />
<div class="flex-grow-1 overflow-hidden">
<div
class="d-flex px-2"
name="activityTitle"
t-out="group.name"
/>
<div class="d-flex">
<span
t-attf-class="#{group.pending_count ? '' : 'text-muted'} py-0 px-2"
>
<t t-out="group.pending_count" /> Pending
</span>
</div>
</div>
</div>
</t>
</div>
</div>
</t>
</Dropdown>
</t>

</templates>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {registry} from "@web/core/registry";

import {useService} from "@web/core/utils/hooks";

const {Component, useState} = owl;
const {Component} = owl;

export class ReviewsTable extends Component {
setup() {
this.docs = useState({});
this.collapse = false;
this.orm = useService("orm");
this.reviews = [];
Expand All @@ -33,4 +32,9 @@ export class ReviewsTable extends Component {
}

ReviewsTable.template = "base_tier_validation.Collapse";
registry.category("fields").add("form.tier_validation", ReviewsTable);

export const reviewsTableComponent = {
component: ReviewsTable,
};

registry.category("fields").add("form.tier_validation", reviewsTableComponent);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="base_tier_validation.Collapse" owl="1">
<t t-name="base_tier_validation.Collapse">
<div class="o_form_sheet panel-group">
<div class="panel panel-default">
<div class="panel-heading">
Expand Down
29 changes: 0 additions & 29 deletions base_tier_validation/static/src/js/ir_model.esm.js

This file was deleted.

7 changes: 0 additions & 7 deletions base_tier_validation/static/src/js/main.esm.js

This file was deleted.

Loading

0 comments on commit 3c26247

Please sign in to comment.