Skip to content
Permalink
Browse files

⬆️1️⃣2️⃣ project_timelog

  • Loading branch information...
GabbasovDinar committed May 21, 2019
1 parent c663e73 commit 262f12bb13bb53665673ac5fa64ee190fe6e1966
@@ -31,7 +31,7 @@ Maintainers

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/>`__.
at `odoo apps store <https://apps.odoo.com/apps/modules/12.0/project_timelog/>`__.

Thank you for understanding!

@@ -40,14 +40,14 @@ Maintainers
Further information
===================

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

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

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

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

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>`_
Notifications on updates: `via Atom <https://github.com/it-projects-llc/misc-addons/commits/12.0/project_timelog.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/misc-addons/commits/12.0/project_timelog.atom>`_

Tested on Odoo 10.0 d89f4d6ec26806389922351eb8e575754b3f60e0
Tested on Odoo 12.0 530f364547af1cc4ccfa9baa66cd70e564bc62cb
@@ -1,9 +1,10 @@
{
"name": """Time Tracker""",
"summary": """Adds Start/Stop buttons to task work lines. Allows to see statistics on Calendar, Graph, Tree views and more""",
"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": "10.0.1.0.0",
"version": "12.0.1.0.0",
"application": False,

"author": "IT-Projects LLC, Dinar Gabbasov",
@@ -14,7 +15,7 @@

"depends": [
"hr_timesheet",
"base_action_rule",
"base_automation",
],
"external_dependencies": {"python": [], "bin": []},
"data": [
@@ -23,9 +24,9 @@
"views/res_config_view.xml",
"views/project_timelog_templates.xml",
"data/project_timelog_data.xml",
"data/pre_install.yml",
],
"qweb": [
"static/src/xml/menu.xml",
],
"demo": [
],
@@ -1,6 +1,6 @@
import datetime
from openerp import http
from openerp.http import request
from odoo import http
from odoo.http import request


class TimelogController(http.Controller):
@@ -33,16 +33,14 @@ def init_timelog(self, **kwargs):
# 1. get common time of current work (current day)
log_timer = 0
if timelogs and timelogs[0].start_datetime is not False:
date_object = datetime.datetime.strptime(timelogs[0].start_datetime, "%Y-%m-%d %H:%M:%S")
if date_object.day == datetime.datetime.now().day:
if timelogs[0].start_datetime.day == datetime.datetime.now().day:
log_timer = int(round(subtask.unit_amount * 3600, 0))

timer_status = False
if timelogs and timelogs[-1].end_datetime is False:
timer_status = True
start_datetime = datetime.datetime.strptime(timelogs[-1].start_datetime, "%Y-%m-%d %H:%M:%S")
end_datetime = datetime.datetime.now()
current_time = (end_datetime - start_datetime).total_seconds()
current_time = (end_datetime - timelogs[-1].start_datetime).total_seconds()
log_timer = int(round(current_time, 0)) + log_timer

# 2. All time in current task for current user
@@ -79,15 +77,13 @@ def init_timelog(self, **kwargs):
week_timer = 0
today = datetime.datetime.today()

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

first_weekday = config.sudo().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 = []
@@ -128,19 +124,17 @@ def init_timelog(self, **kwargs):

timer_stopline = False
if task.datetime_stopline:
stopline_date = datetime.datetime.strptime(task.datetime_stopline, "%Y-%m-%d %H:%M:%S")
if stopline_date <= datetime.datetime.today():
if task.datetime_stopline <= datetime.datetime.today():
timer_stopline = True

# get configs for timer
time_subtasks = int(round(float(config.get_param("project_timelog.time_subtasks"))*convert_sec, 0))
time_subtasks = int(round(float(config.sudo().get_param("project_timelog.time_subtasks"))*convert_sec, 0))
time_warning_subtasks = time_subtasks - int(
round(float(config.get_param("project_timelog.time_warning_subtasks")) * convert_sec, 0))
normal_time_day = int(round(float(config.get_param("project_timelog.normal_time_day")) * convert_sec, 0))
good_time_day = int(round(float(config.get_param("project_timelog.good_time_day")) * convert_sec, 0))
normal_time_week = int(round(float(config.get_param("project_timelog.normal_time_week")) * convert_sec, 0))
good_time_week = int(round(float(config.get_param("project_timelog.good_time_week")) * convert_sec, 0))

round(float(config.sudo().get_param("project_timelog.time_warning_subtasks")) * convert_sec, 0))
normal_time_day = int(round(float(config.sudo().get_param("project_timelog.normal_time_day")) * convert_sec, 0))
good_time_day = int(round(float(config.sudo().get_param("project_timelog.good_time_day")) * convert_sec, 0))
normal_time_week = int(round(float(config.sudo().get_param("project_timelog.normal_time_week")) * convert_sec, 0))
good_time_week = int(round(float(config.sudo().get_param("project_timelog.good_time_week")) * convert_sec, 0))
end_datetime_status = True
if timelogs and timelogs[-1].end_datetime is False:
end_datetime_status = False

