diff --git a/hr_timesheet_sheet_autodraft/README.rst b/hr_timesheet_sheet_autodraft/README.rst new file mode 100644 index 0000000000..50cbe0829f --- /dev/null +++ b/hr_timesheet_sheet_autodraft/README.rst @@ -0,0 +1,101 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================= +HR Timesheet Sheet Auto-draft +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9aee3d939422ab6b330f8164823d22ec9e8527a37d2cfd600d16fa4460a06e29 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/hr_timesheet_sheet_autodraft + :alt: OCA/timesheet +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/timesheet-19-0/timesheet-19-0-hr_timesheet_sheet_autodraft + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds option to auto-draft Timesheet Sheets whenever a +Timesheet entry is created or modified to ensure it's covered by a +relevant Timesheet Sheet. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To enable auto-drafting: + +# Go to *Timesheets > Configuration > Settings* # Enable **Auto-draft +Timesheet Sheets** under **Timesheet Options** + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* CorporateHub + +Contributors +------------ + +- `CorporateHub `__ + + - Alexey Pelykh + - Dhara Solanki + +- `Innovara `__ + + - Manuel Fombuena + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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. + +This module is part of the `OCA/timesheet `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_timesheet_sheet_autodraft/__init__.py b/hr_timesheet_sheet_autodraft/__init__.py new file mode 100644 index 0000000000..4b76c7b2d5 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/hr_timesheet_sheet_autodraft/__manifest__.py b/hr_timesheet_sheet_autodraft/__manifest__.py new file mode 100644 index 0000000000..0b3dc49c59 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2020 CorporateHub (https://corporatehub.eu) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "HR Timesheet Sheet Auto-draft", + "version": "19.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/OCA/timesheet", + "author": "CorporateHub, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "application": False, + "summary": ( + "Automatically draft a Timesheet Sheet for every time entry that does" + " not have a relevant Timesheet Sheet existing." + ), + "depends": ["hr_timesheet_sheet"], + "data": ["views/account_analytic_line.xml", "views/res_config_settings.xml"], +} diff --git a/hr_timesheet_sheet_autodraft/i18n/hr_timesheet_sheet_autodraft.pot b/hr_timesheet_sheet_autodraft/i18n/hr_timesheet_sheet_autodraft.pot new file mode 100644 index 0000000000..254ebcf942 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/i18n/hr_timesheet_sheet_autodraft.pot @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_timesheet_sheet_autodraft +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_account_analytic_line +msgid "Analytic Line" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.actions.server,name:hr_timesheet_sheet_autodraft.action_autodraft_timesheet_sheets +msgid "Auto-draft Timesheet Sheet(s)" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,help:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "" +"Auto-draft Timesheet Sheets whenever a Timesheet entry is created or " +"modified to ensure it's covered by a relevant Timesheet Sheet" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "" +"Auto-draft timesheet when an entry is created and no sheet covering this " +"period exists" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_company +msgid "Companies" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_company__timesheet_sheets_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "Timesheet Sheets Auto-draft" +msgstr "" diff --git a/hr_timesheet_sheet_autodraft/i18n/it.po b/hr_timesheet_sheet_autodraft/i18n/it.po new file mode 100644 index 0000000000..d46408ac10 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/i18n/it.po @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_timesheet_sheet_autodraft +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-01-12 09:44+0000\n" +"Last-Translator: mymage \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 4.14.1\n" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "" +"" +msgstr "" +"" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_account_analytic_line +msgid "Analytic Line" +msgstr "Riga analitica" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.actions.server,name:hr_timesheet_sheet_autodraft.action_autodraft_timesheet_sheets +msgid "Auto-draft Timesheet Sheet(s)" +msgstr "Compilazione automatica scheda(e) foglio ore" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "Auto-draft Timesheet Sheets" +msgstr "Compilazione automatica fogli scheda attività" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,help:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "" +"Auto-draft Timesheet Sheets whenever a Timesheet entry is created or " +"modified to ensure it's covered by a relevant Timesheet Sheet" +msgstr "" +"Compilazione automatica delle schede foglio ore ogni volta che una voce del " +"foglio ore viene creata o modificata per garantire che sia coperta da una " +"scheda del foglio ore pertinente" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "Check to enable Timesheet Sheet(s) auto-drafting on Timesheet altering." +msgstr "" +"Selezionare per abilitare la redazione automatica della scheda(e) del foglio " +"ore durante la modifica del foglio ore." + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni configurazione" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_company__timesheet_sheets_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "Timesheet Sheets Auto-draft" +msgstr "Compilazione automatica fogli scheda attività" + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" diff --git a/hr_timesheet_sheet_autodraft/i18n/nl.po b/hr_timesheet_sheet_autodraft/i18n/nl.po new file mode 100644 index 0000000000..bde3129f36 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/i18n/nl.po @@ -0,0 +1,86 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_timesheet_sheet_autodraft +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-02-04 23:33+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl\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 4.3.2\n" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "" +"" +msgstr "" +"" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_account_analytic_line +msgid "Analytic Line" +msgstr "Kostenplaatsregel" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.actions.server,name:hr_timesheet_sheet_autodraft.action_autodraft_timesheet_sheets +msgid "Auto-draft Timesheet Sheet(s)" +msgstr "Automatisch opstellen Urenstaat formulier(en)" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "Auto-draft Timesheet Sheets" +msgstr "Automatisch opstellen Urenstaat formulieren" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,help:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "" +"Auto-draft Timesheet Sheets whenever a Timesheet entry is created or " +"modified to ensure it's covered by a relevant Timesheet Sheet" +msgstr "" +"Stel automatisch een urenstaat formulier op, wanneer er een urenstaat " +"activiteit is aangemaakt of gewijzigd welke nog niet is vermeld op een " +"urenstaat formulier" + +#. module: hr_timesheet_sheet_autodraft +#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_autodraft.res_config_settings_view_form +msgid "Check to enable Timesheet Sheet(s) auto-drafting on Timesheet altering." +msgstr "" +"Indien aangevinkt stel automatisch urenstaat formulieren op bij wijzigingen " +"op urenstaat activiteiten." + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_company +msgid "Companies" +msgstr "Bedrijven" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model,name:hr_timesheet_sheet_autodraft.model_res_config_settings +msgid "Config Settings" +msgstr "Configuratie instellingen" + +#. module: hr_timesheet_sheet_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_company__timesheet_sheets_autodraft +#: model:ir.model.fields,field_description:hr_timesheet_sheet_autodraft.field_res_config_settings__timesheet_sheets_autodraft +msgid "Timesheet Sheets Auto-draft" +msgstr "Urenstaat formulieren automatisch opstellen" + +#~ msgid "Display Name" +#~ msgstr "Weergave naam" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Laatst gewijzigd op" diff --git a/hr_timesheet_sheet_autodraft/models/__init__.py b/hr_timesheet_sheet_autodraft/models/__init__.py new file mode 100644 index 0000000000..a5e0962fb4 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import res_company +from . import res_config +from . import account_analytic_line diff --git a/hr_timesheet_sheet_autodraft/models/account_analytic_line.py b/hr_timesheet_sheet_autodraft/models/account_analytic_line.py new file mode 100644 index 0000000000..150800097d --- /dev/null +++ b/hr_timesheet_sheet_autodraft/models/account_analytic_line.py @@ -0,0 +1,52 @@ +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + def _determine_sheet(self): + sheet = super()._determine_sheet() + if sheet or not self.company_id.timesheet_sheets_autodraft: + return sheet + return self._autodraft_sheet() + + def _autodraft_sheet(self): + """Hook for extensions""" + self.ensure_one() + HrTimesheetSheet = self.env["hr_timesheet.sheet"] + if not self.env.context.get("manual_autodraft_timesheet_sheet", False): + HrTimesheetSheet = HrTimesheetSheet.sudo() + values = self._get_autodraft_sheet_values() + sheet = HrTimesheetSheet.new( + {**HrTimesheetSheet.default_get(HrTimesheetSheet._fields.keys()), **values} + ) + existing_sheets_domain = sheet._get_overlapping_sheet_domain() + existing_sheets_domain = list( + filter(lambda criteria: criteria[0] != "id", existing_sheets_domain) + ) + if HrTimesheetSheet.search(existing_sheets_domain, limit=1): + return None + sheet = HrTimesheetSheet.create(values) + sheet._compute_timesheet_ids() + return sheet + + def _get_autodraft_sheet_values(self): + """Hook for extensions""" + self.ensure_one() + HrTimesheetSheet = self.env["hr_timesheet.sheet"] + return { + "employee_id": self.employee_id.id, + "company_id": self.company_id.id, + "date_start": HrTimesheetSheet._get_period_start( + self.company_id, self.date + ), + "date_end": HrTimesheetSheet._get_period_end(self.company_id, self.date), + } + + def action_autodraft_timesheet_sheets(self): + self.filtered(lambda aal: not aal.sheet_id).with_context( + manual_autodraft_timesheet_sheet=True + )._compute_sheet() diff --git a/hr_timesheet_sheet_autodraft/models/res_company.py b/hr_timesheet_sheet_autodraft/models/res_company.py new file mode 100644 index 0000000000..535f3a7415 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/models/res_company.py @@ -0,0 +1,10 @@ +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + timesheet_sheets_autodraft = fields.Boolean(string="Timesheet Sheets Auto-draft") diff --git a/hr_timesheet_sheet_autodraft/models/res_config.py b/hr_timesheet_sheet_autodraft/models/res_config.py new file mode 100644 index 0000000000..3feedcb9ac --- /dev/null +++ b/hr_timesheet_sheet_autodraft/models/res_config.py @@ -0,0 +1,19 @@ +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfig(models.TransientModel): + _inherit = "res.config.settings" + + timesheet_sheets_autodraft = fields.Boolean( + related="company_id.timesheet_sheets_autodraft", + string="Timesheet Sheets Auto-draft", + help=( + "Auto-draft Timesheet Sheets whenever a Timesheet entry is created" + " or modified to ensure it's covered by a relevant Timesheet" + " Sheet" + ), + readonly=False, + ) diff --git a/hr_timesheet_sheet_autodraft/pyproject.toml b/hr_timesheet_sheet_autodraft/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/hr_timesheet_sheet_autodraft/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_timesheet_sheet_autodraft/readme/CONFIGURE.md b/hr_timesheet_sheet_autodraft/readme/CONFIGURE.md new file mode 100644 index 0000000000..65578b5374 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +To enable auto-drafting: + +\# Go to *Timesheets \> Configuration \> Settings* \# Enable +**Auto-draft Timesheet Sheets** under **Timesheet Options** diff --git a/hr_timesheet_sheet_autodraft/readme/CONTRIBUTORS.md b/hr_timesheet_sheet_autodraft/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a4995ebfb2 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- [CorporateHub](https://corporatehub.eu/) + - Alexey Pelykh \ + - Dhara Solanki \ +- [Innovara](https://innovara.tech) + - Manuel Fombuena \ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/hr_timesheet_sheet_autodraft/readme/DESCRIPTION.md b/hr_timesheet_sheet_autodraft/readme/DESCRIPTION.md new file mode 100644 index 0000000000..a25e38683f --- /dev/null +++ b/hr_timesheet_sheet_autodraft/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module adds option to auto-draft Timesheet Sheets whenever a +Timesheet entry is created or modified to ensure it's covered by a +relevant Timesheet Sheet. diff --git a/hr_timesheet_sheet_autodraft/static/description/icon.png b/hr_timesheet_sheet_autodraft/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/hr_timesheet_sheet_autodraft/static/description/icon.png differ diff --git a/hr_timesheet_sheet_autodraft/static/description/index.html b/hr_timesheet_sheet_autodraft/static/description/index.html new file mode 100644 index 0000000000..d10014140d --- /dev/null +++ b/hr_timesheet_sheet_autodraft/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

