Commit Graph
78 Commits
Author SHA1 Message Date
Audric Onockx (auon) 2933d5eb5b [FIX] resource : compute the correct default dates when planning a shift
Steps :
- Install Planning
- Users > Mitchell Admin > Preferences > Timezone :
	Europe/Brussels
- Settings > Employees > Company Working Hours > Timezone :
	Japan
- Planning > Gantt View > Week > Mitchell Admin x Friday > Click "+" button

Issue :
- Start date is set by default to Thursday 05:00
	whereas it is expected to be set on Friday 00:00

Cause :
- When we want to plan a shift on a day,
	we look into the 00:00 to 23:59 range for this day in calendar's tz
	to get the closest work time inside of it.
- Yet, this doesn't take the "resource user" into account.

Fix :
- Set these limits for the day in resource's tz.

opw-2678221

closes odoo/odoo#82555

X-original-commit: 1b248ebd58e0a57b070ebf7d67c6da78351a720a
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2022-01-12 16:43:24 +00:00
Thibault Libioulle 74624f43ee [REF] resource,hr{,_contract}: obtain calendar validity per resource
This commit adds methods to easily obtain calendar validity per resource
for a given search period and get the work intervals per resource,
taking into account the validity of their calendars.

In hr, the create and departure date of an employee are taken into
account to compute the calendars validity.

In hr_contract, it looks for every contract of human resources with
employee of type student or employee existing in the search period and
consider the specific calendar of the contract as valid during the
contract-lifetime.

PR: #77362

task-2646630
2021-11-30 12:20:47 +01:00
Thibault Libioulle be23e7436d [IMP] resource: speedup tests
This commit replaces the setUp method by a classmethod in order to speed
up the tests.

PR: #77362

task-2646630
2021-11-30 12:20:31 +01:00
Philippe Wauthy 88d0c49604 [FIX] resource: timezone end before assigning search_range
The end datetime is not timezoned in _adjust_to_calendar before defining the search_range and using the _get_closest_work_time method.
Since _get_closest_work_time will timezone the timestamp received to start searching, the search interval needs to refer to the same end timestamp to avoid erratic behaviors.

Task-2628876

closes odoo/odoo#79049

X-original-commit: cbf0cb6e210959b3ceea554ec68957416a125141
Related: odoo/enterprise#21915
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
2021-10-27 21:06:48 +00:00
William Braeckman faefaf7c39 [IMP] resource: improve _attendance_intervals_batch perf
Improves on _attendance_intervals_batch to profit more from batching.
Resources are grouped by timezone since we know they will all have the
same result except for when there are resource assigned attendances.
Those have to be handled separately but are incoroporated in the same
routine.

TaskId-2674527

closes odoo/odoo#78741

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2021-10-26 13:22:27 +00:00
Philippe Wauthy fd69a22410 [IMP] resource: assign a search_range for calendar_end
Assign a search_range for calendar_end in the _adjust_to_calendar method in all conditions.
The search_range was only assigned a value if the start and end are on the same date before.

The _adjust_to_calendar method receives a start and end from midnight to midnight in the resource timezone.
Start and end datetimes can be set on a different day via the Gantt view set in month or year for example.
This commit ensures that a search_range is always assigned to find the calendar_end and not only when start and end are on the same day.
This allows to find the end of a shift searched over two days if the employee is only working one day.

Task-2628876

closes odoo/odoo#78746

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2021-10-26 07:47:47 +00:00
254d6a71e8 [IMP] hr_holidays: Improve Accruals, dashboards and general UX (Back2basics)
Purpose
=======

Time Off : New Dashboard, Accruals feature, Public holidays, New time off type configuration view.

- Review of Dashboard
- Accrual feature : Currently, when you create an allocation, it's possible to create an
  Accrual, but there is no appraisal Plan. An Appraisal plan is use to define steps of accruals
  for each employee.
  In Belgium, we use accrual Allocation for European Leaves, or compensatory hours, it's a
  simple use case.  But in USA, it's possible to change the calculation mode each year.
  Also, in USA, it's possible to deal your accrual plan when you arrive on the company. It's a
  HR Officer task to create the right Accrual allocation for each new employee.
