[MERGE] resource: add yml tests

bzr revid: rco@openerp.com-20111220135017-2655lv0pnuywhb9o
This commit is contained in:
Raphael Collet 2011-12-20 14:50:17 +01:00
commit bd056f3764
5 changed files with 172 additions and 21 deletions

View File

@ -45,6 +45,10 @@ It also manages the leaves of every resource.
],
'demo_xml': ['resource_demo.xml'
],
'test': [
'test/resource.yml',
'test/duplicate_resource.yml',
],
'installable': True,
'active': False,
'certificate': '00746371192190459469',

View File

@ -22,7 +22,6 @@
from datetime import datetime, timedelta
import math
from faces import *
from new import classobj
from osv import fields, osv
from tools.translate import _
@ -44,9 +43,12 @@ class resource_calendar(osv.osv):
}
def working_hours_on_day(self, cr, uid, resource_calendar_id, day, context=None):
"""
"""Calculates the Working Total Hours based on Resource Calendar and
given working day (datetime object).
@param resource_calendar_id: resource.calendar browse record
@param day: datetime object
@return: returns the working hours (as float) men should work on the given day if is in the attendance_ids of the resource_calendar_id (i.e if that day is a working day), returns 0.0 otherwise
"""
res = 0.0
@ -56,9 +58,16 @@ class resource_calendar(osv.osv):
return res
def _get_leaves(self, cr, uid, id, resource):
"""Private Method to Calculate resource Leaves days
@param id: resource calendar id
@param resource: resource id for which leaves will ew calculated
@return : returns the list of dates, where resource on leave in
resource.calendar.leaves object (e.g.['%Y-%m-%d', '%Y-%m-%d'])
"""
resource_cal_leaves = self.pool.get('resource.calendar.leaves')
dt_leave = []
resource_leave_ids = resource_cal_leaves.search(cr, uid, [('calendar_id','=',id), '|', ('resource_id','=',False), ('resource_id','=',resource)])
#res_leaves = resource_cal_leaves.read(cr, uid, resource_leave_ids, ['date_from', 'date_to'])
res_leaves = resource_cal_leaves.browse(cr, uid, resource_leave_ids)
@ -73,6 +82,21 @@ class resource_calendar(osv.osv):
return dt_leave
def interval_min_get(self, cr, uid, id, dt_from, hours, resource=False):
"""
Calculates the working Schedule from supplied from date to till hours
will be satisfied based or resource calendar id. If resource is also
given then it will consider the resource leave also and than will
calculates resource working schedule
@param dt_from: datetime object, start of working scheduled
@param hours: float, total number working hours needed scheduled from
start date
@param resource : Optional Resource id, if supplied than resource leaves
will also taken into consideration for calculating working
schedule.
@return : List datetime object of working schedule based on supplies
params
"""
if not id:
td = int(hours)*3
return [(dt_from - timedelta(hours=td), dt_from)]
@ -162,10 +186,32 @@ class resource_calendar(osv.osv):
return results
def interval_get(self, cr, uid, id, dt_from, hours, resource=False, byday=True):
"""Calculates Resource Working Internal Timing Based on Resource Calendar.
@param dt_from: start resource schedule calculation.
@param hours : total number of working hours to be scheduled.
@param resource: optional resource id, If supplied it will take care of
resource leave while scheduling.
@param byday: boolean flag bit enforce day wise scheduling
@return : list of scheduled working timing based on resource calendar.
"""
res = self.interval_get_multi(cr, uid, [(dt_from.strftime('%Y-%m-%d %H:%M:%S'), hours, id)], resource, byday)[(dt_from.strftime('%Y-%m-%d %H:%M:%S'), hours, id)]
return res
def interval_hours_get(self, cr, uid, id, dt_from, dt_to, resource=False):
""" Calculates the Total Working hours based on given start_date to
end_date, If resource id is supplied that it will consider the source
leaves also in calculating the hours.
@param dt_from : date start to calculate hours
@param dt_end : date end to calculate hours
@param resource: optional resource id, If given resource leave will be
considered.
@return : Total number of working hours based dt_from and dt_end and
resource if supplied.
"""
if not id:
return 0.0
dt_leave = self._get_leaves(cr, uid, id, resource)
@ -290,6 +336,7 @@ class resource_resource(osv.osv):
def compute_vacation(self, cr, uid, calendar_id, resource_id=False, resource_calendar=False, context=None):
"""
Compute the vacation from the working calendar of the resource.
@param calendar_id : working calendar of the project
@param resource_id : resource working on phase/task
@param resource_calendar : working calendar of the resource
@ -366,13 +413,6 @@ class resource_resource(osv.osv):
wktime_cal.append((non_working[:-1], time_range))
return wktime_cal
#TODO: Write optimized alogrothem for resource availability. : Method Yet not implemented
def check_availability(self, cr, uid, ids, start, end, context=None):
if context == None:
contex = {}
allocation = {}
return allocation
resource_resource()
class resource_calendar_leaves(osv.osv):

