diff --git a/hr_timesheet_portal/README.rst b/hr_timesheet_portal/README.rst new file mode 100644 index 0000000000..a5e5935f43 --- /dev/null +++ b/hr_timesheet_portal/README.rst @@ -0,0 +1,123 @@ +=========================== +Timesheet portal (editable) +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:71ad70eecaa731dc71a21f3dd94731d7c8dca1805e1b2c7532bbc45352a6b0c4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/18.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-18-0/timesheet-18-0-hr_timesheet_portal + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/timesheet&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows portal users to edit their timesheets via the +frontend. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +1. Add users to the group Editable timesheets. If you want all portal + users be able to edit timesheets, add the group as an implied group + of the Portal group + +Usage +===== + +Users in the Website group Editable timesheets will see a plus button +when they hover over Timesheets. + +|Portal general view| + +Clicking the plus button allows them to add a new timesheet line: + +|Add timesheet line| + +They can also edit their timesheet lines by hovering over a line and +clicking the pencil button next to the date, or delete a line by +clicking the cross next to the duration: + +|Edit timesheet line| + +.. |Portal general view| image:: https://raw.githubusercontent.com/OCA/timesheet/18.0/hr_timesheet_portal/static/img/01_portal_general_view.png +.. |Add timesheet line| image:: https://raw.githubusercontent.com/OCA/timesheet/18.0/hr_timesheet_portal/static/img/02_add_timesheet_line.png +.. |Edit timesheet line| image:: https://raw.githubusercontent.com/OCA/timesheet/18.0/hr_timesheet_portal/static/img/03_edit_timesheet_line.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Hunki Enterprises BV + +Contributors +------------ + +- `Hunki Enterprises BV `__ + + - Holger Brunn + +- `Innovara `__ + + - Manuel Fombuena + +- `SISINFO `__ + + - Miguel Gómez León + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_timesheet_portal/__init__.py b/hr_timesheet_portal/__init__.py new file mode 100644 index 0000000000..ef5ae3587f --- /dev/null +++ b/hr_timesheet_portal/__init__.py @@ -0,0 +1 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). diff --git a/hr_timesheet_portal/__manifest__.py b/hr_timesheet_portal/__manifest__.py new file mode 100644 index 0000000000..8f888a08eb --- /dev/null +++ b/hr_timesheet_portal/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright 2021 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Timesheet portal (editable)", + "summary": "Fill in timesheets via the portal", + "version": "18.0.1.0.0", + "development_status": "Alpha", + "category": "Website", + "website": "https://github.com/OCA/timesheet", + "author": "Hunki Enterprises BV, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "hr_timesheet", + "portal", + "website", + ], + "data": [ + "templates/portal.xml", + "security/hr_timesheet_portal_security.xml", + "security/ir.model.access.csv", + "views/hr_employee.xml", + ], + "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 new file mode 100644 index 0000000000..5e846f17f3 --- /dev/null +++ b/hr_timesheet_portal/demo/hr_timesheet_portal.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/hr_timesheet_portal/i18n/hr_timesheet_portal.pot b/hr_timesheet_portal/i18n/hr_timesheet_portal.pot new file mode 100644 index 0000000000..7d10f81214 --- /dev/null +++ b/hr_timesheet_portal/i18n/hr_timesheet_portal.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_timesheet_portal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_timesheet_portal +#: model:res.groups,comment:hr_timesheet_portal.group_hr_timesheet_portal +msgid "Add portal users who should be allowed to edit their timesheets" +msgstr "" + +#. module: hr_timesheet_portal +#: model:res.groups,name:hr_timesheet_portal.group_hr_timesheet_portal +msgid "Editable timesheets" +msgstr "" + +#. module: hr_timesheet_portal +#: model_terms:ir.ui.view,arch_db:hr_timesheet_portal.portal_my_task +msgid "Timesheets " +msgstr "" diff --git a/hr_timesheet_portal/i18n/it.po b/hr_timesheet_portal/i18n/it.po new file mode 100644 index 0000000000..c24f9ec657 --- /dev/null +++ b/hr_timesheet_portal/i18n/it.po @@ -0,0 +1,43 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_timesheet_portal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-01-26 12:45+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: hr_timesheet_portal +#: model:res.groups,comment:hr_timesheet_portal.group_hr_timesheet_portal +msgid "Add portal users who should be allowed to edit their timesheets" +msgstr "" +"Aggiungi utenti portale che devono essere autorizzati a modificare i loro " +"fogli ore" + +#. module: hr_timesheet_portal +#. openerp-web +#: code:addons/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js:125 +#, python-format +msgid "Cancel" +msgstr "Annulla" + +#. module: hr_timesheet_portal +#: model:res.groups,name:hr_timesheet_portal.group_hr_timesheet_portal +msgid "Editable timesheets" +msgstr "Fogli ore modificabili" + +#. module: hr_timesheet_portal +#. openerp-web +#: code:addons/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js:124 +#, python-format +msgid "Submit" +msgstr "Invia" diff --git a/hr_timesheet_portal/pyproject.toml b/hr_timesheet_portal/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/hr_timesheet_portal/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_timesheet_portal/readme/CONFIGURE.md b/hr_timesheet_portal/readme/CONFIGURE.md new file mode 100644 index 0000000000..62b4923b96 --- /dev/null +++ b/hr_timesheet_portal/readme/CONFIGURE.md @@ -0,0 +1,5 @@ +To configure this module, you need to: + +1. Add users to the group Editable timesheets. If you want all portal + users be able to edit timesheets, add the group as an implied group + of the Portal group diff --git a/hr_timesheet_portal/readme/CONTRIBUTORS.md b/hr_timesheet_portal/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ce4bfc5e9d --- /dev/null +++ b/hr_timesheet_portal/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- [Hunki Enterprises BV](https://hunki-enterprises.com) + - Holger Brunn \ +- [Innovara](https://innovara.tech) + - Manuel Fombuena \ +- [SISINFO](https://sisinfo.com.uy) + - Miguel Gómez León \ \ No newline at end of file diff --git a/hr_timesheet_portal/readme/DESCRIPTION.md b/hr_timesheet_portal/readme/DESCRIPTION.md new file mode 100644 index 0000000000..d834fe0d72 --- /dev/null +++ b/hr_timesheet_portal/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows portal users to edit their timesheets via the +frontend. diff --git a/hr_timesheet_portal/readme/USAGE.md b/hr_timesheet_portal/readme/USAGE.md new file mode 100644 index 0000000000..8e6043dc81 --- /dev/null +++ b/hr_timesheet_portal/readme/USAGE.md @@ -0,0 +1,11 @@ +Users in the Website group Editable timesheets will see a plus button when they hover over Timesheets. + +![Portal general view](../static/img/01_portal_general_view.png) + +Clicking the plus button allows them to add a new timesheet line: + +![Add timesheet line](../static/img/02_add_timesheet_line.png) + +They can also edit their timesheet lines by hovering over a line and clicking the pencil button next to the date, or delete a line by clicking the cross next to the duration: + +![Edit timesheet line](../static/img/03_edit_timesheet_line.png) \ No newline at end of file diff --git a/hr_timesheet_portal/security/hr_timesheet_portal_security.xml b/hr_timesheet_portal/security/hr_timesheet_portal_security.xml new file mode 100644 index 0000000000..4f22b59ad3 --- /dev/null +++ b/hr_timesheet_portal/security/hr_timesheet_portal_security.xml @@ -0,0 +1,33 @@ + + + + + Editable timesheets + + Add portal users who should be allowed to edit their timesheets + + + + + + + + + [ + '|', + '&', + ('task_id.project_id.privacy_visibility', '=', 'portal'), + ('task_id.project_id.message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]), + '&', + ('task_id.project_id.privacy_visibility', '=', 'portal'), + ('task_id.message_partner_ids', 'child_of', [user.partner_id.commercial_partner_id.id]), + ] + + + diff --git a/hr_timesheet_portal/security/ir.model.access.csv b/hr_timesheet_portal/security/ir.model.access.csv new file mode 100644 index 0000000000..15a29fcf87 --- /dev/null +++ b/hr_timesheet_portal/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +crud_account_analytic_line,CRUD analytic lines,analytic.model_account_analytic_line,group_hr_timesheet_portal,1,1,1,1 diff --git a/hr_timesheet_portal/static/description/icon.png b/hr_timesheet_portal/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/hr_timesheet_portal/static/description/icon.png differ diff --git a/hr_timesheet_portal/static/description/index.html b/hr_timesheet_portal/static/description/index.html new file mode 100644 index 0000000000..66580051ae --- /dev/null +++ b/hr_timesheet_portal/static/description/index.html @@ -0,0 +1,464 @@ + + + + + +Timesheet portal (editable) + + + +
+