- Public Holidays :
  Improvement of global time off feature located on Working hours calendar. Now, Time off
  application have to manage Public Holidays.
- Review of Time Off type configuration

COM PR: https://github.com/odoo/odoo/pull/72511
ENT PR: https://github.com/odoo/enterprise/pull/19157
UPG PR: https://github.com/odoo/upgrade/pull/2791
TaskID:2475413

closes odoo/odoo#72511

Related: odoo/enterprise#19157
Related: odoo/upgrade#2791
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Co-authored-by: William Braeckman <wbr@odoo.com>
Co-authored-by: Xavier BOL (xbo) <xbo@odoo.com>
Co-authored-by: Laurent Stukkens (LTU) <ltu@odoo.com>
Co-authored-by: Yannick Tivisse <yti@odoo.com>
2021-09-02 12:57:03 +00:00
Yannick Tivisse 3eec4d6a69 [FW][MERGE] resource,calendar,hr_holidays: Improve the performances
TL;DR
=====

Improve performances with nearly a factor of 2. Use case, call action_validate on hr.leave for 100 employees
- 1987 requests -> 844 requests
- 1300 ms -> 700 ms

Purpose
=======

The first purpose of this commit is to add a test ensuring the number of request while creating
a company leave for 100 employees, if 15 of them already have a leave during that period.

It includes, the mass leave generation, and the conflicts resolutions. (Cancelling/Splitting the
already existing one and adapting the dates accordingly).

The second one is to reduce the number of request for this test.

In term of requests, currently we have:
- 5154 requests without bypassing the mail tracking + the activities management
- 1987 requests when bypassing the mail post-process (this is the current value, the bypassing was
  already done several month ago)
- 844 requests with all the optimization done in resource/calendar/hr_holidays

In terms of execution time, we have a reduction from +- 1300 ms to call the method action_validate
to +- 700 ms

As the performances issues severity increases with the number of leaves to create and the real time access
to the database, on the production base, we reduced the execution time to generate more than 500 hr.leaves
from several minutes to 21 seconds. A fix to avoid deadlock was already made at
https://github.com/odoo/enterprise/pull/10740/files

Some contortions were made to avoid changing a signature method in a stable release and thus
introducing for each method a second one, with the "batched" implementation, to keep a retro-compatibility
for the existing custom code.

But surely this could be cleaned in the master version. The old one will be deprecated while waiting to be
removed in a few versions.

closes odoo/odoo#56534

Taskid: 2256705
X-original-commit: 8c96a887d3f05680c923dcd44f9c70c0e5e0bd32
Related: odoo/enterprise#12670
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-08-25 15:44:07 +00:00
Lucas Lefèvre 103feca347 [FIX] resource: Find intervals in the resource timezone
With a user with timezone "Europe/Brussels", add a
slot on the gantt view where the preceding day is a working day.
The default starting time will be the previous day.
Reason: the default starting time is midnight, adjusted to
the closest attendance interval in the employee's calendar.
However, midnight in "Europe/Brussels" is actually 10pm UTC
the previous day.
The method adjusting the datetime to the closest attendance only
checks within the corresponding day.

Two ways to fix this:
1) the business code calling `_adjust_to_calendar` should
   timezone the datetimes itself. To avoid similar bugs in the future,
   the method should be modified to only accept timezoned datetimes.

2) Change `_adjust_to_calendar` to convert datetimes it was given
   to the resource's timezone and consider the dates in those converted
   datetimes.

Option 2 is chosen because it seems to take care of the problem at a lower
level which allows the business code to not think about those timezone details.
While this is technically an API change (in a stable release), the method was
introduced recently by b058ca1 as a fix for an already broken method.

