Meera Trambadia (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-812303-mtr into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #812303 in OpenERP Addons: "Leave request not calculating correct the 
number of days"
  https://bugs.launchpad.net/openobject-addons/+bug/812303

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-812303-mtr/+merge/75951

hr_holidays:-In leave request it now calculates the correct number of days 
using resource.calendar --fixes=lp:812303
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-812303-mtr/+merge/75951
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-812303-mtr.
=== modified file 'hr_holidays/hr_holidays.py'
--- hr_holidays/hr_holidays.py	2011-09-16 06:07:58 +0000
+++ hr_holidays/hr_holidays.py	2011-09-19 05:59:19 +0000
@@ -22,6 +22,8 @@
 ##############################################################################
 
 import datetime
+from datetime import timedelta
+
 from itertools import groupby
 from operator import itemgetter
 
@@ -173,14 +175,26 @@
         return result
 
     # TODO: can be improved using resource calendar method
-    def _get_number_of_days(self, date_from, date_to):
+    def _get_number_of_days(self, cr, uid, ids, date_from, date_to):
         """Returns a float equals to the timedelta between two dates given as string."""
 
+        resource_obj = self.pool.get('resource.resource')
         DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
         from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
         to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
         timedelta = to_dt - from_dt
         diff_day = timedelta.days + float(timedelta.seconds) / 86400
+        nb_of_days = round(diff_day)+1
+        res_id = resource_obj.search(cr, uid,[('user_id', '=', uid)])
+        for resource in resource_obj.browse(cr, uid, res_id):
+            calendar_id = resource.calendar_id
+            if not calendar_id:
+                continue
+        diff_day = 0
+        for day in range(0, int(nb_of_days)):
+            working_hours_on_day = self.pool.get('resource.calendar').working_hours_on_day(cr, uid, calendar_id, from_dt + datetime.timedelta(days=day))
+            if working_hours_on_day:
+                diff_day += 1.0
         return diff_day
 
     def unlink(self, cr, uid, ids, context=None):
@@ -192,9 +206,9 @@
     def onchange_date_from(self, cr, uid, ids, date_to, date_from):
         result = {}
         if date_to and date_from:
-            diff_day = self._get_number_of_days(date_from, date_to)
+            diff_day = self._get_number_of_days(cr, uid, ids, date_from, date_to)
             result['value'] = {
-                'number_of_days_temp': round(diff_day)+1
+                'number_of_days_temp': diff_day
             }
             return result
         result['value'] = {

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to