Commit Graph
43 Commits
Author SHA1 Message Date
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
RomainLibert 894229c268 [FIX] resource: Fix annoying bug with timezones
When encoding global leaves, we put the timezone of this particular
leave to False, which raises an exception when given directly to pytz.

Simple solution is to pass 'UTC' in case we receive False. This
behaviour might be improved in master later.
2018-01-24 14:01:27 +01:00
Martin Trigaux cab7e0d204 [FIX] *: add missing space in multilines messages
Courtesy of @Yenthe666
2018-01-03 11:09:09 +01:00
Christophe Simonis 5851a69aa3 [MERGE] forward port branch saas-16 up to 3f66814a0d 2017-11-28 15:12:31 +01:00
Christophe Simonis 3f66814a0d [MERGE] forward port branch saas-15 up to 09badbed98 2017-11-28 13:37:35 +01:00
Simon Lejeune d7d9603f1b [FIX] resource: mixin: copy
When copying a record implementing the resource mixin, the linked
resource should be copied too and not shared across the records.

Fixes #20956
opw-781508
2017-11-20 09:19:07 +01:00
Christophe Simonis 10128fa7e8 [MERGE] forward port branch saas-16 up to dc2a6c6cd2 2017-10-20 19:27:04 +02:00
Christophe Simonis 25e65d2bcb [MERGE] forward port branch saas-15 up to 8096162bee 2017-10-18 16:57:35 +02:00
Nicolas Martinelli a13120c039 [FIX] resource: default TZ
If TZ is not set on a user, the creation of a `hr.leave` won't populate
the `tz` field of the associated `resource.calendar.leaves` record.
However, the method `_get_leave_intervals` assumes that field field is
always filled in.

Set the TZ to UTC as a fallback.

opw-777031
2017-10-17 16:38:45 +02:00
Christophe Simonis 017ee5eab3 [MERGE] forward port branch saas-17 up to 877e709871 2017-08-24 13:17:53 +02:00
Xavier Morel f315ea4b71 [FIX] resource: P3 rounding issue 2017-08-23 14:34:50 +02:00
Xavier Morel 1edc84dfdf [FIX] P3: surprise, time.time() isn't falsy
https://bugs.python.org/issue13936

That's a pretty sensible change, but it turns out we did have some
bits of resource which implicitly depended on the old behaviour.
2017-08-19 02:34:23 +02:00
Xavier Morel 70599807a1 [FIX] P3: round() compatibility shim
In Python 3 round:

