Skip to content

Commit

Permalink
[MIG] announcement: Migration to 17.0
Browse files Browse the repository at this point in the history
TT50049
  • Loading branch information
chienandalu committed Sep 3, 2024
1 parent 3dbe4f0 commit 2577de3
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 102 deletions.
2 changes: 1 addition & 1 deletion announcement/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Announcement",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"summary": "Notify internal users about relevant organization stuff",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
2 changes: 1 addition & 1 deletion announcement/models/announcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _inverse_specific_user_ids(self):
itself"""
for announcement in self:
for user in announcement.specific_user_ids.filtered(
lambda x: announcement
lambda x, announcement=announcement: announcement
not in (x.read_announcement_ids + x.unread_announcement_ids)
):
user.unread_announcement_ids |= announcement

Check warning on line 102 in announcement/models/announcement.py

View check run for this annotation

Codecov / codecov/patch

announcement/models/announcement.py#L102

Added line #L102 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion announcement/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class IrHttp(models.AbstractModel):
_inherit = "ir.http"

def session_info(self):
res = super(IrHttp, self).session_info()
res = super().session_info()
res["announcements"] = self.env["res.users"].get_announcements()
return res

Check warning on line 12 in announcement/models/ir_http.py

View check run for this annotation

Codecov / codecov/patch

announcement/models/ir_http.py#L10-L12

Added lines #L10 - L12 were not covered by tests
9 changes: 5 additions & 4 deletions announcement/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def _add_attachment_links(self, announcement):
attachment_links += "<div class='list-group'>"

Check warning on line 70 in announcement/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

announcement/models/res_users.py#L70

Added line #L70 was not covered by tests
for attachment in announcement.attachment_ids:
attachment_url = "/web/content/%s?download=false" % attachment.id
attachment_link = """<a href="%s" class="list-group-item list-group-item-action"
target="_blank"><i class="fa fa-download" /> %s</a>""" % (
attachment_url,
attachment.name,
attachment_link = (

Check warning on line 73 in announcement/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

announcement/models/res_users.py#L72-L73

Added lines #L72 - L73 were not covered by tests
f'<a href="{attachment_url}" '
f'class="list-group-item list-group-item-action'
f'target="_blank"><i class="fa fa-download" /> '
f"{attachment.name}</a>"
)
attachment_links += attachment_link
attachment_links += "</div>"

Check warning on line 80 in announcement/models/res_users.py

View check run for this annotation

Codecov / codecov/patch

announcement/models/res_users.py#L79-L80

Added lines #L79 - L80 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
import {Component, markup, onMounted, useState} from "@odoo/owl";
import {_lt} from "@web/core/l10n/translation";
import {AnnouncementDialog} from "../announcement_dialog/announcement_dialog.esm";
import {Dropdown} from "@web/core/dropdown/dropdown";
import {DropdownItem} from "@web/core/dropdown/dropdown_item";
import {session} from "@web/session";
import {deserializeDateTime} from "@web/core/l10n/dates";
import {registry} from "@web/core/registry";
import {session} from "@web/session";
import {useDiscussSystray} from "@mail/utils/common/hooks";
import {useService} from "@web/core/utils/hooks";
import {AnnouncementDialog} from "../announcement_dialog/announcement_dialog.esm";

const {DateTime} = luxon;

export class AnnouncementMenu extends Component {
setup() {
this.discussSystray = useDiscussSystray();
this.orm = useService("orm");
this.dialogService = useService("dialog");
const announcements_service = useService("announcementService");
this.announcements = useState(announcements_service.announcements);
this.announcementMenuView = useState({isOpen: false});
// When the user logs in we show him his unread announcements
onMounted(async () => {
document.addEventListener(
"click",
this._onClickCaptureGlobal.bind(this),
true
);
// Let's check if the user just logged in and to decide if we popup the
// announcements. This delay is hardcoded to 5 minutes, although we could
// allow to configure it in the future.
const user = await this.orm.call("res.users", "read", [
session.uid,
["login_date"],
]);
const login_date = !_.isEmpty(user) && user[0].login_date;
const minutes_since_last_login =
(moment.utc(new Date()).valueOf() - moment.utc(login_date).valueOf()) /
1000 /
(DateTime.now().toSeconds() -
deserializeDateTime(user[0]?.login_date).toSeconds()) /
60;
const popup_announcement = Boolean(minutes_since_last_login < 5);
const launchPopUp = () => {
Expand Down Expand Up @@ -78,30 +76,10 @@ export class AnnouncementMenu extends Component {
// Handlers
// ------------------------------------------------------------

/**
* Toggle dropdown when clicking it
* @private
*/
onClickDropdownToggle() {
this.announcementMenuView.isOpen = !this.announcementMenuView.isOpen;
}

/**
* Hide dropdown when clicking outside
* @private
* @param {MouseEvent} ev
*/
_onClickCaptureGlobal(ev) {
if (this.__owl__.refs.root.contains(ev.target)) {
return;
}
this.announcementMenuView.isOpen = false;
}

/**
* Show announcement popup
* @private
* @param {MouseEvent} event
* @param {MouseEvent} announcement
*/
async openAnnouncement(announcement) {
this.dialogService.add(
Expand Down
93 changes: 39 additions & 54 deletions announcement/static/src/js/announcement_menu/announcement_menu.xml
Original file line number Diff line number Diff line change
@@ -1,71 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="announcement.AnnouncementMenu" owl="1">
<div class="o_ActivityMenuView dropdown" t-ref="root">
<a
class="o_ActivityMenuView_dropdownToggle dropdown-toggle o-no-caret o-dropdown--narrow"
t-att-aria-expanded="announcementMenuView.isOpen ? 'true' : 'false'"
title="Announcements"
href="#"
role="button"
t-on-click="onClickDropdownToggle"
>
<i
class="fa fa-lg fa-bullhorn"
role="img"
aria-label="Announcements"
/> <span
t-if="announcements.count > 0"
class="badge bg-warning"
t-out="announcements.count"
/>
</a>
<div
t-if="announcementMenuView.isOpen"
class="o_ActivityMenuView_dropdownMenu o-dropdown-menu dropdown-menu-end show bg-view"
role="menu"
>
<div class="o_ActivityMenuView_activityGroups">
<t t-if="announcements.count > 0">
<t t-name="announcement.AnnouncementMenu">
<Dropdown
position="'bottom-end'"
autoOpen="false"
menuClass="discussSystray.menuClass"
class="discussSystray.class"
>
<t t-set-slot="toggler">
<i class="fa fa-lg fa-bullhorn" role="img" aria-label="Announcements" />
<span
t-if="announcements.count"
class="o-mail-ActivityMenu-counter badge rounded-pill bg-warning"
><t t-esc="announcements.count" /></span>
</t>
<t t-set-slot="default">
<div t-att-class="`${discussSystray.contentClass} o-mail-ActivityMenu`">
<div
t-if="announcements.count === 0"
class="o-mail-ActivityMenu-empty align-items-center text-muted p-2 opacity-50 d-flex justify-content-center"
>
<span>No announcements.</span>
</div>
<div
class="d-flex flex-column list-group-flush"
name="activityGroups"
>
<t
t-foreach="announcements.data"
t-as="announcement"
t-key="announcement.id"
>
<div
class="o_ActivityMenuView_activityGroup"
class="o-mail-ActivityGroup list-group-item list-group-item-action d-flex p-2 cursor-pointer"
t-on-click="() => this.openAnnouncement(announcement)"
>
<div
class="o_ActivityMenuView_activityGroupIconContainer"
>
<img
src="/announcement/static/description/icon.png"
alt="Announcement"
<img
alt="Announcement"
src="/announcement/static/description/icon.png"
/>
<div class="flex-grow-1 overflow-hidden">
<div
class="d-flex px-2"
name="activityTitle"
t-out="announcement.name"
/>
</div>
<div class="o_ActivityMenuView_activityGroupInfo">
<div class="o_ActivityMenuView_activityGroupTitle">
<span
class="o_ActivityMenuView_activityGroupName"
>
<t t-esc="announcement.name" />
</span>
</div>
</div>
</div>
</t>
</t>
<t t-else="">
<div
class="o_ActivityMenuView_noActivity dropdown-item-text text-center d-flex justify-content-center"
>
<span>No announcements.</span>
</div>
</t>
</div>
</div>
</div>
</div>
</t>
</Dropdown>
</t>
</templates>
<!-- -->
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
/* Copyright 2024 Tecnativa - David Vidal
* Copyright 2024 Tecnativa - Carlos Roca
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
import {reactive} from "@odoo/owl";
import {registry} from "@web/core/registry";
import {session} from "@web/session";

const {reactive} = owl;

export const announcementService = {
dependencies: ["orm"],
async start(env, {orm}) {
Expand Down
13 changes: 6 additions & 7 deletions announcement/views/announcement_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<div class="oe_title">
<h1>
Expand Down Expand Up @@ -138,23 +138,22 @@
</button>
</xpath>
<group name="announcement_validity" position="before">
<group
name="announcement_scope"
attrs="{'invisible': [('is_general_announcement', '=', True)]}"
>
<group name="announcement_scope" invisible="is_general_announcement">
<field name="announcement_type" />
<field
name="specific_user_ids"
string="Users"
options="{'no_create': True}"
attrs="{'invisible': [('announcement_type', '!=', 'specific_users')], 'required': [('announcement_type', '=', 'specific_users')]}"
invisible="announcement_type != 'specific_users'"
required="announcement_type == 'specific_users'"
widget="many2many_tags"
/>
<field
name="user_group_ids"
string="Groups"
options="{'no_create': True}"
attrs="{'invisible': [('announcement_type', '!=', 'user_group')], 'required': [('announcement_type', '=', 'user_group')]}"
invisible="announcement_type != 'user_group'"
required="announcement_type == 'user_group'"
widget="many2many_tags"
/>
</group>
Expand Down

0 comments on commit 2577de3

Please sign in to comment.