View File

@ -5,73 +5,73 @@
<!-- Example employee -->
<record id="timesheet_group1" model="resource.calendar">
<field name="name">38 Hours/Week</field>
<field name="name">45 Hours/Week</field>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_mon1">
<field name="name">Monday morning</field>
<field name="dayofweek">0</field>
<field name="hour_from">08</field>
<field name="hour_to">12</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_mon2">
<field name="name">Monday evening</field>
<field name="dayofweek">0</field>
<field name="hour_from">13</field>
<field name="hour_to">18</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_tue1">
<field name="name">Tuesday morning</field>
<field name="dayofweek">1</field>
<field name="hour_from">08</field>
<field name="hour_to">12</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_tue2">
<field name="name">Tuesday evening</field>
<field name="dayofweek">1</field>
<field name="hour_from">13</field>
<field name="hour_to">18</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_wed1">
<field name="name">Wednesday morning</field>
<field name="dayofweek">2</field>
<field name="hour_from">08</field>
<field name="hour_to">12</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_wed2">
<field name="name">Wednesday evening</field>
<field name="dayofweek">2</field>
<field name="hour_from">13</field>
<field name="hour_to">18</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_thu1">
<field name="name">Thursday morning</field>
<field name="dayofweek">3</field>
<field name="hour_from">08</field>
<field name="hour_to">12</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_thu2">
<field name="name">Thursday evening</field>
<field name="hour_from">13</field>
<field name="hour_to">18</field>
<field name="dayofweek">3</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_fri1">
<field name="name">Friday morning</field>
<field name="dayofweek">4</field>
<field name="hour_from">08</field>
<field name="hour_to">12</field>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record model="resource.calendar.attendance">
<record model="resource.calendar.attendance" id="calendar_attendance_fri2">
<field name="name">Friday evening</field>
<field name="dayofweek">4</field>
<field name="hour_from">13</field>
@ -79,5 +79,47 @@
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record id="resource_analyst" model="resource.resource">
<field eval="1.0" name="time_efficiency"/>
<field name="user_id" ref="base.user_root"/>
<field name="name">Analyst</field>
<field eval="1" name="active"/>
<field name="calendar_id" ref="timesheet_group1"/>
<field name="resource_type">user</field>
</record>
<record id="resource_designer" model="resource.resource">
<field eval="1.0" name="time_efficiency"/>
<field name="user_id" ref="base.user_demo"/>
<field name="name">Designer</field>
<field eval="1" name="active"/>
<field name="calendar_id" ref="timesheet_group1"/>
<field name="resource_type">user</field>
</record>
<record id="resource_developer" model="resource.resource">
<field eval="1.0" name="time_efficiency"/>
<field name="user_id" ref="base.user_demo"/>
<field name="name">Developer</field>
<field eval="1" name="active"/>
<field name="calendar_id" ref="timesheet_group1"/>
<field name="resource_type">user</field>
</record>
<record id="resource_analyst_leaves_demoleave1" model="resource.calendar.leaves">
<field name="name">2 Hours On Leave</field>
<field name="resource_id" ref="resource_analyst"/>
<field name="date_from" eval="time.strftime('%Y-%m-%d 08:00:00')"/>
<field name="date_to" eval="time.strftime('%Y-%m-%d 11:00:00')"/>
<field name="calendar_id" ref="timesheet_group1"/>
</record>
<record id="resource_dummyleave" model="resource.calendar.leaves">
<field name="name">Dummy Resource Leave</field>
<field name="resource_id" ref="resource_analyst"/>
<field name="date_from" eval="time.strftime('%Y-%m-%d 08:00:00')"/>
<field name="date_to" eval="time.strftime('%Y-%m-%d 11:00:00')"/>
</record>
</data>
</openerp>

