Skip to content

[9.0] [backporting] hr_holidays_hour#1

Open
vvrossem wants to merge 13 commits intocoopiteasy:9.0from
vvrossem:9.0-backporting-hr_holidays_hour
Open

[9.0] [backporting] hr_holidays_hour#1
vvrossem wants to merge 13 commits intocoopiteasy:9.0from
vvrossem:9.0-backporting-hr_holidays_hour

Conversation

@vvrossem
Copy link

@vvrossem vvrossem commented Dec 5, 2019

From 10.0

update 09/12/19

I could not override the constraints defined in the old API (hr_holidays : _constraints list). The workaround I am using is to redefine the methods first in old API, then in new API.

Copy link
Member

@robinkeunen robinkeunen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's heavy stuiff, good work on this one. I mainly asked questions or commented on style (discard if you don't agree).

A lundi!

Comment on lines +24 to +28
mapping = dict(
[
(leave["employee_id"][0], leave["number_of_hours"])
for leave in leaves
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write this as a dict comprehension:

mapping = {
    leave["employee_id"][0]: leave["number_of_hours"]
    for leave in leaves
}


@api.onchange("employee_id")
def onchange_employee(self):
# Get result of original onchange_employee from parent class:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When code is readable, no need for comments :-)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +73 to +77
# Workaround for api incompatibility:
if type(res) is dict and res.has_key("value"):
for field, value in res.get("value").items():
if hasattr(self, field):
setattr(self, field, value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta-programming sorcery


self._check_dates()
self._check_employee()
self._set_number_of_hours_temp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's ok to use a multi method from an onchange method. The database cursor will be rolled back (I think)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed onchange don't persist data. not sure it still apply on 12 though.

Comment on lines +181 to +189
working_hours = []
if employee.calendar_id:
working_hours.append(employee.calendar_id)
else:
contracts = employee.sudo().contract_ids
for contract in contracts:
if contract.working_hours:
working_hours.append(contract.working_hours)
return working_hours
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good pythonista is a loop killer. Declarative style is more readable and less bug prone. Also, you don't need to declare the variable upfront here. I'd write:

if employee.calendar_id:
    working_hours = [employee.calendar_id]
else:
    working_hours = [contract.working_hours for contract in contracts if contract.working_hours]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


@api.multi
def name_get(self):
res = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incoming loop killer

Comment on lines +16 to +21
result = {
"max_hours": 0,
"remaining_hours": 0,
"hours_taken": 0,
"virtual_remaining_hours": 0,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use variables in the code and build the dictionary at the end of the method.

Comment on lines +55 to +64
status.hours_taken = 0
status.remaining_hours = 0
status.max_hours = 0
status.virtual_remaining_hours = 0
if employee:
res = status.get_hours(employee)
status.hours_taken = res["hours_taken"]
status.remaining_hours = res["remaining_hours"]
status.max_hours = res["max_hours"]
status.virtual_remaining_hours = res["virtual_remaining_hours"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd write

if employee:
    hours = status.get_hours(employee)
    status.hours_taken = hours["hours_taken"]
    status.remaining_hours = hours["remaining_hours"]
    status.max_hours = hours["max_hours"]
    status.virtual_remaining_hours = hours["virtual_remaining_hours"]
else: 
    status.hours_taken = 0
    status.remaining_hours = 0
    status.max_hours = 0
    status.virtual_remaining_hours = 0

# Computes start_dt, end_dt (with default values if not set)
# + off-interval work limits

def set_work_limits_start(end_dt, start_dt):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this function :/

@robinkeunen
Copy link
Member

@vvrossem Also, try keeping the ci green :-)

remytms pushed a commit that referenced this pull request Jan 4, 2023
remytms pushed a commit that referenced this pull request Jan 4, 2023
huguesdk pushed a commit that referenced this pull request Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants