diff --git a/base_tier_validation/models/tier_review.py b/base_tier_validation/models/tier_review.py index 64432b4a72..6f9b532b29 100644 --- a/base_tier_validation/models/tier_review.py +++ b/base_tier_validation/models/tier_review.py @@ -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__) @@ -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"), @@ -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", @@ -55,7 +51,7 @@ 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", @@ -63,11 +59,9 @@ class TierReview(models.Model): 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) @@ -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) @@ -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): @@ -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) @@ -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() diff --git a/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.esm.js b/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.esm.js index 5869e55172..1511764a04 100644 --- a/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.esm.js +++ b/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.esm.js @@ -1,5 +1,3 @@ -/* @odoo-module */ - import {Component, useState} from "@odoo/owl"; import {Dropdown} from "@web/core/dropdown/dropdown"; import {DropdownItem} from "@web/core/dropdown/dropdown_item"; @@ -7,16 +5,22 @@ 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; @@ -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"], @@ -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, @@ -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}); diff --git a/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.xml b/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.xml index 77e256c0c2..09d33276f2 100644 --- a/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.xml +++ b/base_tier_validation/static/src/components/tier_review_menu/tier_review_menu.xml @@ -4,12 +4,11 @@ - + +
No reviews to do.
- Pending - + Pending +
diff --git a/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.esm.js b/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.esm.js index 953ebd76c3..dfe04c747e 100644 --- a/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.esm.js +++ b/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.esm.js @@ -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; } } diff --git a/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.xml b/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.xml index 5195bce81f..c3df38e16a 100644 --- a/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.xml +++ b/base_tier_validation/static/src/components/tier_review_widget/tier_review_widget.xml @@ -7,7 +7,7 @@

- + - - + + - - + + - - + + - - + + - - + + - + - + - + diff --git a/base_tier_validation/static/src/js/services/tier_review_service.esm.js b/base_tier_validation/static/src/js/services/tier_review_service.esm.js index 41b2708aea..bde257befe 100644 --- a/base_tier_validation/static/src/js/services/tier_review_service.esm.js +++ b/base_tier_validation/static/src/js/services/tier_review_service.esm.js @@ -1,5 +1,4 @@ -/** @odoo-module **/ - +import {reactive} from "@odoo/owl"; import {registry} from "@web/core/registry"; export class TierReviewService { @@ -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; }, };