This file was deleted.

@@ -1,63 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<odoo>
<data noupdate="0">
<!--<data>-->
<!--if user offline then timer will stop-->
<record id="ir_cron_check_stop_timer" model="ir.cron">
<field name="name">Offline stop timer</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">5</field>
<field name="interval_type">minutes</field>
<field name="model_id" ref="model_res_users"/>
<field name="state">code</field>
<field name="code">model.check_stop_timer()</field>
<field name="user_id" ref="base.user_root"/>
<field name='interval_number'>5</field>
<field name='interval_type'>minutes</field>
<field name="numbercall">-1</field>
<field name="model" eval="'res.users'" />
<field name="function" eval="'check_stop_timer'" />
<field name="args" eval="" />
<field name="priority" eval="4" />
</record>

<!--new status for yesterday's timelogs-->
<record id="ir_cron_nonactive_new_timer_status" model="ir.cron">
<field name="name">Nonactive new status</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="model_id" ref="model_account_analytic_line"/>
<field name="state">code</field>
<field name="code">model.subtask_new_status()</field>
<field name="user_id" ref="base.user_root"/>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')" />
<field name="model" eval="'account.analytic.line'" />
<field name="function" eval="'subtask_new_status'" />
<field name="args" eval="" />
<field name="priority" eval="5" />
</record>

<!--clear stopline for yesterday's date-->
<record id="ir_cron_clear_stopline_datetime" model="ir.cron">
<field name="name">Clear stopline datetime</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="model_id" ref="model_project_task"/>
<field name="state">code</field>
<field name="code">model.clear_stopline_datetime()</field>
<field name="user_id" ref="base.user_root"/>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')" />
<field name="model" eval="'project.task'" />
<field name="function" eval="'clear_stopline_datetime'" />
<field name="args" eval="" />
<field name="priority" eval="5" />
</record>

<!--if stopline is not false. If date/time in stopline is current date/time then timer will stop-->
<record id="ir_cron_stopline" model="ir.cron">
<field name="name">Stopline</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="model_id" ref="model_project_task"/>
<field name="state">code</field>
<field name="code">model.stopline_timer()</field>
<field name="user_id" ref="base.user_root"/>
<field name='interval_number'>1</field>
<field name='interval_type'>minutes</field>
<field name="numbercall">-1</field>
<field name="model">project.task</field>
<field name="function">stopline_timer</field>
<field name="args">()</field>
<field name="priority" eval="4" />
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')" />
</record>

<record id="mt_timelog_stopline" model="mail.message.subtype">
@@ -75,24 +72,18 @@
<field name="relation_field">project_id</field>
</record>

<record id="action_auto_stop_timer" model="ir.actions.server">
<field name="name">Auto stop timer for user</field>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_project_task"/>
<record id="rule_auto_stop_timer" model="base.automation">
<field name="name">Set timer info</field>
<field name="model_id" ref="project_timelog.model_project_task"/>
<field name="state">code</field>
<field name="code">
obj.set_stage_timer()
record.set_stage_timer()
</field>
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
</record>

<record id="rule_auto_stop_timer" model="base.action.rule">
<field name="name">Set timer info</field>
<field eval="True" name="active" />
<field name="model_id" ref="model_project_task"/>
<field name="kind">on_write</field>
<field name="server_action_ids"
eval="[(4, ref('action_auto_stop_timer'))]"/>
</record>
<function model="timelog.config.settings" name="init_timer_parametrs"/>

</data>
</openerp>
</odoo>
@@ -1,9 +1,9 @@
import datetime
from openerp import models, fields, api
from openerp.exceptions import Warning as UserError
from openerp.tools.translate import _
from openerp.addons.bus.models.bus_presence import AWAY_TIMER
from openerp.addons.bus.models.bus_presence import DISCONNECTION_TIMER
from odoo import models, fields, api
from odoo.exceptions import Warning as UserError
from odoo.tools.translate import _
from odoo.addons.bus.models.bus_presence import AWAY_TIMER
from odoo.addons.bus.models.bus_presence import DISCONNECTION_TIMER


class ProjectTimelog(models.Model):
@@ -102,8 +102,7 @@ class Task(models.Model):
def clear_stopline_datetime(self):
tasks = self.env["project.task"].search(["datetime_stopline", "!=", False])
for task in tasks:
datetime_stopline = datetime.datetime.strptime(task.datetime_stopline, "%Y-%m-%d %H:%M:%S")
if datetime_stopline.day < datetime.datetime.today().day:
if task.datetime_stopline.day < datetime.datetime.today().day:
task.write({"datetime_stopline": False})

