diff --git a/cb_number_of_holidays_report/README.rst b/cb_number_of_holidays_report/README.rst new file mode 100644 index 00000000..0cf745d4 --- /dev/null +++ b/cb_number_of_holidays_report/README.rst @@ -0,0 +1 @@ +Report para saber quien tiene vacaciones en un intervalo de tiempo. diff --git a/cb_number_of_holidays_report/__init__.py b/cb_number_of_holidays_report/__init__.py new file mode 100644 index 00000000..4d3bc374 --- /dev/null +++ b/cb_number_of_holidays_report/__init__.py @@ -0,0 +1,4 @@ +from . import report +from . import wizards +from . import models +from .hooks import pre_init_hook diff --git a/cb_number_of_holidays_report/__manifest__.py b/cb_number_of_holidays_report/__manifest__.py new file mode 100644 index 00000000..bf095ec4 --- /dev/null +++ b/cb_number_of_holidays_report/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Cb Number Of Holidays Report", + "summary": """ + Report para saber quien tiene vacaciones en un intervalo de tiempo""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "CreuBlanca", + "website": "https://github.com/tegin/cb-hr", + "depends": ["cb_hr_views"], + "data": [ + "security/ir.model.access.csv", + "views/hr_leave_type.xml", + "report/holidays_count_report.xml", + "wizards/wizard_holidays_count.xml", + ], + "pre_init_hook": "pre_init_hook", +} diff --git a/cb_number_of_holidays_report/hooks.py b/cb_number_of_holidays_report/hooks.py new file mode 100644 index 00000000..ebed9810 --- /dev/null +++ b/cb_number_of_holidays_report/hooks.py @@ -0,0 +1,15 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + +logger = logging.getLogger(__name__) + + +def pre_init_hook(cr): + cr.execute( + """ + ALTER TABLE hr_leave + ADD COLUMN IF NOT EXISTS count_in_holidays_report BOOLEAN DEFAULT TRUE + """ + ) diff --git a/cb_number_of_holidays_report/i18n/cb_number_of_holidays_report.pot b/cb_number_of_holidays_report/i18n/cb_number_of_holidays_report.pot new file mode 100644 index 00000000..dbf2a01c --- /dev/null +++ b/cb_number_of_holidays_report/i18n/cb_number_of_holidays_report.pot @@ -0,0 +1,175 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cb_number_of_holidays_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-05-05 10:35+0000\n" +"PO-Revision-Date: 2020-05-05 10:35+0000\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: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "From:" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "To:" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Cancel" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__create_uid +msgid "Created by" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__create_date +msgid "Created on" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__date_from +msgid "Date From" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__date_to +msgid "Date To" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__department_id +msgid "Department" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count__display_name +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__display_name +msgid "Display Name" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__employee_ids +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Employee" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Employees" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Filters" +msgstr "" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/report/holidays_count_report.py:14 +#, python-format +msgid "Form content is missing, this report cannot be printed." +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.actions.report,name:cb_number_of_holidays_report.action_report_holidays_count +msgid "Holidays Count" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count__id +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__id +msgid "ID" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count____last_update +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count____last_update +msgid "Last Modified on" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__write_date +msgid "Last Updated on" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Leaves Count" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__name +msgid "Name" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.actions.act_window,name:cb_number_of_holidays_report.wizard_holidays_count_act_window +msgid "Number Holidays Count" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Number of Days" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.ui.menu,name:cb_number_of_holidays_report.wizard_holidays_count_menu +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Number of Holidays Count" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Print" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model,name:cb_number_of_holidays_report.model_report_cb_number_of_holidays_report_report_holidays_count +msgid "Report of number of holidays" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Search" +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__category_ids +msgid "Tag" +msgstr "" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/wizards/wizard_holidays_count.py:67 +#, python-format +msgid "The start date must be anterior to the end date." +msgstr "" + +#. module: cb_number_of_holidays_report +#: model:ir.model,name:cb_number_of_holidays_report.model_wizard_holidays_count +msgid "Wizard Report of number of holidays" +msgstr "" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/wizards/wizard_holidays_count.py:51 +#, python-format +msgid "You have to select at least one Employee. And try again." +msgstr "" + diff --git a/cb_number_of_holidays_report/i18n/es.po b/cb_number_of_holidays_report/i18n/es.po new file mode 100644 index 00000000..11390925 --- /dev/null +++ b/cb_number_of_holidays_report/i18n/es.po @@ -0,0 +1,176 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * cb_number_of_holidays_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-05-05 10:35+0000\n" +"PO-Revision-Date: 2020-05-05 12:37+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: es\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "From:" +msgstr "From:" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "To:" +msgstr "Hasta:" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__date_from +msgid "Date From" +msgstr "Desde" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__date_to +msgid "Date To" +msgstr "Hasta" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__department_id +msgid "Department" +msgstr "Departamento" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count__display_name +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__employee_ids +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Employee" +msgstr "Empleado" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Employees" +msgstr "Empleados" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Filters" +msgstr "Filtros" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/report/holidays_count_report.py:14 +#, python-format +msgid "Form content is missing, this report cannot be printed." +msgstr "Form content is missing, this report cannot be printed." + +#. module: cb_number_of_holidays_report +#: model:ir.actions.report,name:cb_number_of_holidays_report.action_report_holidays_count +msgid "Holidays Count" +msgstr "Número de Ausencias" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count__id +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__id +msgid "ID" +msgstr "ID" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_report_cb_number_of_holidays_report_report_holidays_count____last_update +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Leaves Count" +msgstr "Número de Ausencias" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__name +msgid "Name" +msgstr "Nombre" + +#. module: cb_number_of_holidays_report +#: model:ir.actions.act_window,name:cb_number_of_holidays_report.wizard_holidays_count_act_window +msgid "Number Holidays Count" +msgstr "Número de Ausencias" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.report_holidays_count +msgid "Number of Days" +msgstr "Número de días" + +#. module: cb_number_of_holidays_report +#: model:ir.ui.menu,name:cb_number_of_holidays_report.wizard_holidays_count_menu +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Number of Holidays Count" +msgstr "Número de Ausencias" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Print" +msgstr "Imprimir" + +#. module: cb_number_of_holidays_report +#: model:ir.model,name:cb_number_of_holidays_report.model_report_cb_number_of_holidays_report_report_holidays_count +msgid "Report of number of holidays" +msgstr "Informe de número de ausencias" + +#. module: cb_number_of_holidays_report +#: model_terms:ir.ui.view,arch_db:cb_number_of_holidays_report.wizard_holidays_count_form_view +msgid "Search" +msgstr "Búsqueda" + +#. module: cb_number_of_holidays_report +#: model:ir.model.fields,field_description:cb_number_of_holidays_report.field_wizard_holidays_count__category_ids +msgid "Tag" +msgstr "Etiqueta" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/wizards/wizard_holidays_count.py:67 +#, python-format +msgid "The start date must be anterior to the end date." +msgstr "La fecha inicial debe ser anterior a la final." + +#. module: cb_number_of_holidays_report +#: model:ir.model,name:cb_number_of_holidays_report.model_wizard_holidays_count +msgid "Wizard Report of number of holidays" +msgstr "Wizard Report of number of holidays" + +#. module: cb_number_of_holidays_report +#: code:addons/cb_number_of_holidays_report/wizards/wizard_holidays_count.py:51 +#, python-format +msgid "You have to select at least one Employee. And try again." +msgstr "Se debe seleccionar al menos un empleado" diff --git a/cb_number_of_holidays_report/models/__init__.py b/cb_number_of_holidays_report/models/__init__.py new file mode 100644 index 00000000..7c444ff5 --- /dev/null +++ b/cb_number_of_holidays_report/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_leave_type +from . import hr_leave diff --git a/cb_number_of_holidays_report/models/hr_leave.py b/cb_number_of_holidays_report/models/hr_leave.py new file mode 100644 index 00000000..259b71e8 --- /dev/null +++ b/cb_number_of_holidays_report/models/hr_leave.py @@ -0,0 +1,13 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class HrLeave(models.Model): + + _inherit = "hr.leave" + + count_in_holidays_report = fields.Boolean( + related="holiday_status_id.count_in_holidays_report", store=True + ) diff --git a/cb_number_of_holidays_report/models/hr_leave_type.py b/cb_number_of_holidays_report/models/hr_leave_type.py new file mode 100644 index 00000000..1189e368 --- /dev/null +++ b/cb_number_of_holidays_report/models/hr_leave_type.py @@ -0,0 +1,13 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class HrLeaveType(models.Model): + + _inherit = "hr.leave.type" + + count_in_holidays_report = fields.Boolean( + string="Count in holidays report", default=True + ) diff --git a/cb_number_of_holidays_report/report/__init__.py b/cb_number_of_holidays_report/report/__init__.py new file mode 100644 index 00000000..4af567aa --- /dev/null +++ b/cb_number_of_holidays_report/report/__init__.py @@ -0,0 +1 @@ +from . import holidays_count_report diff --git a/cb_number_of_holidays_report/report/holidays_count_report.py b/cb_number_of_holidays_report/report/holidays_count_report.py new file mode 100644 index 00000000..973e1ab2 --- /dev/null +++ b/cb_number_of_holidays_report/report/holidays_count_report.py @@ -0,0 +1,110 @@ +from datetime import datetime, time + +import pytz +from pytz import timezone + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class HolidaysCountReport(models.AbstractModel): + _name = "report.cb_number_of_holidays_report.report_holidays_count" + _description = "Report of number of holidays" + + @api.model + def _get_report_values(self, docids, data=None): + timezone(self.env.user.tz) + + if not data.get("form"): + raise UserError( + _("Form content is missing, this report cannot be printed.") + ) + + date_from = fields.Datetime.from_string(data["form"]["date_from"]) + date_to = fields.Datetime.from_string(data["form"]["date_to"]) + + print("date_from", date_from) + print("date_to", date_to) + + docs = [] + for employee in self.env["hr.employee"].browse(data["form"]["employee_ids"]): + print(employee.name) + tz = employee.resource_id.calendar_id.tz + holidays = self.env["hr.leave"].search( + [ + ("employee_id", "=", employee.id), + ("date_from", "<=", date_to), + ("date_to", ">=", date_from), + ("state", "=", "validate"), + ("count_in_holidays_report", "=", True), + ] + ) + + print("holidays empleadoooooooo", holidays[0].read()) + + days_count = 0.0 + # date_from_day = ( + # utz.localize(date_from) + # .astimezone(utc) + # .replace(tzinfo=None) + # ) + date_from_day = datetime.combine( + date_from, time(0, 0, 0, 0, tzinfo=pytz.timezone(tz)) + ) + + # date_to_day = ( + # utz.localize(date_to) + # .astimezone(utc) + # .replace(tzinfo=None) + # ) + date_to_day = datetime.combine( + date_to, time(23, 59, 59, 99999, tzinfo=pytz.timezone(tz)) + ) + + print("date_from_day", date_from_day) + print("date_to_day", date_to_day) + print("holidays", holidays[0].date_from) + print("holidays", holidays[0].date_to) + # date_to_day += timedelta(days=1) + for holiday in holidays: + if date_from_day >= holiday.date_from and ( + date_to_day <= holiday.date_to + ): + print("1111111111111111111111111") + print("number_of_days", holiday.number_of_days) + days = (date_to_day - date_from_day).days + elif date_from_day < holiday.date_from and ( + date_to_day > holiday.date_to + ): + print("2222222222222222222222222") + print("number_of_days", holiday.number_of_days) + + days = abs(holiday.number_of_days) + elif date_from_day >= holiday.date_from and ( + date_to_day >= holiday.date_to + ): + days = self.env["hr.leave"]._get_number_of_days( + fields.Datetime.from_string(date_from), + holiday.date_to, + holiday.employee_id.id, + )["days"] + print("days", days) + else: + print("44444444444444444444444") + print("number_of_days", holiday.number_of_days) + + days = self.env["hr.leave"]._get_number_of_days( + holiday.date_from, + fields.Datetime.from_string(date_to_day), + holiday.employee_id.id, + )["days"] + days_count += days + docs.append({"employee": employee.name, "num_of_days": days_count}) + + return { + "doc_ids": data["ids"], + "doc_model": data["model"], + "date_from": date_from, + "date_to": date_to, + "docs": docs, + } diff --git a/cb_number_of_holidays_report/report/holidays_count_report.xml b/cb_number_of_holidays_report/report/holidays_count_report.xml new file mode 100644 index 00000000..58ce2dc9 --- /dev/null +++ b/cb_number_of_holidays_report/report/holidays_count_report.xml @@ -0,0 +1,50 @@ + + + + + Holidays Count + wizard.holidays.count + qweb-pdf + cb_number_of_holidays_report.report_holidays_count + cb_number_of_holidays_report.report_holidays_count + + + diff --git a/cb_number_of_holidays_report/security/ir.model.access.csv b/cb_number_of_holidays_report/security/ir.model.access.csv new file mode 100644 index 00000000..8b0a32af --- /dev/null +++ b/cb_number_of_holidays_report/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wizard_holidays_count,access_wizard_holidays_count,model_wizard_holidays_count,hr.group_hr_manager,1,1,1,1 diff --git a/cb_number_of_holidays_report/tests/__init__.py b/cb_number_of_holidays_report/tests/__init__.py new file mode 100644 index 00000000..d5a0c97b --- /dev/null +++ b/cb_number_of_holidays_report/tests/__init__.py @@ -0,0 +1 @@ +from . import test_number_of_holidays_report diff --git a/cb_number_of_holidays_report/tests/test_number_of_holidays_report.py b/cb_number_of_holidays_report/tests/test_number_of_holidays_report.py new file mode 100644 index 00000000..75cf79f2 --- /dev/null +++ b/cb_number_of_holidays_report/tests/test_number_of_holidays_report.py @@ -0,0 +1,132 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import datetime as datetime + +from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase + + +class TestNumberOfHolidaysReport(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.holiday_type = cls.env["hr.leave.type"].create( + { + "name": "Holiday Type", + "request_unit": "day", + "requires_allocation": "no", + } + ) + cls.partner_id = cls.env["res.partner"].create( + {"name": "Pieter", "is_practitioner": True} + ) + cls.department = cls.env["hr.department"].create({"name": "Department"}) + cls.category = cls.env["hr.employee.category"].create({"name": "Tag 1"}) + cls.calendar = cls.env["resource.calendar"].create( + {"name": "Calendar 1", "attendance_ids": []} + ) + for i in range(0, 7): + cls.env["resource.calendar.attendance"].create( + { + "name": "Day " + str(i), + "dayofweek": str(i), + "hour_from": 8.0, + "hour_to": 17.0, + "calendar_id": cls.calendar.id, + } + ) + + cls.employee = cls.env["hr.employee"].create( + { + "name": "Pieter", + "partner_id": cls.partner_id.id, + "department_id": cls.department.id, + "resource_calendar_id": cls.calendar.id, + "category_ids": [(4, cls.category.id)], + } + ) + leave_start_datetime = datetime.date(2019, 8, 5) # lunes + leave_end_datetime = datetime.date(2019, 8, 9) # viernes + cls.holiday = cls.env["hr.leave"].create( + { + "employee_id": cls.employee.id, + "holiday_status_id": cls.holiday_type.id, + "date_from": leave_start_datetime, + "date_to": leave_end_datetime + datetime.timedelta(days=1), + } + ) + + # print("holidays", cls.holiday.read()) + # cls.holiday = cls.env["hr.leave"].create( + # { + # "employee_id": cls.employee.id, + # "holiday_status_id": cls.holiday_type.id, + # "date_from": "2019-08-05", + # "date_to": "2019-08-09", + # } + # ) + cls.holiday.action_validate() + cls.wizard = cls.env["wizard.holidays.count"].create( + { + "date_from": "2019-08-04", + "date_to": "2019-08-11", + "department_id": cls.department.id, + "category_ids": [(4, cls.category.id)], + } + ) + + # print("wizard", cls.wizard.read()) + + def test_number_of_holidays_report(self): + self.wizard.populate() + self.assertIn(self.employee.id, self.wizard.employee_ids.ids) + with self.assertRaises(UserError): + self.env[ + "report.cb_number_of_holidays_report.report_holidays_count" + ]._get_report_values(False, {}) + + data = dict({"form": {}}) + data["ids"] = self.wizard.ids + data["model"] = self.wizard._name + data["form"]["employee_ids"] = [self.employee.id] + + data["form"]["date_from"] = "2019-08-04" + data["form"]["date_to"] = "2019-08-11" + result = self.env[ + "report.cb_number_of_holidays_report.report_holidays_count" + ]._get_report_values(False, data) + self.assertEqual(result["docs"][0]["num_of_days"], 5.0) + self.assertEqual(result["docs"][0]["employee"], "Pieter") + + data["form"]["date_from"] = "2019-08-07" + print("data", data) + result = self.env[ + "report.cb_number_of_holidays_report.report_holidays_count" + ]._get_report_values(False, data) + + self.assertEqual(result["docs"][0]["num_of_days"], 3.0) + + data["form"]["date_to"] = "2019-08-08" + result = self.env[ + "report.cb_number_of_holidays_report.report_holidays_count" + ]._get_report_values(False, data) + + self.assertEqual(result["docs"][0]["num_of_days"], 2.0) + + data["form"]["date_from"] = "2019-08-04" + result = self.env[ + "report.cb_number_of_holidays_report.report_holidays_count" + ]._get_report_values(False, data) + + self.assertEqual(result["docs"][0]["num_of_days"], 4.0) + + printing = self.wizard.print_report() + self.assertEqual( + printing["context"]["report_action"]["report_name"], + "cb_number_of_holidays_report.report_holidays_count", + ) + self.assertEqual( + printing["context"]["report_action"]["data"]["form"]["employee_ids"], + [self.employee.id], + ) diff --git a/cb_number_of_holidays_report/views/hr_leave_type.xml b/cb_number_of_holidays_report/views/hr_leave_type.xml new file mode 100644 index 00000000..5f29c8f3 --- /dev/null +++ b/cb_number_of_holidays_report/views/hr_leave_type.xml @@ -0,0 +1,15 @@ + + + + + hr.leave.type.form (in cb_number_of_holidays_report) + hr.leave.type + + + + + + + + diff --git a/cb_number_of_holidays_report/wizards/__init__.py b/cb_number_of_holidays_report/wizards/__init__.py new file mode 100644 index 00000000..8f60d9f6 --- /dev/null +++ b/cb_number_of_holidays_report/wizards/__init__.py @@ -0,0 +1 @@ +from . import wizard_holidays_count diff --git a/cb_number_of_holidays_report/wizards/wizard_holidays_count.py b/cb_number_of_holidays_report/wizards/wizard_holidays_count.py new file mode 100644 index 00000000..6f52eb95 --- /dev/null +++ b/cb_number_of_holidays_report/wizards/wizard_holidays_count.py @@ -0,0 +1,66 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class WizardHolidaysCount(models.TransientModel): + _name = "wizard.holidays.count" + _description = "Wizard Report of number of holidays" + + name = fields.Char() + + date_from = fields.Date(required=True) + date_to = fields.Date(required=True) + + employee_ids = fields.Many2many("hr.employee") + + department_id = fields.Many2one("hr.department", string="Department") + category_ids = fields.Many2many("hr.employee.category", string="Tag") + + @api.model + def default_get(self, fields): + res = super().default_get(fields) + if self.env.user.employee_ids: + res["department_id"] = self.env.user.employee_ids[0].department_id.id + return res + + def _prepare_employee_domain(self): + res = [] + if self.category_ids: + res.append(("category_ids", "in", self.category_ids.ids)) + if self.department_id: + res.append(("department_id", "child_of", self.department_id.id)) + return res + + def populate(self): + domain = self._prepare_employee_domain() + self.employee_ids = self.env["hr.employee"].search(domain) + action = self.get_formview_action() + action["target"] = "new" + return action + + def print_report(self): + self.ensure_one() + [data] = self.read() + if not data.get("employee_ids"): + raise UserError( + _("You have to select at least one Employee. And try again.") + ) + datas = {"ids": self.ids, "model": self._name, "form": data} + return self.env.ref( + "cb_number_of_holidays_report.action_report_holidays_count" + ).report_action(self, data=datas) + + @api.constrains("date_from", "date_to") + def check_date(self): + for record in self: + if ( + record.date_from + and record.date_to + and record.date_from > record.date_to + ): + raise ValidationError( + _("The start date must be anterior to the end date.") + ) diff --git a/cb_number_of_holidays_report/wizards/wizard_holidays_count.xml b/cb_number_of_holidays_report/wizards/wizard_holidays_count.xml new file mode 100644 index 00000000..cd082e1b --- /dev/null +++ b/cb_number_of_holidays_report/wizards/wizard_holidays_count.xml @@ -0,0 +1,75 @@ + + + + + wizard.holidays.count.form (in cb_number_of_holidays_report) + wizard.holidays.count + +
+ + + + + + + + + + + + + + + + +
+
+ + + + + +
+
+
+
+
+ + Number Holidays Count + wizard.holidays.count + form + {} + new + + +
diff --git a/hr_holidays_extendable/models/hr_leave.py b/hr_holidays_extendable/models/hr_leave.py index e68ce4e5..b0941159 100644 --- a/hr_holidays_extendable/models/hr_leave.py +++ b/hr_holidays_extendable/models/hr_leave.py @@ -21,8 +21,11 @@ def _get_number_of_days(self, date_from, date_to, employee_id): We need to modify in order to add the compute_leaves = False """ if not self.env.context.get("no_check_state_date") or not employee_id: + print("estoy dentrooooo") return super()._get_number_of_days(date_from, date_to, employee_id) employee = self.env["hr.employee"].browse(employee_id) + print("estoy dentrooooo 2222222", employee) + return employee._get_work_days_data_batch( date_from, date_to, compute_leaves=False )[employee.id] diff --git a/setup/cb_number_of_holidays_report/odoo/addons/cb_number_of_holidays_report b/setup/cb_number_of_holidays_report/odoo/addons/cb_number_of_holidays_report new file mode 120000 index 00000000..487b34ea --- /dev/null +++ b/setup/cb_number_of_holidays_report/odoo/addons/cb_number_of_holidays_report @@ -0,0 +1 @@ +../../../../cb_number_of_holidays_report \ No newline at end of file diff --git a/setup/cb_number_of_holidays_report/setup.py b/setup/cb_number_of_holidays_report/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/cb_number_of_holidays_report/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)