summaryrefslogtreecommitdiff
path: root/addons/hr_holidays/static/src/bugfix/bugfix.js
diff options
context:
space:
mode:
authorXavier Dubuc <xdu@odoo.com>2020-11-10 08:59:25 +0000
committerSébastien Theys <seb@odoo.com>2020-11-30 15:21:27 +0000
commitd9aa362914945e6cb095b04fa94cfb3469abd907 (patch)
treed234604da02879d539155206949e112d437957c2 /addons/hr_holidays/static/src/bugfix/bugfix.js
parent24d52d4a8d0f475bb62b6653c08ce409e27e1d58 (diff)
[FIX] hr_holidays: bring back the out of office panel in threads
task-2277511 closes odoo/odoo#61586 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/hr_holidays/static/src/bugfix/bugfix.js')
-rw-r--r--addons/hr_holidays/static/src/bugfix/bugfix.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/addons/hr_holidays/static/src/bugfix/bugfix.js b/addons/hr_holidays/static/src/bugfix/bugfix.js
index 1f0782785eb..41d3e558cc0 100644
--- a/addons/hr_holidays/static/src/bugfix/bugfix.js
+++ b/addons/hr_holidays/static/src/bugfix/bugfix.js
@@ -8,3 +8,81 @@ odoo.define('hr_holidays/static/src/bugfix/bugfix.js', function (require) {
'use strict';
});
+
+// FIXME move me in hr_holidays/static/src/models/partner/partner.js
+odoo.define('hr_holidays/static/src/models/partner/partner.js', function (require) {
+'use strict';
+
+const {
+ registerClassPatchModel,
+ registerFieldPatchModel,
+ registerInstancePatchModel,
+} = require('mail/static/src/model/model_core.js');
+const { attr, one2one } = require('mail/static/src/model/model_field.js');
+const { clear } = require('mail/static/src/model/model_field_command.js');
+
+const { str_to_datetime } = require('web.time');
+
+registerClassPatchModel('mail.partner', 'hr_holidays/static/src/models/partner/partner.js', {
+ /**
+ * @override
+ */
+ convertData(data) {
+ const data2 = this._super(data);
+ if ('out_of_office_date_end' in data) {
+ data2.outOfOfficeDateEnd = data.out_of_office_date_end ? data.out_of_office_date_end : clear();
+ }
+ return data2;
+ },
+});
+
+registerInstancePatchModel('mail.partner', 'hr_holidays/static/src/models/partner/partner.js', {
+ /**
+ * @private
+ */
+ _computeOutOfOfficeText() {
+ if (!this.outOfOfficeDateEnd) {
+ return clear();
+ }
+ if (!this.env.messaging.locale.language) {
+ return clear();
+ }
+ const currentDate = new Date();
+ const date = str_to_datetime(this.outOfOfficeDateEnd);
+ const options = { day: 'numeric', month: 'short' };
+ if (currentDate.getFullYear() !== date.getFullYear()) {
+ options.year = 'numeric';
+ }
+ const localeCode = this.env.messaging.locale.language.replace(/_/g,'-');
+ const formattedDate = date.toLocaleDateString(localeCode, options);
+ return _.str.sprintf(this.env._t("Out of office until %s"), formattedDate);
+ },
+
+});
+
+registerFieldPatchModel('mail.partner', 'hr/static/src/models/partner/partner.js', {
+ /**
+ * Serves as compute dependency.
+ */
+ locale: one2one('mail.locale', {
+ related: 'messaging.locale',
+ }),
+ /**
+ * Date of end of the out of office period of the partner as string.
+ * String is expected to use Odoo's datetime string format
+ * (examples: '2011-12-01 15:12:35.832' or '2011-12-01 15:12:35').
+ */
+ outOfOfficeDateEnd: attr(),
+ /**
+ * Text shown when partner is out of office.
+ */
+ outOfOfficeText: attr({
+ compute: '_computeOutOfOfficeText',
+ dependencies: [
+ 'locale',
+ 'outOfOfficeDateEnd',
+ ],
+ }),
+});
+
+});