Skip to content

[18.0][MIG][PATCH] hr_timesheet_calendar #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions hr_timesheet_calendar/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
=====================
HR Timesheet Calendar
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fb7b583d6f0a45f1eddc4b83948e103a969ad3b619626e27f53019ed597d0001
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Ftimesheet-lightgray.png?logo=github
:target: https://github.com/OCA/timesheet/tree/18.0/hr_timesheet_calendar
:alt: OCA/timesheet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/timesheet-18-0/timesheet-18-0-hr_timesheet_calendar
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/timesheet&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to have the calendar view to show or perform time
imputation.

This module depends on the project_timesheet_time_control module from
the OCA/project repo to use the 'date_time_end' field.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/timesheet/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/timesheet/issues/new?body=module:%20hr_timesheet_calendar%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Lansana Barry Sow
* APSL-Nagarro

Contributors
------------

[APSL-Nagarro](https://apsl.tech):

- Lansana Barry Sow <[email protected]>

[glueckkanja AG](https://glueckkanja.com):

- Christopher Rogos <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-lbarry-apsl| image:: https://github.com/lbarry-apsl.png?size=40px
:target: https://github.com/lbarry-apsl
:alt: lbarry-apsl

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lbarry-apsl|

This module is part of the `OCA/timesheet <https://github.com/OCA/timesheet/tree/18.0/hr_timesheet_calendar>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_timesheet_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions hr_timesheet_calendar/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2025 Lansana Barry Sow(APSL-Nagarro)<[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "HR Timesheet Calendar",
"version": "18.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/timesheet",
"author": "Lansana Barry Sow, APSL-Nagarro, Odoo Community Association (OCA)",
"maintainers": ["lbarry-apsl"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"hr_timesheet",
"project_timesheet_time_control",
],
"data": [
"views/hr_timesheet_views.xml",
"views/res_config_settings_view.xml",
],
"assets": {
"web.assets_backend": [
"hr_timesheet_calendar/static/src/views/**/*.js",
"hr_timesheet_calendar/static/src/views/**/*.xml",
]
},
}
38 changes: 38 additions & 0 deletions hr_timesheet_calendar/i18n/hr_timesheet_calendar.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_timesheet_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_timesheet_calendar
#: model:ir.model,name:hr_timesheet_calendar.model_account_analytic_line
msgid "Analytic Line"
msgstr ""

#. module: hr_timesheet_calendar
#. odoo-javascript
#: code:addons/hr_timesheet_calendar/static/src/views/timesheet_calendar/common/timesheet_calendar_common_popover.xml:0
#, python-format
msgid "Duplicate"
msgstr ""

#. module: hr_timesheet_calendar
#. odoo-javascript
#: code:addons/hr_timesheet_calendar/static/src/views/timesheet_calendar/timesheet_calendar_controller.esm.js:0
#, python-format
msgid "New Timesheet Entry"
msgstr ""

#. module: hr_timesheet_calendar
#: model_terms:ir.ui.view,arch_db:hr_timesheet_calendar.hr_timesheet_line_calendar
msgid "Timesheets"
msgstr ""
41 changes: 41 additions & 0 deletions hr_timesheet_calendar/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_timesheet_calendar
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-05-03 17:24+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.4\n"

#. module: hr_timesheet_calendar
#: model:ir.model,name:hr_timesheet_calendar.model_account_analytic_line
msgid "Analytic Line"
msgstr "Riga analitica"

#. module: hr_timesheet_calendar
#. odoo-javascript
#: code:addons/hr_timesheet_calendar/static/src/views/timesheet_calendar/common/timesheet_calendar_common_popover.xml:0
#, python-format
msgid "Duplicate"
msgstr "Duplica"

#. module: hr_timesheet_calendar
#. odoo-javascript
#: code:addons/hr_timesheet_calendar/static/src/views/timesheet_calendar/timesheet_calendar_controller.esm.js:0
#, python-format
msgid "New Timesheet Entry"
msgstr "Nuova registrazione foglio ore"

#. module: hr_timesheet_calendar
#: model_terms:ir.ui.view,arch_db:hr_timesheet_calendar.hr_timesheet_line_calendar
msgid "Timesheets"
msgstr "Fogli ore"
4 changes: 4 additions & 0 deletions hr_timesheet_calendar/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import account_analytic_line
from . import res_config_settings
130 changes: 130 additions & 0 deletions hr_timesheet_calendar/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from datetime import datetime, time, timedelta

import pytz

from odoo import api, fields, models


class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"

@api.model
def _get_default_start_time(self):
# Set the default start time according to setting to now
# or after the previous entry.
params = self.env["ir.config_parameter"].sudo()
timesheet_alignment = params.get_param(
"project_timesheet_time_control.timesheet_alignment"
)
# default to now
now = fields.Datetime.now()
start_time = datetime.combine(
now.date(), time(hour=now.hour, minute=now.minute, second=0)
)
if timesheet_alignment == "now":
return start_time
defaults = self.default_get(["employee_id", "company_id", "date"])
date_day = defaults.get("date", now.date())
employee_id = defaults.get(
"employee_id",
self._context.get("default_employee_id", self.env.user.employee_id.id),
)
if not employee_id:
return start_time
# get the last entry of the employee on the same day
# (searching for date_time_end would be better, but is not working)
analytic_lines = self.env[self._name].search(
[
["employee_id", "=", employee_id],
["date", "=", date_day],
["date_time", "!=", False],
],
order="date_time desc",
limit=1,
)
if analytic_lines.date_time_end:
start_time = analytic_lines.date_time_end
if not analytic_lines:
# if employee has no analytic_lines at this day,
# get the employee calendar and set the start time
# to the first interval of the day
employee = self.env["hr.employee"].browse(employee_id)
if employee.resource_calendar_id:
start_date = datetime.combine(
date_day, time(0, tzinfo=pytz.timezone(employee.tz))
)
end_date = start_date + timedelta(days=1)
intervals = employee.resource_calendar_id._work_intervals_batch(
start_date, end_date
).get(False, False)
if intervals and intervals._items:
start_time = (
intervals._items[0][0].astimezone(pytz.UTC).replace(tzinfo=None)
)
return start_time

date_time = fields.Datetime(
string="Start Time", default=_get_default_start_time, copy=False
)

@api.onchange("product_uom_id", "date_time", "date_time_end")
def _compute_unit_amount(self):
hour_uom = self.env.ref("uom.product_uom_hour")
for record in self:
if (
record.product_uom_id == hour_uom
and record.date_time_end
and record.date_time
):
# When date_time_end or date_time is not set, the unit_amount is updated
record.unit_amount = (
record.date_time_end - record.date_time
).total_seconds() / 3600

@api.model
def default_get(self, fields_list):
vals = super().default_get(fields_list)
if (
self._context.get("is_timesheet", False)
and "product_uom_id" in fields_list
and "product_uom_id" not in vals
):
company_id = vals.get("company_id")
company = False
if company_id:
company = self.env["res.company"].browse(company_id)
if not company:
employee_in_id = vals.get(
"employee_id", self._context.get("default_employee_id", False)
)
if employee_in_id:
company = self.env["hr.employee"].browse(employee_in_id).company_id
else:
company = self.env["res.company"].browse(self.env.company.id)

if "company_id" in fields_list:
vals["company_id"] = company.id

if company:
vals["product_uom_id"] = company.project_time_mode_id.id

return vals

@api.model
def duplicate_today(self, record_id):
record = self.browse(record_id)
date_today = fields.Datetime.now(self.env.user.partner_id.tz).date()
date_time_today = datetime.combine(date_today, record.date_time.time())
date_time_end_today = datetime.combine(
date_today,
record.date_time_end.time()
if record.date_time_end
else date_time_today.time(),
)
defaults = {
"date": date_today,
"date_time": date_time_today,
"date_time_end": date_time_end_today,
}
new_record = record.copy(defaults)
return new_record.id
15 changes: 15 additions & 0 deletions hr_timesheet_calendar/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

timesheet_alignment = fields.Selection(
selection=[
("now", "Set Start Date to Now"),
("no-gap", "Align to previous entry"),
],
default="now",
config_parameter="project_timesheet_time_control.timesheet_alignment",
help="Choose the alignment of new timesheet entries without start time.",
)
3 changes: 3 additions & 0 deletions hr_timesheet_calendar/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions hr_timesheet_calendar/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\[APSL-Nagarro\](<https://apsl.tech>):
- Lansana Barry Sow \<<[email protected]>\>

\[glueckkanja AG\](<https://glueckkanja.com>):
- Christopher Rogos \<<[email protected]>\>
3 changes: 3 additions & 0 deletions hr_timesheet_calendar/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows you to have the calendar view to show or perform time imputation.

This module depends on the project_timesheet_time_control module from the OCA/project repo to use the 'date_time_end' field.
Binary file added hr_timesheet_calendar/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading