Round total time of tasks to two decimals

This fixes misrepresentation errors.  This occus for example when a task
has a length that would be represented using a floating point number that
has more than 2 decimals.

For example:  a task of length 59 minutes (i.e. 0.9833333333333333... hour)
is shown on the invoice as having a length of 0.98 hours while in
calculations still the unrounded task length is used.  When a hourly rate
of €100 pe rhour is defined, the invoice will show:

  0.98h x €100/h = €98.33.

which is confusing and although correct given maximal accurancy, it will
obviously not be accepted by book keeping programs.
This commit is contained in:
Paul van Tilburg 2014-10-12 17:04:18 +02:00
parent e61fa8e3cc
commit 97b6098bcd
1 changed files with 3 additions and 2 deletions

View File

@ -344,9 +344,10 @@ module StopTime::Models
belongs_to :task
has_one :customer, :through => :task
# Returns the total amount of time, the duration, in hours.
# Returns the total amount of time, the duration, in hours (up to
# 2 decimals only!).
def hours_total
(self.end - self.start) / 1.hour
((self.end - self.start) / 1.hour).round(2)
end
end