Skip to content

Commit

Permalink
[MIG] hr_timesheet_portal to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jan 9, 2025
1 parent 83bcab8 commit 410cf0b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 67 deletions.
10 changes: 5 additions & 5 deletions hr_timesheet_portal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ 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/14.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-14-0/timesheet-14-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=12.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/timesheet&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -53,7 +53,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/timesheet/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 <https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_portal%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_portal%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -83,6 +83,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 <https://github.com/OCA/timesheet/tree/12.0/hr_timesheet_portal>`_ project on GitHub.
This module is part of the `OCA/timesheet <https://github.com/OCA/timesheet/tree/14.0/hr_timesheet_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_timesheet_portal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Timesheet portal (editable)",
"summary": "Fill in timesheets via the portal",
"version": "12.0.1.0.1",
"version": "14.0.1.0.0",
"development_status": "Alpha",
"category": "Website",
"website": "https://github.com/OCA/timesheet",
Expand Down
7 changes: 3 additions & 4 deletions hr_timesheet_portal/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">Timesheet portal (editable)</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b83149749c355494cfa2ceb00ef516875d7fab19a7e347b02e2bae0b5614449e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/timesheet/tree/12.0/hr_timesheet_portal"><img alt="OCA/timesheet" src="https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/timesheet-12-0/timesheet-12-0-hr_timesheet_portal"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/timesheet&amp;target_branch=12.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/timesheet/tree/14.0/hr_timesheet_portal"><img alt="OCA/timesheet" src="https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/timesheet-14-0/timesheet-14-0-hr_timesheet_portal"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/timesheet&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows portal users to edit their timesheets via the frontend.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
Expand Down Expand Up @@ -402,7 +401,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/timesheet/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_portal%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_portal%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -426,7 +425,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/timesheet/tree/12.0/hr_timesheet_portal">OCA/timesheet</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/timesheet/tree/14.0/hr_timesheet_portal">OCA/timesheet</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
89 changes: 40 additions & 49 deletions hr_timesheet_portal/static/src/js/hr_timesheet_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
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;
const sAnimation = require("website.content.snippets.animation");
const core = require("web.core");
const _t = core._t;

sAnimation.registry.hr_timesheet_portal = sAnimation.Class.extend({
selector: "div.hr_timesheet_portal",
disabledInEditableMode: true,
events: {
"click h5": "_onclick_add",
"click tr[data-line-id]:not(.edit)": "_onclick_edit",
Expand All @@ -20,47 +20,35 @@ odoo.define("hr_timesheet_portal", function (require) {
"click button.cancel": "_reload_timesheet",
},

start: function (editable_mode) {
if (editable_mode) {
this.stop();
return;
}
},

_onclick_delete: function (e) {
e.stopPropagation();
rpc.query({
return this._rpc({
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"), 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 this._rpc({
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);
});
}, this.proxy("_display_failure"));
},

_onclick_edit: function (e) {
Expand All @@ -75,14 +63,11 @@ odoo.define("hr_timesheet_portal", function (require) {
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"));
return this._rpc({
model: "account.analytic.line",
method: "write",
args: [$tr.data("line-id"), data],
}).then(this.proxy("_reload_timesheet"), this.proxy("_display_failure"));
},

_reload_timesheet: function () {
Expand All @@ -96,17 +81,23 @@ odoo.define("hr_timesheet_portal", function (require) {
jQuery(element).find("div.hr_timesheet_portal").length > 0
);
}),
$tbody = jQuery(timesheets).find("tbody");
$tbody = jQuery(timesheets).find("tbody"),
$existing_tbody = self.$("tbody");
if (!$existing_tbody.length) {
return self.$("thead").after($tbody);
}
return self.$("tbody").replaceWith($tbody);
});
},

_display_failure: function (error) {
this.$el.prepend(
jQuery('<div class="alert alert-danger">').text(error.data.message)
jQuery('<div class="alert alert-danger">').text(
error.message.data.message
)
);
this.$el.prepend(
jQuery('<div class="alert alert-danger">').text(error.message)
jQuery('<div class="alert alert-danger">').text(error.message.message)
);
},

Expand Down Expand Up @@ -142,5 +133,5 @@ odoo.define("hr_timesheet_portal", function (require) {
},
});

return {animation: hr_timesheet_portal};
return {animation: sAnimation.registry.hr_timesheet_portal};
});
31 changes: 23 additions & 8 deletions hr_timesheet_portal/templates/portal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@
<odoo>

<template id="portal_my_task" inherit_id="hr_timesheet.portal_my_task">
<div t-if="task.timesheet_ids" position="attributes">
<div t-if="timesheets" position="attributes">
<attribute name="class" add="hr_timesheet_portal" separator=" " />
<attribute name="t-att-data-project-id">task.project_id.id</attribute>
<attribute
name="t-att-data-account-id"
>task.project_id.analytic_account_id.id</attribute>
<attribute name="t-att-data-task-id">task.id</attribute>
</div>
<xpath expr="//div[@t-if='task.timesheet_ids']//h5" position="inside">
<xpath expr="//div[@t-if='timesheets']//h5" position="inside">
<i class="fa fa-plus" />
</xpath>
<tr t-foreach="task.timesheet_ids" position="attributes">
<div t-if="timesheets" position="after">
<div
t-if="not timesheets and task.project_id.allow_timesheets"
class="container hr_timesheet_portal"
t-att-data-project-id="task.project_id.id"
t-att-data-account-id="task.project_id.analytic_account_id.id"
t-att-data-task-id="task.id"
>
<hr class="mt-4 mb-1" />
<h5 class="mt-2 mb-2">Timesheets <i class="fa fa-plus" /></h5>
<t t-call="hr_timesheet.portal_timesheet_table" />
</div>
</div>
</template>
<template
id="portal_timesheet_table"
inherit_id="hr_timesheet.portal_timesheet_table"
>
<tr t-foreach="timesheets" position="attributes">
<attribute name="t-att-data-line-id">timesheet.id</attribute>
</tr>
<xpath expr="//tr[@t-foreach='task.timesheet_ids']/td" position="inside">
<xpath expr="//tr[@t-foreach='timesheets']/td" position="inside">
<i t-if="timesheet.user_id == request.env.user" class="fa fa-edit" />
</xpath>
<xpath
expr="//tr[@t-foreach='task.timesheet_ids']/td[last()]"
position="inside"
>
<xpath expr="//tr[@t-foreach='timesheets']/td[last()]" position="inside">
<i t-if="timesheet.user_id == request.env.user" class="fa fa-remove" />
</xpath>
<xpath expr="//t[@t-esc='timesheet.name']/parent::td" position="attributes">
Expand Down

0 comments on commit 410cf0b

Please sign in to comment.