Skip to content

Commit

Permalink
[IMP] resource_calendar_get_days: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 authored and xaviedoanhduy committed Aug 22, 2024
1 parent 6e973aa commit 26f2526
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions resource_calendar_get_days/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Calculate number of leave days relative to company working hours.
""",
"author": "Mint System GmbH, Odoo Community Association (OCA)",
"website": "https://www.mint-system.ch",
"website": "https://github.com/OCA/hr-holidays",
"category": "Human Resources",
"version": "14.0.2.0.0",
"license": "AGPL-3",
"demo": ["demo/resource_data.xml"],
"demo": ["demo/resource_data.xml"],
"depends": ["hr_holidays"],
"installable": True,
"application": False,
Expand Down
12 changes: 7 additions & 5 deletions resource_calendar_get_days/demo/resource_data.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="resource_calendar_std_42h" model="resource.calendar">
<field name="name">Standard 42 hours/week</field>
<field name="company_id" ref="base.main_company"/>
<field name="company_id" ref="base.main_company" />
<field name="hours_per_day">8.4</field>
<field name="attendance_ids"
<field
name="attendance_ids"
eval="[(5, 0, 0),
(0, 0, {'name': 'Monday Morning', 'dayofweek': '0', 'hour_from': 7.5, 'hour_to': 11.75, 'day_period': 'morning'}),
(0, 0, {'name': 'Monday Afternoon', 'dayofweek': '0', 'hour_from': 13.33333, 'hour_to': 17.66666, 'day_period': 'afternoon'}),
Expand All @@ -23,9 +24,10 @@

<record id="resource_calendar_std_25_2h" model="resource.calendar">
<field name="name">Standard 25.2 hours/week</field>
<field name="company_id" ref="base.main_company"/>
<field name="company_id" ref="base.main_company" />
<field name="hours_per_day">5.04</field>
<field name="attendance_ids"
<field
name="attendance_ids"
eval="[(5, 0, 0),
(0, 0, {'name': 'Tuesday Morning', 'dayofweek': '1', 'hour_from': 7, 'hour_to': 11.7, 'day_period': 'morning'}),
(0, 0, {'name': 'Wednesday Morning', 'dayofweek': '2', 'hour_from': 10.5, 'hour_to': 12, 'day_period': 'morning'}),
Expand Down
2 changes: 1 addition & 1 deletion resource_calendar_get_days/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import resource_calendar
from . import hr_leave_allocation
from . import hr_leave_allocation
13 changes: 8 additions & 5 deletions resource_calendar_get_days/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from odoo import api, fields, models, _
from odoo import api, models


class HolidaysAllocation(models.Model):
_inherit = 'hr.leave.allocation'
_inherit = "hr.leave.allocation"

@api.depends('number_of_days', 'employee_id')
@api.depends("number_of_days", "employee_id")
def _compute_number_of_hours_display(self):
for allocation in self:
if allocation.number_of_days:
allocation.number_of_hours_display = allocation.number_of_days * allocation.employee_id.sudo().resource_id.calendar_id.hours_per_day
allocation.number_of_hours_display = (
allocation.number_of_days
* allocation.employee_id.sudo().resource_id.calendar_id.hours_per_day
)
else:
allocation.number_of_hours_display = 0.0
allocation.number_of_hours_display = 0.0
18 changes: 12 additions & 6 deletions resource_calendar_get_days/models/resource_calendar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from odoo import models
from collections import defaultdict

from odoo import models
from odoo.tools import float_utils

HOURS_PER_DAY = 8
Expand All @@ -16,14 +17,19 @@ def _get_days_data(self, intervals, day_total):
day_hours = defaultdict(float)
for start, stop, meta in intervals:
day_hours[start.date()] += (stop - start).total_seconds() / 3600

# compute number of days as quarters
hours_per_day = self.company_id.resource_calendar_id.hours_per_day
days = sum(
float_utils.round(ROUNDING_FACTOR * day_hours[day] / hours_per_day or day_total[day]) / ROUNDING_FACTOR if day_total[day] else 0
float_utils.round(
ROUNDING_FACTOR * day_hours[day] / hours_per_day or day_total[day]
)
/ ROUNDING_FACTOR
if day_total[day]
else 0
for day in day_hours
)
return {
'days': days,
'hours': sum(day_hours.values()),
}
"days": days,
"hours": sum(day_hours.values()),
}
3 changes: 3 additions & 0 deletions resource_calendar_get_days/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"

0 comments on commit 26f2526

Please sign in to comment.