Skip to content

Commit

Permalink
[ADD] allow adding calendar links to time off calendar, default icals
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Sep 25, 2023
1 parent f63ec5d commit 0fdbe99
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 0 deletions.
5 changes: 5 additions & 0 deletions verdigado_attendance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
"license": "AGPL-3",
"installable": True,
"depends": [
"base_ical",
"hr_attendance",
"hr_holidays_attendance",
"l10n_de_holidays",
"hr_holidays_public_overtime",
],
"data": [
"data/base_ical.xml",
"data/hr_leave_type.xml",
"data/res.lang.csv",
"security/verdigado_attendance.xml",
"security/ir.model.access.csv",
"views/base_ical.xml",
"views/hr_attendance_view.xml",
"views/hr_leave_type.xml",
"views/hr_menu_human_resources_configuration.xml",
Expand All @@ -28,10 +31,12 @@
"web.assets_backend": [
"verdigado_attendance/static/src/scss/backend.scss",
"verdigado_attendance/static/src/js/systray.esm.js",
"verdigado_attendance/static/src/js/time_off_calendar.js",
],
"web.assets_qweb": [
"verdigado_attendance/static/src/xml/hr_holidays.xml",
"verdigado_attendance/static/src/xml/systray.xml",
"verdigado_attendance/static/src/xml/time_off_calendar.xml",
],
},
}
40 changes: 40 additions & 0 deletions verdigado_attendance/data/base_ical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="ical_my_leaves" model="base.ical">
<field name="name">My leaves</field>
<field name="model_id" ref="hr_holidays.model_hr_leave" />
<field name="domain">[('user_id', '=', user.id)]</field>
<field name="expression_uid">str(record.id)</field>
<field name="expression_dtstart">
(record.request_unit_half or record.request_unit_hours) and record.date_from
or record.date_from.date()
</field>
<field name="expression_dtend">
(record.request_unit_half or record.request_unit_hours) and record.date_to
or (record.date_to.date() + timedelta(days=1))
</field>
<field name="expression_summary">record.name</field>
<field name="auto" eval="True" />
<field name="show_on_holiday_calendar" eval="True" />
</record>
<record id="ical_my_team_leaves" model="base.ical">
<field name="name">My team leaves</field>
<field name="model_id" ref="hr_holidays.model_hr_leave" />
<field name="domain">
[('user_id.employee_id.department_id', '=',
user.employee_id.department_id.id), ('user_id', '!=', user.id)]
</field>
<field name="expression_uid">str(record.id)</field>
<field name="expression_dtstart">
(record.request_unit_half or record.request_unit_hours) and record.date_from
or record.date_from.date()
</field>
<field name="expression_dtend">
(record.request_unit_half or record.request_unit_hours) and record.date_to
or (record.date_to.date() + timedelta(days=1))
</field>
<field name="expression_summary">record.name</field>
<field name="auto" eval="True" />
<field name="show_on_holiday_calendar" eval="True" />
</record>
</odoo>
1 change: 1 addition & 0 deletions verdigado_attendance/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import base_ical
from . import hr_attendance
from . import hr_leave_type
11 changes: 11 additions & 0 deletions verdigado_attendance/models/base_ical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2023 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)


from odoo import fields, models


class BaseIcal(models.Model):
_inherit = "base.ical"

show_on_holiday_calendar = fields.Boolean("Show on holiday calendar")
42 changes: 42 additions & 0 deletions verdigado_attendance/static/src/js/time_off_calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
odoo.define("verdigado_attendance.time_off_calendar", function (require) {
"use strict";

var viewRegistry = require("web.view_registry");
// Even though core doesn't return anything here, we need the require for correct dependencies
require("hr_holidays.dashboard.view_custo");

viewRegistry.get("time_off_calendar_all").prototype.config.Renderer.include({
_render: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
return self
._rpc({
model: "base.ical",
method: "search_read",
args: [
[["show_on_holiday_calendar", "=", true]],
["user_active", "user_url", "name"],
],
context: self.state.context,
})
.then(function (ical_calendars) {
var $links = self.$(".ical_links");
if (ical_calendars.length === 0) {
$links.hide();
} else {
_.chain(ical_calendars)
.filter("user_active")
.each(function (ical) {
var $a = jQuery(
'<a href="' + ical.user_url + '"/>'
);
$a.text(ical.name);
$links.append($a);
$links.append("<br/>");
});
}
});
});
},
});
});
10 changes: 10 additions & 0 deletions verdigado_attendance/static/src/xml/time_off_calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<templates>
<t t-extend="TimeOff.CalendarView.extend">
<t t-jquery="div.o_timeoff_legend" t-operation="after">
<div class="ical_links">
<h5>Calendar links</h5>
<ul />
</div>
</t>
</t>
</templates>
14 changes: 14 additions & 0 deletions verdigado_attendance/views/base_ical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="view_base_ical_form" model="ir.ui.view">
<field name="model">base.ical</field>
<field name="inherit_id" ref="base_ical.view_base_ical_form" />
<field name="arch" type="xml">
<field name="auto" position="after">
<field name="show_on_holiday_calendar" />
</field>
</field>
</record>
</data>

0 comments on commit 0fdbe99

Please sign in to comment.