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

10.0 public holidays next year #291

Merged
merged 10 commits into from
Feb 28, 2017

Conversation

jcdrubay
Copy link

@jcdrubay jcdrubay commented Nov 4, 2016

Allow the creation of public holidays for next year through a wizard.

Minor odoolint fixes

Note: Recent merged PR#290 has been taken into account.

@oca-clabot
Copy link

Hey @jcdrubay, thank you for your Pull Request.

It looks like some users haven't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement here: http://odoo-community.org/page/website.cla
Here is a list of the users:

Appreciation of efforts,
OCA CLAbot

Copy link

@LeartS LeartS left a comment

Choose a reason for hiding this comment

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

I think it would be useful to let the user select which hr.public.holiday to replicate, defaulting to the most recent one for each country as it is now; and also let the user choose the year (defaulting to the next).
For example if 2016 was a special year with an additional public holiday for the 150th anniversary of the Italian unification, I'd want to replicate the 2015 Italian holidays to 2017.

<field name="model">public.holidays.next.year.wizard</field>
<field name="arch" type="xml">
<form string="Create Next Year Public Holidays">
<footer>
Copy link

Choose a reason for hiding this comment

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

I would add a little description here that briefly explains what the wizard does. The empty wizard looks, well, empty

def create_next_year_public_holidays(self):

ph_env = self.env['hr.holidays.public']
pholidays = ph_env.search([])
Copy link

Choose a reason for hiding this comment

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

why not directly pholidays = self.env['hr.holidays.public'].search([]), as you never use ph_env again?

Copy link
Author

@jcdrubay jcdrubay Nov 7, 2016

Choose a reason for hiding this comment

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

Mainly because of an habit.
But in next commit, it will make it easier to use later if necessary. In the next commit, it will also simplify a bit to avoid code on 2 lines for this:

        ph_env = self.env['hr.holidays.public']
        pholidays = self.template_ids or ph_env.search([])

Also, I think it will mean less changes if we need to re-use it later on.

If required, I can change, let me know.

last_ph_dict = {}
for ph in pholidays:

curr_country = ph.country_id and ph.country_id.id or NO_COUNTRY
Copy link

Choose a reason for hiding this comment

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

idiomatic python: curr_country = ph.country_id.id if ph.country_id else NO_COUNTRY
But you could even put directly the country recordset as the dict keys and skip the check altoghether. This is possible because recordset implements the hash method.
last_ph_country = last_ph_dict.get(ph.country_id, False)

Copy link
Author

Choose a reason for hiding this comment

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

Nice trick! :)


NO_COUNTRY = 'NO_COUNTRY'
last_ph_dict = {}
for ph in pholidays:
Copy link

@LeartS LeartS Nov 6, 2016

Choose a reason for hiding this comment

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

Maybe a warning/error if no holidays defined?

for last_ph_line in last_ph.line_ids:

ph_line_date = fields.Date.from_string(last_ph_line.date)
new_date = ph_line_date.replace(ph_line_date.year + 1)
Copy link

Choose a reason for hiding this comment

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

Very rare to have a public holiday in that day, but if the date is February 29 of a leap year, you'll get ValueError: day is out of range for month when doing this

Copy link
Author

Choose a reason for hiding this comment

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

Three cases this year.
image

Source: http://www.qppstudio.net/monthlyholidays/bank-holidays-february-2016.htm

Handling this rare case will mean quite a lot of complexity because previous or next day might also be a public holiday.

I suggest to block the user with a UserError: "You cannot use a the template of a year that includes public holidays on 29th of February (2016, 2020...), please select a template from another year.". Since I take into account your first comment, the users will be able to select the public holidays from 2015 instead for 2017; I guess it is good enough.

@jcdrubay
Copy link
Author

jcdrubay commented Nov 7, 2016

Thanks @LeartS for your great feedback. I tried to take them into account in the best way. I am a bit scared so about the template and year field on the wizard as they create a lot of complexity for the users. I tried to make it clear on the wizard page with some documentation...

Please let me know if you have any additional suggestion.

<form string="Create Next Year Public Holidays">
<sheet>
<div>
Use this wizard to create pulic holidays based on the
Copy link

Choose a reason for hiding this comment

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

s/pulic/public

<group string="Optional">
<div colspan="2">
The below optional fields are here only to handle
special situtaions like "2016 was a special year with
Copy link

Choose a reason for hiding this comment

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

  • s/situtaions/situations
  • (The 150th anniversary of Italian unification was actually in 2011, I used 2016 in my example just to make it more current 😁 )
  • I would put this group under the first one instead of next to it, it looks clumsy:
    screenshot from 2016-11-07 10-04-54
    Or we could even maybe put the two groups in two notebook pages so that the Optional section is "hidden" unless one explicitly clicks on it; while the "Defaults" explanation is immediately displayed. This could make the wizard look simpler and not overload the user with options/fields, what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I like your notebook idea 👍

@feketemihai feketemihai added this to the 10.0 milestone Feb 23, 2017
@feketemihai
Copy link
Member

@jcdrubay Thanks for the contribution, good module...

@jcdrubay
Copy link
Author

Yeah! 3 approvals reached 🎉 Thank you everyone 👍

@feketemihai feketemihai merged commit cd26253 into OCA:10.0 Feb 28, 2017
leemannd pushed a commit to leemannd/hr that referenced this pull request Jun 12, 2017
* [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
@oca-clabot
Copy link

Hey @jcdrubay,
We acknowledge that the following users have signed our Contributor License Agreement:

Appreciation of efforts,
OCA CLAbot

hieulucky111 pushed a commit to hieulucky111/hr that referenced this pull request Oct 12, 2017
* [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
hieulucky111 pushed a commit to hieulucky111/hr that referenced this pull request Oct 12, 2017
* [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
hieulucky111 pushed a commit to hieulucky111/hr that referenced this pull request Oct 12, 2017
* [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
feketemihai pushed a commit to feketemihai/hr that referenced this pull request Nov 12, 2017
* [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
feketemihai pushed a commit to feketemihai/hr that referenced this pull request Nov 14, 2017
* [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
feketemihai pushed a commit to feketemihai/hr that referenced this pull request Nov 16, 2017
* [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
feketemihai pushed a commit to feketemihai/hr that referenced this pull request Mar 21, 2018
* [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
sambarros pushed a commit to sambarros/hr that referenced this pull request Jul 26, 2018
…_account2

[BSSFL-410] Update product account
pedrobaeza pushed a commit to ForgeFlow/hr that referenced this pull request Sep 2, 2018
* [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
Trivedi-Vacha-SerpentCS pushed a commit to Trivedi-Vacha-SerpentCS/hr that referenced this pull request Sep 28, 2018
* [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
i-vyshnevska pushed a commit to i-vyshnevska/hr that referenced this pull request Mar 5, 2019
* [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
i-vyshnevska pushed a commit to i-vyshnevska/hr that referenced this pull request Mar 12, 2019
* [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
quentingigon pushed a commit to quentingigon/hr that referenced this pull request Oct 11, 2019
* [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
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