HR Timesheet Sheet Auto-draft

+ +

Beta License: AGPL-3 OCA/timesheet Translate me on Weblate Try me on Runboat

+

This module adds option to auto-draft Timesheet Sheets whenever a +Timesheet entry is created or modified to ensure it’s covered by a +relevant Timesheet Sheet.

+

Table of contents

+ +
+

Configuration

+

To enable auto-drafting:

+

# Go to Timesheets > Configuration > Settings # Enable Auto-draft +Timesheet Sheets under Timesheet Options

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • CorporateHub
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/timesheet project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/hr_timesheet_sheet_autodraft/tests/__init__.py b/hr_timesheet_sheet_autodraft/tests/__init__.py new file mode 100644 index 0000000000..46510a8285 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_hr_timesheet_sheet_autodraft diff --git a/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py b/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py new file mode 100644 index 0000000000..e74657f4e5 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/tests/test_hr_timesheet_sheet_autodraft.py @@ -0,0 +1,179 @@ +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon + + +class TestHrTimesheetSheetAutodraft(BaseCommon): + def setUp(self): + super().setUp() + + self.ResUsers = self.env["res.users"] + self.Company = self.env["res.company"] + self.Project = self.env["project.project"] + self.HrEmployee = self.env["hr.employee"] + self.HrTimesheetSheet = self.env["hr_timesheet.sheet"] + self.AccountAnalyticLine = self.env["account.analytic.line"] + self.company_id = self.env.company + + def test_no_autocreate_by_default(self): + user = self.ResUsers.sudo().create( + { + "name": "User", + "login": "user", + "email": "user@example.com", + "company_id": self.company_id.id, + "group_ids": [ + Command.link( + self.env.ref("hr_timesheet.group_hr_timesheet_user").id + ) + ], + } + ) + employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + project = self.Project.create({"name": "Project"}) + + aal = self.AccountAnalyticLine.create( + {"project_id": project.id, "employee_id": employee.id, "name": "Time Entry"} + ) + + self.assertFalse(aal.sheet_id) + + def test_autocreate(self): + user = self.ResUsers.sudo().create( + { + "name": "User", + "login": "user", + "email": "user@example.com", + "company_id": self.company_id.id, + "group_ids": [ + Command.link( + self.env.ref("hr_timesheet.group_hr_timesheet_user").id + ) + ], + } + ) + employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + project = self.Project.create({"name": "Project"}) + + aal_1 = self.AccountAnalyticLine.create( + { + "project_id": project.id, + "employee_id": employee.id, + "name": "Time Entry 1", + } + ) + + self.company_id.timesheet_sheets_autodraft = True + + aal_2 = self.AccountAnalyticLine.create( + { + "project_id": project.id, + "employee_id": employee.id, + "name": "Time Entry 2", + } + ) + + self.assertTrue(aal_1.sheet_id) + self.assertTrue(aal_2.sheet_id) + self.assertEqual(aal_1.sheet_id, aal_2.sheet_id) + + def test_already_confirmed(self): + user = self.ResUsers.sudo().create( + { + "name": "User", + "login": "user", + "email": "user@example.com", + "company_id": self.company_id.id, + "group_ids": [ + Command.link( + self.env.ref("hr_timesheet.group_hr_timesheet_user").id + ) + ], + } + ) + employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + project = self.Project.create({"name": "Project"}) + + self.company_id.timesheet_sheets_autodraft = True + + aal_1 = self.AccountAnalyticLine.create( + { + "project_id": project.id, + "employee_id": employee.id, + "name": "Time Entry 1", + } + ) + + aal_1.sheet_id.with_user(user).action_timesheet_confirm() + + aal_2 = self.AccountAnalyticLine.create( + { + "project_id": project.id, + "employee_id": employee.id, + "name": "Time Entry 2", + } + ) + self.assertFalse(aal_2.sheet_id) + + def test_repeated_auto_draft(self): + user = self.ResUsers.sudo().create( + { + "name": "User", + "login": "user", + "email": "user@example.com", + "company_id": self.company_id.id, + "group_ids": [ + Command.link( + self.env.ref("hr_timesheet.group_hr_timesheet_user").id + ) + ], + } + ) + employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + project = self.Project.create({"name": "Project"}) + + self.company_id.timesheet_sheets_autodraft = True + + aal = self.AccountAnalyticLine.create( + {"project_id": project.id, "employee_id": employee.id, "name": "Time Entry"} + ) + sheet = aal.sheet_id + + aal.sheet_id.with_user(user).action_timesheet_confirm() + + aal.action_autodraft_timesheet_sheets() + + self.assertEqual(aal.sheet_id, sheet) + + def test_manual_autodraft_timesheet_sheet(self): + user = self.ResUsers.sudo().create( + { + "name": "User", + "login": "user", + "email": "user@example.com", + "company_id": self.company_id.id, + "group_ids": [ + Command.link( + self.env.ref("hr_timesheet.group_hr_timesheet_user").id + ) + ], + } + ) + employee = self.HrEmployee.create({"name": "Employee", "user_id": user.id}) + project = self.Project.create({"name": "Project"}) + + self.company_id.timesheet_sheets_autodraft = True + + aal = self.AccountAnalyticLine.with_context( + manual_autodraft_timesheet_sheet=True + ).create( + { + "project_id": project.id, + "employee_id": employee.id, + "name": "Time Entry", + } + ) + self.assertTrue(aal.sheet_id) diff --git a/hr_timesheet_sheet_autodraft/views/account_analytic_line.xml b/hr_timesheet_sheet_autodraft/views/account_analytic_line.xml new file mode 100644 index 0000000000..f2463994d5 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/views/account_analytic_line.xml @@ -0,0 +1,18 @@ + + + + + Auto-draft Timesheet Sheet(s) + ir.actions.server + + + code + + if records: + action = records.action_autodraft_timesheet_sheets() + + + diff --git a/hr_timesheet_sheet_autodraft/views/res_config_settings.xml b/hr_timesheet_sheet_autodraft/views/res_config_settings.xml new file mode 100644 index 0000000000..e59f01a0b6 --- /dev/null +++ b/hr_timesheet_sheet_autodraft/views/res_config_settings.xml @@ -0,0 +1,29 @@ + + + + + res.config.settings.view.form + res.config.settings + + + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..2ceaf84957 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-hr_timesheet_sheet @ git+https://github.com/OCA/timesheet.git@refs/pull/841/head#subdirectory=hr_timesheet_sheet +odoo-addon-web_widget_x2many_2d_matrix @ git+https://github.com/OCA/web.git@refs/pull/3310/head#subdirectory=web_widget_x2many_2d_matrix