Skip to content

Commit

Permalink
TA#72124 [16.0][MIG] hr_working_space
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Jan 17, 2025
1 parent 4aef2ce commit 214c0cf
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 63 deletions.
1 change: 0 additions & 1 deletion hr_working_space/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"assets": {
"web.assets_backend": [
"hr_working_space/static/src/js/working_space_my_attendances.js",
"hr_working_space/static/src/css/hr_working_space.css",
"hr_working_space/static/src/xml/working_space_attendance.xml",
],
},
Expand Down
1 change: 1 addition & 0 deletions hr_working_space/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

from . import hr_working_space

Check notice on line 4 in hr_working_space/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/models/__init__.py#L4

'.hr_working_space' imported but unused (F401)
from . import hr_attendance

Check notice on line 5 in hr_working_space/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/models/__init__.py#L5

'.hr_attendance' imported but unused (F401)
from . import hr_employee

Check notice on line 6 in hr_working_space/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/models/__init__.py#L6

'.hr_employee' imported but unused (F401)
17 changes: 0 additions & 17 deletions hr_working_space/models/hr_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,3 @@ class HRWorkingSpace(models.Model):
working_space_id = fields.Many2one(
'hr.working.space', string='Working Space', required=True
)


class HREmployeeWorkingSpace(models.Model):
"""Add the management of the working space at the attendance."""

_inherit = 'hr.employee'

def attendance_manual_working_space(
self, next_action, working_space_id=None, entered_pin=None
):
res = self.attendance_manual(next_action, entered_pin=entered_pin)
if working_space_id:
attendance = self.env['hr.attendance'].search(
[('id', '=', res['action']['attendance']['id'])], limit=1
)
attendance.working_space_id = int(working_space_id)
return res
21 changes: 21 additions & 0 deletions hr_working_space/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models


class HREmployeeWorkingSpace(models.Model):
"""Add the management of the working space at the attendance."""

_inherit = 'hr.employee'

def attendance_manual_working_space(
self, next_action, working_space_id=None, entered_pin=None
):
res = self.attendance_manual(next_action, entered_pin=entered_pin)
if working_space_id:
attendance = self.env['hr.attendance'].search(
[('id', '=', res['action']['attendance']['id'])], limit=1
)
attendance.working_space_id = int(working_space_id)
return res
Binary file modified hr_working_space/static/description/check-in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions hr_working_space/static/src/css/hr_working_space.css

This file was deleted.

