de580315890a47eca19cc02084b6be7f2e8e5973
Followup to odoo/odoo#65314: turns out there's a bunch of other leave requests in the file which will eventually fall on a weekend, and will probably blow up due to the new validation in 14.0: - hr_holidays_sl_al in March 2021 because April 17th, 2021 is a saturday - hr_holidays_cl_mit_2 in June 2021 because June 5th, 2021 is a saturday - hr_holidays_sl_vad in September 2021 because September 25th, 2021 is a saturday - hr_holidays_sl_kim in April 2021 because May 1st, 2021 is a saturday - hr_holidays_sl_kim_2 in March 2021 because July 3rd, 2021 is a saturday Solution ======== Instead of hard-coding month-days, move to the first monday after the original date e.g. if we were looking for the 20, now get the monday after the 22. In relativedelta terms, `weekday=0` is "the next monday". The date is then formatted inclusive of the month-day rather than hard-coding one. One nit is for the end date:"the next wednesday" may come before "the next monday" if we're on TU or WE. So we need to first jump to the next MO *then* to the WE after that, which makes the code a bit longer (and more redundant). As a result the end date is now "the wednesday after <the start date>" rather than being a literal 2 days later or whatever. The PR updates all the 1-day and 2-day intervals, it also updates the 3 days inclusive (those over 3 which include start and end dates rather than without) including those updated by #65314 for clarity / coherence of small intervals. Longer intervals are left untouched, although we may eventually want to update them so `number_of_days` computations are more reliable. Redundancy issues ----------------- There are a bunch of redundancies / verbosities which don't seem easy or possible to remove: * While lxml does resolve entities by default it doesn't load DTDs (let alone validate them), aliasing various datetimes & deltas as entities is not an option, not to mention for security reasons we'd rather stop resolving entities entirely than allow custom ones. * While it's possible to define nested safe_eval'd `context` on nodes, the evaluation context for *those* contains neither datetime nor relativedelta, so storing a bunch of constants in the (environment's) context and using that in the expression is not an option either. * Leaving `date_from`/`date_to` off of some records breaks, probably because some other field necessary to properly compute *them* is missing. Other changes ============= * Removed explicit settings to `number_of_days` and explicit calls to `_compute_number_of_days`, seems redundant and unnecessary as the compute works fine as long as we let it. * While at it, updated the calls to `action_approve`: moved them next to the corresponding record (instead of being on the other side of the file) and used direct references to the subject records rather than complicated searches. * Also updated two leave allocations to be created validated OOTB instead of manually calling action_validate as that's what's being done elsewhere in the file. Notes ===== * In relativedelta lingo, "the next X" is inclusive of the current date e.g. when looking for the next WE, if the date being offset is already WE there will be no movement, this can be unexpected. * Normally relativedelta would be used with the MO/TU/WE/... constants for weekdays, but we're not exposing those to `@eval` so integer literals it is. closes odoo/odoo#65430 X-original-commit: 7840b21483c0012174e6028a39b114ce56f06158 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com> Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Odoo
Odoo is a suite of web based open source business apps.
The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...
Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.
Getting started with Odoo
For a standard installation please follow the Setup instructions from the documentation.
To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials
Languages
Python
49.6%
JavaScript
47.8%
SCSS
2%
CSS
0.3%
HTML
0.2%