Skip to content

[19.0][MIG] hr_attendance#5705

Open
hbrunn wants to merge 4 commits into
OCA:19.0from
hbrunn:19.0-hr_attendance
Open

[19.0][MIG] hr_attendance#5705
hbrunn wants to merge 4 commits into
OCA:19.0from
hbrunn:19.0-hr_attendance

Conversation

@hbrunn

@hbrunn hbrunn commented Jun 9, 2026

Copy link
Copy Markdown
Member

No description provided.

@hbrunn hbrunn added this to the 19.0 milestone Jun 9, 2026
@hbrunn

hbrunn commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

/ocabot migration hr_attendance

Depends on :

@legalsylvain

This comment was marked as duplicate.

@hbrunn

This comment was marked as off-topic.

@legalsylvain

This comment was marked as off-topic.

@hbrunn

This comment was marked as off-topic.

@legalsylvain

This comment was marked as off-topic.

@hbrunn

This comment was marked as off-topic.

@legalsylvain

This comment was marked as off-topic.

@hbrunn

hbrunn commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

@legalsylvain done in #5745, now setting our whole discussion as off-topic

@legalsylvain

Copy link
Copy Markdown
Contributor

@legalsylvain done in #5745, now setting our whole discussion as off-topic

thanks a lot for this Job. I manually run the script a last time for the V19. new 19 PR should be handled by your script.

---Models in module 'hr_attendance'---
obsolete model hr.attendance.overtime (renamed to hr.attendance.overtime.line)
new model hr.attendance.overtime.line (renamed from hr.attendance.overtime)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why adding these empty lines that makes the reading harder? I think the comment should be together with the analysis lines block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

well I think the empty lines improve readability. If that's so important to you, add it to https://oca.github.io/OpenUpgrade/090_contribute.html#how-to-contribute-new-migration-scripts and I'll bulk update the whole branch, as I've been doing this for a long time


# NOTHING TO DO

hr_attendance / hr.attendance / in_location (char) : NEW

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reorganize this line into in_city DEL comment for seeing both together and to understand the change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hard disagree about reordering lines in the work file. I want to be able to say diff upgrade_analysis* to easily verify all lines from the generated file are in the work file (=only whitespace or comments in the diff)

