Skip to content

Commit

Permalink
[18.0][MIG] Menu Display and Color Table
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaraspearhead committed Jan 16, 2025
1 parent 713d5c3 commit 16735b3
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 78 deletions.
39 changes: 20 additions & 19 deletions base_tier_validation/models/tier_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytz

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

_logger = logging.getLogger(__name__)
Expand All @@ -15,7 +15,7 @@ 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 @@ -32,14 +32,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 @@ -55,19 +51,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"
)
last_reminder_date = fields.Datetime(readonly=True)

Expand Down Expand Up @@ -141,7 +135,10 @@ 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 %(reviewer_group_name)s",
reviewer_group_name=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 @@ -157,7 +154,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(
self.env._("There are no res.users in the selected field")
)
return reviewer_field

def _notify_pending_status(self, review_ids):
Expand All @@ -173,7 +172,9 @@ def _get_reminder_activity_type(self):

def _notify_review_reminder_body(self):
delay = (fields.Datetime.now() - self.create_date).days
return _("A review has been requested %s days ago.") % (delay)
return self.env._(
"A review has been requested %(delay)s days ago.", delay=delay
)

def _send_review_reminder(self):
record = self.env[self.model].browse(self.res_id)
Expand All @@ -183,7 +184,7 @@ def _send_review_reminder(self):
elif hasattr(record, "message_post"):
self._notify_review_reminder(record)
else:
msg = "Could not send reminder for record {record}"
msg = f"Could not send reminder for record {record}"
_logger.exception(msg)
self.last_reminder_date = fields.Datetime.now()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* @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");
const {document} = globalThis;

export class TierReviewMenu extends Component {
static components = {Dropdown, DropdownItem};
static props = [];
static template = "base_tier_validation.TierReviewMenu";

setup() {
super.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;
Expand All @@ -26,9 +30,11 @@ export class TierReviewMenu extends Component {
this.store.tierReviewCounter = total;
this.store.tierReviewGroups = groups;
}

onBeforeOpen() {
this.fetchSystrayReviewer();
return this.fetchSystrayReviewer();
}

availableViews() {
return [
[false, "kanban"],
Expand All @@ -37,17 +43,18 @@ export class TierReviewMenu extends Component {
[false, "activity"],
];
}
openReviewGroup(group) {

async openReviewGroup(group) {
document.body.click();
// Hack to close dropdown
const context = {};
var domain = [["can_review", "=", true]];
const domain = [["can_review", "=", true]];
if (group.active_field) {
domain.push(["active", "in", [true, false]]);
}
const views = this.availableViews();

this.action.doAction(
await this.action.doAction(
{
context,
domain,
Expand All @@ -64,10 +71,10 @@ export class TierReviewMenu extends Component {
}
}

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

export const systrayItem = {Component: TierReviewMenu};
export const systrayItem = {
Component: TierReviewMenu,
};

systrayRegistry.add("base_tier_validation.ReviewerMenu", systrayItem, {sequence: 99});
registry
.category("systray")
.add("base_tier_validation.ReviewerMenu", systrayItem, {sequence: 99});
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
<t t-name="base_tier_validation.TierReviewMenu">
<Dropdown
position="'bottom-end'"
state="dropdown"
beforeOpen.bind="onBeforeOpen"
autoOpen="false"
menuClass="discussSystray.menuClass"
class="discussSystray.class"
>
<t t-set-slot="toggler">
<button>
<i
class="fa fa-lg fa-pencil-square-o"
role="img"
Expand All @@ -20,8 +19,8 @@
class="o-mail-ActivityMenu-counter badge rounded-pill"
t-out="store.tierReviewCounter"
/>
</t>
<t t-set-slot="default">
</button>
<t t-set-slot="content">
<div t-att-class="`${discussSystray.contentClass} o-mail-ActivityMenu`">
<div
t-if="store.tierReviewCounter === 0"
Expand All @@ -30,7 +29,7 @@
<span>No reviews to do.</span>
</div>
<div
class="d-flex flex-column list-group-flush"
class="d-flex flex-column list-group list-group-flush"
name="activityGroups"
>
<t
Expand All @@ -55,8 +54,8 @@
<span
t-attf-class="#{group.pending_count ? '' : 'text-muted'} py-0 px-2"
>
<t t-out="group.pending_count" /> Pending
</span>
<t t-out="group.pending_count" /> Pending
</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
/** @odoo-module **/

import {Component, useState} from "@odoo/owl";
import {registry} from "@web/core/registry";

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

const {Component} = owl;
const {document} = globalThis;

export class ReviewsTable extends Component {
setup() {
this.collapse = false;
super.setup();
this.orm = useService("orm");
this.reviews = [];
this.state = useState({
collapse: false,
reviews: [],
});
}

_getReviewData() {
const records = this.env.model.root.data.review_ids.records;
const reviews = [];
for (var i = 0; i < records.length; i++) {
reviews.push(records[i].data);
}
return reviews;
return records.map((record) => record.data);
}

onToggleCollapse(ev) {
var $panelHeading = $(ev.currentTarget).closest(".panel-heading");
if (this.collapse) {
$panelHeading.next("div#collapse1").hide();
const panelHeading = ev.currentTarget.closest(".panel-heading");
if (!panelHeading) return;
const collapseDiv = document.getElementById("collapse1");
if (!collapseDiv) return;
this.state.collapse = !this.state.collapse;
if (this.state.collapse) {
collapseDiv.style.display = "none";
} else {
$panelHeading.next("div#collapse1").show();
collapseDiv.style.display = "block";
}
this.collapse = !this.collapse;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h4 class="panel-title">
<a
class="o_info_btn"
data-toggle="collapse"
data-toggle="state.collapse"
href="#"
data-target="#collapse1"
t-on-click="onToggleCollapse"
Expand Down Expand Up @@ -74,42 +74,42 @@
<t
t-if="review.status == 'approved'"
t-set="status_class"
t-value="'alert-success'"
t-value="'table-success'"
/>
<t
t-if="review.status == 'rejected'"
t-set="status_class"
t-value="'alert-danger'"
t-value="'table-danger'"
/>
<tr t-att-class="status_class">
<td name="td_sequence" class="text-center">
<span t-esc="review.sequence" />
<span t-out="review.sequence" />
</td>
<td name="td_requested_by" class="text-left">
<span t-esc="review.requested_by[1]" />
<td name="td_requested_by" class="text-start">
<span t-out="review.requested_by[1]" />
</td>
<td name="td_name" class="text-right">
<span t-esc="review.name" />
<td name="td_name" class="text-end">
<span t-out="review.name" />
</td>
<td name="td_display_status" class="text-right">
<span t-esc="review.display_status" />
<td name="td_display_status" class="text-end">
<span t-out="review.display_status" />
</td>
<td name="td_todo_by" class="text-right">
<span t-esc="review.todo_by" />
<td name="td_todo_by" class="text-end">
<span t-out="review.todo_by" />
</td>
<td name="td_done_by" class="text-right">
<span t-esc="review.done_by[1]" />
<td name="td_done_by" class="text-end">
<span t-out="review.done_by[1]" />
</td>
<td name="td_reviewed_date" class="text-right">
<td name="td_reviewed_date" class="text-end">
<t t-if="review.reviewed_formated_date">
<span
t-esc="review.reviewed_formated_date"
t-out="review.reviewed_formated_date"
/>
</t>
</td>
<td name="td_comment" class="text-left">
<td name="td_comment" class="text-start">
<t t-if="review.comment">
<span t-esc="review.comment" />
<span t-out="review.comment" />
</t>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @odoo-module **/

import {reactive} from "@odoo/owl";
import {registry} from "@web/core/registry";

export class TierReviewService {
Expand All @@ -25,8 +24,8 @@ export const tierReviewService = {
dependencies: ["bus_service", "mail.store"],

start(env, services) {
const tier_review_service = new TierReviewService(env, services);
tier_review_service.setup(env, services);
const tier_review_service = reactive(new TierReviewService(env, services));
tier_review_service.setup();
return tier_review_service;
},
};
Expand Down

0 comments on commit 16735b3

Please sign in to comment.