70 changes: 49 additions & 21 deletions hr_working_space/static/src/js/working_space_my_attendances.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
odoo.define("hr_working_space.working_space_my_attendances", (require) => {
odoo.define("hr_working_space.working_space_my_attendances", function (require) {

Check notice on line 1 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L1

'odoo' is not defined.
"use strict";

var core = require("web.core");
var AttendanceWidget = require('hr_attendance.my_attendances');
var AttendanceWidget = require("hr_attendance.my_attendances");
const session = require('web.session');

Check notice on line 5 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L5

Strings must use doublequote.

AttendanceWidget.include({
events: _.extend({}, AttendanceWidget.prototype.events, {

Check notice on line 8 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L8

'_' is not defined.
"click .o_hr_working_space_sign_in": function (event) {
"click .o_hr_attendance_sign_in_out_icon": _.debounce(function (event) {

Check notice on line 9 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L9

'_' is not defined.
this.sign_in_with_working_space(event);
},
}, 200, true),
}),
willStart() {

willStart: function () {

Check warning on line 14 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L14

Expected method shorthand.
var self = this;
var def = this._rpc({
model: "hr.working.space",
method: "search_read",
fields: ["name", "icon"]
}).then((workingSpaces) => {
this.workingSpaces = workingSpaces;
});
return $.when(def, this._super.apply(this, arguments));
fields: ["name", "icon"],
context: session.user_context,
})
.then(function (workingSpaces) {
self.workingSpaces = workingSpaces || [];
})
.catch(function () {
self.workingSpaces = [];
self.displayNotification({
title: "Error",
message: "Failed to fetch working spaces.",
type: "danger",
});
});
return Promise.all([def, this._super.apply(this, arguments)]);
},
sign_in_with_working_space(event) {
var workingSpaceID = event.target.id;

sign_in_with_working_space: function (event) {

Check warning on line 36 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L36

Expected method shorthand.

Check notice on line 36 in hr_working_space/static/src/js/working_space_my_attendances.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

hr_working_space/static/src/js/working_space_my_attendances.js#L36

Identifier 'sign_in_with_working_space' is not in camel case.
var self = this;
var workingSpaceID = event.currentTarget.dataset.id;
this._rpc({
model: "hr.employee",
method: "attendance_manual_working_space",
args: [[this.employee.id], "hr_attendance.hr_attendance_action_my_attendances", workingSpaceID]
args: [
[self.employee.id],
"hr_attendance.hr_attendance_action_my_attendances",
workingSpaceID,
],
context: session.user_context,
})
.then((result) => {
if (result.action) {
this.do_action(result.action);
} else if (result.warning) {
this.do_warn(result.warning);
}
});
.then(function (result) {
if (result.action) {
self.do_action(result.action);
} else if (result.warning) {
self.displayNotification({ title: result.warning, type: "danger" });
}
})
.catch(function () {
self.displayNotification({
title: "Error",
message: "Failed to sign in with the selected working space.",
type: "danger",
});
});
},
});

return AttendanceWidget;
});
41 changes: 27 additions & 14 deletions hr_working_space/static/src/xml/working_space_attendance.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<template xml:space="preserve">

<t t-extend="HrAttendanceCheckInOutButtons">
<xpath t-jquery="button" t-operation="replace">
<t t-if="widget.workingSpaces">
<t t-foreach="widget.workingSpaces" t-as="working_space" t-if="!checked_in">
<i t-att-id="working_space.id"
t-att-title="working_space.name"
t-att-class="working_space.icon + ' fa-3x fa o_hr_working_space_sign_in btn btn-primary o_hr_working_space_icon'" />
</t>
<t t-if="checked_in">
<button t-attf-class="o_hr_attendance_sign_in_out_icon btn btn-{{ checked_in ? 'warning' : 'success' }} align-self-center px-5 py-3 mt-4 mb-2">
<span class="align-middle fs-2 ms-3">Check OUT</span>
<t t-extend="HrAttendanceMyMainMenu">
<t t-jquery="t[t-call='HrAttendanceCheckInOutButtons']" t-operation="replace">
<t t-if="widget.workingSpaces and widget.workingSpaces.length > 0">
<t t-call="HRAttendanceWorkingSpace"/>
</t>
<t t-else="">
<t t-call="HrAttendanceCheckInOutButtons"/>
</t>
</t>
</t>
<t t-name="HRAttendanceWorkingSpace">
<div class="flex-grow-1">
<t t-if="!checked_in">
<t t-foreach="widget.workingSpaces" t-as="working_space" >
<button t-att-id="working_space.id" t-att-title="working_space.name"
class="o_hr_attendance_sign_in_out_icon btn btn-primary align-self-center mt-4 mb-2"
style="width: 80px">
<i t-attf-class="fa fa-4x {{ working_space.icon }} align-middle"/>
</button>
</t>
</t>
</xpath>

<t t-else="">
<button class="o_hr_attendance_sign_in_out_icon btn btn-warning align-self-center px-5 py-3 mt-4 mb-2">
<i class="fa fa-4x fa-sign-out align-middle"/>
<span class="align-middle fs-2 ms-3">Check OUT</span>
</button>
</t>
</div>
</t>

</template>


4 changes: 2 additions & 2 deletions hr_working_space/views/hr_working_space.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<group>
<field name="icon" />
<field name="active" />
<field name="active" widget="boolean_toggle" />
</group>
</sheet>
</form>
Expand All @@ -31,7 +31,7 @@
<tree string="Working Spaces">
<field name="name" />
<field name="icon" />
<field name="active" />
<field name="active" widget="boolean_toggle" />
</tree>
</field>
</record>
Expand Down

0 comments on commit 214c0cf

Please sign in to comment.