Skip to content
Permalink
Browse files

Merge pull request #772 from KolushovAlexandr/10.0-timelog-tests

10.0 timelog tests
  • Loading branch information...
yelizariev committed Jul 5, 2019
2 parents 27246f7 + 520a12e commit f77602b2035785141d85295f53f7893a70d0c2c3
@@ -3,6 +3,8 @@
odoo.define('base_attendance.tour', function (require) {
"use strict";

var TourManager = require("web_tour.TourManager");
TourManager = new TourManager();
var tour = require("web_tour.tour");
var core = require('web.core');
var _t = core._t;
@@ -25,7 +27,7 @@ odoo.define('base_attendance.tour', function (require) {
}];
}

var steps = [{
var steps = [TourManager.STEPS.MENU_MORE, {
trigger: 'a.oe_menu_toggler:contains("Attendance")',
content: _t("Click to enter menu attendances"),
position: 'bottom',
@@ -0,0 +1,61 @@
From dd3337079ddf96b6ae9ab7545ed5f2af1422d834 Mon Sep 17 00:00:00 2001
From: GabbasovDinar <gabbasov@it-projects.info>
Date: Thu, 21 Jun 2018 14:22:54 +0500
Subject: [PATCH] [IMP] support grouping by weeks starting with Sunday

---
odoo/models.py | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/odoo/models.py b/odoo/models.py
index d04e664..f85ba18 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -1794,6 +1794,7 @@ class BaseModel(object):
# Cfr: http://babel.pocoo.org/docs/dates/#date-fields
'day': 'dd MMM yyyy', # yyyy = normal year
'week': "'W'w YYYY", # w YYYY = ISO week-year
+ 'week_sunday': "'W'w'(s)' YYYY", # w YYYY = ISO week-year
'month': 'MMMM yyyy',
'quarter': 'QQQ yyyy',
'year': 'yyyy',
@@ -1801,13 +1802,24 @@ class BaseModel(object):
time_intervals = {
'day': dateutil.relativedelta.relativedelta(days=1),
'week': datetime.timedelta(days=7),
+ 'week_sunday': datetime.timedelta(days=7),
'month': dateutil.relativedelta.relativedelta(months=1),
'quarter': dateutil.relativedelta.relativedelta(months=3),
'year': dateutil.relativedelta.relativedelta(years=1)
}
if tz_convert:
qualified_field = "timezone('%s', timezone('UTC',%s))" % (self._context.get('tz', 'UTC'), qualified_field)
- qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
+ if gb_function == 'week_sunday':
+ # postgres's date_trunc supports only weeks starting with Monday
+ # So, make this hack to support weeks starting with Sunday
+ if field_type == 'date':
+ # interger must be used to don't convert DATE to TIMESTAMP
+ interval_day = "integer '1'"
+ else:
+ interval_day = "interval '1 day'"
+ qualified_field = "date_trunc('week', %s + %s)" % (qualified_field, interval_day)
+ else:
+ qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
if field_type == 'boolean':
qualified_field = "coalesce(%s,false)" % qualified_field
return {
@@ -1861,6 +1873,10 @@ class BaseModel(object):
if ftype == 'many2one':
value = value[0]
elif ftype in ('date', 'datetime'):
+ if ':week_sunday' in gb['groupby']:
+ # postgres's date_trunc supports only weeks starting with Monday
+ # So, make this hack to support weeks starting with Sunday
+ value -= dateutil.relativedelta.relativedelta(days=1)
locale = self._context.get('lang') or 'en_US'
fmt = DEFAULT_SERVER_DATETIME_FORMAT if ftype == 'datetime' else DEFAULT_SERVER_DATE_FORMAT
tzinfo = None
--
1.9.1

@@ -1,3 +1,7 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3

==============
Time Tracker
==============
@@ -15,21 +19,35 @@ Credits

Contributors
------------
* Dinar Gabbasov <gabbasov@it-projects.info>
* `Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar>`__

Sponsors
--------
* `IT-Projects LLC <https://it-projects.info>`_
* `IT-Projects LLC <https://it-projects.info>`__

Maintainers
-----------
* `IT-Projects LLC <https://it-projects.info>`__

To get a guaranteed support
you are kindly requested to purchase the module
at `odoo apps store <https://apps.odoo.com/apps/modules/10.0/project_timelog/>`__.

Thank you for understanding!

`IT-Projects Team <https://www.it-projects.info/team>`__

Further information
===================

Demo: http://runbot.it-projects.info/demo/misc-addons/8.0
Demo: http://runbot.it-projects.info/demo/misc-addons/10.0

HTML Description: https://apps.odoo.com/apps/modules/8.0/project_timelog/
HTML Description: https://apps.odoo.com/apps/modules/10.0/project_timelog/

Usage instructions: `<doc/index.rst>`_

Changelog: `<doc/changelog.rst>`_

Tested on Odoo 8.0 6a1ecef7759dd72d30d23fe1c55966e1a97bac01
Notifications on updates: `via Atom <https://github.com/it-projects-llc/misc-addons/commits/10.0/project_timelog.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/misc-addons/commits/10.0/project_timelog.atom>`_

Tested on Odoo 10.0 d89f4d6ec26806389922351eb8e575754b3f60e0
@@ -4,7 +4,7 @@
"summary": """Adds Start/Stop buttons to task work lines. Allows to see statistics on Calendar, Graph, Tree views and more""",
"category": "Project",
"images": ["images/timelog.png"],
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
@@ -14,9 +14,8 @@
"currency": "EUR",

"depends": [
"project_issue_sheet",
"hr_timesheet",
"base_action_rule",
"bus",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
@@ -37,5 +36,5 @@
"post_init_hook": None,

"auto_install": False,
"installable": False,
"installable": True,
}
@@ -74,12 +74,22 @@ def init_timelog(self, **kwargs):
if timer_status:
day_timer = day_timer + current_time

config = request.env["ir.config_parameter"]

# 4. All time this week
week_timer = 0
today = datetime.datetime.today()
monday = today - datetime.timedelta(datetime.datetime.weekday(today))
sunday = today + datetime.timedelta(6 - datetime.datetime.weekday(today))
timelog_this_week = timelog_obj.search([("user_id", "=", user.id), ("start_datetime", ">=", monday.strftime('%Y-%m-%d 00:00:00')), ("start_datetime", "<=", sunday.strftime('%Y-%m-%d 23:59:59'))])

first_weekday = config.get_param("project_timelog.first_weekday")

if first_weekday == 'monday':
first_day_of_week = today - datetime.timedelta(datetime.datetime.weekday(today))
last_day_of_week = today + datetime.timedelta(6 - datetime.datetime.weekday(today))
elif first_weekday == 'sunday':
first_day_of_week = today - datetime.timedelta(1 + datetime.datetime.weekday(today))
last_day_of_week = today + datetime.timedelta(5 - datetime.datetime.weekday(today))

timelog_this_week = timelog_obj.search([("user_id", "=", user.id), ("start_datetime", ">=", first_day_of_week.strftime('%Y-%m-%d 00:00:00')), ("start_datetime", "<=", last_day_of_week.strftime('%Y-%m-%d 23:59:59'))])
if timelog_this_week:
week_work_ids = []
for r in timelog_this_week:
@@ -100,24 +110,21 @@ def init_timelog(self, **kwargs):
if timelogs_other_users:
another_users = []
for u in timelogs_other_users:
another_users.append({
'id': u.user_id.id,
'name': u.user_id.name
})
another_users.append(u.user_id.id)
another_users = list(set(another_users))
for u in another_users:
res = timelog_obj.search([("user_id", "=", u['id']), ("work_id.task_id", "=", task.id)])
for user_id in another_users:
res = timelog_obj.search([("user_id", "=", user_id), ("work_id.task_id", "=", task.id)])
sum_another_timelog = 0
for i in res:
sum_another_timelog = sum_another_timelog + i.corrected_duration
sum_another_timelog = 3600 * sum_another_timelog
sum_another_timelog = datetime.timedelta(seconds=round(sum_another_timelog, 0))
second_timer_info.append(u['name'] + ": " + str(sum_another_timelog) + "\n")
current_user = request.env['res.users'].browse(user_id)
second_timer_info.append(current_user.name + ": " + str(sum_another_timelog) + "\n")

for r in second_timer_info:
desctiption_timer = desctiption_timer + r

config = request.env["ir.config_parameter"]
convert_sec = 3600

timer_stopline = False
@@ -165,7 +172,9 @@ def init_timelog(self, **kwargs):
"task_name": task_name,

"timelog_id": last_timelog,
"end_datetime_status": end_datetime_status
"end_datetime_status": end_datetime_status,

"first_weekday": first_weekday,
}

@http.route('/timelog/connection', type='http', auth="public")
@@ -1,3 +1,3 @@
-
!python {model: timelog.config.settings}: |
self.init_timer_parametrs(cr, uid)
self.init_timer_parametrs()
@@ -6,6 +6,11 @@ Installation
============

* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way
* To use the module, you need to be sure that your odoo instance support longpolling, i.e. Instant Messaging works. Read more about how to use the `longpolling <https://odoo-development.readthedocs.io/en/latest/admin/longpolling.html>`_
* You need to install a patch to use the new group (the beginning of the week is Sunday). The use of the patch is optional and needed only to use Sunday grouping (otherwise only Monday works). More `here. <https://github.com/odoo/odoo/pull/25086>`__ To apply the patch execute::

cd /path/to/odoo/source
patch -p1 < /path/to/0001-IMP-support-grouping-by-weeks-starting-with-Sunday.patch

Usage
=====
@@ -37,8 +42,3 @@ Forced completion of the task
Uninstallation
==============
* Open the``Project timelog`` module by going to Apps and click on the ``Uninstall`` button.

Note
====

* To use the module, you need to be sure that your odoo instance support longpolling, i.e. Instant Messaging works. Read more about how to use the `longpolling <https://odoo-development.readthedocs.io/en/latest/admin/longpolling.html>`_
@@ -92,7 +92,7 @@ def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=Fals
class Task(models.Model):
_inherit = "project.task"

datetime_stopline = fields.Datetime(string="Stopline", select=True, track_visibility='onchange', copy=False)
datetime_stopline = fields.Datetime(string="Stopline", index=True, track_visibility='onchange', copy=False)
_track = {
'datetime_stopline': {
'project_timelog.mt_timelog_stopline': lambda self, cr, uid, obj, ctx=None: bool(obj.datetime_stopline),
@@ -202,7 +202,7 @@ def _search_im_status(self, operator, value):
WHERE user_id IN %s""", ("%s seconds" % DISCONNECTION_TIMER, "%s seconds" % AWAY_TIMER, tuple(ids)))
res = dict(((status['id'], status['status']) for status in self.env.cr.dictfetchall()))
if operator == '=':
value_ids = [id for id in ids if res.get(id, 'offline') == value]
value_ids = [vid for vid in ids if res.get(id, 'offline') == value]
return [('id', 'in', value_ids)]

# This function is called every 5 minutes
@@ -216,9 +216,9 @@ def check_stop_timer(self):
for u in user:
all_timelog = u.active_work_id.timelog_ids
sum_time = datetime.timedelta(0)
for id in all_timelog:
date_start_object = datetime.datetime.strptime(id.start_datetime, "%Y-%m-%d %H:%M:%S")
date_end_object = id.end_datetime and datetime.datetime.strptime(id.end_datetime, "%Y-%m-%d %H:%M:%S") or datetime.datetime.now()
for tid in all_timelog:
date_start_object = datetime.datetime.strptime(tid.start_datetime, "%Y-%m-%d %H:%M:%S")
date_end_object = tid.end_datetime and datetime.datetime.strptime(tid.end_datetime, "%Y-%m-%d %H:%M:%S") or datetime.datetime.now()
sum_time = sum_time + (date_end_object-date_start_object)
sum_time = int(round(sum_time.total_seconds(), 0))
if sum_time >= time_subtask:
@@ -14,6 +14,7 @@ class TimelogConfigSettings(models.TransientModel):

normal_time_week = fields.Float(string='Set normal time', help="""Setting time standards provided throughout the week""")
good_time_week = fields.Float(string='Set good time', help="""Set in excess of the time allowed for the week""")
first_weekday = fields.Selection([('monday', 'Monday'), ('sunday', 'Sunday')], string='Beginning of the Week', default='monday')

@api.multi
def set_custom_parameters(self):
@@ -26,6 +27,7 @@ def set_custom_parameters(self):
config_parameters.set_param(key="project_timelog.good_time_day", value=record.good_time_day)
config_parameters.set_param(key="project_timelog.normal_time_week", value=record.normal_time_week)
config_parameters.set_param(key="project_timelog.good_time_week", value=record.good_time_week)
config_parameters.set_param(key="project_timelog.first_weekday", value=record.first_weekday)

@api.multi
def get_default_custom_parameters(self, fields=None):
@@ -37,6 +39,7 @@ def get_default_custom_parameters(self, fields=None):
'good_time_day': icp.get_param('project_timelog.good_time_day'),
'normal_time_week': icp.get_param('project_timelog.normal_time_week'),
'good_time_week': icp.get_param('project_timelog.good_time_week'),
'first_weekday': icp.get_param('project_timelog.first_weekday'),
}

@api.model
@@ -48,3 +51,4 @@ def init_timer_parametrs(self):
icp.set_param(key="project_timelog.good_time_day", value=6)
icp.set_param(key="project_timelog.normal_time_week", value=30)
icp.set_param(key="project_timelog.good_time_week", value=40)
icp.set_param(key="project_timelog.first_weekday", value='monday')
@@ -217,7 +217,7 @@ <h2>Need our service?</h2>
-o-transform: rotate(12deg);
-moz-transform: rotate(12deg);
-ms-transform: rotate(12deg);">
Tested on Odoo<br/>9.0 community
Tested on Odoo<br/>10.0 community
</div>
</div>
</div>

This file was deleted.

@@ -20,7 +20,7 @@ odoo.define('project_timelog.timelog', function(require){
show_application: function() {
var timelog_widget = new TimeLog.TimelogWidget(this);
timelog_widget.appendTo(this.$el.parents().find('.oe_timelog_placeholder'));
this._super();
return this._super();
}
});
TimeLog.Manager = Widget.extend({
@@ -450,10 +450,14 @@ odoo.define('project_timelog.timelog', function(require){
};
} else {
context = {
'search_default_week': 1,
'search_default_group_tasks': 1,
'search_default_group_subtasks': 1,
};
if (this.config.first_weekday === 'sunday') {
context.search_default_week_sunday = 1;
} else {
context.search_default_week = 1;
}
}
if (!action) {
action = {

0 comments on commit f77602b

Please sign in to comment.
You can’t perform that action at this time.