mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-23 19:32:00 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -0,0 +1,43 @@
|
|||
import { registry } from "@web/core/registry";
|
||||
import { formView } from "@web/views/form/form_view";
|
||||
import { FormRenderer } from "@web/views/form/form_renderer";
|
||||
import { EmployeeFormController } from "@hr/views/form_view";
|
||||
import { onMounted } from "@odoo/owl";
|
||||
|
||||
class BadgeTabRenderer extends FormRenderer {
|
||||
setup() {
|
||||
super.setup();
|
||||
|
||||
onMounted(() => {
|
||||
const record = this.props.record
|
||||
const context = record.context?.params || record.context;
|
||||
if (context?.open_badges_tab && record.resModel === "hr.employee.public") {
|
||||
const tab = document.querySelector('[name="received_badges"]');
|
||||
if (tab) {
|
||||
tab.click();
|
||||
setTimeout(() => {
|
||||
const badges = record.data.badge_ids?.records || [];
|
||||
const badgeToHighlight = badges.find(badge => badge.resId === context.user_badge_id);
|
||||
if (!badgeToHighlight) return;
|
||||
|
||||
const userBadge = document.querySelector(`[data-id="${badgeToHighlight.id}"]`);
|
||||
if (!userBadge) return;
|
||||
|
||||
userBadge.classList.add('user-badge', 'user-badge-lift');
|
||||
setTimeout(() => {
|
||||
userBadge.classList.remove('user-badge-lift');
|
||||
}, 2000);
|
||||
},100);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const hrEmployeeFormView = {
|
||||
...formView,
|
||||
Controller: EmployeeFormController,
|
||||
Renderer: BadgeTabRenderer,
|
||||
}
|
||||
|
||||
registry.category("views").add("hr_employee_form", hrEmployeeFormView, { force: true });
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import { MessagingMenu } from "@mail/core/public_web/messaging_menu";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { user } from "@web/core/user";
|
||||
|
||||
patch(MessagingMenu.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.action = useService("action");
|
||||
this.orm = useService("orm");
|
||||
},
|
||||
|
||||
onClickThread(isMarkAsRead, thread, message) {
|
||||
if (!isMarkAsRead && thread.model === "gamification.badge.user") {
|
||||
this.openEmployeeView(thread);
|
||||
} else {
|
||||
super.onClickThread(...arguments);
|
||||
}
|
||||
},
|
||||
|
||||
async openEmployeeView(thread) {
|
||||
const employeeId = await this.orm.searchRead("hr.employee.public",
|
||||
[["user_id", "=", user.userId],
|
||||
["company_id", "in", user.activeCompany.id]],
|
||||
["id"]
|
||||
)
|
||||
|
||||
if (employeeId.length > 0) {
|
||||
await this.action.doAction({
|
||||
type: "ir.actions.act_window",
|
||||
res_model: 'hr.employee.public',
|
||||
res_id: employeeId[0].id,
|
||||
views: [[false, "form"]],
|
||||
target: "current",
|
||||
context: {
|
||||
open_badges_tab: true,
|
||||
user_badge_id: thread.id
|
||||
},
|
||||
});
|
||||
this.markAsRead(thread);
|
||||
this.dropdown.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
// the nocontent helper in fields for hr employee gamification badge view form
|
||||
.o_field_nocontent {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
height: 200px;
|
||||
width: 100%;
|
||||
|
||||
.o_nocontent_help {
|
||||
@include o-nocontent-empty;
|
||||
|
||||
.o_view_nocontent_neutral_face:before {
|
||||
@extend %o-nocontent-init-image;
|
||||
width: 120px;
|
||||
height: 140px;
|
||||
background: transparent url(/web/static/img/neutral_face.svg) no-repeat center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.user-badge {
|
||||
transition: transform 1s ease, box-shadow 1s ease;
|
||||
}
|
||||
|
||||
.user-badge-lift {
|
||||
transform: translateY(-10px);
|
||||
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.grant_badge_btn {
|
||||
border-radius: 0.5rem !important;
|
||||
width: 18rem;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { hrModels } from "@hr/../tests/hr_test_helpers";
|
||||
import { defineModels } from "@web/../tests/web_test_helpers";
|
||||
import { GamificationBadge } from "./mock_server/mock_models/gamification_badge";
|
||||
import { GamificationBadgeUser } from "./mock_server/mock_models/gamification_badge_user";
|
||||
|
||||
export function defineHrGamificationModels() {
|
||||
return defineModels(hrGamificationModels);
|
||||
}
|
||||
|
||||
export const hrGamificationModels = {
|
||||
...hrModels,
|
||||
GamificationBadge,
|
||||
GamificationBadgeUser,
|
||||
};
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import { click, start } from "@mail/../tests/mail_test_helpers";
|
||||
import { expect, test } from "@odoo/hoot";
|
||||
import { defineHrGamificationModels } from "@hr_gamification/../tests/hr_gamification_test_helpers";
|
||||
import { asyncStep, makeMockServer, mockService, serverState, waitForSteps } from "@web/../tests/web_test_helpers";
|
||||
import { user } from "@web/core/user";
|
||||
|
||||
defineHrGamificationModels();
|
||||
|
||||
test("badge notification opens employee form", async () => {
|
||||
const { env } = await makeMockServer();
|
||||
|
||||
const badgeUserId = env["gamification.badge.user"].create({
|
||||
badge_name: "Best Employee",
|
||||
user_id: serverState.userId,
|
||||
user_partner_id: serverState.partnerId,
|
||||
});
|
||||
|
||||
const employeeId = env["hr.employee.public"].create(
|
||||
{
|
||||
name: "Demo",
|
||||
user_id: serverState.userId,
|
||||
company_id: user.activeCompany.id,
|
||||
})
|
||||
|
||||
const messageId = env["mail.message"].create(
|
||||
{
|
||||
message_type: 'user_notification',
|
||||
model: "gamification.badge.user",
|
||||
res_id: badgeUserId,
|
||||
body: "You've received a badge!",
|
||||
needaction: true,
|
||||
});
|
||||
|
||||
env["mail.notification"].create(
|
||||
{
|
||||
mail_message_id: messageId,
|
||||
res_partner_id: serverState.partnerId,
|
||||
notification_status: "sent",
|
||||
notification_type: "inbox",
|
||||
},
|
||||
);
|
||||
|
||||
mockService("action", {
|
||||
doAction(action) {
|
||||
asyncStep("do_action");
|
||||
expect(action.type).toBe("ir.actions.act_window");
|
||||
expect(action.res_model).toBe("hr.employee.public");
|
||||
expect(action.views).toEqual([[false, "form"]]);
|
||||
expect(action.res_id).toBe(employeeId);
|
||||
},})
|
||||
|
||||
await start();
|
||||
await click(".o_menu_systray i[aria-label='Messages']");
|
||||
await click(".o-mail-NotificationItem", {
|
||||
text: "You've received a badge!",
|
||||
});
|
||||
await waitForSteps(["do_action"]);
|
||||
});
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class GamificationBadge extends models.ServerModel {
|
||||
_name = "gamification.badge";
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class GamificationBadgeUser extends models.ServerModel {
|
||||
_name = "gamification.badge.user";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue