Amit Parmar (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-leave_status_report_improve-aar into 
lp:~openerp-dev/openobject-addons/trunk-leave_status_report-uco.

Requested reviews:
  Ujjvala Collins (OpenERP) (uco-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-leave_status_report_improve-aar/+merge/82114

Hello Mam,
   
    I have made changes as you specified

Thanks
Amit Parmar
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-leave_status_report_improve-aar/+merge/82114
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-leave_status_report-uco.
=== modified file 'hr_holidays/hr_holidays.py'
--- hr_holidays/hr_holidays.py	2011-11-14 09:50:26 +0000
+++ hr_holidays/hr_holidays.py	2011-11-14 10:12:37 +0000
@@ -115,11 +115,13 @@
     def _get_carryforward_leaves(self, cr, uid, ids, name, args, context=None):
         from datetime import datetime
         result = {}
-        ids = self.search(cr, uid, [], context=context)
-        for hol in self.browse(cr, uid, ids, context=context):
+        previous_carry = 0
+        emp_id = 0
+        contract_obj = self.pool.get('hr.contract')
+        holidays_ids = self.search(cr, uid, [], context=context)
+        holidays_ids.sort()
+        for hol in self.browse(cr, uid, holidays_ids, context=context):
             if hol.type == 'remove':
-                if hol.id not in result.keys():
-                    result[hol.id] = 0
                 date_start1 = datetime.strptime(hol.date_from,'%Y-%m-%d %H:%M:%S')
                 date_start = (datetime(date_start1.year, date_start1.month, 1, 0, 0, 0) + relativedelta(months=-1))
                 last_day = calendar.monthrange(date_start1.year,date_start1.month)[1]
@@ -130,20 +132,60 @@
                                     and s.id = h.holiday_status_id and s.name='Paid Leaves' '''
                            %(date_start, date_end, hol.employee_id.id))
                 prev_days = cr.fetchone()
-                if prev_days[0] is None and hol.id not in result.keys():
-                    result[hol.id] += hol.assigned_leaves
                 cr.execute('''SELECT distinct(to_char(date_from, 'MM')) as month, id, max(date_from) as max_date
                               FROM hr_holidays 
                               WHERE employee_id=%s AND type='remove' AND 
-                                    date_from >= '%s' AND date_from < (select max(date_from) from hr_holidays)
+                                    date_from >= '%s'
                               GROUP BY date_from, id ORDER BY id LIMIT 2'''
                               % (hol.employee_id.id, hol.date_from))
                 diff_months = [(d[1], int(d[0])) for d in cr.fetchall()]
                 if len(diff_months) == 2:
                     key = diff_months[1][0]
+                    key1 = diff_months[0][0]
                     if diff_months[0][0] > diff_months[1][0]:
                         key = diff_months[0][0]
-                    result[key] = diff_months[1][1] - diff_months[0][1]
+                        key1 = diff_months[1][0]
+                    leaves = self.browse(cr, uid, key)
+                    if hol.id not in result.keys():
+                        contract_ids = contract_obj.search(cr, uid, [('employee_id','=',hol.employee_id.id)])
+                        month = 0
+                        if len(contract_ids):
+                            contract = contract_obj.browse(cr, uid, contract_ids[0])
+                            date = contract.date_start.split('-')
+                            month = int(date[1])
+                        if month != 0:
+                            if key1 == diff_months[0][0]:
+                                result[key1] =  diff_months[0][1] - month
+                            elif key1 == diff_months[1][0]:
+                                result[key1] =  diff_months[1][1] - month
+                        else:
+                            if key1 == diff_months[0][0]:
+                                result[key1] =  diff_months[0][1] - 1
+                            elif key1 == diff_months[1][0]:
+                                result[key1] =  diff_months[1][1] - 1
+                        previous_carry = result[key1]
+                        month = 0
+                    if (diff_months[1][1] - diff_months[0][1]) != 0:
+                        if previous_carry != 0:
+                            if leaves.holiday_status_id.name == 'Paid Leaves':
+                                result[key] = previous_carry + diff_months[1][1] - diff_months[0][1] - 1
+                            else:
+                                result[key] = previous_carry + diff_months[1][1] - diff_months[0][1]
+                        else:
+                            result[key] = diff_months[1][1] - 1
+                    else:
+                        if previous_carry != 0:
+                            if leaves.holiday_status_id.name == 'Paid Leaves':
+                                result[key] = previous_carry - 1
+                            else:
+                                result[key] = previous_carry
+                        else:
+                            result[key] = diff_months[1][1] - 1
+                    previous_carry = result[key]
+                    emp_id = leaves.employee_id.id
+                elif len(diff_months) == 1:
+                    if not result.has_key(diff_months[0][0]):
+                        result[diff_months[0][0]] = diff_months[0][1] - 1
             else:
                 result[hol.id] = 0
         return result

=== modified file 'hr_holidays/hr_holidays_data.xml'
--- hr_holidays/hr_holidays_data.xml	2011-07-22 11:31:47 +0000
+++ hr_holidays/hr_holidays_data.xml	2011-11-14 10:12:37 +0000
@@ -25,7 +25,7 @@
 
     <!--Unpaid Leave -->
     <record model="hr.holidays.status" id="holiday_status_unpaid">
-      <field name="name">Unpaid</field>
+      <field name="name">Unpaid Leaves</field>
       <field name="limit">True</field>
       <field name="color_name">brown</field>
     </record>

=== modified file 'hr_holidays/report/holidays_status_of_employees.py'
--- hr_holidays/report/holidays_status_of_employees.py	2011-11-02 12:23:03 +0000
+++ hr_holidays/report/holidays_status_of_employees.py	2011-11-14 10:12:37 +0000
@@ -20,13 +20,15 @@
 ##############################################################################
 
 import time
-
 from report import report_sxw
 
+
 class holidays_status(report_sxw.rml_parse):
     def __init__(self, cr, uid, name, context=None):
         super(holidays_status, self).__init__(cr, uid, name, context=context)
         self.months = {}
+        self.previous_month_carry = 0
+        self.start_date = 0
         self.localcontext.update({
             'time': time,
             'get_data': self._get_data,
@@ -56,19 +58,47 @@
             vals = {'assigned': holidays.assigned_leaves, 'cf': holidays.carry_forward_leaves or 0, 'emp_name': holidays.employee_id.name}
             d.update(vals)
             self.months.update({d['employee_id']: []})
-
         for d in data:
             self.months[d['employee_id']].append(d)
-
         return self.months
 
     def _get_monthly_data(self, obj, month, value):
         data = 0
+        flag = False
+        flag1 = False
+        contract_object = self.pool.get('hr.contract')
         for res in self.months.get(obj):
-            if not month:
+            if not month and value == 'emp_name':
                 data = res[value]
+                self.previous_month_carry = 0
+                contract_ids = contract_object.search(self.cr, self.uid, [('employee_id','=',res['employee_id'])])
+                if len(contract_ids):
+                    contract = contract_object.browse(self.cr, self.uid, contract_ids[0])
+                    date = contract.date_start.split('-')
+                    self.start_date = int(date[1])
+                else:
+                    self.start_date = 0      
+                flag = True
             elif res['month'] == month:
                 data += res[value]
+                flag = True
+                if value == 'cf':
+                    data = res[value]
+                    self.previous_month_carry = res['cf']
+        if not flag and month and value in ('cf','assigned','paid','unpaid'):
+            if self.start_date != 0:
+                if int(month) < self.start_date:
+                    data = 0
+                elif value == 'cf':
+                    self.previous_month_carry += 1
+                    data = self.previous_month_carry
+                elif value == 'assigned':
+                    data = 1
+            elif value == 'cf':
+                self.previous_month_carry += 1
+                data = self.previous_month_carry
+            elif value == 'assigned':
+                data = 1
         return data
 
 report_sxw.report_sxw('report.holidays.status', 'hr.holidays', 'addons/hr_holidays/report/holidays_status_of_employees.rml', parser=holidays_status, header="internal landscape")

=== modified file 'hr_holidays/report/holidays_status_of_employees.rml'
--- hr_holidays/report/holidays_status_of_employees.rml	2011-11-02 12:23:03 +0000
+++ hr_holidays/report/holidays_status_of_employees.rml	2011-11-14 10:12:37 +0000
@@ -500,7 +500,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'01','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'01','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'01','paid') or '0' ]] </para>
@@ -518,7 +518,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'02','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'02','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'02','paid') or '0' ]] </para>
@@ -536,7 +536,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'03','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'03','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'03','paid') or '0' ]] </para>
@@ -554,7 +554,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'04','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'04','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'04','paid') or '0' ]] </para>
@@ -572,7 +572,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'05','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'05','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'05','paid') or '0' ]] </para>
@@ -590,7 +590,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'06','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'06','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'06','paid') or '0' ]] </para>
@@ -608,7 +608,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'07','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'07','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'07','paid') or '0' ]] </para>
@@ -626,7 +626,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'08','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'08','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'08','paid') or '0' ]] </para>
@@ -644,7 +644,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'09','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'09','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'09','paid') or '0' ]] </para>
@@ -662,7 +662,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'10','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'10','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'10','paid') or '0' ]] </para>
@@ -680,7 +680,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'11','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'11','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'11','paid') or '0' ]] </para>
@@ -698,7 +698,7 @@
               <blockTable colWidths="13,13,13,13" style="Table4">
                 <tr>
                   <td>
-                    <para style="P5"> [[ get_monthly_data(o,'12','assigned') or '1' ]] </para>
+                    <para style="P5"> [[ get_monthly_data(o,'12','assigned') or '0' ]] </para>
                   </td>
                   <td>
                     <para style="P5"> [[ get_monthly_data(o,'12','paid') or '0' ]] </para>

_______________________________________________
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