-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#72124 [16.0][MIG] hr_working_space
- Loading branch information
Showing
9 changed files
with
100 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
from . import hr_working_space | ||
from . import hr_attendance | ||
from . import hr_employee | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
70 changes: 49 additions & 21 deletions
70
hr_working_space/static/src/js/working_space_my_attendances.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
"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'); | ||
|
||
AttendanceWidget.include({ | ||
events: _.extend({}, AttendanceWidget.prototype.events, { | ||
"click .o_hr_working_space_sign_in": function (event) { | ||
"click .o_hr_attendance_sign_in_out_icon": _.debounce(function (event) { | ||
this.sign_in_with_working_space(event); | ||
}, | ||
}, 200, true), | ||
}), | ||
willStart() { | ||
|
||
willStart: function () { | ||
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 Codacy Production / Codacy Static Code Analysishr_working_space/static/src/js/working_space_my_attendances.js#L36
Check notice on line 36 in hr_working_space/static/src/js/working_space_my_attendances.js Codacy Production / Codacy Static Code Analysishr_working_space/static/src/js/working_space_my_attendances.js#L36
|
||
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
41
hr_working_space/static/src/xml/working_space_attendance.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters