Commit Graph
68 Commits
Author SHA1 Message Date
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
Thibault Delavallée c8a313d51e [IMP] various: use odoo for imports instead of openerp and update class names 2016-08-10 15:48:07 +02:00
Ravi Gohil dc77ed4f90 [MIG] resource: Migrated unittest cases to new api
- Converted yml test cases to python unittest
- now, 'self.calendar' recordset from common.py will carry forward its context
  so no need to pass context explicitely to the methods calling using that recordset.
- removed commented code
- used odoo.fields.Datetime to covert dates instead of python datetime library
2016-07-13 12:53:34 +02:00
Xavier Morel 4a6adff30d [ADD] resource: work day helpers
Add methods to query work days (entire) for resources for systems
working daily insted of hourly.
2016-06-07 17:41:44 +02:00
Christophe Simonis d1a79ec704 [MERGE] forward port of branch saas-6 up to 9363372 2016-02-17 16:28:56 +01:00
Christophe Simonis 9363372efe [MERGE] forward port of branch 8.0 up to 0f46e6a 2016-02-17 16:20:23 +01:00
Adrien Peiffer (ACSONE) b21773456c [ADD] Add test with half hours to compute working hours. 2016-02-16 17:24:39 +01:00
Christophe Simonis 57168a9e90 [MERGE] forward port of branch saas-6 up to a669433 2015-09-23 14:34:26 +02:00
Christophe Simonis 3fd91d4244 [MERGE] forward port of branch 8.0 up to d05ee26 2015-09-22 15:43:12 +02:00
Christophe Simonis d05ee26a72 [MERGE] forward port of branch saas-3 up to 24bcdb7 2015-09-22 15:40:28 +02:00
Christophe Simonis 024177ebc4 [FIX] resource: get_working_intervals_of_day
Use patch from 8.0 (64e1c28e35) instead of
the one from 7.0 (bbd15cdca6).
2015-09-11 18:07:49 +02:00