closes odoo/odoo#53582

X-original-commit: c6cecac60360a1d8b0c62ee155a818a3a28505e1
Related: odoo/enterprise#11399
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-06-24 12:35:11 +00:00
Lucas Lefèvre b674e4401d [FIX] resource: Adjust time span to calendar
The method `_get_work_interval` has several problems:

1) The name is not self explanatory in any way

2) It should be defined on the `resource.mixin`

3) It simply does not work (as described in its docstring).
   Here is a simplified example (only concerned about hours):
   Currently, given two attendances: 8-12 and 13-17,
   with parameters start=9 and end=18 it returns (9, 17)
   while it should return (8, 17).

   This leads to strange behaviors in the planning app:
   Given employee A with calendar 8-17 and employee B 8-16.
   Create a planning slot and assign employee A: the start and end times
   are set to 8-17.
   Then assign employee B, the start and end times are correcly set to 8-16.
   Now reassign employee A: the start and end times are not set to 8-17.

Task 2229296

closes odoo/odoo#50804

X-original-commit: 7dfab89bc0025cf6424f00b6992fef1f42463ffe
Related: odoo/enterprise#10426
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: lul-odoo <LucasLefevre@users.noreply.github.com>
2020-05-07 08:22:22 +00:00
jbm-odoo 1e8db02368 [IMP] resource: Manage calendars over 2 weeks
Purpose
=======

In Belgium, we need to support some partial time on 2 weeks.
For instance, a mid time, means you could work on monday, tuesday
and wednesday on week1 and monday and tuesday on week 2. Others payroll
softwares manage this.

Specification
=============

Add a checkbox on resource calendar to manage 2 weeks. --> Consider even/odd weeks.
Add sections on calendars (Like sales orders)
Modify methods in resources to apply this behavor generically.

Check that attendances aren't overlapped

Write an integration test for holidays - benefits - payslip
to check all this, + "credit temps" and wage modification.

Note
====

For the sake of simplicity, we only manage calendars over 2 weeks
to consider the odd/even weeks and keep an easy implementation.
For more complicated calendars (eg: over a months with specific targetted days),
it's better to create specific allocation requests and apply specific leaves
for those days, as it would be the case for parental leaves.

closes odoo/odoo#31674

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-06-25 08:02:14 +00:00
Yannick Tivisse 624a1fc56b [FIX] resource: Make get_leave_days_data private 2019-02-18 15:28:15 +00:00
Yannick Tivisse 9cbc68b8ab [FIX] resource: Make get_work_days_data private 2019-02-18 15:28:15 +00:00
Christophe Simonis b4e1be8ab0 [MERGE] forward port branch saas-11.3 up to b09f624f20 2018-11-22 20:06:48 +01:00
Christophe Simonis b09f624f20 [MERGE] forward port branch 11.0 up to 263b388c50 2018-11-22 17:52:57 +01:00
Дмитро Катюха f68c5261f9 [FIX] resource: Fix work/leaves hours count methods
Purpose
=======

Buggy example:
I have a 35h working schedule. I work every week day:
- From 8h to 12h
- From 12h to 16h

Let's say that I want to retrieve the working hours from Wednesday 14h03
to Thursday 11h03.

The working hours are:
- From 14h03 to 16h --> 1h57
- From 8h to 11h03  --> 3h03
----------------------------
TOTAL                   5h

Currently the result will be 1.95, i.e. 1h57 because the second day
is not taken into account as start time > end time, and thus rrule
doesn't manage this correctly and returns only the datetime corresponding
to the first day.

Specification
=============

Force the until parameter of rrule to be set at the end of the day, do
avoid skipping the second day. Do this in the methods that compute the
work hours and the leave hours.

Add a test to ensure the robustness of the fix.

Closes #21297

closes odoo/odoo#28920
2018-11-21 15:42:48 +00:00
RomainLibert 1d28525d6b [FIX] resource: increase the rounding factor in resource_mixin
In order to be more precise in the number of hours shown in leaves, we
need more precision in resource_mixin

