Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][MIG] hr_public_holidays > hr_holidays_public #465

Merged
merged 26 commits into from
Sep 4, 2018

Conversation

MiquelRForgeFlow
Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow commented Jul 10, 2018

Superseeds #401.

cc @Tecnativa

@MiquelRForgeFlow
Copy link
Contributor Author

Hey everybody! something on Odoo changed that makes a test fail. Previously was all green some months ago in the commit of @feketemihai . My changes didn't affect the tests but the PR is red. I can't find what's the cause or what's wrong, so please, can someone help to fix this?

sambarros pushed a commit to sambarros/hr that referenced this pull request Jul 26, 2018
[BSSFL-556] Propagate lot from sale line to 3 delivery steps
Copy link
Member

@astirpe astirpe left a comment

Choose a reason for hiding this comment

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

Thank you for this PR! Please check my comments for the code review.

I personally would prefer a pure porting of this module from https://github.com/OCA/hr/tree/10.0/hr_public_holidays to V11, without adding so much other stuff. The module version =< 10 was meant to be a technical module, useful for being extended for further customization. But with the latest PRs this module is becoming something else.

The calculation of the hours should be delegated to a specific module hr_holidays_hour, which migration to V11 is proposed here: #450.

Odoo V12 will have the code for the leave management almost completely rewritten, supporting also the hours calculation, so do we really want to spend so much effort to rewrite the hours management in this module, with the risk to restart all over in V12 (will be released next October 😮 )?

Anyway I will not block this PR if you have different needs, just think about it.

from datetime import date

from odoo import api, fields, models, _
from odoo.exceptions import Warning as UserError
Copy link
Member

Choose a reason for hiding this comment

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

Just use:
from odoo.exceptions import UserError

import logging

from odoo import api, models, fields, _
from odoo.exceptions import Warning as UserError
Copy link
Member

Choose a reason for hiding this comment

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

from odoo.exceptions import UserError

# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import ValidationError
from odoo.exceptions import Warning as UserError
Copy link
Member

Choose a reason for hiding this comment

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

from odoo.exceptions import UserError, ValidationError

<field name="model">hr.holidays.public</field>
<field name="arch" type="xml">
<tree string="Public Holidays">
<field name="year"/>
Copy link
Member

Choose a reason for hiding this comment

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

Could you replace <field name="year"/> with <field name="display_name"/> here?


<notebook>
<page name="defaults" string="Defaults">
<div>

This comment was marked as resolved.

