Skip to content

Commit

Permalink
[MIG] hr_timesheet_portal: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mhachraf committed Mar 21, 2023
1 parent 8ae77d8 commit 51ea850
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 135 deletions.
11 changes: 6 additions & 5 deletions hr_timesheet_portal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -66,6 +66,7 @@ Contributors
~~~~~~~~~~~~

* Holger Brunn <[email protected]> (https://hunki-enterprises.com)
* Achraf Mhadhbi <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -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 <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/16.0/hr_timesheet_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
9 changes: 7 additions & 2 deletions hr_timesheet_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -15,12 +16,16 @@
"website",
],
"data": [
"templates/assets.xml",
"templates/portal.xml",
"security/hr_timesheet_portal_security.xml",
"security/ir.model.access.csv",
],
"demo": [
"demo/hr_timesheet_portal.xml",
],
"assets": {
"web.assets_frontend": [
"hr_timesheet_portal/static/src/**/*",
],
},
}
3 changes: 1 addition & 2 deletions hr_timesheet_portal/demo/hr_timesheet_portal.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="base.group_portal" model="res.groups">
Expand Down
1 change: 1 addition & 0 deletions hr_timesheet_portal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Holger Brunn <[email protected]> (https://hunki-enterprises.com)
* Achraf Mhadhbi <[email protected]>
Empty file.
17 changes: 9 additions & 8 deletions hr_timesheet_portal/security/hr_timesheet_portal_security.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="group_hr_timesheet_portal" model="res.groups">
<field name="name">Editable timesheets</field>
<field name="category_id" ref="base.module_category_website"/>
<field name="comment">Add portal users who should be allowed to edit their timesheets</field>
<field name="category_id" ref="base.module_category_website" />
<field
name="comment"
>Add portal users who should be allowed to edit their timesheets</field>
</record>

<record id="rule_account_analytic_line" model="ir.rule">
<field name="model_id" ref="analytic.model_account_analytic_line"/>
<field name="model_id" ref="analytic.model_account_analytic_line" />
<field name="domain_force">[
'|',
'&amp;',
Expand All @@ -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]),
]</field>
<field name="groups" eval="[(4, ref('group_hr_timesheet_portal'))]"/>
<field name="groups" eval="[(4, ref('group_hr_timesheet_portal'))]" />
</record>

<record id="rule_hr_employee" model="ir.rule">
<field name="model_id" ref="hr.model_hr_employee"/>
<field name="model_id" ref="hr.model_hr_employee" />
<field name="domain_force">[(0, '=', 1)]</field>
<field name="groups" eval="[(4, ref('group_hr_timesheet_portal'))]"/>
<field name="groups" eval="[(4, ref('group_hr_timesheet_portal'))]" />
</record>

</odoo>
14 changes: 8 additions & 6 deletions hr_timesheet_portal/static/src/css/hr_timesheet_portal.css
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
171 changes: 91 additions & 80 deletions hr_timesheet_portal/static/src/js/hr_timesheet_portal.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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('<div class="alert alert-danger">').text(error.data.message));
this.$el.prepend(jQuery('<div class="alert alert-danger">').text(error.message));
this.$el.prepend(
jQuery('<div class="alert alert-danger">').text(error.data.message)
);
this.$el.prepend(
jQuery('<div class="alert alert-danger">').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('<input>', {
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("<input>", {
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('<form>', {
id: 'hr_timesheet_portal_form',
}), $submit = jQuery('<button class="btn btn-primary submit">'),
$edit_line.addClass("edit");
var $form = jQuery("<form>", {
id: "hr_timesheet_portal_form",
}),
$submit = jQuery('<button class="btn btn-primary submit">'),
$cancel = jQuery('<button class="btn cancel" type="reset">');
$edit_line.children('td:last-child').append($form);
$submit.text(_t('Submit'));
$cancel.text(_t('Cancel'));
$edit_line.children("td:last-child").append($form);
$submit.text(_t("Submit"));
$cancel.text(_t("Cancel"));
$form.append($submit, $cancel);
$edit_line.find('input:first').focus();
$edit_line.find("input:first").focus();
$line.hide();
},
});

return {animation: hr_timesheet_portal};

return {hr_timesheet_portal: sAnimation.registry.hr_timesheet_portal};
});
16 changes: 0 additions & 16 deletions hr_timesheet_portal/templates/assets.xml

This file was deleted.

Loading

0 comments on commit 51ea850

Please sign in to comment.