closes odoo/odoo#28907
2018-11-21 13:04:55 +00:00
William Henrotin 701d0f0e1a [FIX] resource: allow to plan 0 hours
The method `plan_hours` does nothing if the `hours` parameter is equal to 0.
This commit adds the 0 case in the logic, and add an optional `resource` in the
parameters.

Example: A workorder works each days between 8am and 4pm. If we call
`plan_hours(0)` at 9pm, we want to get 8am the next day. Currently, it
sends back 9pm.

Before this commit, a hack existed consisting to send a very small value to
`plan_hours`. The holidays and non-working time were taken into account and the
result was rounded to the second.  We can now send explicitely 0 and the
non-working hours will be skipped.
2018-08-22 16:02:52 +02:00
Christophe Simonis c302a90b6e [FIX] resource: oversights of previous forward-port 2018-06-28 21:50:23 +02:00
Christophe Simonis c8bb02141d [MERGE] forward port branch saas-11.3 up to 3cdcbce93c 2018-06-28 19:01:52 +02:00
Christophe Simonis 40836194c2 [MERGE] forward port branch saas-11.2 up to 12ddec3a76 2018-06-27 13:41:00 +02:00
Nicolas Martinelli f90434b96c [FIX] resource: 24h shift
Create a resource working 24 hours / day.
If we record it as:
- From 00:00 ; To 24:00 => crash
- From 00:00 ; To 23:59 => 1 minute lost

The `float_time` widget doesn't allow to be more accurate than 1 minute,
therefore it is not possible to record an end time of 23:59:59.999999.
We allow a value of 24:00 which is automatically interpreted as
23:59:59.999999. Only 1 microsecond is lost for such use case, which
should be acceptable for our level of accuracy.

opw-1856943
2018-06-21 09:20:33 +02:00
Raphael Collet d3e2cf5585 [FIX] resource: methods plan_* can return naive datetimes
Make those methods return a datetime in the same (naive or aware) timezone as
their argument.
2018-06-19 16:44:56 +02:00
RomainLibert b6642f1b70 [IMP] hr_holidays: add support for taking leaves differently
We would like to be able to take leaves using different units, currently
we only support taking leaves by hours because we use datetimes.

We need to support three units:
 * days
 * half days
 * hours

These units will be defined on the leave type.