# date is required in v19, fill with create_date if empty, possibly wrong
env.cr.execute(
f"""
UPDATE hr_attendance_overtime_line SET date=(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not get it the same from the nearest attendance record?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

how do you propose to find the nearest record? create_date? that's just as prone to filling in a wrong date here.

I consider overtime lines without date garbage data which people should clean up, and do the update only to satisfy the non-null constraint

SQL_EMPLOYEE2TZ = """
(
SELECT
hr_employee.id employee_id,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find you new SQL style a bit difficult to read, and very vertical scroll intensive. Either indent the lines after the command (SELECT, FROM, etc), or put them in the same line as always.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not so new, but indeed was lacking indentation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on the link, this formatting does not follow the recommended style https://docs.telemetry.mozilla.org/concepts/sql_style.html#join-conditions
Image

Suggested change
hr_employee.id employee_id,
FROM
hr_employee
JOIN
resource_resource
ON hr_employee.resource_id=resource_resource.id
LEFT JOIN
resource_calendar
ON resource_resource.calendar_id=resource_calendar.id
JOIN
res_company
ON hr_employee.company_id=res_company.id
LEFT JOIN
resource_calendar company_resource_calendar
ON res_company.resource_calendar_id=company_resource_calendar.id

WHERE
hr_attendance.employee_id=hr_attendance_overtime_line.employee_id
AND
hr_attendance.date=hr_attendance_overtime_line.date

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This part may not fit according current code, and even more, we may have more than one record for the same date.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

which code do you mean? and indeed this can lead to updating the same record multiple times, but how does this matter?

Comment thread openupgrade_scripts/scripts/hr_attendance/19.0.2.0/pre-migration.py Outdated
@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels Jun 30, 2026

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TT58628

SQL_EMPLOYEE2TZ = """
(
SELECT
hr_employee.id employee_id,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on the link, this formatting does not follow the recommended style https://docs.telemetry.mozilla.org/concepts/sql_style.html#join-conditions
Image

Suggested change
hr_employee.id employee_id,
FROM
hr_employee
JOIN
resource_resource
ON hr_employee.resource_id=resource_resource.id
LEFT JOIN
resource_calendar
ON resource_resource.calendar_id=resource_calendar.id
JOIN
res_company
ON hr_employee.company_id=res_company.id
LEFT JOIN
resource_calendar company_resource_calendar
ON res_company.resource_calendar_id=company_resource_calendar.id

Comment thread openupgrade_scripts/scripts/hr_attendance/19.0.2.0/pre-migration.py Outdated
Comment on lines +44 to +67
default_rule.employer_tolerance = main_company.overtime_company_threshold / 60.0
default_rule.employee_tolerance = main_company.overtime_employee_threshold / 60.0
for company in env["res.company"].search([]):
rule = default_rule
if (
default_rule.employer_tolerance != company.overtime_company_threshold
or default_rule.employee_tolerance != company.overtime_employee_threshold
):
rule = default_rule.copy(
{
"employer_tolerance": company.overtime_company_threshold / 60.0,
"employee_tolerance": company.overtime_employee_threshold / 60.0,
"ruleset_id": default_rule.ruleset_id.copy(
{
"company_id": company.id,
"rule_ids": [
Command.link(other_rule.copy().id)
for other_rule in default_rule.ruleset_id.rule_ids
if other_rule != default_rule
],
}
).id,
}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't agree with this logic.

Why are you setting the fields on the default rule and then copying that rule to every company?

I don't think the fields should be set on the default rule.

If the default rule does not have a company_id set, why should it take the values from the main company?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this results in the default rule without company applying to all companies that have the same settings as the main company, which probably is the most common case. you only get specific rules for companies that have different settings than the main company.

what would your alternative do?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this results in the default rule without company applying to all companies that have the same settings as the main company, which probably is the most common case. you only get specific rules for companies that have different settings than the main company.

what would your alternative do?

Option 1: If you create or duplicate the rule for the main_company, then don't set these fields on the default rule. Otherwise, we assume that the values from the main company are the same for all other companies. In other words, don't modify the default rule; instead, create a new rule for each company that has these fields set.

Option 2: If the default rule without a company_id is intended to preserve the field values from the main_company, then don't create or duplicate another rule for the main_company.

Example:

My Company has these fields set.
C2 has these fields set, but with values different from My Company.
C3 does not have these fields set.

With Option 1, I would expect the following:

Don't modify the default rule, so it can be used by C3.
Don't create a rule for C3, because the default rule is shared.
Create a dedicated rule for My Company and C2, with the specific values configured for each company.

What I see as incorrect behavior:

A rule is created for C3, even though this company does not have these fields set.
The default rule receives the same values as My Company, but another rule is also created for My Company. Instead, it should use the default rule rather than creating a new one.

image

I prefer Option 1. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i believe i implemented option 2, and i think that's the good one. would expect no new rule for main company in your example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i believe i implemented option 2, and i think that's the good one. would expect no new rule for main company in your example

OK, if you want to use Option 2, that's fine. However, in this case a new rule is still created for My Company. Please check my screenshot; this is a database migrated from v18.

The rule is created because, in the if statement, you compare values that have been divided by 60 when assigned to the default rule, while the values on the company fields are not divided by 60. As a result, they are never equal, and the code always enters the block that copies the rule.

default_rule.employer_tolerance != company.overtime_company_threshold

It should be:

default_rule.employer_tolerance != (company.overtime_company_threshold / 60.0)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks, your code would never create a new rule though. I think d698ab8 gets it right

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, but after testing the latest changes, I'm not convinced by the results.

Following my example:

  • My Company has these fields set.
  • C2 has these fields set, but with values different from My Company.
  • C3 does not have these fields set.

Currently, a new rule is created for C3, but I would expect no rule to be created for this company.

The default rule (without company_id set) takes the values from main_company, but this rule is shared. As a result, other companies inherit values from main_company incorrectly.

I made these changes locally, and the behavior is correct according to my expectations:

  • No rule is created for C3.
  • An explicit rule is created for every company that has these fields set.
  • The default rule remains untouched.

I think this behavior is more correct because the default rule remains shared and is used by companies that do not have specific values configured, while companies with customized values get their own dedicated rules.

Image Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

well, I disagree this is the most natural expectation. I think we should treat everything that's different from the main company the exception, and whatever the main company does should be the default for new companies

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, while another person can review this and decide whether the values configured on main_company can be used by other companies.

Please avoid creating rules for companies that do not have these fields set, because the default rule without a company_id should be used instead.

In my example, no rule should be created for C3.

Could you apply this change?
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we need this rule because otherwise the default one will be active. remember the goal here is to get v19 to behave in a similar way it was in v18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants