Skip to content

Commit

Permalink
[IMP] hr_timesheet_portal: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jan 9, 2025
1 parent 399a1d5 commit 83bcab8
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 106 deletions.
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
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
162 changes: 87 additions & 75 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'),
var sAnimation = require("website.content.snippets.animation"),
rpc = require("web.rpc"),
core = require("web.core"),
_t = core._t;

sAnimation.registry.hr_timesheet_portal = sAnimation.Class.extend({
selector: 'div.hr_timesheet_portal',
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,117 @@ 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'));
.done(this.proxy("_reload_timesheet"))
.fail(this.proxy("_display_failure"));
},

_onclick_add: function (e) {
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: "/",
},
],
})
.done(function (line_id) {
return self._reload_timesheet().then(function () {
setTimeout(self._edit_line.bind(self, line_id), 0);
});
})
.fail(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],
})
.done(this.proxy("_reload_timesheet"))
.fail(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};

});
15 changes: 9 additions & 6 deletions hr_timesheet_portal/templates/assets.xml
Original file line number Diff line number Diff line change
@@ -1,15 +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>

<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr=".">
<link rel="stylesheet"
href="/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css"/>
<script type="text/javascript"
src="/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js"/>
<link
rel="stylesheet"
href="/hr_timesheet_portal/static/src/css/hr_timesheet_portal.css"
/>
<script
type="text/javascript"
src="/hr_timesheet_portal/static/src/js/hr_timesheet_portal.js"
/>
</xpath>
</template>

Expand Down
25 changes: 16 additions & 9 deletions hr_timesheet_portal/templates/portal.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?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>

<template id="portal_my_task" inherit_id="hr_timesheet.portal_my_task">
<div t-if="task.timesheet_ids" 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-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">
<i class="fa fa-plus"></i>
<i class="fa fa-plus" />
</xpath>
<tr t-foreach="task.timesheet_ids" position="attributes">
<attribute name="t-att-data-line-id">timesheet.id</attribute>
</tr>
<xpath expr="//tr[@t-foreach='task.timesheet_ids']/td" position="inside">
<i t-if="timesheet.user_id == request.env.user" class="fa fa-edit"></i>
<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">
<i t-if="timesheet.user_id == request.env.user" class="fa fa-remove"></i>
<xpath
expr="//tr[@t-foreach='task.timesheet_ids']/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">
<attribute name="data-field-name">name</attribute>
Expand All @@ -31,11 +35,14 @@
<attribute name="data-field-type">date</attribute>
<attribute name="t-att-data-field-value">timesheet.date</attribute>
</xpath>
<xpath expr="//span[@t-field='timesheet.unit_amount']/parent::td" position="attributes">
<xpath
expr="//span[@t-field='timesheet.unit_amount']/parent::td"
position="attributes"
>
<attribute name="data-field-name">unit_amount</attribute>
<attribute name="data-field-type">number</attribute>
<attribute name="t-att-data-field-value">timesheet.unit_amount</attribute>
</xpath>
</template>

</odoo>
</odoo>
1 change: 1 addition & 0 deletions setup/hr_timesheet_portal/odoo/addons/hr_timesheet_portal
6 changes: 6 additions & 0 deletions setup/hr_timesheet_portal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 83bcab8

Please sign in to comment.