Task #40995
Closes #21760
2018-06-06 17:04:07 +02:00
Raphael Collet 975c6c8639 [REF] resource calendar (#24717)
Refactor resource calendar and resource mixin:
 - add a required timezone field on models 'resource.calendar' and 'resource.resource';
 - resource calendar attendances are now computed in the timezone of the resource
   or the calendar;
 - improve API of 'resource.calendar' and 'resource.mixin';
 - avoid other modules from using the implementation methods of 'resource.calendar';
 - refactor implementation of 'resource.calendar' to make it more efficient.
2018-05-31 20:28:12 +02:00
RomainLibert 05bb9848a2 [IMP] resource: add time_type field on resource.calendar.leaves
We would like to have an overview of project forecast that include
leaves, for this we need to implement several kind of 'leaves' directly
in resource module.

These kind of 'leaves' can be defined via the hr.leave.type model (only
visible in base.group_no_one (choices currently are 'leave' and 'other')

    * Add field time_type on resource.calendar.leaves
    * Add a domain restriction that allows for filtering on this field
    * Add tests
2018-02-19 10:43:25 +01:00
RomainLibert 6d870463d0 [IMP] resource: Add possibility to pass in a domain
It will enable to retrieve data from the resource module based on a
domain that we pass to the model. It can be used in order to filter on
certain leave types only.

  * In resource_mixin and resource add a way to use a domain in order to
  filter the leaves
  * In resource_mixin add a method to get the work/leaves hours count
2018-02-19 10:43:25 +01:00
RomainLibert 9717026dcc [IMP] Resource: Expand testing on timezones
We need to check if resource module takes into account the timezone of
the employee taking a leave and the timezone of the user asking to see
when this employee has taken some leave.

Basically everything should be done in UTC internally and then converted
back to the user's timezone.
2018-02-14 14:43:38 +01:00
RomainLibert bb02b93c3a [IMP] resource: timezone support for global leaves
Purpose
=======

We should add some real timezone support for the global leaves
(resource.calendar.leaves without a resource assigned) currently it is
declared in UTC and never changed to the user or employee timezone.

Specification
=============

In order to support this, we have to add some choices for the user
defining the global leave. He can specify how the timezone is
configured,
  - no value is specified, we keep the dates in UTC then convert those to
    user timezone
  - current user timezone specified, we set the timezone of the leave to
    the company timezone
  - a timezone is specified, we keep this specific timezone
2018-02-05 14:45:42 +01:00
RomainLibert a5cbf2105c [FIX] resource: _interval_and not working with disjoint intervals
When we pass two disjoint intervals the behaviour of _interval_and is a
little strange, it returns an interval wich begins after it finishes.
In order to fix that we return None when the intervals are disjoint.
2018-01-30 17:38:30 +01:00
Christophe Simonis 34b432d528 [MERGE] forward port branch saas-15 up to 4d79a1ff58 2017-06-26 19:19:39 +02:00
Nicolas Martinelli a74c5a42bc [IMP] resource: add test case
Test case known to be problematic in v10.
2017-06-16 13:25:38 +02:00
Christophe Simonis 2a008d5168 [MERGE] forward port branch saas-15 up to 2f6edfef49 2017-06-15 19:04:51 +02:00
Christophe Simonis 2f6edfef49 [FIX] resource: remove bad test introduced by previous forward-port 2017-06-15 19:00:54 +02:00
Christophe Simonis 1b50c829ef [MERGE] forward port branch saas-15 up to 9713dc2e1f 2017-06-15 18:44:16 +02:00
Christophe Simonis 9713dc2e1f [MERGE] forward port branch saas-14 up to 96595772e0 2017-06-15 18:39:59 +02:00
Thibault Delavallée 8b886bd316 [FIX] resource: fix timezone management when planning hours and days
Low-level methods have to convert datetime into a naive user timezone
in order to match the attendances and leaves. Returned values are already
in UTC ready for display. Therefore no postprocessing is necessary for
output.
2017-06-13 12:40:44 +02:00
Thibault Delavallée 6baa42ed57 [FIX] resource: return correct date when planning hours
Planning hours can be done forwards or backwards. In first case the
returned datetime should be the last one aka the date when the job is
finished. In second case it should be the first one, aka the date when
the job begins. Those are the dates user want to know and manipulate when
programming working hours.

Manual forward port of 577eb10c0b .
2017-06-13 12:30:14 +02:00
Thibault Delavallée 577eb10c0b [FIX] resource: return correct date when planning hours
Planning hours can be done forwards or backwards. In first case the
returned datetime should be the last one aka the date when the job is
finished. In second case it should be the first one, aka the date when
the job begins. Those are the dates user want to know and manipulate when
programming working hours.
2017-06-13 10:56:25 +02:00
xmo-odoo 2e6a589f41 [FIX] builtins removed from Python 3
* Reverse wrapper courtesy of @rco-odoo's original P3 branch
* thin compat module stripped down from werkzeug (to augment as needed)

issue 8530
2017-04-27 13:59:33 +02:00
Thibault Delavallée 9944209ef7 [IMP] resource: add resource mixin adding fields and an API for resource
Purpose is to replace existing inherits of resource.resource by an inherit
on the mixin itself. The mixin offers several methods to compute working
intervals, attendance, hours, ... This mixin will be improved in future
commits when new methods that will be required with future improvements
of various service apps.

This commit also adds tests for the mixin itself. A new model is defined
only for testing purpose to test the mixin.
2017-02-27 14:04:48 +01:00
Thibault Delavallée ff32384b8f [REF] resource: correctly take into account timezones and clean code
Currently timezones were not or incorrectly taken into account in resource
computation. Indeed complexity comes from attendances being expressed in
naive timezones valid for all users, whereas dates and leaves are computed
into UTC. Computation should always be done in user timezone so that there
are no overlapping days and all time intervals are correctly computed.

A new timezone field is added on leaves to know in which timezone they
were originally encoded. Indeed putting them in naive user timezone
require its original timezone, not the current user timezone, as those
can be different.

This commit also contains code cleaning in resource to be a bit more
pythonic, simplify method parameters and offer a more simple api to
other modules.

Eventually code field is removed on resource as it is not really necessary
for resources. It is explicitly added on workcenter model who use it.
2017-02-27 14:04:48 +01:00
Thibault Delavallée ac26fa3dd4 [REF] resource: include attendance and leave info in intervals
Calendar and resource scheduling work on time intervals. However in some
cases it is useful to have info about attendances and / or leaves linked
to those intervals. Internal interval tuples is thus extended to keep
records about resource.calendar.attendance and resource.calendar.leaves.
This will notably allow to remove some hacks in stock_calendar module.
Hooray.
2017-02-27 14:04:48 +01:00
Thibault Delavallée be01aaa99f [REF] resource: remove deprecated compatibility and rename methods
Old methods are still present since a long time and are deprecated since
saas-3. This compatibility layer adds unnecessary complexity to the module
API. Those methods should now be removed. Some renaming is also performed
to ease resource api understanding, notably to better differentiate
internal methods from other methods.

All addons are updated accordingly.
2017-02-27 14:04:48 +01:00
Thibault Delavallée 06f36ddbe9 [REF] resource: remove pseudo-default working hours computation
Companies now always have a default calendar configured. All methods in
resource module should therefore be able to use a real resource.calendar.
This commit removes the computation based on a pseudo 8-17 calendar
given as weird method parameters.

Project is updated in order to use the company calendar by default.
2017-02-27 14:04:48 +01:00
Thibault Delavallée 2b90398cb6 [REF] resource: strengthen link between companies and calendars
Purpose of this commit is to always have a default calendar for each
company and ensure it is correctly set on resources.

Some cleaning is also performed in resource models to remove unused
fields, improve labels and make views a bit more odoo-ish.

 * [REF] res_company: add a m2o to the default calendar to use in the
   company as well as a o2m linking all resource calendars used in the
   company. Some code has been added to correctly update existing
   companies when installing the module;
 * [REF] resource_calendar
  * [REM] manager field on resource.calendar: this field is never used
    and is not necessary anyway
  * [ADD] global_leave_ids: filter leaves on a calendar to see global
    company leaves
  * [IMP] better default company / calendar computation to ensure there
    is always a calendar attached to a resource
  * [IMP] improve resource and calendar views in order to look more like
    other odoo views
2017-01-18 10:26:53 +01:00
Thibault Delavallée 1c4ea80f78 [IMP] resource: clean tests code
This commit cleans resource test code by removing unnecessary stuff
and simplifying code. Purpose is to lessen number of lines and improve
readability of tests. Some duplicated tests have been removed.
2017-01-18 10:24:24 +01:00
qdp-odoo 4f29b77e3d [MERGE] foward port of 10.0 up to revision 84a650e33a 2016-12-30 17:21:25 +01:00
Thibault Delavallée 84a650e33a [FIX] resource: fix computation of limited attendances
Due to an error introduced when migrating the module at new API
at commit a4e57ea16c limited attendances
having date_from and / or date_to were not correctly taken into
account.

Tests have been added to avoid regression.
2016-12-30 16:38:02 +01:00
Raphael Collet ffdafd3f8a [REM] most uses of _model (useless in most cases) 2016-08-16 09:55:46 +02:00