Skip to content

Commit

Permalink
[MIG] 13.0 hr_attendance_report_theoretical_time
Browse files Browse the repository at this point in the history
  • Loading branch information
pegonzalezspesol committed Jan 1, 2020
1 parent cc1b4f3 commit 098aed8
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 35 deletions.
8 changes: 4 additions & 4 deletions hr_attendance_report_theoretical_time/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Theoretical vs Attended Time Analysis
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/12.0/hr_attendance_report_theoretical_time
:target: https://github.com/OCA/hr/tree/13.0/hr_attendance_report_theoretical_time
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_attendance_report_theoretical_time
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/12.0
:target: https://runbot.odoo-community.org/runbot/116/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -122,7 +122,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_attendance_report_theoretical_time%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_attendance_report_theoretical_time%0Aversion:%2013.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.

Expand Down Expand Up @@ -162,6 +162,6 @@ 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/hr <https://github.com/OCA/hr/tree/12.0/hr_attendance_report_theoretical_time>`_ project on GitHub.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/13.0/hr_attendance_report_theoretical_time>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_attendance_report_theoretical_time/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2019-05-24 14:19+0000\n"
"Last-Translator: Kévin Allard <[email protected]>\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* Pedro M. Baeza.
* David Vidal
* Pedro Gonzalez <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def _group_by(self):
date
"""

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute(
Expand Down Expand Up @@ -174,7 +173,7 @@ def _theoretical_hours(self, employee, date):
tz = employee.resource_id.calendar_id.tz
return employee.with_context(
exclude_public_holidays=True, employee_id=employee.id
).get_work_days_data(
)._get_work_days_data(
datetime.combine(date, time(0, 0, 0, 0, tzinfo=pytz.timezone(tz))),
datetime.combine(date, time(23, 59, 59, 99999, tzinfo=pytz.timezone(tz))),
# Pass this domain for excluding leaves whose type is included in
Expand Down Expand Up @@ -206,12 +205,15 @@ def read_group(
orderby=orderby,
lazy=lazy,
)
if "theoretical_hours" not in fields:

if "theoretical_hours:sum" not in fields:
return res

full_fields = all(
x in fields for x in {"theoretical_hours", "worked_hours", "difference"}
x in fields
for x in {"theoretical_hours:sum", "worked_hours:sum", "difference:sum"}
)
difference_field = "difference" in fields
difference_field = "difference:sum" in fields
for line in res:
day_dict = {}
records = self.search(line.get("__domain", domain))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<record id="hr_attendance_theoretical_action" model="ir.actions.act_window">
<field name="name">Theoretical vs Attended Time Analysis</field>
<field name="res_model">hr.attendance.theoretical.time.report</field>
<field name="view_type">form</field>
<field name="context">{'search_default_previous_month': 1, 'search_default_current_month': 1, 'search_default_my': 1}</field>
<field name="view_mode">pivot,graph</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Theoretical vs Attended Time Analysis</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr/tree/12.0/hr_attendance_report_theoretical_time"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_attendance_report_theoretical_time"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/116/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/hr/tree/13.0/hr_attendance_report_theoretical_time"><img alt="OCA/hr" src="https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_attendance_report_theoretical_time"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/116/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds a new report called “Theoretical vs Attended Time Analysis”
that compares worked time, measured through attendances records, with the
theoretical time, computed from employee’s working calendar, public holidays
Expand Down Expand Up @@ -472,7 +472,7 @@ <h1><a class="toc-backref" href="#id5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_attendance_report_theoretical_time%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr/issues/new?body=module:%20hr_attendance_report_theoretical_time%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -507,7 +507,7 @@ <h2><a class="toc-backref" href="#id10">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/12.0/hr_attendance_report_theoretical_time">OCA/hr</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr/tree/13.0/hr_attendance_report_theoretical_time">OCA/hr</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_theoretical_hours(self):
# 1946-12-25 - Global public holiday
self.assertEqual(self.attendances[4].theoretical_hours, 0)
self.assertEqual(self.attendances[5].theoretical_hours, 0)
# 1946-12-26
# 1946-12-26 - Employee on Holidays
self.assertEqual(self.attendances[6].theoretical_hours, 0)
self.assertEqual(self.attendances[7].theoretical_hours, 0)
# EMPLOYEE 2
Expand Down Expand Up @@ -196,7 +196,12 @@ def test_hr_attendance_read_group(self):
("date", "<", "1946-12-31"),
("employee_id", "in", (self.employee_1.id, self.employee_2.id)),
],
["employee_id", "theoretical_hours", "worked_hours", "difference"],
[
"employee_id",
"theoretical_hours:sum",
"worked_hours:sum",
"difference:sum",
],
["employee_id"],
)
# It should include 4 working days (25 is holiday and 26 is leave)
Expand All @@ -214,7 +219,7 @@ def test_hr_attendance_read_group(self):
("date", "<", "1946-12-31"),
("employee_id", "=", self.employee_1.id),
],
["employee_id", "theoretical_hours", "date"],
["employee_id", "theoretical_hours:sum", "date"],
["date:day"],
)
self.assertEqual(res[0]["theoretical_hours"], 8) # 1946-12-23
Expand Down
25 changes: 13 additions & 12 deletions hr_attendance_report_theoretical_time/views/hr_employee_views.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<act_window
id="recompute_employee_theoretical_attendance"
name="Recompute Theoretical Attendance"
binding_model="hr.employee"
res_model="recompute.theoretical.attendance"
view_mode="form"
context="{'default_employee_ids': active_ids, 'employee_ids': active_ids}"
target="new"
groups="hr_attendance.group_hr_attendance_manager"
/>

<record id="view_employee_form_inherit_hr_attendance" model="ir.ui.view">
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr_attendance.view_employee_form_inherit_hr_attendance"/>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name="manual_attendance" position="after">
<field name="pin" position="before">
<field name="theoretical_hours_start_date"/>
</field>
</field>
</record>

<act_window id="recompute_employee_theoretical_attendance"
name="Recompute Theoretical Attendance"
src_model="hr.employee"
res_model="recompute.theoretical.attendance"
context="{'default_employee_ids': active_ids, 'employee_ids': active_ids}"
view_type="form" view_mode="form"
key2="client_action_multi" target="new"
groups="hr_attendance.group_hr_attendance_manager"/>

</odoo>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import fields, models


class RecomputeTheoreticalAttendance(models.TransientModel):
Expand All @@ -20,7 +20,6 @@ class RecomputeTheoreticalAttendance(models.TransientModel):
string="To", required=True, help="Recompute attendances up to this date"
)

@api.multi
def action_recompute(self):
self.ensure_one()
attendances = self.env["hr.attendance"].search(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<record id="act_wizard_recompute_theoretical_attendance" model="ir.actions.act_window">
<field name="name">Recompute Theoretical Attendances</field>
<field name="res_model">recompute.theoretical.attendance</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def _prepare_employee_domain(self):
res.append(("department_id", "child_of", self.department_id.id))
return res

@api.multi
def populate(self):
domain = self._prepare_employee_domain()
self.employee_ids = self.env["hr.employee"].search(domain)
Expand All @@ -44,7 +43,6 @@ def populate(self):
}
return action

@api.multi
def view_report(self):
self.ensure_one()
action = {
Expand Down
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hr-holidays

0 comments on commit 098aed8

Please sign in to comment.