Timesheet portal (editable)

+ + +

Alpha License: AGPL-3 OCA/timesheet Translate me on Weblate Try me on Runboat

+

This module allows portal users to edit their timesheets via the +frontend.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Add users to the group Editable timesheets. If you want all portal +users be able to edit timesheets, add the group as an implied group +of the Portal group
  2. +
+
+
+

Usage

+

Users in the Website group Editable timesheets will see a plus button +when they hover over Timesheets.

+

Portal general view

+

Clicking the plus button allows them to add a new timesheet line:

+

Add timesheet line

+

They can also edit their timesheet lines by hovering over a line and +clicking the pencil button next to the date, or delete a line by +clicking the cross next to the duration:

+

Edit timesheet line

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Hunki Enterprises BV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_timesheet_portal/static/img/01_portal_general_view.png b/hr_timesheet_portal/static/img/01_portal_general_view.png new file mode 100644 index 0000000000..91ab632fca Binary files /dev/null and b/hr_timesheet_portal/static/img/01_portal_general_view.png differ diff --git a/hr_timesheet_portal/static/img/02_add_timesheet_line.png b/hr_timesheet_portal/static/img/02_add_timesheet_line.png new file mode 100644 index 0000000000..62ca860dd7 Binary files /dev/null and b/hr_timesheet_portal/static/img/02_add_timesheet_line.png differ diff --git a/hr_timesheet_portal/static/img/03_edit_timesheet_line.png b/hr_timesheet_portal/static/img/03_edit_timesheet_line.png new file mode 100644 index 0000000000..d6c2be4637 Binary files /dev/null and b/hr_timesheet_portal/static/img/03_edit_timesheet_line.png differ diff --git a/hr_timesheet_portal/static/src/js/hr_timesheet_portal.esm.js b/hr_timesheet_portal/static/src/js/hr_timesheet_portal.esm.js new file mode 100644 index 0000000000..3d0491aee5 --- /dev/null +++ b/hr_timesheet_portal/static/src/js/hr_timesheet_portal.esm.js @@ -0,0 +1,164 @@ +import {browser} from "@web/core/browser/browser"; +import publicWidget from "@web/legacy/js/public/public_widget"; +import {user} from "@web/core/user"; + +export const HrTimesheetPortal = publicWidget.Widget.extend({ + selector: "div.hr_timesheet_portal", + disabledInEditableMode: true, + events: { + "click h5 .fa-plus": "_onclick_add", + "click tr[data-line-id].editable:not(.edit)": "_onclick_edit", + "click tr[data-line-id].editable i.fa-remove": "_onclick_delete", + "click button.submit": "_onclick_submit", + "submit form": "_onclick_submit", + "click button.cancel": "_reload_timesheet", + }, + + /** + * @override + */ + init() { + this._super(...arguments); + this.orm = this.bindService("orm"); + this.ui = this.bindService("ui"); + }, + + _onclick_delete: async function (e) { + e.stopPropagation(); + this.ui.block(); + const line = jQuery(e.currentTarget).parents("tr").data("line-id"); + await this.orm + .unlink("account.analytic.line", [line]) + .then(this.proxy("_reload_timesheet")) + .catch(this.proxy("_display_failure")) + .finally(() => { + this.ui.unblock(); + }); + }, + + _onclick_add: async function () { + const self = this; + const uid = user.userId; + const account = this.$el.data("account-id"); + const project = this.$el.data("project-id"); + const task = this.$el.data("task-id"); + + this.ui.block(); + await this.orm + .call("account.analytic.line", "create", [ + [ + { + user_id: uid, + account_id: account, + project_id: project, + task_id: task, + unit_amount: 0, + name: "/", + }, + ], + ]) + .then(function (line_id) { + return self._reload_timesheet().then(function () { + browser.setTimeout(() => self._edit_line(line_id), 0); + }); + }) + .catch(this.proxy("_display_failure")) + .finally(() => { + this.ui.unblock(); + }); + }, + + _onclick_edit: function (e) { + return this._edit_line(jQuery(e.target).parents("tr").data("line-id")); + }, + + _onclick_submit: async function (e) { + e.preventDefault(); + this.ui.block(); + const $tr = jQuery(e.target).parents("tr"), + data = Object.fromEntries( + $tr + .find("form") + .serializeArray() + .map((field) => [field.name, field.value]) + ); + await this.orm + .write("account.analytic.line", [$tr.data("line-id")], data) + .then(this.proxy("_reload_timesheet")) + .catch(this.proxy("_display_failure")) + .finally(() => { + this.ui.unblock(); + }); + }, + + _reload_timesheet: function () { + this.$el.children("div.alert").remove(); + return $.ajax({ + dataType: "html", + }).then(function (data) { + const timesheets = jQuery.parseHTML(data).filter(function (element) { + const dhtp = jQuery(element).find("div.hr_timesheet_portal"); + return dhtp.length > 0; + }); + + const $tableTimesheet = $(".hr_timesheet_portal .o_portal_my_doc_table"); + const $tableSubtotal = $(".hr_timesheet_portal .container_subtotal table"); + $tableTimesheet.find("tbody").remove(); + $tableSubtotal.find("tbody").remove(); + + const $tbodyTimesheet = jQuery(timesheets).find( + ".hr_timesheet_portal .o_portal_my_doc_table tbody" + ); + const $tbodySubtotal = jQuery(timesheets).find( + ".hr_timesheet_portal .container_subtotal table tbody" + ); + if ($tbodyTimesheet.length && $tbodyTimesheet.children().length > 0) { + $tableTimesheet.append($tbodyTimesheet); + } + if ($tbodySubtotal.length && $tbodySubtotal.children().length > 0) { + $tableSubtotal.append($tbodySubtotal); + } + }); + }, + + _display_failure: function (error) { + this.$el.prepend( + jQuery('
').text(error.data.message) + ); + }, + + _edit_line(line_id) { + const $line = this.$(`tr[data-line-id="${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 () { + const $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"), + }); + $this.empty().append($input); + }); + $edit_line.addClass("edit"); + const $form = jQuery("
", { + id: "hr_timesheet_portal_form", + }), + $submit = jQuery( + '