show_full_days = fields.Boolean(
string="Show Full Days",
related="holiday_status_id.compute_full_days")
number_of_hours_temp = fields.Float(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this module inherit from hr_holidays_hour? The module hr_holidays_hour already defines those fields for managing the hours. There would be an overall simplification of code by inheriting from hr_holidays_hour, for example you could take advantage of methods for the conversion to hours, the onchanges and the views.

Migration of hr_holidays_hour to V11 is proposed here: #450.

Copy link
Contributor Author

@MiquelRForgeFlow MiquelRForgeFlow Aug 3, 2018

Choose a reason for hiding this comment

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

Ok, I will wait then until that module is merged.

Copy link
Member

Choose a reason for hiding this comment

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

@astirpe I have been reviewing the module hr_holidays_hour and the dependency should be just the contrary: to add public holidays, we don't need to make the computation by hours first, but to adjust current Odoo core methods for obtaining the days in float. The hour one should go on top of this. I'm reviewing right now this one and proceed to merge for unlocking this, but I'm available to review any adjustment you need to make over this one for correctly pasting both together. I hope you understand.

@pedrobaeza pedrobaeza added this to the 11.0 milestone Aug 7, 2018
@pedrobaeza pedrobaeza mentioned this pull request Aug 7, 2018
71 tasks
@pedrobaeza pedrobaeza changed the title [11.0][MIG] hr_public_holidays [11.0][MIG] hr_public_holidays > hr_holidays_public Sep 2, 2018
@pedrobaeza pedrobaeza force-pushed the 11.0-mig-hr_public_holidays branch 2 times, most recently from 9d3b5bf to 4b61577 Compare September 2, 2018 18:16
miketelahun and others added 14 commits September 2, 2018 20:19
[MIG] hr_public_holidays
[MIG] hr_public_holidays/hr_holidays_compute_days: port to 10.0
* [ADD] public holidays: add a wizard to create public holidays for the following year

* [REF] odoolint improvements

* [REF] adjustments for flake8 and pylint test

* Move public holidays menu under Leaves menu. (OCA#290)

* [ADJ] hr_public_holidays: take into account the need of several sub-menus

* [ADD] Allow the creation of public holidays from a specific template for a specific year, and display a UserError for templates including February 29th.

* [REF] removing useless comments

* [ADJ] hr_public_holidays: Improving wizard display

* [REF] Removing tab characters
* hr_public_holidays: use group 'hr_holidays.group_hr_holidays_manager'

* hr_public_holidays: Update README.rst
Add correct calculation of holidays in hr_public_holidays, instead of hr_holidays_compute_days.

Remove dependancy of contracts.

Add unlink at onchnage of public holiday lines.

Update code.

Fix flake.

Update code, add calculation in hours, update views.

Update flake.

Update calendar creation with no attendances, otherwise default values were set.

Remove config of show days/hours.

Update flake.

Update readme.

Rename module.

Updated holiday reports.

Update klake and pylint.

Update flaket.

Update hr_holidays_views.xml

Add readonly to show_full_days.

Update code according with comments.

Increase coverage.

update flake8.
@pedrobaeza
Copy link
Member

After been thinking about this a lot, this is the best option I have found:

  • Leave hr_holidays_public with the public holidays definition, the exclude_public_holidays field in leave types, and the computation of the days intervals according this definition. This will be transparent for other modules not depending on this one, as the working intervals won't have public holidays and they are able to handle this interval days the way they want.
  • Rescue hr_holidays_compute_days module for adding day selection helpers (full day selectors for example) and exclude_rest_days and compute_full_days options on leave types, touching the working days computation the way it's done right now in this PR (although avoiding full method overriding).
  • hr_holidays_hour can plug together with this in 2 ways:
    • Putting a hook in this second module and depending of it for not repeating computations.
    • Being totally isolated, but repeating some of the computations.

I'm implementing this tomorrow. What do you think?

@astirpe
Copy link
Member

astirpe commented Sep 3, 2018

@pedrobaeza I would prefer to keep hr_holidays_hour independent from other modules, since the idea is to keep it as a technical module that replaces the days with hours. I understand that we prefer to avoid repetition of code, but in this case I don't see any real benefit in doing that.

@pedrobaeza
Copy link
Member

OK, no problem, as stated, you can do it repeating some of the code. Just take a look for not screwing up inheritance for allowing the installation of the 3 of them.

@pedrobaeza
Copy link
Member

@mreficent I'm doing the other changes, but thanks for the lint fixup.

MiquelRForgeFlow and others added 10 commits September 3, 2018 21:12
Hours part will be in module hr_holidays_hour.
* Squash commits into a single one.

* Update tests with old onchange methods.

* Fix variable name in tests..

* Update tests.

* Update flake8.

* Update security rules so that employee can read his schedule and contract, and hr manager to have the same rigths as defined in hr_contract.

* Improve onchange employee, add tests for onchange.

* Fix flake, whitespaces.
[MIG] hr_public_holidays/hr_holidays_compute_days: port to 10.0
the name collision between _compute_number_of_days defined in this addon
and the method for the field number_of_days computation in the base addon hr_holidays
caused the latter to not be called => the field number_of_days would be 0 for
holidays allocation, and have the wrong sign for holidays request (because it was
forced in the the reimplemented version.

This patch:
* adds tests for the expected value of number_of_days
* adds a test for the behavior of the method for holidays allocation
* renames the method _compute_number_of_days to _recompute_number_of_days
* To not depend on hr_contract. Working times are set also in employee,
  and v11 rely on this data, not in contract working time. This simplifies
  also the code.
* To not include all the checks while selecting start or end leave date.
  At the end, it's the same for you: what counts is the number of leave
  days. As the compute algorithm already handles overlapping leaves,
  rest days and public holidays, there's no problem with this.
* It handles fraction of days!! New algorithm put the part of the working
  day that you are leaving. There's a new option at leave type level
  for keeping the behavior of including full days. This option is checked
  by default also for keeping backwards compatibility. This code has been
  made similar to v11.
* It includes UI helps for being better to select dates in the form view,
  allowing to select only dates instead of date + time.
* The number of days is not manually modifiable by leave users, but to
  leave managers. If this behavior is not desirable, you can manually
  add other groups to the view, as this won't be overwritten with module
  update.
@pedrobaeza
Copy link
Member

I have finished the adaptation, reducing the code to the minimal and decoupling all modules from each other. I think it has been a good job 😃

For handling module renaming in OpenUpgrade, there's OCA/OpenUpgrade#1509

Copy link
Member

@astirpe astirpe left a comment

Choose a reason for hiding this comment

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

Review of module hr_holidays_public only

<form string="Public Holidays">
<group>
<field name="year"/>
<field name="country_id"/>
Copy link
Member

Choose a reason for hiding this comment

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

We already have a module that extends this one. Would be nice if you write this block this way (to ease the extensions):

                <group>
                    <group name="name">
                        <field name="year"/>
                        <field name="country_id"/>
                    </group>
                    <group name="extra">
                    </group>
                </group>


<odoo>

<record id="holidays_public_next_year_wizard_view" model="ir.ui.view">
Copy link
Member

Choose a reason for hiding this comment

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

Could you indent the records more to the right, making this xml consistent with the other views?

'state_id',
'Related States'
)
calendar_leave_id = fields.Many2one(
Copy link
Member

Choose a reason for hiding this comment

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

Why this field was added?

Copy link
Member

Choose a reason for hiding this comment

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

No idea...

)
else:
obj = self
return super(HrHolidays, obj,)._get_number_of_days(
Copy link
Member

Choose a reason for hiding this comment

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

Could you remove the trailing comma after obj?

@pedrobaeza
Copy link
Member

Hehe, you have just reviewed the untouched part. Checking the comments...

Reduce to the minimum the footprint of this module, adding only public
holidays as leaves in a transparent way by other modules.
This has been totally reworked for decoupling parts, not depending now
on hr_holidays_public, and making transparent its use for compatibility
with other modules.
@pedrobaeza
Copy link
Member

Changes done

@astirpe
Copy link
Member

astirpe commented Sep 4, 2018

Thanks!

We are not using hr_holidays_compute_days, so I think is better to let someone else (more interested) doing the functional review. I could do a code review later when I will have more time.

Module hr_holidays_public 👍

@pedrobaeza
Copy link
Member

I think we are going to move forward, and if any problem, we can fill new PRs. This is done for not interfering with your module, so I don't think you will find troubles.

@pedrobaeza pedrobaeza merged commit adac20a into OCA:11.0 Sep 4, 2018
@MiquelRForgeFlow MiquelRForgeFlow deleted the 11.0-mig-hr_public_holidays branch September 4, 2018 09:57
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.

None yet