View File

@ -0,0 +1,6 @@
-
I duplicate the resource "Analyst"
-
!python {model: resource.resource}: |
copied_id = self.copy(cr, uid, ref("resource_analyst"))
assert copied_id, "Unable to Duplicate Resource"

View File

@ -0,0 +1,59 @@
-
In order to test resource.
-
I assign working calendar '45 Hours/Week' to human resource.
-
!python {model: resource.resource}: |
self.write(cr, uid, [ref('resource_analyst'), ref('resource_designer'), ref('resource_developer')], {'calendar_id' : ref('timesheet_group1'), 'resource_type': 'user'})
-
I had Project of OpenERP Integration of 50 Hours with three human resource assigned on it. I have started project from this week start.
-
First, I generate the resource detail and check the resource Efficiency assigned.
-
!python {model: resource.resource}: |
resources = self.generate_resources(cr, uid, [ref('base.user_root'),ref('base.user_demo')], ref('timesheet_group1'), context)
for resource in resources.values():
assert resource.get('efficiency', 0.0) == 1.0, 'Invalid resource generated.'
-
I check per day work hour availability of the Resource based on Working Calendar Assigned to each resource, for first day of the week.
-
!python {model: resource.resource}: |
calendar_pool = self.pool.get('resource.calendar')
resources = self.browse(cr, uid, [ref('resource_analyst'), ref('resource_designer'), ref('resource_developer')], context)
from datetime import datetime, timedelta
now = datetime.now()
dt = now - timedelta(days=now.weekday())
for resource in resources:
result = calendar_pool.working_hours_on_day(cr, uid, resource.calendar_id, dt, context)
assert result == 9.0, 'Wrong calculation of day work hour availability of the Resource.'
-
Now, resource "Developer" drafted leave on Thursday in this week.
-
!python {model: resource.calendar.leaves}: |
from datetime import datetime,timedelta
now = datetime.now()
dt = (now - timedelta(days=now.weekday()) ) + timedelta(days=3)
self.write(cr, uid, [ref('resource_dummyleave')], {'resource_id': ref('resource_developer'), 'calendar_id': ref('timesheet_group1'), 'date_from': dt.strftime("%Y-%m-%d 09:00:00"), 'date_to': dt.strftime("%Y-%m-%d 18:00:00")})
-
I check Actual working hours on resource 'Developer' from this week
-
!python {model: resource.calendar}: |
from datetime import datetime, timedelta
now = datetime.now()
dt_from = now - timedelta(days=now.weekday())
dt_to = dt_from+ timedelta(days=6)
hours = self.interval_hours_get(cr, uid, ref('timesheet_group1'), dt_from, dt_to, resource=ref('resource_developer'))
assert hours > 27 , 'Invalid Total Week working hour calculated'
-
Project Analysis work is of 20 hours which will start from Week start so i will calculate working schedule for resource Analyst for the same.
-
!python {model: resource.calendar}: |
from datetime import datetime, timedelta
now = datetime.now()
work_intreval = self.interval_min_get(cr, uid, ref('timesheet_group1'), now, 20.0, resource=ref('resource_designer'))
assert len(work_intreval) >= 5, 'Wrong Schedule Calculated'