From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/hr_timesheet/wizard/__init__.py | 4 +++ .../wizard/project_task_create_timesheet.py | 32 ++++++++++++++++++++++ .../wizard/project_task_create_timesheet_views.xml | 22 +++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 addons/hr_timesheet/wizard/__init__.py create mode 100644 addons/hr_timesheet/wizard/project_task_create_timesheet.py create mode 100644 addons/hr_timesheet/wizard/project_task_create_timesheet_views.xml (limited to 'addons/hr_timesheet/wizard') diff --git a/addons/hr_timesheet/wizard/__init__.py b/addons/hr_timesheet/wizard/__init__.py new file mode 100644 index 00000000..9030e15e --- /dev/null +++ b/addons/hr_timesheet/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import project_task_create_timesheet diff --git a/addons/hr_timesheet/wizard/project_task_create_timesheet.py b/addons/hr_timesheet/wizard/project_task_create_timesheet.py new file mode 100644 index 00000000..db4c8be4 --- /dev/null +++ b/addons/hr_timesheet/wizard/project_task_create_timesheet.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from datetime import datetime + + +class ProjectTaskCreateTimesheet(models.TransientModel): + _name = 'project.task.create.timesheet' + _description = "Create Timesheet from task" + + _sql_constraints = [('time_positive', 'CHECK(time_spent > 0)', 'The timesheet\'s time must be positive' )] + + time_spent = fields.Float('Time', digits=(16, 2)) + description = fields.Char('Description') + task_id = fields.Many2one( + 'project.task', "Task", required=True, + default=lambda self: self.env.context.get('active_id', None), + help="Task for which we are creating a sales order", + ) + + def save_timesheet(self): + values = { + 'task_id': self.task_id.id, + 'project_id': self.task_id.project_id.id, + 'date': fields.Date.context_today(self), + 'name': self.description, + 'user_id': self.env.uid, + 'unit_amount': self.time_spent, + } + self.task_id.user_timer_id.unlink() + return self.env['account.analytic.line'].create(values) diff --git a/addons/hr_timesheet/wizard/project_task_create_timesheet_views.xml b/addons/hr_timesheet/wizard/project_task_create_timesheet_views.xml new file mode 100644 index 00000000..db26070c --- /dev/null +++ b/addons/hr_timesheet/wizard/project_task_create_timesheet_views.xml @@ -0,0 +1,22 @@ + + + + + project.task.create.timesheet.wizard.form + project.task.create.timesheet + +
+ + + + + + +
+
+
+ +
-- cgit v1.2.3