diff --git a/hr_timesheet_portal/README.rst b/hr_timesheet_portal/README.rst index bffa4226f..7202e5a54 100644 --- a/hr_timesheet_portal/README.rst +++ b/hr_timesheet_portal/README.rst @@ -14,16 +14,16 @@ Timesheet portal (editable) :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github - :target: https://github.com/OCA/timesheet/tree/12.0/hr_timesheet_portal + :target: https://github.com/OCA/timesheet/tree/16.0/hr_timesheet_portal :alt: OCA/timesheet .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/timesheet-12-0/timesheet-12-0-hr_timesheet_portal + :target: https://translation.odoo-community.org/projects/timesheet-16-0/timesheet-16-0-hr_timesheet_portal :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/117/12.0 + :target: https://runbot.odoo-community.org/runbot/117/16.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This module allows portal users to edit their timesheets via the frontend. @@ -66,6 +66,7 @@ Contributors ~~~~~~~~~~~~ * Holger Brunn (https://hunki-enterprises.com) +* Achraf Mhadhbi Maintainers ~~~~~~~~~~~ @@ -80,6 +81,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/timesheet `_ project on GitHub. +This module is part of the `OCA/timesheet `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_timesheet_portal/__manifest__.py b/hr_timesheet_portal/__manifest__.py index 30e9f9162..ab08cb774 100644 --- a/hr_timesheet_portal/__manifest__.py +++ b/hr_timesheet_portal/__manifest__.py @@ -1,9 +1,10 @@ # Copyright 2021 Hunki Enterprises BV +# Copyright 2023 bloopark systems - Achraf Mhadhbi # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Timesheet portal (editable)", "summary": "Fill in timesheets via the portal", - "version": "12.0.1.0.1", + "version": "16.0.1.0.1", "development_status": "Alpha", "category": "Website", "website": "https://github.com/OCA/timesheet", @@ -15,7 +16,6 @@ "website", ], "data": [ - "templates/assets.xml", "templates/portal.xml", "security/hr_timesheet_portal_security.xml", "security/ir.model.access.csv", @@ -23,4 +23,9 @@ "demo": [ "demo/hr_timesheet_portal.xml", ], + "assets": { + "web.assets_frontend": [ + "hr_timesheet_portal/static/src/**/*", + ], + }, } diff --git a/hr_timesheet_portal/demo/hr_timesheet_portal.xml b/hr_timesheet_portal/demo/hr_timesheet_portal.xml index ee730e337..c01b0ff67 100644 --- a/hr_timesheet_portal/demo/hr_timesheet_portal.xml +++ b/hr_timesheet_portal/demo/hr_timesheet_portal.xml @@ -1,7 +1,6 @@ - + - diff --git a/hr_timesheet_portal/readme/CONTRIBUTORS.rst b/hr_timesheet_portal/readme/CONTRIBUTORS.rst index 33b6eb2c3..0c917a9ef 100644 --- a/hr_timesheet_portal/readme/CONTRIBUTORS.rst +++ b/hr_timesheet_portal/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Holger Brunn (https://hunki-enterprises.com) +* Achraf Mhadhbi diff --git a/hr_timesheet_portal/readme/newsfragments/.gitkeep b/hr_timesheet_portal/readme/newsfragments/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/hr_timesheet_portal/security/hr_timesheet_portal_security.xml b/hr_timesheet_portal/security/hr_timesheet_portal_security.xml index ec9b63940..05374113b 100644 --- a/hr_timesheet_portal/security/hr_timesheet_portal_security.xml +++ b/hr_timesheet_portal/security/hr_timesheet_portal_security.xml @@ -1,17 +1,18 @@ - + - Editable timesheets - - Add portal users who should be allowed to edit their timesheets + + Add portal users who should be allowed to edit their timesheets - + [ '|', '&', @@ -21,13 +22,13 @@ ('task_id.project_id.privacy_visibility', '=', 'portal'), ('task_id.message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]), ] - + - + [(0, '=', 1)] - + diff --git a/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css b/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css index b2d3541eb..2fbb7f4b4 100644 --- a/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css +++ b/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css @@ -1,7 +1,9 @@ /* Copyright 2021 Hunki Enterprises BV * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ -div.hr_timesheet_portal h5 i,div.hr_timesheet_portal tr i, div.hr_timesheet_portal tr:hover.edit i { +div.hr_timesheet_portal h5 i, +div.hr_timesheet_portal tr i, +div.hr_timesheet_portal tr:hover.edit i { display: none; } div.hr_timesheet_portal:hover h5 i { @@ -15,15 +17,15 @@ div.hr_timesheet_portal tr[data-line-id]:hover i { display: block; cursor: pointer; position: absolute; - top: .3em; + top: 0.3em; background: #fff; - padding: .3em; + padding: 0.3em; } div.hr_timesheet_portal tr[data-line-id]:hover i.fa-remove { - right: .2em; + right: 0.2em; } div.hr_timesheet_portal tr[data-line-id]:hover i.fa-edit { - left: .2em; + left: 0.2em; } div.hr_timesheet_portal tr[data-line-id] td { position: relative; @@ -32,7 +34,7 @@ div.hr_timesheet_portal tr form { display: inline-block; } div.hr_timesheet_portal tr form button { - margin-left: .2em; + margin-left: 0.2em; } div.hr_timesheet_portal tr td { vertical-align: middle; diff --git a/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js b/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js index 3db87fc28..6e453e6ac 100644 --- a/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js +++ b/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js @@ -1,23 +1,23 @@ /* Copyright 2021 Hunki Enterprises BV * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ -odoo.define('hr_timesheet_portal', function(require){ +odoo.define("hr_timesheet_portal", function (require) { "use strict"; - var sAnimation = require('website.content.snippets.animation'), - rpc = require('web.rpc'), - core = require('web.core'), - _t = core._t; + var sAnimation = require("website.content.snippets.animation"); + var rpc = require("web.rpc"); + var core = require("web.core"); + var _t = core._t; - sAnimation.registry.hr_timesheet_portal = sAnimation.Class.extend({ - selector: 'div.hr_timesheet_portal', + sAnimation.registry.hr_timesheet_portal = sAnimation.Widget.extend({ + selector: "div.hr_timesheet_portal", events: { - 'click h5': '_onclick_add', - 'click tr[data-line-id]:not(.edit)': '_onclick_edit', - 'click i.fa-remove': '_onclick_delete', - 'click button.submit': '_onclick_submit', - 'submit form': '_onclick_submit', - 'click button.cancel': '_reload_timesheet', + "click h5": "_onclick_add", + "click tr[data-line-id]:not(.edit)": "_onclick_edit", + "click i.fa-remove": "_onclick_delete", + "click button.submit": "_onclick_submit", + "submit form": "_onclick_submit", + "click button.cancel": "_reload_timesheet", }, start: function (editable_mode) { @@ -30,105 +30,116 @@ odoo.define('hr_timesheet_portal', function(require){ _onclick_delete: function (e) { e.stopPropagation(); rpc.query({ - model: 'account.analytic.line', - method: 'unlink', - args: [[jQuery(e.currentTarget).parents('tr').data('line-id')]] + model: "account.analytic.line", + method: "unlink", + args: [[jQuery(e.currentTarget).parents("tr").data("line-id")]], }) - .done(this.proxy('_reload_timesheet')) - .fail(this.proxy('_display_failure')); + .then(this.proxy("_reload_timesheet")) + .catch(this.proxy("_display_failure")); }, - _onclick_add: function (e) { + _onclick_add: function () { var self = this; - return rpc.query({ - model: 'account.analytic.line', - method: 'create', - args: [{ - user_id: this.getSession().user_id, - account_id: this.$el.data('account-id'), - project_id: this.$el.data('project-id'), - task_id: this.$el.data('task-id'), - unit_amount: 0, - name: '/', - }], - }) - .done(function (line_id) { - return self._reload_timesheet().then(function () { - setTimeout(self._edit_line.bind(self, line_id), 0); - }); - }) - .fail(this.proxy('_display_failure')); + return rpc + .query({ + model: "account.analytic.line", + method: "create", + args: [ + { + user_id: this.getSession().user_id, + account_id: this.$el.data("account-id"), + project_id: this.$el.data("project-id"), + task_id: this.$el.data("task-id"), + unit_amount: 0, + name: "/", + }, + ], + }) + .then(function (line_id) { + return self._reload_timesheet().then(function () { + setTimeout(self._edit_line.bind(self, line_id), 0); + }); + }) + .catch(this.proxy("_display_failure")); }, _onclick_edit: function (e) { - return this._edit_line(jQuery(e.target).parents('tr').data('line-id')); + return this._edit_line(jQuery(e.target).parents("tr").data("line-id")); }, _onclick_submit: function (e) { e.preventDefault(); - var $tr = jQuery(e.target).parents('tr'), - data = _.object(_.map($tr.find('form').serializeArray(), function(a) { - return [a.name, a.value] - })); - return rpc.query({ - model: 'account.analytic.line', - method: 'write', - args: [$tr.data('line-id'), data], - }) - .done(this.proxy('_reload_timesheet')) - .fail(this.proxy('_display_failure')); - + var $tr = jQuery(e.target).parents("tr"), + data = _.object( + _.map($tr.find("form").serializeArray(), function (a) { + return [a.name, a.value]; + }) + ); + return rpc + .query({ + model: "account.analytic.line", + method: "write", + args: [$tr.data("line-id"), data], + }) + .then(this.proxy("_reload_timesheet")) + .catch(this.proxy("_display_failure")); }, _reload_timesheet: function () { var self = this; - this.$el.children('div.alert').remove(); + this.$el.children("div.alert").remove(); return $.ajax({ - dataType: 'html', + dataType: "html", }).then(function (data) { var timesheets = _.filter(jQuery.parseHTML(data), function (element) { - return jQuery(element).find('div.hr_timesheet_portal').length > 0; - }), $tbody = jQuery(timesheets).find('tbody'); - return self.$('tbody').replaceWith($tbody); + return ( + jQuery(element).find("div.hr_timesheet_portal").length > 0 + ); + }), + $tbody = jQuery(timesheets).find("tbody"); + return self.$("tbody").replaceWith($tbody); }); }, _display_failure: function (error) { - this.$el.prepend(jQuery('
').text(error.data.message)); - this.$el.prepend(jQuery('
').text(error.message)); + this.$el.prepend( + jQuery('
').text(error.data.message) + ); + this.$el.prepend( + jQuery('
').text(error.message) + ); }, - _edit_line (line_id) { - var $line = this.$(_.str.sprintf('tr[data-line-id=%s]', line_id)), + _edit_line(line_id) { + var $line = this.$(_.str.sprintf("tr[data-line-id=%s]", line_id)), $edit_line = $line.clone(); - this.$('tbody tr.edit').remove(); - this.$('tbody tr').show(); - $line.before($edit_line) - $edit_line.children('[data-field-name]').each(function () { + this.$("tbody tr.edit").remove(); + this.$("tbody tr").show(); + $line.before($edit_line); + $edit_line.children("[data-field-name]").each(function () { var $this = jQuery(this), - $input = jQuery('', { - class: 'form-control', - type: $this.data('field-type') || 'text', - value: $this.data('field-value') || $this.text(), - form: 'hr_timesheet_portal_form', - name: $this.data('field-name'), + $input = jQuery("", { + class: "form-control", + type: $this.data("field-type") || "text", + value: $this.data("field-value") || $this.text(), + form: "hr_timesheet_portal_form", + name: $this.data("field-name"), }); $this.empty().append($input); }); - $edit_line.addClass('edit'); - var $form = jQuery('
', { - id: 'hr_timesheet_portal_form', - }), $submit = jQuery('