Browse Source

[FIX] Bug Fixed 'project_task_timer'

pull/129/head
Ajmalcybrosys 6 years ago
parent
commit
2de0573dbb
  1. 2
      project_task_timer/__manifest__.py
  2. 4
      project_task_timer/doc/RELEASE_NOTES.md
  3. 17
      project_task_timer/models/project_task_timer.py

2
project_task_timer/__manifest__.py

@ -19,7 +19,7 @@
############################################################################## ##############################################################################
{ {
'name': 'Project Task Timer', 'name': 'Project Task Timer',
'version': '12.0.2.0.1', 'version': '12.0.2.0.2',
'summary': """Task Timer With Start & Stop""", 'summary': """Task Timer With Start & Stop""",
'description': """"This module helps you to track time sheet in project automatically.""", 'description': """"This module helps you to track time sheet in project automatically.""",
'category': 'Project', 'category': 'Project',

4
project_task_timer/doc/RELEASE_NOTES.md

@ -12,3 +12,7 @@ Bug Fixed
#### 06.11.2019 #### 06.11.2019
#### Version 12.0.2.0.1 #### Version 12.0.2.0.1
Bug Fixed Bug Fixed
#### 06.11.2019
#### Version 12.0.2.0.2
Bug Fixed

17
project_task_timer/models/project_task_timer.py

@ -18,7 +18,11 @@
# #
############################################################################## ##############################################################################
from datetime import datetime from datetime import datetime
from AptUrl.Helpers import _
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import UserError
class ProjectTaskTimeSheet(models.Model): class ProjectTaskTimeSheet(models.Model):
@ -51,8 +55,13 @@ class ProjectTaskTimer(models.Model):
def toggle_start(self): def toggle_start(self):
for record in self: for record in self:
record.task_timer = not record.task_timer record.task_timer = not record.task_timer
project_obj = self.env['project.task'].search([])
for data in project_obj:
if self.task_timer: if self.task_timer:
print("self.task_timer") if data.user_id.id == self.user_id.id and data.task_timer == False:
print("success")
raise UserError(_('you cannot start timer for more than one task at the same time'))
elif self.task_timer:
self.write({'is_user_working': True}) self.write({'is_user_working': True})
time_line = self.env['account.analytic.line'] time_line = self.env['account.analytic.line']
print(time_line, "time_line") print(time_line, "time_line")
@ -64,20 +73,16 @@ class ProjectTaskTimer(models.Model):
'project_id': time_sheet.project_id.id, 'project_id': time_sheet.project_id.id,
'date_start': datetime.now(), 'date_start': datetime.now(),
}) })
break
else: else:
self.write({'is_user_working': False}) self.write({'is_user_working': False})
time_line_obj = self.env['account.analytic.line'] time_line_obj = self.env['account.analytic.line']
print(time_line_obj, "time_line_obj")
domain = [('task_id', 'in', self.ids), ('date_end', '=', False)] domain = [('task_id', 'in', self.ids), ('date_end', '=', False)]
for time_line in time_line_obj.search(domain): for time_line in time_line_obj.search(domain):
print(time_line, "else")
time_line.write({'date_end': fields.Datetime.now()}) time_line.write({'date_end': fields.Datetime.now()})
if time_line.date_end: if time_line.date_end:
diff = fields.Datetime.from_string(time_line.date_end) - fields.Datetime.from_string( diff = fields.Datetime.from_string(time_line.date_end) - fields.Datetime.from_string(
time_line.date_start) time_line.date_start)
print(len(time_line) - 1, "time_line - 1")
# if time_line == len(time_line) - 1:
print(len(time_line), "-----------------------")
time_line.timer_duration = round(diff.total_seconds() / 60.0, 2) time_line.timer_duration = round(diff.total_seconds() / 60.0, 2)
time_line.unit_amount = round(diff.total_seconds() / (60.0 * 60.0), 2) time_line.unit_amount = round(diff.total_seconds() / (60.0 * 60.0), 2)
else: else:

Loading…
Cancel
Save