@api.model
@@ -113,13 +112,12 @@ def stopline_timer(self):
task = u.active_task_id
if task.datetime_stopline is False:
return False
stopline_date = datetime.datetime.strptime(task.datetime_stopline, "%Y-%m-%d %H:%M:%S")
if stopline_date <= datetime.datetime.today():
if task.datetime_stopline <= datetime.datetime.today():
u.active_work_id.sudo(u).stop_timer(play_a_sound=False, stopline=True)
if u.active_work_id.status is not 'nonactive':
u.active_work_id.sudo(u).write({'status': 'nonactive'})
else:
warning_time = stopline_date - datetime.timedelta(minutes=20)
warning_time = task.datetime_stopline - datetime.timedelta(minutes=20)
notifications = []
time = {
'year': warning_time.year,
@@ -156,7 +154,7 @@ def set_stage_timer(self):
if existing_work.user_id.id == w.user_id.id:
new_work = existing_work
if new_work.timelog_ids[0].end_datetime is not False: # there are timelogs yesterday
date_object = datetime.datetime.strptime(new_work.timelog_ids[0].end_datetime, "%Y-%m-%d %H:%M:%S")
date_object = new_work.timelog_ids[0].end_datetime
if date_object is not False and date_object.day != current_date.day:
subtask_name = str(current_date.day) + '.' + str(current_date.month) + '.' + str(current_date.year) + ' ' + w.name
else:
@@ -211,13 +209,13 @@ def check_stop_timer(self):
for r in status:
r.active_work_id.sudo(r).stop_timer(play_a_sound=False)
user = self.search([("active_work_id.status", "=", "play")])
time_subtask = int(round(float(self.env["ir.config_parameter"].get_param('project_timelog.time_subtasks'))*3600, 0))
time_subtask = int(round(float(self.env["ir.config_parameter"].sudo().get_param('project_timelog.time_subtasks'))*3600, 0))
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()
date_start_object = id.start_datetime
date_end_object = id.end_datetime 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:
@@ -239,16 +237,12 @@ class AccountAnalyticLine(models.Model):
status = fields.Char(string="Status", default="active")
task_allow_logs = fields.Boolean(related='stage_id.allow_log_time', readonly=True)
user_current = fields.Boolean(compute="_compute_user_current", default=True)
project_id = fields.Many2one(readonly=True, related='task_id.project_id', store=True)

unit_amount_computed = fields.Float(string='Time Spent', compute="_compute_unit_amount", default=0)
combined_name = fields.Char('Task and Summary', compute="_compute_combined_name")
_sql_constraints = [
('name_task_uniq', 'unique (name,stage_id,task_id)', 'The name of the subtask must be unique per stage!')
]

unit_amount_computed = fields.Float(string='Time Spent', compute="_compute_unit_amount", default=0)

combined_name = fields.Char('Task and Summary', compute="_compute_combined_name")

@api.multi
def _compute_combined_name(self):
for r in self:
@@ -319,13 +313,12 @@ def play_timer(self):

datetime_stopline = project_task.datetime_stopline
if datetime_stopline is not False and self.task_id.id == self.env.user.active_task_id:
stopline_date = datetime.datetime.strptime(datetime_stopline, "%Y-%m-%d %H:%M:%S")
if stopline_date <= datetime.datetime.now():
if datetime_stopline <= datetime.datetime.now():
return self.show_warning_message(title=_("Error."),
message=_("Unable to create logs until it is modified or deleted stopline."))
stage = project_task.stage_id.id
corrected_duration = self.env["project.timelog"].search([("work_id", "=", self.id), ("user_id", "=", self.env.user.id)])
config = self.env["ir.config_parameter"].get_param("project_timelog.time_subtasks")
config = self.env["ir.config_parameter"].sudo().get_param("project_timelog.time_subtasks")

sum_timelog = 0.0
if corrected_duration and config:
@@ -340,8 +333,7 @@ def play_timer(self):
first_timelog = self.env["project.timelog"].search([("work_id", "=", self.id)])

if first_timelog and first_timelog[0].end_datetime is not False:
date_object = datetime.datetime.strptime(first_timelog[0].end_datetime, "%Y-%m-%d %H:%M:%S")
if date_object is not False and date_object.day != current_date.day:
if first_timelog[0].end_datetime is not False and first_timelog[0].end_datetime.day != current_date.day:
# there are timelogs yesterday
return self.show_warning_message(title=_("Error."),
message=_("Yesterday's timelogs."))

0 comments on commit 262f12b

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