* rounds half to even (banker's rounding) rather than up
* returns an int if not given a precision (or given a precision of
  None)
* discards the negative sign when rounding to 0

Add a compatibility shim which implements P2 behaviour and at least
allows passing float_utils's tests.

Implementing float_round on top of Decimal was attempted but did not
work: although Decimal.quantize takes a non-integral
Decimal (e.g. ``d.quantize(D('0.001'))``) it only supports integral
powers of 10 and does not support quantizing to e.g. 0.05: while that
will not fail it will just use the exponent for quantization and 0.05
is thus equivalent to 0.01, which is not what we want if e.g. need to
round a value to 5 cents.

This is hinted at but maybe not clearly spelled out by the official
documentation:

> Return a value equal to the first operand after rounding
> and **having the exponent of** the second operand.

Also convert a bunch of hand-rolled currency rounding to just using
the round() method on res.currency.
2017-08-19 02:34:20 +02:00
Xavier Morel bc3cbe9eca [FIX] P3: surprise, time.time() isn't falsy
https://bugs.python.org/issue13936

That's a pretty sensible change, but it turns out we did have some
bits of resource which implicitly depended on the old behaviour.
2017-07-18 11:49:28 +02:00
Xavier Morel ace4ee39e8 [FIX] P3: round() compatibility shim
In Python 3 round:

* rounds half to even (banker's rounding) rather than up
* returns an int if not given a precision (or given a precision of
  None)
* discards the negative sign when rounding to 0

Add a compatibility shim which implements P2 behaviour and at least
allows passing float_utils's tests.

Implementing float_round on top of Decimal was attempted but did not
work: although Decimal.quantize takes a non-integral
Decimal (e.g. ``d.quantize(D('0.001'))``) it only supports integral
powers of 10 and does not support quantizing to e.g. 0.05: while that
will not fail it will just use the exponent for quantization and 0.05
is thus equivalent to 0.01, which is not what we want if e.g. need to
round a value to 5 cents.

This is hinted at but maybe not clearly spelled out by the official
documentation:

> Return a value equal to the first operand after rounding
> and **having the exponent of** the second operand.

Also convert a bunch of hand-rolled currency rounding to just using
the round() method on res.currency.
2017-07-18 11:49:28 +02:00
Christophe Simonis db2f82d5f1 [MERGE] forward port branch saas-16 up to 4ca3d9cadf 2017-07-14 15:51:59 +02:00
Christophe Simonis 4ca3d9cadf [MERGE] forward port branch saas-15 up to aa19cb61f4 2017-07-14 14:27:38 +02:00
Goffin Simon 45e7389a1e [FIX] mrp, resource: Wrong default value for Time Efficiency
The time efficiency cannot be set to 0 otherwise it raised an error
when creating a workorder.

opw:751638, 752035
2017-07-12 13:32:51 +02:00
Yannick Tivisse 83c01a461c [IMP] resource: Ensure time_efficiency to be strictly positive 2017-07-11 17:01:34 +02:00
Christophe Simonis ed2ddeccdf [MERGE] forward port branch saas-16 up to 1b50c829ef 2017-06-15 18:46:47 +02:00
Christophe Simonis 1b50c829ef [MERGE] forward port branch saas-15 up to 9713dc2e1f 2017-06-15 18:44:16 +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
xmo-odoo fffaf735f5 [FIX] P3: list -> iterable builtins (#16811)
In Python 3:

* various builtins and dict methods were changed to return
  view/iterable objects rather than lists
* and the separate Python 2 view/iterable builtins and methods were
  removed altogether

This is problematic when using these items as list (which the happens
repeatedly in Odoo), but more viciously when iterating *multiple times*
over them (which also happens, which I've messed up multiple times while
writing this, and which is a pain to debug even when you've just created
the issue).

Convert all code using these to semantics-matching cross-version
helper functions to get the LCD behaviour between P2 and P3, and
forbid the builtins via lint.

issue #8530
2017-05-10 09:39:55 +02:00
Thibault Delavallée 69631078ba [IMP] resource: add iterator on work hours count between two datetimes 2017-05-03 10:13:24 +02:00
xmo-odoo b4429c2a91 [FIX] Various P3-related import changes
* LDAP import: python-ldap is not python3-compatible, pyldap is

  Warning: only supported from debian Stretch (current testing)?
  https://packages.debian.org/search?searchon=names&keywords=pyldap

* implicitly relative imports
* imports of moved or removed stdlib modules

issue #8530
2017-04-28 09:06:53 +02:00
Christophe Simonis 65a5ced979 [MERGE] forward port branch saas-14 up to 777a87cde8 2017-03-13 17:37:20 +01:00
Christophe Simonis 777a87cde8 [MERGE] forward port branch 10.0 up to 2ef43281c2 2017-03-13 16:22:57 +01:00
Laurent Mignon (ACSONE) 1dea8a53fb [FIX] resource: correct also microsecond information
A lot of methods are designed to work with pure datetime objects as args. If
the value comes from the database it will be rounded at the level of seconds
(0 microsecond). If it comes from a call do datetime.now() / datetime.utcnow()
the datetime object has a value != 0 for its mircroseconds attribute. Therefore
some methods have unpredictable results depending of the origin of the values
manipulated since the microsecond argument is missing into all the calls to
datetime.replace

Closes #15768
2017-03-09 14:07:58 +01: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 44971c2be1 [FIX] resource: compute working hours of current day using only the current day
Tomorrow never dies; however no need to add its working hours today.
Indeed rrule until parameter is inclusive. This means that in
current implementation next day is included in computation. This commit
fixes that.
2017-02-16 17:34:35 +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
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
cst-odoo 9a777f315e [IMP] resource: Improve time_efficiency help tooltip
Rewrote help tooltip to improve English and clarity.

Closes #14696
2016-12-13 10:04:37 +01:00
Christophe Simonis 3bb022d57c [MERGE] forward port branch saas-12 up to 6f8e40c 2016-10-27 18:17:59 +02:00
Thibault Delavallée 82635140b3 [IMP] resource: add default value on calendar manager being the current user to ease calendar use 2016-09-14 15:44:49 +02:00
Mansi Gandhi a4e57ea16c [MIG] resource: Migrated to new api. 2016-07-13 12:53:34 +02:00
Ravi Gohil 22ef7c15b5 [MOV] resource: Organized/renamed files as per new api guidelines. 2016-07-13 12:53:34 +02:00