← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-payroll-refund into lp:openobject-addons

 

Mustufa Rangwala (Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-payroll-refund into lp:openobject-addons.

Requested reviews:
  qdp (OpenERP) (qdp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-refund/+merge/56910
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-refund/+merge/56910
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-payroll-refund.
=== modified file 'hr/hr.py'
--- hr/hr.py	2011-03-11 17:29:52 +0000
+++ hr/hr.py	2011-04-08 10:36:40 +0000
@@ -139,6 +139,7 @@
         'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
         'sinid': fields.char('SIN No', size=32, help="Social Insurance Number"),
         'identification_id': fields.char('Identification No', size=32),
+        'otherid': fields.char('Other Id', size=64),
         'gender': fields.selection([('male', 'Male'),('female', 'Female')], 'Gender'),
         'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
         'department_id':fields.many2one('hr.department', 'Department'),

=== modified file 'hr/hr_view.xml'
--- hr/hr_view.xml	2011-03-11 13:41:36 +0000
+++ hr/hr_view.xml	2011-04-08 10:36:40 +0000
@@ -43,6 +43,7 @@
                                 <field name="sinid" groups="base.group_extended"/>
                                 <field name="identification_id" groups="base.group_extended"/>
                                 <field name="passport_id"/>
+                                <field name="otherid"/>
                             </group>
                             <group col="2" colspan="2" groups="base.group_hr_user">
                                 <separator string="Status" colspan="2"/>

=== modified file 'hr_contract/__openerp__.py'
--- hr_contract/__openerp__.py	2011-03-18 14:06:18 +0000
+++ hr_contract/__openerp__.py	2011-04-08 10:36:40 +0000
@@ -44,7 +44,9 @@
         'hr_contract_view.xml'
         ],
     'demo_xml': [],
-    'test': ['test/test_hr_contract.yml'],
+    'test': [
+             'test/test_hr_contract.yml'
+             ],
     'installable': True,
     'active': False,
     'certificate': '0046298028637',

=== modified file 'hr_contract/hr_contract.py'
--- hr_contract/hr_contract.py	2011-01-14 00:11:01 +0000
+++ hr_contract/hr_contract.py	2011-04-08 10:36:40 +0000
@@ -51,35 +51,28 @@
 
 hr_employee()
 
-#Contract wage type period name
-class hr_contract_wage_type_period(osv.osv):
-    _name='hr.contract.wage.type.period'
-    _description='Wage Period'
-    _columns = {
-        'name': fields.char('Period Name', size=50, required=True, select=True),
-        'factor_days': fields.float('Hours in the period', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work wased on the contract of the employee')
-    }
-    _defaults = {
-        'factor_days': 168.0
-    }
-hr_contract_wage_type_period()
-
-#Contract wage type (hourly, daily, monthly, ...)
-class hr_contract_wage_type(osv.osv):
-    _name = 'hr.contract.wage.type'
-    _description = 'Wage Type'
-    _columns = {
-        'name': fields.char('Wage Type Name', size=50, required=True, select=True),
-        'period_id': fields.many2one('hr.contract.wage.type.period', 'Wage Period', required=True),
-        'type': fields.selection([('gross','Gross'), ('net','Net')], 'Type', required=True),
-        'factor_type': fields.float('Factor for hour cost', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work wased on the contract of the employee')
-    }
-    _defaults = {
-        'type': 'gross',
-        'factor_type': 1.8
-    }
-hr_contract_wage_type()
-
+class hr_passport(osv.osv):
+    """
+    Employee Passport
+    Passport based Contracts for Employees
+    """
+
+    _name = 'hr.passport'
+    _description = 'Passport Detail'
+    _columns = {
+        'employee_id': fields.many2one('hr.employee', 'Employee', required=True),
+        'name': fields.char('Passport No', size=64, required=True, readonly=False),
+        'country_id': fields.many2one('res.country', 'Country of Issue', required=True),
+        'address_id': fields.many2one('res.partner.address', 'Address', required=False),
+        'date_issue': fields.date('Passport Issue Date', required=True),
+        'date_expire': fields.date('Passport Expire Date', required=True),
+        'note': fields.text('Description'),
+        'contracts_ids': fields.one2many('hr.contract', 'passport_id', 'Contracts', required=False, readonly=True),
+    }
+    _sql_constraints = [
+        ('passport_no_uniq', 'unique (employee_id, name)', 'The Passport No must be unique !'),
+    ]
+hr_passport()
 
 class hr_contract_type(osv.osv):
     _name = 'hr.contract.type'
@@ -103,15 +96,22 @@
         'trial_date_start': fields.date('Trial Start Date'),
         'trial_date_end': fields.date('Trial End Date'),
         'working_hours': fields.many2one('resource.calendar','Working Schedule'),
-        'wage_type_id': fields.many2one('hr.contract.wage.type', 'Wage Type', required=True),
-        'wage': fields.float('Wage', digits=(16,2), required=True),
+        'wage': fields.float('Wage', digits=(16,2), required=True, help="Basic Salary of the employee"),
         'advantages': fields.text('Advantages'),
-        'advantages_net': fields.float('Net Advantages Value', digits=(16,2)),
-        'advantages_gross': fields.float('Gross Advantages Value', digits=(16,2)),
         'notes': fields.text('Notes'),
+        'permit_no': fields.char('Work Permit No', size=256, required=False, readonly=False),
+        'passport_id': fields.many2one('hr.passport', 'Passport', required=False),
+        'visa_no': fields.char('Visa No', size=64, required=False, readonly=False),
+        'visa_expire': fields.date('Visa Expire Date'),
     }
+
+    def _get_type(self, cr, uid, context=None):
+        type_ids = self.pool.get('hr.contract.type').search(cr, uid, [('name', '=', 'Employee')])
+        return type_ids and type_ids[0] or False
+
     _defaults = {
         'date_start': lambda *a: time.strftime("%Y-%m-%d"),
+        'type_id': _get_type
     }
 
     def _check_dates(self, cr, uid, ids, context=None):
@@ -123,9 +123,6 @@
     _constraints = [
         (_check_dates, 'Error! contract start-date must be lower then contract end-date.', ['date_start', 'date_end'])
     ]
-
-
-
 hr_contract()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'hr_contract/hr_contract_data.xml'
--- hr_contract/hr_contract_data.xml	2011-01-14 00:11:01 +0000
+++ hr_contract/hr_contract_data.xml	2011-04-08 10:36:40 +0000
@@ -1,43 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <openerp>
     <data noupdate="1">
-        
-        <!-- Contract Period Names -->
-        <record id="hr_contract_wage_type_period_daily" model="hr.contract.wage.type.period">
-            <field name="name">daily</field>
-        </record>
-        <record id="hr_contract_wage_type_period_weekly" model="hr.contract.wage.type.period">
-            <field name="name">weekly</field>
-        </record>
-        <record id="hr_contract_wage_type_period_monthly" model="hr.contract.wage.type.period">
-            <field name="name">monthly</field>
-        </record>
-        
-        <!-- Contract Wage Types -->
-        <record id="hr_contract_monthly_gross" model="hr.contract.wage.type">
-            <field name="name">Monthly Gross Wage</field>
-            <field name="type">gross</field>
-            <field name="period_id" ref="hr_contract_wage_type_period_monthly"/>
-        </record>
 
-        <record id="hr_contract_monthly_net" model="hr.contract.wage.type">
-            <field name="name">Monthly Net Wage</field>
-            <field name="type">net</field>
-            <field name="period_id" ref="hr_contract_wage_type_period_monthly"/>
-        </record> 
-        
-        <!-- Contract Types -->               
+        <!-- Contract Types -->
         <record id="hr_contract_type_emp" model="hr.contract.type">
             <field name="name">Employee</field>
-        </record> 
-                 
+        </record>
+
         <record id="hr_contract_type_wrkr" model="hr.contract.type">
             <field name="name">Worker</field>
-        </record> 
-         
+        </record>
+
         <record id="hr_contract_type_sub" model="hr.contract.type">
             <field name="name">Subcontractor</field>
-        </record>                        
-        
+        </record>
+
     </data>
 </openerp>

=== modified file 'hr_contract/hr_contract_view.xml'
--- hr_contract/hr_contract_view.xml	2011-01-27 09:49:39 +0000
+++ hr_contract/hr_contract_view.xml	2011-04-08 10:36:40 +0000
@@ -2,99 +2,83 @@
 <openerp>
     <data>
 
-        <record id="hr_contract_wage_type_view_form" model="ir.ui.view">
-            <field name="name">hr.contract.wage.type.view.form</field>
-            <field name="model">hr.contract.wage.type</field>
+        <!-- Passport Views    -->
+        <record id="hr_passport_form" model="ir.ui.view">
+            <field name="name">hr.passport.form</field>
+            <field name="model">hr.passport</field>
             <field name="type">form</field>
             <field name="arch" type="xml">
-                <form string="Wage Type">
-                    <field colspan="4" name="name"/>
-                    <field name="period_id" widget="selection"/>
-                    <field name="type"/>
-                    <separator colspan="4" string="Hourly cost computation"/>
-                    <field name="factor_type"/>
+                <form string="Passport">
+                    <group col="6" colspan="4">
+                        <field name="name" select="1" colspan="4"/>
+                        <field name="employee_id" />
+                    </group>
+                    <group col="2" colspan="2">
+                        <separator string="Country &amp; Address" colspan="4"/>
+                        <field name="country_id" select="1"/>
+                        <field name="address_id" select="1"/>
+                    </group>
+                    <group col="2" colspan="2">
+                        <separator string="Valid From" colspan="2"/>
+                        <field name="date_issue" select="1"/>
+                        <field name="date_expire" select="1"/>
+                    </group>
+                    <notebook colspan="4">
+                        <page string="Description">
+                            <separator string="Description" colspan="2"/>
+                            <field name="note" colspan="4" nolabel="1"/>
+                        </page>
+                    </notebook>
                 </form>
             </field>
         </record>
-
-        <record id="hr_contract_wage_type_view_tree" model="ir.ui.view">
-            <field name="name">hr.contract.wage.type.view.tree</field>
-            <field name="model">hr.contract.wage.type</field>
+        <record id="hr_passport_tree" model="ir.ui.view">
+            <field name="name">hr.passport.tree</field>
+            <field name="model">hr.passport</field>
             <field name="type">tree</field>
             <field name="arch" type="xml">
-                <tree string="Wage Types">
-                    <field name="name"/>
-                    <field name="type"/>
-                    <field name="period_id" invisible="1"/>
+                <tree string="Passport">
+                    <field name="name" />
+                    <field name="employee_id" />
+                    <field name="address_id"/>
+                    <field name="country_id" />
+                    <field name="date_expire"/>
+                    <field name="date_issue" />
                 </tree>
             </field>
         </record>
 
-        <record id="hr_contract_wage_type_view_search" model="ir.ui.view">
-            <field name="name">hr.contract.wage.type.view.search</field>
-            <field name="model">hr.contract.wage.type</field>
+        <record id="view_hr_passport_filter" model="ir.ui.view">
+            <field name="name">hr.passport.select</field>
+            <field name="model">hr.passport</field>
             <field name="type">search</field>
             <field name="arch" type="xml">
-                <search string="Search Wage Type">
-                   <group col='15' colspan='4'>
-                   <field name="name"/>
-                   <field name="type"/>
-                   </group>
-                   <newline/>
-                   <group expand="0" string="Group By..." colspan="4" col="20">
-                   <filter string="Period" icon="terp-go-month" domain="[]" context="{'group_by':'period_id'}"/>
-                   </group>
-               </search>
+                <search string="Search Passport">
+                    <group col="8" colspan="4">
+                        <field name="name"/>
+                        <field name="employee_id"/>
+                        <field name="country_id"/>
+                        <field name="address_id"/>
+                    </group>
+                    <newline/>
+                    <group col="8" colspan="4" expand="0" string="Group By...">
+                        <filter string="Employees" icon="terp-partner" name="employee_id" context="{'group_by':'employee_id'}"/>
+                        <filter string="Country" name="country_id" icon="terp-go-home" context="{'group_by':'country_id'}"/>
+                        <filter string="Expire" name="date_expire" icon="terp-go-month" context="{'group_by':'date_expire'}"/>
+                        <filter string="Issue" name="date_issue" icon="terp-go-month" context="{'group_by':'date_issue'}"/>
+                    </group>
+                </search>
             </field>
         </record>
-
-        <record id="action_hr_contract_wage_type" model="ir.actions.act_window">
-            <field name="name">Wage Type</field>
-            <field name="res_model">hr.contract.wage.type</field>
+        <record id="action_hr_passport_tree" model="ir.actions.act_window">
+            <field name="name">All Passports</field>
+            <field name="res_model">hr.passport</field>
             <field name="view_type">form</field>
-            <field name="view_mode">tree,form</field>
-            <field name="domain">[]</field>
-            <field name="search_view_id" ref="hr_contract_wage_type_view_search"/>
+            <field name="view_id" ref="hr_passport_tree"/>
+            <field name="search_view_id" ref="view_hr_passport_filter"/>
         </record>
-
+        <!-- End Passport Views -->
         <menuitem id="next_id_56" name="Contract" parent="hr.menu_hr_management" sequence="5"/>
-        <menuitem action="action_hr_contract_wage_type" id="hr_menu_contract_wage_type" parent="next_id_56" sequence="7"/>
-
-        <record id="hr_contract_wage_type_period_view_form" model="ir.ui.view">
-            <field name="name">hr.contract.wage.type.period.view.form</field>
-            <field name="model">hr.contract.wage.type.period</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Wage Period">
-                    <field colspan="4" name="name"/>
-                    <field name="factor_days"/>
-                </form>
-            </field>
-        </record>
-
-        <record id="hr_contract_wage_type_period_view_search" model="ir.ui.view">
-            <field name="name">hr.contract.wage.type.period.view.search</field>
-            <field name="model">hr.contract.wage.type.period</field>
-            <field name="type">search</field>
-            <field name="arch" type="xml">
-                <search string="Search Wage Period">
-                   <group col='15' colspan='4'>
-                    <field name="name"/>
-                   </group>
-               </search>
-            </field>
-        </record>
-
-        <record id="action_hr_contract_wage_type_period" model="ir.actions.act_window">
-            <field name="name">Wage period</field>
-            <field name="res_model">hr.contract.wage.type.period</field>
-            <field name="view_type">form</field>
-            <field name="domain">[]</field>
-            <field name="search_view_id" ref="hr_contract_wage_type_period_view_search"/>
-        </record>
-
-        <menuitem action="action_hr_contract_wage_type_period" id="hr_menu_contract_wage_type_period"
-                parent="hr_contract.next_id_56"/>
 
         <record id="hr_hr_employee_view_form2" model="ir.ui.view">
             <field name="name">hr.hr.employee.view.form2</field>
@@ -132,9 +116,9 @@
             <field name="arch" type="xml">
                 <search string="Search Contract">
                    <group col='15' colspan='4'>
-                   <filter string="Current" icon="terp-check" name="current"  domain="['|',('date_end','&gt;=', time.strftime('%%Y-%%m-%%d')),('date_end','=',False)]" help="Contracts in progress"/> 
-                   <filter string="Overpassed" icon="terp-emblem-important" domain="[('date_end','&lt;', time.strftime('%%Y-%%m-%%d'))]" help="Contracts whose end date already passed"/>   
-                   <separator orientation="vertical"/>                  
+                   <filter string="Current" icon="terp-check" name="current"  domain="['|',('date_end','&gt;=', time.strftime('%%Y-%%m-%%d')),('date_end','=',False)]" help="Contracts in progress"/>
+                   <filter string="Overpassed" icon="terp-emblem-important" domain="[('date_end','&lt;', time.strftime('%%Y-%%m-%%d'))]" help="Contracts whose end date already passed"/>
+                   <separator orientation="vertical"/>
                    <field name="name"/>
                    <field name="employee_id"/>
                    <field name="working_hours"/>
@@ -143,11 +127,11 @@
                    </group>
                    <newline/>
                    <group expand="0" string="Group By..." colspan="4" col="20">
-                   <filter string="Employee" icon="terp-personal" domain="[]" context="{'group_by':'employee_id'}"/> 
-                   <separator orientation="vertical"/> 
+                   <filter string="Employee" icon="terp-personal" domain="[]" context="{'group_by':'employee_id'}"/>
+                   <separator orientation="vertical"/>
                    <filter string="Working Schedule" icon="terp-go-week" domain="[]" context="{'group_by':'working_hours'}"/>
                    <filter string="Job" icon="terp-gtk-select-all" domain="[]" context="{'group_by':'job_id'}"/>
-                    <separator orientation="vertical"/> 
+                    <separator orientation="vertical"/>
                     <filter string="Contract Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'type_id'}"/>
                    </group>
                </search>
@@ -161,33 +145,42 @@
             <field name="arch" type="xml">
                 <form string="Contract">
                     <group colspan="3" col="6">
-                    <field name="name" />
-                    <field name="employee_id" />
-                    <field name="job_id"/>
-                    <field name="wage"/>
-                    <field name="wage_type_id" widget="selection"/>
-                    <field name="type_id" widget="selection"/>
+                        <field name="name" />
+                        <field name="employee_id" />
+                        <field name="job_id"/>
+                        <field name="wage"/>
+                        <field name="type_id" widget="selection"/>
                     </group>
                     <notebook>
                     <page string="Information">
                         <group col="2" colspan="2">
-                        <separator colspan="2" string="Duration"/>
-                        <field name="date_start" />
-                        <field name="date_end" />
-                        <field name="working_hours"/>
-                        <separator colspan="2" string="Trial Period"/> 
-                        <field name="trial_date_start" />
-                        <field name="trial_date_end" />
-                        </group>                 
-                        <group col="2" colspan="2">
-                        <separator colspan="2" string="Advantages"/>
-                        <field name="advantages_net"/>
-                        <field name="advantages_gross"/>
-                        <field name="advantages" nolabel="1" colspan="2"/>
+                            <separator colspan="2" string="Duration"/>
+                            <field name="date_start" />
+                            <field name="date_end" />
+                            <field name="working_hours"/>
+                            <separator colspan="2" string="Trial Period"/>
+                            <field name="trial_date_start" />
+                            <field name="trial_date_end" />
+                        </group>
+                            <group col="2" colspan="2">
+                            <separator colspan="2" string="Advantages"/>
+                            <field name="advantages" nolabel="1" colspan="2"/>
                         </group>
                         <separator colspan="4" string="Notes"/>
                         <field colspan="4" name="notes" nolabel="1"/>
                     </page>
+                    <page string="Work Permit">
+                        <group col="2" colspan="2">
+                            <separator colspan="2" string="Passport"/>
+                            <field name="passport_id" domain="[('employee_id','=',employee_id)]"/>
+                        </group>
+                        <group col="2" colspan="2">
+                            <separator colspan="2" string="Valid for"/>
+                            <field name="visa_no"/>
+                            <field name="permit_no"/>
+                            <field name="visa_expire"/>
+                        </group>
+                    </page>
                     </notebook>
                 </form>
             </field>
@@ -203,11 +196,9 @@
                     <field name="employee_id"/>
                     <field name="type_id"/>
                     <field name="job_id"/>
-                    <!--field name="department_id"/-->
-                    <field name="working_hours"/>                    
+                    <field name="working_hours"/>
                     <field name="date_start"/>
                     <field name="date_end"/>
-                    <field name="wage_type_id" invisible="1"/>
                     <field name="wage" invisible="1"/>
                 </tree>
             </field>
@@ -270,11 +261,12 @@
         <menuitem action="action_hr_contract" id="hr_menu_contract" parent="hr.menu_hr_main" name="Contracts" sequence="4" groups="base.group_hr_manager"/>
 
         <!-- Contracts Button on Employee Form -->
-        <act_window 
+
+        <act_window
         context="{'search_default_employee_id': [active_id], 'default_employee_id': active_id}"
-        id="act_hr_employee_2_hr_contract" 
-        name="Contracts" 
-        res_model="hr.contract" 
+        id="act_hr_employee_2_hr_contract"
+        name="Contracts"
+        res_model="hr.contract"
         src_model="hr.employee"
         groups="base.group_hr_manager"/>
 

=== modified file 'hr_contract/security/ir.model.access.csv'
--- hr_contract/security/ir.model.access.csv	2011-01-14 00:11:01 +0000
+++ hr_contract/security/ir.model.access.csv	2011-04-08 10:36:40 +0000
@@ -1,7 +1,7 @@
 "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
-"access_hr_contract_wage_type_period_user","hr.contract.wage.type.period.user","model_hr_contract_wage_type_period","base.group_hr_user",1,1,1,1
-"access_hr_contract_wage_type_user","hr.contract.wage.type.user","model_hr_contract_wage_type","base.group_hr_user",1,1,1,1
 "access_hr_resource_manager","hr.employee.resource.manager","resource.model_resource_resource","base.group_hr_manager",1,1,1,1
 "access_hr_resource_calendar_user","hr.employee.resource.calendar.user","resource.model_resource_calendar","base.group_hr_user",1,1,1,1
 "access_hr_contract_type_manager","hr.contract.type.manager","model_hr_contract_type","base.group_hr_manager",1,1,1,1
 "access_hr_contract_manager","hr.contract.manager","model_hr_contract","base.group_hr_manager",1,1,1,1
+"access_hr_passport_manager","hr.passport.manager","model_hr_passport","base.group_hr_manager",1,1,1,1
+"access_hr_passport","hr.passport","model_hr_passport","base.group_hr_user",1,1,1,1

=== modified file 'hr_contract/test/test_hr_contract.yml'
--- hr_contract/test/test_hr_contract.yml	2011-01-14 00:11:01 +0000
+++ hr_contract/test/test_hr_contract.yml	2011-04-08 10:36:40 +0000
@@ -16,35 +16,16 @@
     vehicle: 'No'
     vehicle_distance: 12
 
-
--
-  I create a new Contract wage period.
--
-  !record {model: hr.contract.wage.type.period, id: hr_contract_wage_type_period_monthly0}:
-    factor_days: 176.0
-    name: monthly
--
-  I create a new Contract Wage Type.
--
-  !record {model: hr.contract.wage.type, id: hr_contract_wage_type_monthlygrosswage0}:
-    factor_type: 1.9
-    name: Monthly Gross Wage
-    period_id: 'hr_contract_wage_type_period_monthly0'
-    type: gross
-
 -
   I create a new contract for "Mark Johnson".
 -
   !record {model: hr.contract, id: hr_contract_contract0}:
-    advantages_gross: 0.0
     employee_id: 'hr_employee_employee0'
-    advantages_net: 0.0
     date_end: !eval "'%s-05-18' %(datetime.now().year+1)"
     date_start: !eval "'%s-05-18' %(datetime.now().year)"
     trial_date_end: !eval "'%s-03-01' %(datetime.now().year)"
     trial_date_start: !eval "'%s-04-30' %(datetime.now().year)"
     name: contract1
     wage: 1.0
-    wage_type_id: hr_contract_wage_type_monthlygrosswage0
     type_id: hr_contract_type_emp
     working_hours: resource.timesheet_group1

=== modified file 'hr_payroll/__openerp__.py'
--- hr_payroll/__openerp__.py	2011-03-25 10:24:13 +0000
+++ hr_payroll/__openerp__.py	2011-04-08 10:36:40 +0000
@@ -52,16 +52,16 @@
         'hr_payroll_view.xml',
         'hr_payroll_workflow.xml',
         'hr_payroll_sequence.xml',
-        'hr_paroll_report.xml',
+        'hr_payroll_report.xml',
         'hr_payroll_data.xml',
         'security/ir.model.access.csv',
         'wizard/hr_payroll_employees_detail.xml',
         'wizard/hr_payroll_year_salary.xml',
     ],
     'test': [
-         'test/payslip.yml',
-         'test/payment_advice.yml',
-         'test/payroll_register.yml',
+#         'test/payslip.yml',
+#         'test/payment_advice.yml',
+#         'test/payroll_register.yml',
         # 'test/hr_payroll_report.yml',
     ],
     'demo_xml': [

=== modified file 'hr_payroll/hr_payroll.py'
--- hr_payroll/hr_payroll.py	2011-01-14 00:11:01 +0000
+++ hr_payroll/hr_payroll.py	2011-04-08 10:36:40 +0000
@@ -24,6 +24,7 @@
 from datetime import date
 from datetime import datetime
 from datetime import timedelta
+from dateutil import relativedelta
 
 import netsvc
 from osv import fields, osv
@@ -31,72 +32,24 @@
 from tools.translate import _
 import decimal_precision as dp
 
-def prev_bounds(cdate=False):
-    when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d")))
-    this_first = date(when.year, when.month, 1)
-    month = when.month + 1
-    year = when.year
-    if month > 12:
-        month = 1
-        year += 1
-    next_month = date(year, month, 1)
-    prev_end = next_month - timedelta(days=1)
-    return this_first, prev_end
-
-class hr_contract_wage_type(osv.osv):
-    """
-    Wage types
-    Basic = Basic Salary
-    Grows = Basic + Allowances
-    New = Grows - Deductions
-    """
-
-    _inherit = 'hr.contract.wage.type'
-    _columns = {
-        'type': fields.selection([('basic','Basic'), ('gross','Gross'), ('net','Net')], 'Type', required=True),
-    }
-
-hr_contract_wage_type()
-
-class hr_passport(osv.osv):
-    """
-    Employee Passport
-    Passport based Contratacts for Employees
-    """
-
-    _name = 'hr.passport'
-    _description = 'Passport Detail'
-    _columns = {
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
-        'name':fields.char('Passport No', size=64, required=True, readonly=False),
-        'country_id':fields.many2one('res.country', 'Country of Issue', required=True),
-        'address_id':fields.many2one('res.partner.address', 'Address', required=False),
-        'date_issue': fields.date('Passport Issue Date', required=True),
-        'date_expire': fields.date('Passport Expire Date', required=True),
-        'contracts_ids':fields.one2many('hr.contract', 'passport_id', 'Contracts', required=False, readonly=True),
-        'note': fields.text('Description'),
-    }
-    _sql_constraints = [
-        ('passport_no_uniq', 'unique (employee_id, name)', 'The Passport No must be unique !'),
-    ]
-hr_passport()
+from tools.safe_eval import safe_eval as eval
 
 class hr_payroll_structure(osv.osv):
     """
     Salary structure used to defined
     - Basic
-    - Allowlance
+    - Allowances
     - Deductions
     """
 
     _name = 'hr.payroll.structure'
     _description = 'Salary Structure'
     _columns = {
-        'name':fields.char('Name', size=256, required=True, readonly=False),
-        'code':fields.char('Code', size=64, required=True, readonly=False),
-        'line_ids':fields.one2many('hr.payslip.line', 'function_id', 'Salary Structure', required=False),
-        'company_id':fields.many2one('res.company', 'Company', required=False),
+        'name':fields.char('Name', size=256, required=True),
+        'code':fields.char('Reference', size=64, required=True),
+        'company_id':fields.many2one('res.company', 'Company', required=True),
         'note': fields.text('Description'),
+        'parent_id':fields.many2one('hr.payroll.structure', 'Parent'),
     }
     _defaults = {
         'company_id': lambda self, cr, uid, context: \
@@ -115,473 +68,76 @@
 
         @return: returns a id of newly created record
         """
-        code = self.browse(cr, uid, id, context=context).code
-        default = {
-            'code':code+"(copy)",
-            'company_id':self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
-        }
+        if not default:
+            default = {}
+        default.update({
+            'code': self.browse(cr, uid, id, context=context).code + "(copy)",
+            'company_id': self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
+        })
         return super(hr_payroll_structure, self).copy(cr, uid, id, default, context=context)
 
+    def get_all_rules(self, cr, uid, structure_ids, context=None):
+        """
+        @param structure_ids: list of structure
+        @return: returns a list of tuple (id, sequence) of rules that are maybe to apply
+        """
+        def recursive_search_of_rule(rule_ids):
+            children_rules = []
+            for rule in rule_ids:
+                if rule.child_ids:
+                    children_rules += recursive_search_of_rule(rule.child_ids)
+            return [(r.id, r.sequence) for r in rule_ids] + children_rules
+
+        all_rules = []
+        for struct in self.browse(cr, uid, structure_ids, context=context):
+            all_rules += recursive_search_of_rule(struct.rule_ids)
+        return all_rules
+
+    def _get_parent_structure(self, cr, uid, struct_ids, context=None):
+        if not struct_ids:
+            return []
+        parent = []
+        for struct in self.browse(cr, uid, struct_ids, context=context):
+            if struct.parent_id:
+                parent.append(struct.parent_id.id)
+        if parent:
+            parent = self._get_parent_structure(cr, uid, parent, context)
+        return parent + struct_ids
+
 hr_payroll_structure()
 
 class hr_contract(osv.osv):
     """
     Employee contract based on the visa, work permits
-    allowas to configure different Salary structure
+    allows to configure different Salary structure
     """
 
-    def compute_basic(self, cr, uid, ids, context=None):
-        res = {}
-        if context is None:
-            context = {}
-        ids += context.get('employee_structure', [])
-
-        slip_line_pool = self.pool.get('hr.payslip.line')
-
-        for contract in self.browse(cr, uid, ids, context=context):
-            all_per = 0.0
-            ded_per = 0.0
-            all_fix = 0.0
-            ded_fix = 0.0
-            obj = {'basic':0.0}
-            update = {}
-            if contract.wage_type_id.type == 'gross':
-                obj['gross'] = contract.wage
-                update['gross'] = contract.wage
-            if contract.wage_type_id.type == 'net':
-                obj['net'] = contract.wage
-                update['net'] = contract.wage
-            if contract.wage_type_id.type == 'basic':
-                obj['basic'] = contract.wage
-                update['basic'] = contract.wage
-
-            sal_type = contract.wage_type_id.type
-#            function = contract.struct_id.id
-            lines = contract.struct_id.line_ids
-            if not contract.struct_id:
-                res[contract.id] = obj['basic']
-                continue
-
-            ad = []
-            for line in lines:
-                cd = line.code.lower()
-                obj[cd] = line.amount or 0.0
-
-            for line in lines:
-                if line.category_id.code in ad:
-                    continue
-                ad.append(line.category_id.code)
-                cd = line.category_id.code.lower()
-                calculate = False
-                try:
-                    exp = line.category_id.condition
-                    calculate = eval(exp, obj)
-                except Exception, e:
-                    raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-
-                if not calculate:
-                    continue
-
-                percent = 0.0
-                value = 0.0
-                base = False
-#                company_contrib = 0.0
-                base = line.category_id.base
-
-                try:
-                    #Please have a look at the configuration guide.
-                    amt = eval(base, obj)
-                except Exception, e:
-                    raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-
-                if sal_type in ('gross', 'net'):
-                    if line.amount_type == 'per':
-                        percent = line.amount
-                        if amt > 1:
-                            value = percent * amt
-                        elif amt > 0 and amt <= 1:
-                            percent = percent * amt
-                        if value > 0:
-                            percent = 0.0
-                    elif line.amount_type == 'fix':
-                        value = line.amount
-                    elif line.amount_type == 'func':
-                        value = slip_line_pool.execute_function(cr, uid, line.id, amt, context)
-                        line.amount = value
-                else:
-                    if line.amount_type in ('fix', 'per'):
-                        value = line.amount
-                    elif line.amount_type == 'func':
-                        value = slip_line_pool.execute_function(cr, uid, line.id, amt, context)
-                        line.amount = value
-                if line.type == 'allowance':
-                    all_per += percent
-                    all_fix += value
-                elif line.type == 'deduction':
-                    ded_per += percent
-                    ded_fix += value
-            if sal_type in ('gross', 'net'):
-                sal = contract.wage
-                if sal_type == 'net':
-                    sal += ded_fix
-                sal -= all_fix
-                per = 0.0
-                if sal_type == 'net':
-                    per = (all_per - ded_per)
-                else:
-                    per = all_per
-                if per <=0:
-                    per *= -1
-                final = (per * 100) + 100
-                basic = (sal * 100) / final
-            else:
-                basic = contract.wage
-
-            res[contract.id] = basic
-
-        return res
-
-    def check_vals(self, val1, val2):
-        if val1 == val2 and val1 == 0:
-            return True
-        return False
-
-    def _calculate_salary(self, cr, uid, ids, field_names, arg, context=None):
-        res = self.compute_basic(cr, uid, ids, context=context)
-        vals = {}
-        for rs in self.browse(cr, uid, ids, context=context):
-            allow = 0.0
-            deduct = 0.0
-            others = 0.0
-            obj = {'basic':res[rs.id], 'gross':0.0, 'net':0.0}
-            if rs.wage_type_id.type == 'gross':
-                obj['gross'] = rs.wage
-            if rs.wage_type_id.type == 'net':
-                obj['net'] = rs.net
-
-            if not rs.struct_id:
-                if self.check_vals(obj['basic'], obj['gross']):
-                    obj['gross'] = obj['basic'] = obj['net']
-                elif self.check_vals(obj['gross'], obj['net']):
-                    obj['gross']= obj['net'] = obj['basic']
-                elif self.check_vals(obj['net'], obj['basic']):
-                    obj['net'] = obj['basic'] = obj['gross']
-                record = {
-                    'advantages_gross':0.0,
-                    'advantages_net':0.0,
-                    'basic':obj['basic'],
-                    'gross':obj['gross'],
-                    'net':obj['net']
-                }
-                vals[rs.id] = record
-                continue
-
-            for line in rs.struct_id.line_ids:
-                amount = 0.0
-                if line.amount_type == 'per':
-                    try:
-                        amount = line.amount * eval(str(line.category_id.base), obj)
-                    except Exception, e:
-                        raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-                elif line.amount_type in ('fix', 'func'):
-                    amount = line.amount
-                cd = line.category_id.code.lower()
-                obj[cd] = amount
-
-                if line.type == 'allowance':
-                    allow += amount
-                elif line.type == 'deduction':
-                    deduct += amount
-                elif line.type == 'advance':
-                    others += amount
-                elif line.type == 'loan':
-                    others += amount
-                elif line.type == 'otherpay':
-                    others += amount
-            record = {
-                'advantages_gross':round(allow),
-                'advantages_net':round(deduct),
-                'basic':obj['basic'],
-                'gross':round(obj['basic'] + allow),
-                'net':round(obj['basic'] + allow - deduct)
-            }
-            vals[rs.id] = record
-
-        return vals
-
     _inherit = 'hr.contract'
     _description = 'Employee Contract'
     _columns = {
-        'permit_no': fields.char('Work Permit No', size=256, required=False, readonly=False),
-        'passport_id': fields.many2one('hr.passport', 'Passport No', required=False),
-        'visa_no': fields.char('Visa No', size=64, required=False, readonly=False),
-        'visa_expire': fields.date('Visa Expire Date'),
         'struct_id': fields.many2one('hr.payroll.structure', 'Salary Structure'),
-        'working_days_per_week': fields.integer('Working Days', help="No of Working days / week for an employee"),
-        'basic': fields.function(_calculate_salary, method=True, store=True, multi='dc', type='float', string='Basic Salary', digits=(14,2)),
-        'gross': fields.function(_calculate_salary, method=True, store=True, multi='dc', type='float', string='Gross Salary', digits=(14,2)),
-        'net': fields.function(_calculate_salary, method=True, store=True, multi='dc', type='float', string='Net Salary', digits=(14,2)),
-        'advantages_net': fields.function(_calculate_salary, method=True, store=True, multi='dc', type='float', string='Deductions', digits=(14,2)),
-        'advantages_gross': fields.function(_calculate_salary, method=True, store=True, multi='dc', type='float', string='Allowances', digits=(14,2)),
-    }
-    _defaults = {
-        'working_days_per_week': lambda *a: 5,
-    }
+        'schedule_pay': fields.selection([
+            ('monthly', 'Monthly'),
+            ('quarterly', 'Quarterly'),
+            ('semi-annually', 'Semi-annually'),
+            ('annually', 'Annually'),
+            ('weekly', 'Weekly'),
+            ('bi-weekly', 'Bi-weekly'),
+            ('bi-monthly', 'Bi-monthly'),
+            ], 'Scheduled Pay', select=True),
+    }
+
+    def get_all_structures(self, cr, uid, contract_ids, context=None):
+        """
+        @param contract_ids: list of contracts
+        @return: the structures linked to the given contracts, ordered by hierachy (parent=False first, then first level children and so on) and without duplicata
+        """
+        all_structures = []
+        structure_ids = [contract.struct_id.id for contract in self.browse(cr, uid, contract_ids, context=context)]
+        return list(set(self.pool.get('hr.payroll.structure')._get_parent_structure(cr, uid, structure_ids, context=context)))
+
 hr_contract()
 
-class payroll_register(osv.osv):
-    """
-    Payroll Register
-    """
-
-    _name = 'hr.payroll.register'
-    _description = 'Payroll Register'
-
-    def _calculate(self, cr, uid, ids, field_names, arg, context=None):
-        res = {}
-        allounce = 0.0
-        deduction = 0.0
-        net = 0.0
-        grows = 0.0
-        for register in self.browse(cr, uid, ids, context=context):
-            for slip in register.line_ids:
-                allounce += slip.allounce
-                deduction += slip.deduction
-                net += slip.net
-                grows += slip.grows
-
-            res[register.id] = {
-                'allounce':allounce,
-                'deduction':deduction,
-                'net':net,
-                'grows':grows
-            }
-        return res
-
-    _columns = {
-        'name':fields.char('Name', size=64, required=True, readonly=False),
-        'date': fields.date('Date', required=True),
-        'number':fields.char('Number', size=64, required=False, readonly=True),
-        'line_ids':fields.one2many('hr.payslip', 'register_id', 'Payslips', required=False),
-        'state':fields.selection([
-            ('new','New Slip'),
-            ('draft','Wating for Verification'),
-            ('hr_check','Wating for HR Verification'),
-            ('accont_check','Wating for Account Verification'),
-            ('confirm','Confirm Sheet'),
-            ('done','Paid Salary'),
-            ('cancel','Reject'),
-        ],'State', select=True, readonly=True),
-        'active':fields.boolean('Active', required=False),
-        'company_id':fields.many2one('res.company', 'Company', required=False),
-        'grows': fields.function(_calculate, method=True, store=True, multi='dc', string='Gross Salary', type='float', digits=(16, 4)),
-        'net': fields.function(_calculate, method=True, store=True, multi='dc', string='Net Salary', digits=(16, 4)),
-        'allounce': fields.function(_calculate, method=True, store=True, multi='dc', string='Allowance', digits=(16, 4)),
-        'deduction': fields.function(_calculate, method=True, store=True, multi='dc', string='Deduction', digits=(16, 4)),
-        'note': fields.text('Description'),
-        'bank_id':fields.many2one('res.bank', 'Bank', required=False, help="Select the Bank Address from whcih the salary is going to be paid"),
-    }
-
-    _defaults = {
-        'date': lambda *a: time.strftime('%Y-%m-%d'),
-        'state': lambda *a: 'new',
-        'active': lambda *a: True,
-        'company_id': lambda self, cr, uid, context: \
-                self.pool.get('res.users').browse(cr, uid, uid,
-                    context=context).company_id.id,
-    }
-
-    def compute_sheet(self, cr, uid, ids, context=None):
-        emp_pool = self.pool.get('hr.employee')
-        slip_pool = self.pool.get('hr.payslip')
-        wf_service = netsvc.LocalService("workflow")
-        if context is None:
-            context = {}
-
-        vals = self.browse(cr, uid, ids[0], context=context)
-        emp_ids = emp_pool.search(cr, uid, [], context=context)
-
-        for emp in emp_pool.browse(cr, uid, emp_ids, context=context):
-            old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)], context=context)
-            if old_slips:
-                slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]}, context=context)
-                for sid in old_slips:
-                    wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr)
-            else:
-                res = {
-                    'employee_id':emp.id,
-                    'basic':0.0,
-                    'register_id':ids[0],
-                    'name':vals.name,
-                    'date':vals.date,
-                }
-                slip_id = slip_pool.create(cr, uid, res, context=context)
-                wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr)
-
-        number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register')
-        self.write(cr, uid, ids, {'state':'draft', 'number':number}, context=context)
-        return True
-
-    def set_to_draft(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'draft'}, context=context)
-        return True
-
-    def cancel_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'cancel'}, context=context)
-        return True
-
-    def verify_sheet(self, cr, uid, ids, context=None):
-        slip_pool = self.pool.get('hr.payslip')
-
-        for id in ids:
-            sids = slip_pool.search(cr, uid, [('register_id','=',id)], context=context)
-            wf_service = netsvc.LocalService("workflow")
-            for sid in sids:
-                wf_service.trg_validate(uid, 'hr.payslip', sid, 'verify_sheet', cr)
-
-        self.write(cr, uid, ids, {'state':'hr_check'}, context=context)
-        return True
-
-    def final_verify_sheet(self, cr, uid, ids, context=None):
-        slip_pool = self.pool.get('hr.payslip')
-        advice_pool = self.pool.get('hr.payroll.advice')
-        advice_line_pool = self.pool.get('hr.payroll.advice.line')
-        sequence_pool = self.pool.get('ir.sequence')
-        users_pool = self.pool.get('res.users')
-
-        for id in ids:
-            sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','hr_check')], context=context)
-            wf_service = netsvc.LocalService("workflow")
-            for sid in sids:
-                wf_service.trg_validate(uid, 'hr.payslip', sid, 'final_verify_sheet', cr)
-
-        company_name = users_pool.browse(cr, uid, uid, context=context).company_id.name
-        for reg in self.browse(cr, uid, ids, context=context):
-            advice = {
-                'name': 'Payment Advice from %s' % (company_name),
-                'number': sequence_pool.get(cr, uid, 'payment.advice'),
-                'register_id':reg.id
-            }
-            pid = advice_pool.create(cr, uid, advice, context=context)
-
-            for slip in reg.line_ids:
-                if not slip.employee_id.bank_account_id:
-                    raise osv.except_osv(_('Error !'), _('Please define bank account for the %s employee') % (slip.employee_id.name))
-                pline = {
-                    'advice_id':pid,
-                    'name':slip.employee_id.bank_account_id.acc_number,
-                    'employee_id':slip.employee_id.id,
-                    'amount':slip.other_pay + slip.net,
-                    'bysal':slip.net
-                }
-                id = advice_line_pool.create(cr, uid, pline, context=context)
-
-        self.write(cr, uid, ids, {'state':'confirm'}, context=context)
-        return True
-
-    def process_sheet(self, cr, uid, ids, context=None):
-        slip_pool = self.pool.get('hr.payslip')
-        for id in ids:
-            sids = slip_pool.search(cr, uid, [('register_id','=',id), ('state','=','confirm')], context=context)
-            wf_service = netsvc.LocalService("workflow")
-            for sid in sids:
-                wf_service.trg_validate(uid, 'hr.payslip', sid, 'process_sheet', cr)
-
-        self.write(cr, uid, ids, {'state':'done'}, context=context)
-        return True
-
-payroll_register()
-
-class payroll_advice(osv.osv):
-    '''
-    Bank Advice Note
-    '''
-
-    _name = 'hr.payroll.advice'
-    _description = 'Bank Advice Note'
-    _columns = {
-        'register_id':fields.many2one('hr.payroll.register', 'Payroll Register', required=False),
-        'name':fields.char('Name', size=2048, required=True, readonly=False),
-        'note': fields.text('Description'),
-        'date': fields.date('Date'),
-        'state':fields.selection([
-            ('draft','Draft Sheet'),
-            ('confirm','Confirm Sheet'),
-            ('cancel','Reject'),
-        ],'State', select=True, readonly=True),
-        'number':fields.char('Number', size=64, required=False, readonly=True),
-        'line_ids':fields.one2many('hr.payroll.advice.line', 'advice_id', 'Employee Salary', required=False),
-        'chaque_nos':fields.char('Chaque Nos', size=256, required=False, readonly=False),
-        'company_id':fields.many2one('res.company', 'Company', required=False),
-        'bank_id': fields.related('register_id','bank_id', type='many2one', relation='res.bank', string='Bank', help="Select the Bank Address from whcih the salary is going to be paid"),
-    }
-    _defaults = {
-        'date': lambda *a: time.strftime('%Y-%m-%d'),
-        'state': lambda *a: 'draft',
-        'company_id': lambda self, cr, uid, context: \
-                self.pool.get('res.users').browse(cr, uid, uid,
-                    context=context).company_id.id,
-    }
-
-    def confirm_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'confirm'}, context=context)
-        return True
-
-    def set_to_draft(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'draft'}, context=context)
-        return True
-
-    def cancel_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'cancel'}, context=context)
-        return True
-
-    def onchange_company_id(self, cr, uid, ids, company_id=False, context=None):
-        res = {}
-        if company_id:
-            company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
-            if company.partner_id.bank_ids:
-                res.update({'bank': company.partner_id.bank_ids[0].bank.name})
-        return {
-            'value':res
-        }
-payroll_advice()
-
-class payroll_advice_line(osv.osv):
-    '''
-    Bank Advice Lines
-    '''
-
-    _name = 'hr.payroll.advice.line'
-    _description = 'Bank Advice Lines'
-    _columns = {
-        'advice_id':fields.many2one('hr.payroll.advice', 'Bank Advice', required=False),
-        'name':fields.char('Bank Account A/C', size=64, required=True, readonly=False),
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
-        'amount': fields.float('Amount', digits=(16, 4)),
-        'bysal': fields.float('By Salary', digits=(16, 4)),
-        'flag':fields.char('D/C', size=8, required=True, readonly=False),
-    }
-    _defaults = {
-        'flag': lambda *a: 'C',
-    }
-
-    def onchange_employee_id(self, cr, uid, ids, ddate, employee_id, context=None):
-        vals = {}
-        slip_pool = self.pool.get('hr.payslip')
-        if employee_id:
-            dates = prev_bounds(ddate)
-            sids = False
-            sids = slip_pool.search(cr, uid, [('paid','=',False),('state','=','confirm'),('date','>=',dates[0]), ('employee_id','=',employee_id), ('date','<=',dates[1])], context=context)
-            if sids:
-                slip = slip_pool.browse(cr, uid, sids[0], context=context)
-                vals['name'] = slip.employee_id.identification_id
-                vals['amount'] = slip.net + slip.other_pay
-                vals['bysal'] = slip.net
-        return {
-            'value':vals
-        }
-payroll_advice_line()
-
 class contrib_register(osv.osv):
     '''
     Contribution Register
@@ -590,29 +146,10 @@
     _name = 'hr.contibution.register'
     _description = 'Contribution Register'
 
-    def _total_contrib(self, cr, uid, ids, field_names, arg, context=None):
-        line_pool = self.pool.get('hr.contibution.register.line')
-
-        res = {}
-        for cur in self.browse(cr, uid, ids, context=context):
-            current = line_pool.search(cr, uid, [('register_id','=',cur.id)], context=context)
-            e_month = 0.0
-            c_month = 0.0
-            for i in line_pool.browse(cr, uid, current, context=context):
-                e_month += i.emp_deduction
-                c_month += i.comp_deduction
-            res[cur.id]={
-                'monthly_total_by_emp':e_month,
-                'monthly_total_by_comp':c_month,
-            }
-        return res
-
     _columns = {
         'company_id':fields.many2one('res.company', 'Company', required=False),
         'name':fields.char('Name', size=256, required=True, readonly=False),
-        'register_line_ids':fields.one2many('hr.contibution.register.line', 'register_id', 'Register Line', readonly=True),
-        'monthly_total_by_emp': fields.function(_total_contrib, method=True, multi='dc', string='Total By Employee', digits=(16, 4)),
-        'monthly_total_by_comp': fields.function(_total_contrib, method=True, multi='dc', string='Total By Company', digits=(16, 4)),
+        'register_line_ids':fields.one2many('hr.payslip.line', 'register_id', 'Register Line', readonly=True),
         'note': fields.text('Description'),
     }
     _defaults = {
@@ -620,92 +157,492 @@
                 self.pool.get('res.users').browse(cr, uid, uid,
                     context=context).company_id.id,
     }
+
 contrib_register()
 
-class contrib_register_line(osv.osv):
-    '''
-    Contribution Register Line
-    '''
-
-    _name = 'hr.contibution.register.line'
-    _description = 'Contribution Register Line'
-
-    def _total(self, cr, uid, ids, field_names, arg, context=None):
-        res={}
-        for line in self.browse(cr, uid, ids, context=context):
-            res[line.id] = line.emp_deduction + line.comp_deduction
-            return res
-
+class hr_salary_head(osv.osv):
+    """
+    HR Salary Head
+    """
+
+    _name = 'hr.salary.head'
+    _description = 'Salary Head'
+    _columns = {
+        'name':fields.char('Name', size=64, required=True, readonly=False),
+        'code':fields.char('Code', size=64, required=True, readonly=False),
+        'parent_id':fields.many2one('hr.salary.head', 'Parent', help="Linking a salary head to its parent is used only for the reporting purpose."),
+        'note': fields.text('Description'),
+        'company_id':fields.many2one('res.company', 'Company', required=False),
+        'sequence': fields.integer('Sequence', required=True, help='Display sequence order'),
+    }
+
+    _defaults = {
+        'company_id': lambda self, cr, uid, context: \
+                self.pool.get('res.users').browse(cr, uid, uid,
+                    context=context).company_id.id,
+        'sequence': 5
+    }
+
+hr_salary_head()
+
+class hr_payslip(osv.osv):
+    '''
+    Pay Slip
+    '''
+
+    _name = 'hr.payslip'
+    _description = 'Pay Slip'
+
+#TODO unused for now, cause the field is commented but we want to put it back
+#    def _get_salary_rules(self, cr, uid, ids, field_names, arg=None, context=None):
+#        structure_obj = self.pool.get('hr.payroll.structure')
+#        contract_obj = self.pool.get('hr.contract')
+#        res = {}
+#        rules = []
+#        contracts = []
+#        structures = []
+#        rule_ids = []
+#        sorted_salary_heads = []
+#        for record in self.browse(cr, uid, ids, context=context):
+#            if record.contract_id:
+#                contracts.append(record.contract_id.id)
+#            else:
+#                contracts = self.get_contract(cr, uid, record.employee_id, record.date, context=context)
+#            for contract in contracts:
+#                structures = contract_obj.get_all_structures(cr, uid, [contract], context)
+#            res[record.id] = {}
+#            for struct in structures:
+#                rule_ids = structure_obj.get_all_rules(cr, uid, [struct], context=None)
+#                for rl in rule_ids:
+#                    if rl[0] not in rules:
+#                        rules.append(rl[0])
+#            cr.execute('''SELECT sr.id FROM hr_salary_rule as sr, hr_salary_head as sh
+#               WHERE sr.category_id = sh.id AND sr.id in %s ORDER BY sh.sequence''',(tuple(rules),))
+#            for x in cr.fetchall():
+#                sorted_salary_heads.append(x[0])
+#            for fn in field_names:
+#               if fn == 'details_by_salary_head':
+#                   res[record.id] = {fn: sorted_salary_heads}
+#        return res
+
+    _columns = {
+        'struct_id': fields.many2one('hr.payroll.structure', 'Structure', help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'),
+        'name': fields.char('Description', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'number': fields.char('Reference', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'employee_id': fields.many2one('hr.employee', 'Employee', required=True, readonly=True, states={'draft': [('readonly', False)]}),
+        'date_from': fields.date('Date From', readonly=True, states={'draft': [('readonly', False)]}, required=True),
+        'date_to': fields.date('Date To', readonly=True, states={'draft': [('readonly', False)]}, required=True),
+        'state': fields.selection([
+            ('draft', 'Waiting for Verification'),
+            ('hr_check', 'Waiting for HR Verification'),
+            ('accont_check', 'Waiting for Account Verification'),
+            ('confirm', 'Confirm Sheet'),
+            ('done', 'Paid Salary'),
+            ('cancel', 'Reject'),
+        ], 'State', select=True, readonly=True,
+            help=' * When the payslip is created the state is \'Waiting for verification\'.\
+            \n* It is varified by the user and payslip is sent for HR varification, the state is \'Waiting for HR Verification\'. \
+            \n* If HR varify the payslip, it is sent for account verification, the state is \'Waiting for Account Verification\'. \
+            \n* It is confirmed by the accountant and the state set to \'Confirm Sheet\'.\
+            \n* If the salary is paid then state is set to \'Paid Salary\'.\
+            \n* The \'Reject\' state is used when user cancel payslip.'),
+        'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'company_id': fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'input_line_ids': fields.one2many('hr.payslip.input', 'payslip_id', 'Payslip Inputs', required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'note': fields.text('Description'),
+        'contract_id': fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}),
+        'credit_note': fields.boolean('Credit Note', help="It indicates that the payslip has been refunded", readonly=True),
+       #TODO put me back
+       # 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head', multi='details_by_salary_head'),
+    }
+    _defaults = {
+        'date_from': lambda *a: time.strftime('%Y-%m-01'),
+        'date_to': lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],
+        'state': 'draft',
+        'credit_note': False,
+        'company_id': lambda self, cr, uid, context: \
+                self.pool.get('res.users').browse(cr, uid, uid,
+                    context=context).company_id.id,
+    }
+
+    def copy(self, cr, uid, id, default=None, context=None):
+        if not default:
+            default = {}
+        company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
+        default.update({
+            'line_ids': [],
+            'move_ids': [],
+            'move_line_ids': [],
+            'move_payment_ids': [],
+            'company_id': company_id,
+            'period_id': False,
+            'basic_before_leaves': 0.0,
+            'basic_amount': 0.0
+        })
+        return super(hr_payslip, self).copy(cr, uid, id, default, context=context)
+
+    def set_to_draft(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
+
+    def cancel_sheet(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
+
+    def account_check_sheet(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'accont_check'}, context=context)
+
+    def hr_check_sheet(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'hr_check'}, context=context)
+
+    def process_sheet(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'paid': True, 'state': 'done'}, context=context)
+
+    def refund_sheet(self, cr, uid, ids, context=None):
+        mod_obj = self.pool.get('ir.model.data')
+        wf_service = netsvc.LocalService("workflow")
+        for id in ids:
+            id_copy = self.copy(cr, uid, id, {'credit_note': True}, context=context)
+            self.compute_sheet(cr, uid, [id_copy], context=context)
+            wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'verify_sheet', cr)
+            wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'final_verify_sheet', cr)
+            wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'process_sheet', cr)
+
+        form_id = mod_obj.get_object_reference(cr, uid, 'hr_payroll', 'view_hr_payslip_form')
+        form_res = form_id and form_id[1] or False
+        tree_id = mod_obj.get_object_reference(cr, uid, 'hr_payroll', 'view_hr_payslip_tree')
+        tree_res = tree_id and tree_id[1] or False
+        return {
+            'name':_("Refund Payslip"),
+            'view_mode': 'tree, form',
+            'view_id': False,
+            'view_type': 'form',
+            'res_model': 'hr.payslip',
+            'type': 'ir.actions.act_window',
+            'nodestroy': True,
+            'target': 'current',
+            'domain': "[('id', 'in', %s)]" % [id_copy],
+            'views': [(tree_res, 'tree'), (form_res, 'form')],
+            'context': {}
+        }
+
+    def verify_sheet(self, cr, uid, ids, context=None):
+         #TODO clean me: this function should create the register lines accordingly to the rules computed (run the compute_sheet first)
+#        holiday_pool = self.pool.get('hr.holidays')
+#        salary_rule_pool = self.pool.get('hr.salary.rule')
+#        structure_pool = self.pool.get('hr.payroll.structure')
+#        register_line_pool = self.pool.get('hr.contibution.register.line')
+#        contracts = []
+#        structures = []
+#        rules = []
+#        lines = []
+#        sal_structures =[]
+#        for slip in self.browse(cr, uid, ids, context=context):
+#            if slip.contract_id:
+#                contracts.append(slip.contract_id)
+#            else:
+#                contracts = self.get_contract(cr, uid, slip.employee_id, slip.date, context=context)
+#            for contract in contracts:
+#                structures.append(contract.struct_id.id)
+#                leave_ids = self._get_leaves(cr, uid, slip.date, slip.employee_id, contract, context)
+#                for hday in holiday_pool.browse(cr, uid, leave_ids, context=context):
+#                    salary_rules = salary_rule_pool.search(cr, uid, [('code', '=', hday.holiday_status_id.code)], context=context)
+#                    rules +=  salary_rule_pool.browse(cr, uid, salary_rules, context=context)
+#            for structure in structures:
+#                sal_structures = self._get_parent_structure(cr, uid, [structure], context=context)
+#                for struct in sal_structures:
+#                    lines = structure_pool.browse(cr, uid, struct, context=context).rule_ids
+#                    for line in lines:
+#                        if line.child_ids:
+#                            for r in line.child_ids:
+#                                lines.append(r)
+#                        rules.append(line)
+#            base = {
+#                'basic': slip.basic_amount,
+#            }
+#            if rules:
+#                for rule in rules:
+#                    if rule.company_contribution:
+#                        base[rule.code.lower()] = rule.amount
+#                        if rule.register_id:
+#                            for slip in slip.line_ids:
+#                                if slip.category_id == rule.category_id:
+#                                    line_tot = slip.total
+#                            value = eval(rule.computational_expression, base)
+#                            company_contrib = self._compute(cr, uid, rule.id, value, employee, contract, context)
+#                            reg_line = {
+#                                'name': rule.name,
+#                                'register_id': rule.register_id.id,
+#                                'code': rule.code,
+#                                'employee_id': slip.employee_id.id,
+#                                'emp_deduction': line_tot,
+#                                'comp_deduction': company_contrib,
+#                                'total': rule.amount + line_tot
+#                            }
+#                            register_line_pool.create(cr, uid, reg_line, context=context)
+        return self.write(cr, uid, ids, {'state': 'confirm'}, context=context)
+
+    #TODO move this function into hr_contract module, on hr.employee object
+    def get_contract(self, cr, uid, employee, date_from, date_to, context=None):
+        """
+        @param employee: browse record of employee
+        @param date_from: date field
+        @param date_to: date field
+        @return: returns the ids of all the contracts for the given employee that need to be considered for the given dates
+        """
+        contract_obj = self.pool.get('hr.contract')
+        clause = []
+        #a contract is valid if it ends between the given dates
+        clause_1 = ['&',('date_end', '<=', date_to),('date_end','>=', date_from)]
+        #OR if it starts between the given dates
+        clause_2 = ['&',('date_start', '<=', date_to),('date_start','>=', date_from)]
+        #OR if it starts before the date_from and finish after the date_end (or never finish)
+        clause_3 = [('date_start','<=', date_from),'|',('date_end', '=', False),('date_end','>=', date)]
+        clause_final =  [('employee_id', '=', employee.id),'|','|'] + clause_1 + clause_2 + clause_3
+        contract_ids = contract_obj.search(cr, uid, [('employee_id', '=', employee.id),], context=context)
+        return contract_ids
+
+    def compute_sheet(self, cr, uid, ids, context=None):
+        slip_line_pool = self.pool.get('hr.payslip.line')
+        for payslip in self.browse(cr, uid, ids, context=context):
+            #delete old payslip lines
+            old_slipline_ids = slip_line_pool.search(cr, uid, [('slip_id', '=', payslip.id)], context=context)
+            old_slipline_ids
+            if old_slipline_ids:
+                slip_line_pool.unlink(cr, uid, old_slipline_ids, context=context)
+            if payslip.contract_id:
+                #set the list of contract for which the rules have to be applied
+                contract_ids = [payslip.contract_id.id]
+            else:
+                #if we don't give the contract, then the rules to apply should be for all current contracts of the employee
+                contract_ids = self.get_contract(cr, uid, payslip.employee_id, payslip.date_from, payslip.date_to, context=context)
+            lines = [(0,0,line) for line in self.pool.get('hr.payslip').get_payslip_lines(cr, uid, contract_ids, payslip.id, context=context)]
+            self.write(cr, uid, [payslip.id], {'line_ids': lines}, context=context)
+        return True
+
+    def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None):
+        """
+        @param contract_ids: list of contract id
+        @return: returns a list of dict containing the input that should be applied for the given contract between date_from and date_to
+        """
+        def was_on_leave(employee_id, datetime_day, context=None):
+            res = False
+            day = datetime_day.strftime("%Y-%m-%d")
+            holiday_ids = self.pool.get('hr.holidays').search(cr, uid, [('state','=','validate'),('employee_id','=',employee_id),('type','=','remove'),('date_from','<=',day),('date_to','>=',day)])
+            if holiday_ids:
+                res = self.pool.get('hr.holidays').browse(cr, uid, holiday_ids, context=context)[0].holiday_status_id.name
+            return res
+
+        res = []
+        for contract in self.pool.get('hr.contract').browse(cr, uid, contract_ids, context=context):
+            if not contract.working_hours:
+                #fill only if the contract as a working schedule linked
+                continue
+            attendances = {
+                 'name': _("Normal Working Days paid at 100%"),
+                 'sequence': 1,
+                 'code': 'WORK100',
+                 'number_of_days': 0.0,
+                 'number_of_hours': 0.0,
+                 'contract_id': contract.id,
+            }
+            leaves = {}
+            day_from = datetime.strptime(date_from,"%Y-%m-%d")
+            day_to = datetime.strptime(date_to,"%Y-%m-%d")
+            nb_of_days = (day_to - day_from).days + 1
+            for day in range(0, nb_of_days):
+                working_hours_on_day = self.pool.get('resource.calendar').working_hours_on_day(cr, uid, contract.working_hours, day_from + timedelta(days=day), context)
+                if working_hours_on_day:
+                    #the employee had to work
+                    leave_type = was_on_leave(contract.employee_id.id, day_from + timedelta(days=day), context=context)
+                    if leave_type:
+                        #if he was on leave, fill the leaves dict
+                        if leave_type in leaves:
+                            leaves[leave_type]['number_of_days'] += 1.0
+                            leaves[leave_type]['number_of_hours'] += working_hours_on_day
+                        else:
+                            leaves[leave_type] = {
+                                'name': leave_type,
+                                'sequence': 5,
+                                'code': leave_type,
+                                'number_of_days': 1.0,
+                                'number_of_hours': working_hours_on_day,
+                                'contract_id': contract.id,
+                            }
+                    else:
+                        #add the input vals to tmp (increment if existing)
+                        attendances['number_of_days'] += 1.0
+                        attendances['number_of_hours'] += working_hours_on_day
+            leaves = [value for key,value in leaves.items()]
+            res += [attendances] + leaves
+        return res
+
+    def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context):
+        result = []
+        payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context)
+        localdict = {'rules': {}, 'heads': {}, 'payslip': payslip}
+        #get the ids of the structures on the contracts and their parent id as well
+        structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context)
+        #get the rules of the structure and thier children
+        rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, structure_ids, context=context)
+        #run the rules by sequence
+        #import pdb;pdb.set_trace()
+        sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])]
+
+        for contract in self.pool.get('hr.contract').browse(cr, uid, contract_ids, context=context):
+            employee = contract.employee_id
+            localdict.update({'employee': employee, 'contract': contract})
+            for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context):
+                #check if the rule can be applied
+                if self.pool.get('hr.salary.rule').satisfy_condition(cr, uid, rule.id, localdict, context=context):
+                    amount = self.pool.get('hr.salary.rule').compute_rule(cr, uid, rule.id, localdict, context=context)
+                    #set/overwrite the amount computed for this rule in the localdict
+                    localdict['rules'][rule.code] = amount
+                    #sum the amount for its salary head
+                    localdict['heads'][rule.category_id.code] = rule.category_id.code in localdict['heads'] and localdict['heads'][rule.category_id.code] + amount or amount
+                    vals = {
+                        'name': rule.name,
+                        'code': rule.code,
+                        'category_id': rule.category_id.id,
+                        'sequence': rule.sequence,
+                        'appears_on_payslip': rule.appears_on_payslip,
+                        'condition_select': rule.condition_select,
+                        'condition_python': rule.condition_python,
+                        'condition_range': rule.condition_range,
+                        'condition_range_min': rule.condition_range_min,
+                        'condition_range_max': rule.condition_range_max,
+                        'amount_select': rule.amount_select,
+                        'amount_fix': rule.amount_fix,
+                        'amount_python_compute': rule.amount_python_compute,
+                        'amount_percentage': rule.amount_percentage,
+                        'amount_percentage_base': rule.amount_percentage_base,
+                        'register_id': rule.register_id.id,
+                        'total': amount,
+                        'employee_id': contract.employee_id.id,
+                    }
+                    result.append(vals)
+        return result
+
+    def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None):
+        empolyee_obj = self.pool.get('hr.employee')
+        contract_obj = self.pool.get('hr.contract')
+        input_obj = self.pool.get('hr.payslip.input')
+
+        if context is None:
+            context = {}
+        #delete old input lines
+        old_input_ids = ids and input_obj.search(cr, uid, [('payslip_id', '=', ids[0])], context=context) or False
+        if old_input_ids:
+            input_obj.unlink(cr, uid, old_input_ids, context=context)
+
+        #defaults
+        res = {'value':{
+                      'line_ids':[],
+                      #'details_by_salary_head':[], TODO put me back
+                      'name':'',
+                      'contract_id': False,
+                      'struct_id': False,
+                      }
+                 }
+        if not employee_id:
+            return res
+        ttyme = datetime.fromtimestamp(time.mktime(time.strptime(date_from, "%Y-%m-%d")))
+        employee_id = empolyee_obj.browse(cr, uid, employee_id, context=context)
+        res['value'].update({
+                           'name': _('Salary Slip of %s for %s') % (employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
+                           'company_id': employee_id.company_id.id
+                           })
+
+        if not context.get('contract', False):
+            #fill with the first contract of the employee
+            contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
+            res['value'].update({
+                    'struct_id': contract_ids and contract_obj.read(cr, uid, contract_ids[0], ['struct_id'], context=context)['struct_id'][0] or False,
+                    'contract_id': contract_ids and contract_ids[0] or False,
+            })
+        else:
+            if contract_id:
+                #set the list of contract for which the input have to be filled
+                contract_ids = [contract_id]
+                #fill the structure with the one on the selected contract
+                contract_record = contract_obj.browse(cr, uid, contract_id, context=context)
+                res['value'].update({'struct_id': contract_record.struct_id.id, 'contract_id': contract_id})
+            else:
+                #if we don't give the contract, then the input to fill should be for all current contracts of the employee
+                contract_ids = self.get_contract(cr, uid, employee_id, date_from, date_to, context=context)
+                if not contract_ids:
+                    return res
+
+        #computation of the salary input
+        input_line_ids = self.get_input_lines(cr, uid, contract_ids, date_from, date_to, context=context)
+        res['value'].update({
+                    'input_line_ids': input_line_ids,
+            })
+        return res
+
+    def onchange_contract_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None):
+        if context is None:
+            context = {}
+        res = {'value':{
+                 'line_ids': [],
+                 'name': '',
+                 }
+              }
+        context.update({'contract': True})
+        if not contract_id:
+            res['value'].update({'struct_id': False})
+        return self.onchange_employee_id(cr, uid, ids, date_from=date_from, date_to=date_to, employee_id=employee_id, contract_id=contract_id, context=context)
+
+hr_payslip()
+
+class hr_payslip_input(osv.osv):
+    '''
+    Payslip Input
+    '''
+
+    _name = 'hr.payslip.input'
+    _description = 'Payslip Input'
+    _columns = {
+        'name': fields.char('Description', size=256, required=True),
+        'payslip_id': fields.many2one('hr.payslip', 'Pay Slip', required=True),
+        'sequence': fields.integer('Sequence', required=True,),
+        'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"),
+        'number_of_days': fields.float('Number of Days'),
+        'number_of_hours': fields.float('Number of Hours'),
+        'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"),
+    }
+    _order = 'payslip_id,sequence'
+    _defaults = {
+        'sequence': 10,
+    }
+hr_payslip_input()
+
+class hr_salary_rule(osv.osv):
+
+    _name = 'hr.salary.rule'
     _columns = {
         'name':fields.char('Name', size=256, required=True, readonly=False),
-        'register_id':fields.many2one('hr.contibution.register', 'Register', required=False),
-        'code':fields.char('Code', size=64, required=False, readonly=False),
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
-        'date': fields.date('Date'),
-        'emp_deduction': fields.float('Employee Deduction', digits=(16, 4)),
-        'comp_deduction': fields.float('Company Deduction', digits=(16, 4)),
-        'total': fields.function(_total, method=True, store=True,  string='Total', digits=(16, 4)),
-    }
-    _defaults = {
-        'date': lambda *a: time.strftime('%Y-%m-%d'),
-    }
-contrib_register_line()
-
-class payment_category(osv.osv):
-    """
-    Allowance, Deduction Heads
-    House Rent Allowance, Medical Allowance, Food Allowance
-    Professional Tax, Advance TDS, Providend Funds, etc
-    """
-
-    _name = 'hr.allounce.deduction.categoty'
-    _description = 'Allowance Deduction Heads'
-    _columns = {
-        'name':fields.char('Category Name', size=64, required=True, readonly=False),
-        'code':fields.char('Category Code', size=64, required=True, readonly=False),
-        'type':fields.selection([
-            ('allowance','Allowance'),
-            ('deduction','Deduction'),
-            ('leaves','Leaves'),
-            ('advance','Advance'),
-            ('loan','Loan'),
-            ('installment','Loan Installment'),
-            ('otherpay','Other Payment'),
-            ('otherdeduct','Other Deduction'),
-        ],'Type', select=True, required=True),
-        'base':fields.text('Based on', required=True, readonly=False, help='This will use to computer the % fields values, in general its on basic, but You can use all heads code field in small letter as a variable name i.e. hra, ma, lta, etc...., also you can use, static varible basic'),
-        'condition':fields.char('Condition', size=1024, required=True, readonly=False, help='Applied this head for calculation if condition is true'),
+        'code':fields.char('Code', size=64, required=True),
         'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'),
-        'note': fields.text('Description'),
-        'user_id':fields.char('User', size=64, required=False, readonly=False),
-        'state':fields.char('Label', size=64, required=False, readonly=False),
+        'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True),
+        'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."),
+        'appears_on_payslip': fields.boolean('Appears on Payslip', help="Used for the display of rule on payslip"),
+        'parent_rule_id':fields.many2one('hr.salary.rule', 'Parent Salary Rule', select=True),
         'company_id':fields.many2one('res.company', 'Company', required=False),
-        'contribute_ids':fields.one2many('company.contribution', 'category_id', 'Contributions', required=False),
-    }
-    _defaults = {
-        'condition': lambda *a: 'True',
-        'base': lambda *a:'basic',
-        'sequence': lambda *a:5,
-        'company_id': lambda self, cr, uid, context: \
-                self.pool.get('res.users').browse(cr, uid, uid,
-                    context=context).company_id.id,
-    }
-payment_category()
-
-class company_contribution(osv.osv):
-    """
-    Company contribution
-    Allows to configure company contribution for some taxes
-    """
-
-    _name = 'company.contribution'
-    _description = "Company Contribution"
-    _columns = {
-        'category_id':fields.many2one('hr.allounce.deduction.categoty', 'Heads', required=False),
-        'name':fields.char('Name', size=256, required=True, readonly=False),
-        'code':fields.char('Code', size=64, required=True, readonly=False),
-        'gratuity':fields.boolean('Use for Gratuity ?', required=False),
-        'line_ids':fields.one2many('company.contribution.line', 'contribution_id', 'Calculations', required=False),
+        'condition_select': fields.selection([('none', 'Always True'),('range', 'Range'), ('python', 'Python Expression')], "Condition Based on", required=True),
+        'condition_range':fields.char('Range Based on',size=1024, readonly=False, help='This will use to computer the % fields values, in general its on basic, but You can use all heads code field in small letter as a variable name i.e. hra, ma, lta, etc...., also you can use, static varible basic'),#old name = conputional expression
+        'condition_python':fields.text('Python Condition', required=True, readonly=False, help='Applied this rule for calculation if condition is true. You can specify condition like basic > 1000.'),#old name = conditions
+        'condition_range_min': fields.float('Minimum Range', required=False, help="The minimum amount, applied for this rule."),
+        'condition_range_max': fields.float('Maximum Range', required=False, help="The maximum amount, applied for this rule."),
+        'amount_select':fields.selection([
+            ('percentage','Percentage (%)'),
+            ('fix','Fixed Amount'),
+            ('code','Python Code'),
+        ],'Amount Type', select=True, required=True, help="The computation method for the rule amount."),
+        'amount_fix': fields.float('Fixed Amount', digits_compute=dp.get_precision('Account'),),
+        'amount_percentage': fields.float('Percentage (%)', digits_compute=dp.get_precision('Account'), help='For example, enter 50.0 to apply a percentage of 50%'),
+        'amount_python_compute':fields.text('Python Code'),
+        'amount_percentage_base':fields.char('Percentage based on',size=1024, required=False, readonly=False, help='result will be affected to a variable'), #old name = expressiont
+        'child_ids':fields.one2many('hr.salary.rule', 'parent_rule_id', 'Child Salary Rule'),
         'register_id':fields.property(
             'hr.contibution.register',
             type='many2one',
@@ -716,563 +653,80 @@
             help="Contribution register based on company",
             required=False
         ),
-        'amount_type':fields.selection([
-            ('fix','Fixed Amount'),
-            ('per','Percentage'),
-            ('func','Function Calculation'),
-        ],'Amount Type', select=True),
-        'contribute_per':fields.float('Contribution', digits=(16, 4), help='Define Company contribution ratio 1.00=100% contribution.'),
-        'company_id':fields.many2one('res.company', 'Company', required=False),
-        'active':fields.boolean('Active', required=False),
-        'note': fields.text('Description'),
-    }
-
+        'note':fields.text('Description'),
+     }
     _defaults = {
-        'amount_type': lambda *a:'fix',
-        'active': lambda *a:True,
+        'amount_python_compute': '''
+# Available variables:
+#----------------------
+# payslip: hr.payslip object
+# employee: hr.employee object
+# contract: hr.contract object
+# rules: dictionary containing the previsouly computed rules. Keys are the rule codes.
+# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
+
+# Note: returned value have to be set in the variable 'result'
+
+result = contract.wage * 0.10''',
+        'condition_python':
+'''
+# Available variables:
+#----------------------
+# payslip: hr.payslip object
+# employee: hr.employee object
+# contract: hr.contract object
+# rules: dictionary containing the previsouly computed rules. Keys are the rule codes.
+# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
+
+# Note: returned value have to be set in the variable 'result'
+
+result = rules['NET'] > heads['NET'] * 0.10''',
+        'condition_range': 'contract.wage',
+        'sequence': 5,
+        'appears_on_payslip': True,
+        'active': True,
         'company_id': lambda self, cr, uid, context: \
                 self.pool.get('res.users').browse(cr, uid, uid,
                     context=context).company_id.id,
-    }
+        'condition_select': 'none',
+        'amount_select': 'fix',
+        'amount_fix': 0.0,
+        'amount_percentage': 0.0,
+     }
 
-    def _execute_function(self, cr, uid, id, value, context=None):
-        """
-        self: pointer to self object
-        cr: cursor to database
-        uid: user id of current executer
-        """
-        line_pool = self.pool.get('company.contribution.line')
-        res = 0
-        ids = line_pool.search(cr, uid, [('category_id','=',id), ('to_val','>=',value),('from_val','<=',value)], context=context)
-        if not ids:
-            ids = line_pool.search(cr, uid, [('category_id','=',id), ('from','<=',value)], context=context)
-        if not ids:
-            res = 0
+    #TODO should add some checks on the type of result (should be float)
+    def compute_rule(self, cr, uid, rule_id, localdict, context=None):
+        """
+        @param rule_id: id of rule to compute
+        @param localdict: dictionary containing the environement in which to compute the rule
+        @return: returns the result of computation as float
+        """
+        rule = self.browse(cr, uid, rule_id, context=context)
+        if rule.amount_select == 'fix':
+            return rule.amount_fix
+        elif rule.amount_select == 'percentage':
+            return rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100
         else:
-            res = line_pool.browse(cr, uid, ids, context=context)[0].value
-        return res
-
-    def compute(self, cr, uid, id, value, context=None):
-        contrib = self.browse(cr, uid, id, context=context)
-        if contrib.amount_type == 'fix':
-            return contrib.contribute_per
-        elif contrib.amount_type == 'per':
-            return value * contrib.contribute_per
-        elif contrib.amount_type == 'func':
-            return self._execute_function(cr, uid, id, value, context)
-        return 0.0
-company_contribution()
-
-class company_contribution_line(osv.osv):
-    """
-    Company contribution lines
-    """
-
-    _name = 'company.contribution.line'
-    _description = 'Allowance Deduction Category'
-    _order = 'sequence'
-    _columns = {
-        'contribution_id':fields.many2one('company.contribution', 'Contribution', required=False),
-        'name':fields.char('Name', size=64, required=False, readonly=False),
-        'from_val': fields.float('From', digits=(16, 4)),
-        'to_val': fields.float('To', digits=(16, 4)),
-        'amount_type':fields.selection([
-            ('fix','Fixed Amount'),
-        ],'Amount Type', select=True),
-        'sequence':fields.integer('Sequence'),
-        'value': fields.float('Value', digits=(16, 4)),
-    }
-company_contribution_line()
-
-class hr_holidays_status(osv.osv):
-
-    _inherit = "hr.holidays.status"
-    _columns = {
-        'company_id':fields.many2one('res.company', 'Company', required=False),
-        'type':fields.selection([
-            ('paid','Paid Holiday'),
-            ('unpaid','Un-Paid Holiday'),
-            ('halfpaid','Half-Pay Holiday')
-            ], string='Payment'),
-        'head_id': fields.many2one('hr.allounce.deduction.categoty', 'Payroll Head', domain=[('type','=','deduction')]),
-        'code': fields.related('head_id','code', type='char', relation='hr.allounce.deduction.categoty', string='Code'),
-#        'code':fields.char('Code', size=64, required=False, readonly=False),
-    }
-    _defaults = {
-        'type': lambda *args: 'unpaid',
-        'company_id': lambda self, cr, uid, context: \
-                self.pool.get('res.users').browse(cr, uid, uid,
-                    context=context).company_id.id,
-    }
-hr_holidays_status()
-
-class hr_payslip(osv.osv):
-    '''
-    Pay Slip
-    '''
-
-    _name = 'hr.payslip'
-    _description = 'Pay Slip'
-
-    def _calculate(self, cr, uid, ids, field_names, arg, context=None):
-        slip_line_obj = self.pool.get('hr.payslip.line')
-        res = {}
-        for rs in self.browse(cr, uid, ids, context=context):
-            allow = 0.0
-            deduct = 0.0
-            others = 0.0
-            obj = {'basic':rs.basic}
-            if rs.igross > 0:
-                obj['gross'] = rs.igross
-            if rs.inet > 0:
-                obj['net'] = rs.inet
-            for line in rs.line_ids:
-                amount = 0.0
-                if line.amount_type == 'per':
-                    try:
-                        amount = line.amount * eval(str(line.category_id.base), obj)
-                    except Exception, e:
-                        raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-                elif line.amount_type in ('fix', 'func'):
-                    amount = line.amount
-                cd = line.category_id.code.lower()
-                obj[cd] = amount
-                contrib = 0.0
-                if line.type == 'allowance':
-                    allow += amount
-                    others += contrib
-                    amount -= contrib
-                elif line.type == 'deduction':
-                    deduct += amount
-                    others -= contrib
-                    amount += contrib
-                elif line.type == 'advance':
-                    others += amount
-                elif line.type == 'loan':
-                    others += amount
-                elif line.type == 'otherpay':
-                    others += amount
-                slip_line_obj.write(cr, uid, [line.id], {'total':amount}, context=context)
-
-            record = {
-                'allounce':allow,
-                'deduction':deduct,
-                'grows':rs.basic + allow,
-                'net':rs.basic + allow - deduct,
-                'other_pay':others,
-                'total_pay':rs.basic + allow - deduct
-            }
-            res[rs.id] = record
-        return res
-
-    _columns = {
-        'deg_id':fields.many2one('hr.payroll.structure', 'Designation', readonly=True, states={'draft': [('readonly', False)]}),
-        'register_id':fields.many2one('hr.payroll.register', 'Register', required=False, readonly=True, states={'new': [('readonly', False)]}),
-        'name':fields.char('Name', size=64, required=False, readonly=True, states={'new': [('readonly', False)]}),
-        'number':fields.char('Number', size=64, required=False, readonly=True),
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=True, readonly=True, states={'new': [('readonly', False)]}),
-        'date': fields.date('Date', readonly=True, states={'new': [('readonly', False)]}),
-        'state':fields.selection([
-            ('new','New Slip'),
-            ('draft','Wating for Verification'),
-            ('hr_check','Wating for HR Verification'),
-            ('accont_check','Wating for Account Verification'),
-            ('confirm','Confirm Sheet'),
-            ('done','Paid Salary'),
-            ('cancel','Reject'),
-        ],'State', select=True, readonly=True),
-        'basic_before_leaves': fields.float('Basic Salary', readonly=True,  digits_compute=dp.get_precision('Account')),
-        'leaves': fields.float('Leave Deductions', readonly=True,  digits_compute=dp.get_precision('Account')),
-        'basic': fields.float('Net Basic', readonly=True,  digits_compute=dp.get_precision('Account')),
-        'grows': fields.function(_calculate, method=True, store=True, multi='dc', string='Gross Salary', digits_compute=dp.get_precision('Account')),
-        'net': fields.function(_calculate, method=True, store=True, multi='dc', string='Net Salary', digits_compute=dp.get_precision('Account')),
-        'allounce': fields.function(_calculate, method=True, store=True, multi='dc', string='Allowance', digits_compute=dp.get_precision('Account')),
-        'deduction': fields.function(_calculate, method=True, store=True, multi='dc', string='Deduction', digits_compute=dp.get_precision('Account')),
-        'other_pay': fields.function(_calculate, method=True, store=True, multi='dc', string='Others', digits_compute=dp.get_precision('Account')),
-        'total_pay': fields.function(_calculate, method=True, store=True, multi='dc', string='Total Payment', digits_compute=dp.get_precision('Account')),
-        'line_ids':fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'company_id':fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'holiday_days': fields.float('No of Leaves', readonly=True),
-        'worked_days': fields.float('Worked Day', readonly=True),
-        'working_days': fields.float('Working Days', readonly=True),
-        'paid':fields.boolean('Paid ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'note':fields.text('Description'),
-        'contract_id':fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'igross': fields.float('Calculaton Field', readonly=True,  digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"),
-        'inet': fields.float('Calculaton Field', readonly=True,  digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"),
-    }
-    _defaults = {
-        'date': lambda *a: time.strftime('%Y-%m-%d'),
-        'state': lambda *a: 'new',
-        'company_id': lambda self, cr, uid, context: \
-                self.pool.get('res.users').browse(cr, uid, uid,
-                    context=context).company_id.id,
-    }
-
-    def copy(self, cr, uid, id, default=None, context=None):
-        company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
-        default = {
-            'line_ids': False,
-            'move_ids': False,
-            'move_line_ids': False,
-            'move_payment_ids': False,
-            'company_id':company_id,
-            'period_id': False,
-            'basic_before_leaves':0,
-            'basic':0
-        }
-        res_id = super(hr_payslip, self).copy(cr, uid, id, default, context=context)
-        return res_id
-
-    def create_voucher(self, cr, uid, ids, name, voucher, sequence=5):
-        slip_move = self.pool.get('hr.payslip.account.move')
-        for slip in ids:
-            res = {
-                'slip_id':slip,
-                'move_id':voucher,
-                'sequence':sequence,
-                'name':name
-            }
-            slip_move.create(cr, uid, res)
-
-    def set_to_draft(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'draft'}, context=context)
-        return True
-
-    def cancel_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'cancel'}, context=context)
-        return True
-
-    def account_check_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'accont_check'}, context=context)
-        return True
-
-    def hr_check_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'state':'hr_check'}, context=context)
-        return True
-
-    def process_sheet(self, cr, uid, ids, context=None):
-        self.write(cr, uid, ids, {'paid':True, 'state':'done'}, context=context)
-        return True
-
-    def verify_sheet(self, cr, uid, ids, context=None):
-        register_pool = self.pool.get('company.contribution')
-        register_line_pool = self.pool.get('hr.contibution.register.line')
-
-        for slip in self.browse(cr, uid, ids, context=context):
-            base = {
-                'basic':slip.basic,
-                'net':slip.net,
-                'gross':slip.grows,
-            }
-            for line in slip.line_ids:
-                base[line.code.lower()] = line.total
-                for contrib in line.category_id.contribute_ids:
-                    if contrib.register_id:
-                        value = eval(line.category_id.base, base)
-                        company_contrib = register_pool.compute(cr, uid, contrib.id, value, context)
-                        reg_line = {
-                            'name':line.name,
-                            'register_id': contrib.register_id.id,
-                            'code':line.code,
-                            'employee_id':slip.employee_id.id,
-                            'emp_deduction':line.total,
-                            'comp_deduction':company_contrib,
-                            'total':line.total + line.total
-                        }
-                        register_line_pool.create(cr, uid, reg_line)
-
-        self.write(cr, uid, ids, {'state':'confirm'}, context=context)
-        return True
-
-    def get_contract(self, cr, uid, employee, date, context=None):
-        sql_req= '''
-            SELECT c.id as id, c.wage as wage, struct_id as function
-            FROM hr_contract c
-              LEFT JOIN hr_employee emp on (c.employee_id=emp.id)
-              LEFT JOIN hr_contract_wage_type cwt on (cwt.id = c.wage_type_id)
-              LEFT JOIN hr_contract_wage_type_period p on (cwt.period_id = p.id)
-            WHERE
-              (emp.id=%s) AND
-              (date_start <= %s) AND
-              (date_end IS NULL OR date_end >= %s)
-            LIMIT 1
-            '''
-        cr.execute(sql_req, (employee.id, date, date))
-        contract = cr.dictfetchone()
-
-        contract = contract and contract or {}
-        return contract
-
-    def _get_leaves(self, cr, user, slip, employee, context=None):
-        """
-        Compute leaves for an employee
-
-        @param cr: cursor to database
-        @param user: id of current user
-        @param slip: object of the hr.payroll.slip model
-        @param employee: object of the hr.employee model
-        @param context: context arguments, like lang, time zone
-
-        @return: return a result
-        """
-        result = []
-
-        dates = prev_bounds(slip.date)
-        sql = '''select id from hr_holidays
-                    where date_from >= '%s' and date_to <= '%s'
-                    and employee_id = %s
-                    and state = 'validate' ''' % (dates[0], dates[1], slip.employee_id.id)
-        cr.execute(sql)
-        res = cr.fetchall()
-
-        if res:
-            result = [x[0] for x in res]
-
-        return result
-
-    def compute_sheet(self, cr, uid, ids, context=None):
-        func_pool = self.pool.get('hr.payroll.structure')
-        slip_line_pool = self.pool.get('hr.payslip.line')
-        holiday_pool = self.pool.get('hr.holidays')
-        sequence_obj = self.pool.get('ir.sequence')
-        if context is None:
-            context = {}
-        date = self.read(cr, uid, ids, ['date'], context=context)[0]['date']
-
-        #Check for the Holidays
-        def get_days(start, end, month, year, calc_day):
-            import datetime
-            count = 0
-            for day in range(start, end):
-                if datetime.date(year, month, day).weekday() == calc_day:
-                    count += 1
-            return count
-
-        for slip in self.browse(cr, uid, ids, context=context):
-            old_slip_ids = slip_line_pool.search(cr, uid, [('slip_id','=',slip.id)], context=context)
-            slip_line_pool.unlink(cr, uid, old_slip_ids, context=context)
-            update = {}
-            ttyme = datetime.fromtimestamp(time.mktime(time.strptime(slip.date,"%Y-%m-%d")))
-            contracts = self.get_contract(cr, uid, slip.employee_id, date, context)
-            if contracts.get('id', False) == False:
-                update.update({
-                    'basic': round(0.0),
-                    'basic_before_leaves': round(0.0),
-                    'name':'Salary Slip of %s for %s' % (slip.employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
-                    'state':'draft',
-                    'contract_id':False,
-                    'company_id':slip.employee_id.company_id.id
-                })
-                self.write(cr, uid, [slip.id], update, context=context)
-                continue
-
-            contract = slip.employee_id.contract_id
-            sal_type = contract.wage_type_id.type
-            function = contract.struct_id.id
-            lines = []
-            if function:
-                func = func_pool.read(cr, uid, function, ['line_ids'], context=context)
-                lines = slip_line_pool.browse(cr, uid, func['line_ids'], context=context)
-
-            #lines += slip.employee_id.line_ids
-
-            ad = []
-            all_per = 0.0
-            ded_per = 0.0
-            all_fix = 0.0
-            ded_fix = 0.0
-
-            obj = {'basic':0.0}
-            if contract.wage_type_id.type == 'gross':
-                obj['gross'] = contract.wage
-                update['igross'] = contract.wage
-            if contract.wage_type_id.type == 'net':
-                obj['net'] = contract.wage
-                update['inet'] = contract.wage
-            if contract.wage_type_id.type == 'basic':
-                obj['basic'] = contract.wage
-                update['basic'] = contract.wage
-
-            for line in lines:
-                cd = line.code.lower()
-                obj[cd] = line.amount or 0.0
-
-            for line in lines:
-                if line.category_id.code in ad:
-                    continue
-                ad.append(line.category_id.code)
-                cd = line.category_id.code.lower()
-                calculate = False
-                try:
-                    exp = line.category_id.condition
-                    calculate = eval(exp, obj)
-                except Exception, e:
-                    raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-
-                if not calculate:
-                    continue
-
-                percent = 0.0
-                value = 0.0
-                base = False
-#                company_contrib = 0.0
-                base = line.category_id.base
-
-                try:
-                    #Please have a look at the configuration guide.
-                    amt = eval(base, obj)
-                except Exception, e:
-                    raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-
-                if sal_type in ('gross', 'net'):
-                    if line.amount_type == 'per':
-                        percent = line.amount
-                        if amt > 1:
-                            value = percent * amt
-                        elif amt > 0 and amt <= 1:
-                            percent = percent * amt
-                        if value > 0:
-                            percent = 0.0
-                    elif line.amount_type == 'fix':
-                        value = line.amount
-                    elif line.amount_type == 'func':
-                        value = slip_line_pool.execute_function(cr, uid, line.id, amt, context)
-                        line.amount = value
-                else:
-                    if line.amount_type in ('fix', 'per'):
-                        value = line.amount
-                    elif line.amount_type == 'func':
-                        value = slip_line_pool.execute_function(cr, uid, line.id, amt, context)
-                        line.amount = value
-                if line.type == 'allowance':
-                    all_per += percent
-                    all_fix += value
-                elif line.type == 'deduction':
-                    ded_per += percent
-                    ded_fix += value
-                vals = {
-                    'amount':line.amount,
-                    'slip_id':slip.id,
-                    'employee_id':False,
-                    'function_id':False,
-                    'base':base
-                }
-                slip_line_pool.copy(cr, uid, line.id, vals, {})
-            if sal_type in ('gross', 'net'):
-                sal = contract.wage
-                if sal_type == 'net':
-                    sal += ded_fix
-                sal -= all_fix
-                per = 0.0
-                if sal_type == 'net':
-                    per = (all_per - ded_per)
-                else:
-                    per = all_per
-                if per <=0:
-                    per *= -1
-                final = (per * 100) + 100
-                basic = (sal * 100) / final
-            else:
-                basic = contract.wage
-
-            number = sequence_obj.get(cr, uid, 'salary.slip')
-            update.update({
-                'deg_id':function,
-                'number':number,
-                'basic': round(basic),
-                'basic_before_leaves': round(basic),
-                'name':'Salary Slip of %s for %s' % (slip.employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
-                'state':'draft',
-                'contract_id':contract.id,
-                'company_id':slip.employee_id.company_id.id
-            })
-
-            for line in slip.employee_id.line_ids:
-                vals = {
-                    'amount':line.amount,
-                    'slip_id':slip.id,
-                    'employee_id':False,
-                    'function_id':False,
-                    'base':base
-                }
-                slip_line_pool.copy(cr, uid, line.id, vals, {})
-
-            self.write(cr, uid, [slip.id], update, context=context)
-
-        for slip in self.browse(cr, uid, ids, context=context):
-            if not slip.contract_id:
-                continue
-
-            basic_before_leaves = slip.basic
-            working_day = 0
-            off_days = 0
-            dates = prev_bounds(slip.date)
-
-            days_arr = [0, 1, 2, 3, 4, 5, 6]
-            for dy in range(slip.employee_id.contract_id.working_days_per_week, 7):
-                off_days += get_days(1, dates[1].day, dates[1].month, dates[1].year, days_arr[dy])
-            total_off = off_days
-            working_day = dates[1].day - total_off
-            perday = slip.net / working_day
-            total = 0.0
-            leave = 0.0
-            leave_ids = self._get_leaves(cr, uid, slip, slip.employee_id, context)
-            total_leave = 0.0
-            paid_leave = 0.0
-            for hday in holiday_pool.browse(cr, uid, leave_ids, context=context):
-                if not hday.holiday_status_id.head_id:
-                    raise osv.except_osv(_('Error !'), _('Please check configuration of %s, payroll head is missing') % (hday.holiday_status_id.name))
-
-                res = {
-                    'slip_id':slip.id,
-                    'name':hday.holiday_status_id.name + '-%s' % (hday.number_of_days),
-                    'code':hday.holiday_status_id.code,
-                    'amount_type':'fix',
-                    'category_id':hday.holiday_status_id.head_id.id,
-                    'sequence':hday.holiday_status_id.head_id.sequence
-                }
-                days = hday.number_of_days
-                if hday.number_of_days < 0:
-                    days = hday.number_of_days * -1
-                total_leave += days
-                if hday.holiday_status_id.type == 'paid':
-                    paid_leave += days
-                    continue
-#                    res['name'] = hday.holiday_status_id.name + '-%s' % (days)
-#                    res['amount'] = perday * days
-#                    res['type'] = 'allowance'
-#                    leave += days
-#                    total += perday * days
-
-                elif hday.holiday_status_id.type == 'halfpaid':
-                    paid_leave += (days / 2)
-                    res['name'] = hday.holiday_status_id.name + '-%s/2' % (days)
-                    res['amount'] = perday * (days/2)
-                    total += perday * (days/2)
-                    leave += days / 2
-                    res['type'] = 'deduction'
-                else:
-                    res['name'] = hday.holiday_status_id.name + '-%s' % (days)
-                    res['amount'] = perday * days
-                    res['type'] = 'deduction'
-                    leave += days
-                    total += perday * days
-
-                slip_line_pool.create(cr, uid, res, context=context)
-            basic = basic - total
-#            leaves = total
-            update.update({
-                'basic':basic,
-                'basic_before_leaves': round(basic_before_leaves),
-                'leaves':total,
-                'holiday_days':leave,
-                'worked_days':working_day - leave,
-                'working_days':working_day,
-            })
-            self.write(cr, uid, [slip.id], update, context=context)
-        return True
-hr_payslip()
+            eval(rule.amount_python_compute, localdict, mode='exec', nocopy=True)
+            return localdict['result']
+
+    def satisfy_condition(self, cr, uid, rule_id, localdict, context=None):
+        """
+        @param rule_id: id of hr.salary.rule to be tested
+        @param contract_id: id of hr.contract to be tested
+        @return: returns True if the given rule match the condition for the given contract. Return False otherwise.
+        """
+        rule = self.browse(cr, uid, rule_id, context=context)
+
+        if rule.condition_select == 'none':
+            return True
+        elif rule.condition_select == 'range':
+            result = eval(rule.condition_range, localdict)
+            return rule.condition_range_min <=  result and result <= rule.condition_range_max or False
+        else: #python code
+            eval(rule.condition_python, localdict, mode='exec', nocopy=True)
+            return 'result' in localdict and localdict['result'] or False
+hr_salary_rule()
 
 class hr_payslip_line(osv.osv):
     '''
@@ -1280,99 +734,27 @@
     '''
 
     _name = 'hr.payslip.line'
+    _inherit = 'hr.salary.rule'
     _description = 'Payslip Line'
-
-    def onchange_category(self, cr, uid, ids, category_id):
-        res = {
-        }
-        if category_id:
-            category = self.pool.get('hr.allounce.deduction.categoty').browse(cr, uid, category_id)
-            res.update({
-                'sequence':category.sequence,
-                'name':category.name,
-                'code':category.code,
-                'type':category.type
-            })
-        return {'value':res}
-
-    def onchange_amount(self, cr, uid, ids, amount, typ):
-        amt = amount
-        if typ and typ == 'per':
-            if int(amt) > 0:
-                amt = amt / 100
-        return {'value':{'amount':amt}}
+    _order = 'sequence'
 
     _columns = {
-        'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=False),
-        'function_id':fields.many2one('hr.payroll.structure', 'Function', required=False),
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=False),
-        'name':fields.char('Name', size=256, required=True, readonly=False),
-        'base':fields.char('Formula', size=1024, required=False, readonly=False),
-        'code':fields.char('Code', size=64, required=False, readonly=False),
-        'category_id':fields.many2one('hr.allounce.deduction.categoty', 'Category', required=True),
-        'type':fields.selection([
-            ('allowance','Allowance'),
-            ('deduction','Deduction'),
-            ('leaves','Leaves'),
-            ('advance','Advance'),
-            ('loan','Loan'),
-            ('installment','Loan Installment'),
-            ('otherpay','Other Payment'),
-            ('otherdeduct','Other Deduction'),
-        ],'Type', select=True, required=True),
-        #TODO: link type to the category_id instead of define again
-        #'type': fields.related('category_id','type', type='selection', size=64, relation='hr.allounce.deduction.categoty', string='Type', store=True),
-        'amount_type':fields.selection([
-            ('per','Percentage (%)'),
-            ('fix','Fixed Amount'),
-            ('func','Function Value'),
-        ],'Amount Type', select=True, required=True),
-        'amount': fields.float('Amount / Percentage', digits=(16, 4)),
-        'total': fields.float('Sub Total', readonly=True, digits_compute=dp.get_precision('Account')),
-        'company_contrib': fields.float('Company Contribution', readonly=True, digits=(16, 4)),
-        'sequence': fields.integer('Sequence'),
-        'note':fields.text('Description'),
-        'line_ids':fields.one2many('hr.payslip.line.line', 'slipline_id', 'Calculations', required=False)
-    }
-    _order = 'sequence'
-    _defaults = {
-        'amount_type': lambda *a: 'per'
-    }
-
-    def execute_function(self, cr, uid, id, value, context=None):
-        line_pool = self.pool.get('hr.payslip.line.line')
-        res = 0
-        ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value), ('to_val','>=',value)], context=context)
-        if not ids:
-            ids = line_pool.search(cr, uid, [('slipline_id','=',id), ('from_val','<=',value)], context=context)
-        if not ids:
-            return res
-
-        res = line_pool.browse(cr, uid, ids, context=context)[-1].value
-        return res
+        'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=True),
+        'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
+        'total': fields.float('Amount', digits_compute=dp.get_precision('Account')),
+        'company_contrib': fields.float('Company Contribution', readonly=True, digits_compute=dp.get_precision('Account')),
+    }
 
 hr_payslip_line()
 
-class hr_payslip_line_line(osv.osv):
-    '''
-    Function Line
-    '''
+class hr_payroll_structure(osv.osv):
 
-    _name = 'hr.payslip.line.line'
-    _description = 'Function Line'
-    _order = 'sequence'
+    _inherit = 'hr.payroll.structure'
     _columns = {
-        'slipline_id':fields.many2one('hr.payslip.line', 'Slip Line', required=False),
-        'name':fields.char('Name', size=64, required=False, readonly=False),
-        'from_val': fields.float('From', digits=(16, 4)),
-        'to_val': fields.float('To', digits=(16, 4)),
-        'amount_type':fields.selection([
-            ('fix','Fixed Amount'),
-        ],'Amount Type', select=True),
-        'sequence':fields.integer('Sequence'),
-        'value': fields.float('Value', digits=(16, 4)),
+        'rule_ids':fields.many2many('hr.salary.rule', 'hr_structure_salary_rule_rel', 'struct_id', 'rule_id', 'Salary Rules'),
     }
-hr_payslip_line_line()
+
+hr_payroll_structure()
 
 class hr_employee(osv.osv):
     '''
@@ -1382,66 +764,29 @@
     _inherit = 'hr.employee'
     _description = 'Employee'
 
-    def _calculate_salary(self, cr, uid, ids, field_names, arg, context=None):
-        vals = {}
-        slip_line_pool = self.pool.get('hr.payslip.line')
-
+    def _calculate_total_wage(self, cr, uid, ids, name, args, context):
+        if not ids: return {}
+        res = {}
+        current_date = datetime.now().strftime('%Y-%m-%d')
         for employee in self.browse(cr, uid, ids, context=context):
-            if not employee.contract_id:
-                vals[employee.id] = {'basic':0.0, 'gross':0.0, 'net':0.0, 'advantages_gross':0.0, 'advantages_net':0.0}
+            if not employee.contract_ids:
+                res[employee.id] = {'basic': 0.0}
                 continue
-
-            basic = employee.contract_id.basic
-            gross = employee.contract_id.gross
-            net = employee.contract_id.net
-            allowance = employee.contract_id.advantages_gross
-            deduction = employee.contract_id.advantages_net
-
-            obj = {
-                'basic':basic,
-                'gross':gross,
-                'net':net
-            }
-            for line in employee.line_ids:
-                base = line.category_id.base
-                try:
-                    amt = eval(base, obj)
-                except Exception, e:
-                    raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
-                amount = 0.0
-                if line.amount_type == 'per':
-                    amount = amt * line.amount
-                elif line.amount_type == 'func':
-                    amount = slip_line_pool.execute_function(cr, uid, line.id, amt, context)
-                elif line.amount_type == 'fix':
-                    amount = line.amount
-
-                if line.type == 'allowance':
-                    allowance += amount
-                elif line.type == 'deduction':
-                    deduction += amount
-
-            vals[employee.id] = {
-                'basic':basic,
-                'advantages_gross':allowance,
-                'gross':basic + allowance,
-                'advantages_net':deduction,
-                'net':basic + allowance - deduction
-            }
-        return vals
+            cr.execute( 'SELECT SUM(wage) '\
+                        'FROM hr_contract '\
+                        'WHERE employee_id = %s '\
+                        'AND date_start <= %s '\
+                        'AND (date_end > %s OR date_end is NULL)',
+                         (employee.id, current_date, current_date))
+            result = dict(cr.dictfetchone())
+            res[employee.id] = {'basic': result['sum']}
+        return res
 
     _columns = {
-        'passport_id':fields.many2one('hr.passport', 'Passport No', required=False, domain="[('employee_id','=',active_id), ('address_id','=',address_home_id)]", help="Employee Passport Information"),
-        'line_ids':fields.one2many('hr.payslip.line', 'employee_id', 'Salary Structure', required=False),
         'slip_ids':fields.one2many('hr.payslip', 'employee_id', 'Payslips', required=False, readonly=True),
-        'otherid': fields.char('Other Id', size=64),
+        'total_wage': fields.function(_calculate_total_wage, method=True, type='float', string='Total Basic Salary', digits_compute=dp.get_precision('Account'), help="Sum of all current contract's wage of employee."),
+    }
 
-        'basic': fields.function(_calculate_salary, method=True, multi='dc', type='float', string='Basic Salary', digits=(14,2)),
-        'gross': fields.function(_calculate_salary, method=True, multi='dc', type='float', string='Gross Salary', digits=(14,2)),
-        'net': fields.function(_calculate_salary, method=True, multi='dc', type='float', string='Net Salary', digits=(14,2)),
-        'advantages_net': fields.function(_calculate_salary, method=True, multi='dc', type='float', string='Deductions', digits=(14,2)),
-        'advantages_gross': fields.function(_calculate_salary, method=True, multi='dc', type='float', string='Allowances', digits=(14,2)),
-    }
 hr_employee()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'hr_payroll/hr_payroll_data.xml'
--- hr_payroll/hr_payroll_data.xml	2011-01-14 00:11:01 +0000
+++ hr_payroll/hr_payroll_data.xml	2011-04-08 10:36:40 +0000
@@ -1,137 +1,144 @@
 <?xml version="1.0" encoding="utf-8"?>
 <openerp>
     <data noupdate="1">
-        <record id="HRA" model="hr.allounce.deduction.categoty">
+    
+        <record id="AL" model="hr.salary.head">
+            <field name="name">Allowance</field>
+            <field name="code">ALW</field>
+        </record>
+        
+        <record id="DED" model="hr.salary.head">
+            <field name="name">Deduction</field>
+            <field name="code">DED</field>
+        </record>
+        
+        <record id="HRA" model="hr.salary.head">
             <field name="code">HRA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">House Rent Allowance</field>
             <field name="sequence" eval="5"/>
         </record>
 
-        <record id="CA" model="hr.allounce.deduction.categoty">
+        <record id="CA" model="hr.salary.head">
             <field name="code">CA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Conveyance Allowance</field>
             <field name="sequence" eval="10"/>
         </record>
         
-        <record id="MA" model="hr.allounce.deduction.categoty">
+        <record id="MA" model="hr.salary.head">
             <field name="code">MA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Medical Allowance</field>
             <field name="sequence" eval="15"/>
         </record>
 
-        <record id="TELA" model="hr.allounce.deduction.categoty">
+        <record id="TELA" model="hr.salary.head">
             <field name="code">TELA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Telephone Allowance</field>
             <field name="sequence" eval="20"/>
         </record>
         
-        <record id="LTA" model="hr.allounce.deduction.categoty">
+        <record id="LTA" model="hr.salary.head">
             <field name="code">LTA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Leave Travel Allowance</field>
             <field name="sequence" eval="25"/>
         </record>
         
-        <record id="NA" model="hr.allounce.deduction.categoty">
+        <record id="NA" model="hr.salary.head">
             <field name="code">NA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Newspaper Allowance</field>
             <field name="sequence" eval="30"/>
         </record>
         
-        <record id="TA" model="hr.allounce.deduction.categoty">
+        <record id="TA" model="hr.salary.head">
             <field name="code">TA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Traveling Allowance</field>
             <field name="sequence" eval="35"/>
         </record>
         
-        <record id="FA" model="hr.allounce.deduction.categoty">
+        <record id="FA" model="hr.salary.head">
             <field name="code">FA</field>
-            <field name="type">allowance</field>
+            <field name="parent_id" ref="AL"/>
             <field name="name">Food Allowance</field>
             <field name="sequence" eval="40"/>
         </record>
         
-        <record id="DA" model="hr.allounce.deduction.categoty">
+        <record id="DA" model="hr.salary.head">
             <field name="code">DA</field>
-            <field name="type">allowance</field>
+           <field name="parent_id" ref="AL"/>
             <field name="name">Dearness Allowance</field>
             <field name="sequence" eval="45"/>
         </record>
         
-        <record id="PF" model="hr.allounce.deduction.categoty">
+        <record id="PF" model="hr.salary.head">
             <field name="code">PF</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Provident Fund</field>
             <field name="sequence" eval="50"/>
         </record>
         
-        <record id="PT" model="hr.allounce.deduction.categoty">
+        <record id="PT" model="hr.salary.head">
             <field name="code">PT</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Professional Tax</field>
             <field name="sequence" eval="55"/>
         </record>
         
-        <record id="WF" model="hr.allounce.deduction.categoty">
+        <record id="WF" model="hr.salary.head">
             <field name="code">WF</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Welfare</field>
             <field name="sequence" eval="60"/>
         </record>
         
-        <record id="TDS" model="hr.allounce.deduction.categoty">
+        <record id="TDS" model="hr.salary.head">
             <field name="code">TDS</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Tax Deduct at Source</field>
             <field name="sequence" eval="65"/>
         </record>
         
-        <record id="LWP" model="hr.allounce.deduction.categoty">
+        <record id="LWP" model="hr.salary.head">
             <field name="code">LWP</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Leave without pay</field>
             <field name="sequence" eval="70"/>
         </record>
         
-        <record id="FC" model="hr.allounce.deduction.categoty">
+        <record id="FC" model="hr.salary.head">
             <field name="code">FC</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Food Coupons</field>
             <field name="sequence" eval="75"/>
         </record>
         
-        <record id="ESI" model="hr.allounce.deduction.categoty">
+        <record id="ESI" model="hr.salary.head">
             <field name="code">ESI</field>
-            <field name="type">deduction</field>
+            <field name="parent_id" ref="DED"/>
             <field name="name">Employee's State Insurance</field>
             <field name="sequence" eval="80"/>
         </record>
         
-        <record id="OTHERD" model="hr.allounce.deduction.categoty">
-            <field name="code">OTHERD</field>
-            <field name="type">otherdeduct</field>
-            <field name="name">Other Deduction</field>
+        <record id="NET" model="hr.salary.head">
+            <field name="code">TP</field>
+            <field name="parent_id" ref="AL"/>
+            <field name="name">Total Payment</field>
             <field name="sequence" eval="85"/>
         </record>
         
-        <record id="OTHERA" model="hr.allounce.deduction.categoty">
-            <field name="code">OTHERA</field>
-            <field name="type">otherpay</field>
-            <field name="name">Other Taxable Allowance</field>
-            <field name="sequence" eval="90"/>
+        <record id="hr_salary_rule_net" model="hr.salary.rule">
+            <field name="amount_type">code</field>
+            <field name="code">NET</field>
+            <field name="category_id" ref="NET"/>
+            <field name="name">NET</field>
+            <field name="sequence" eval="500"/>
+            <field name="python_compute">total = basic+allowance+deduction</field>
         </record>
         
-        <!-- Contract Wage Types -->
-        <record id="hr_contract_monthly_basic" model="hr.contract.wage.type">
-            <field name="name">Monthly Basic Wage</field>
-            <field name="type">basic</field>
-            <field name="period_id" ref="hr_contract.hr_contract_wage_type_period_monthly"/>
-        </record>
     </data>
 </openerp>

=== modified file 'hr_payroll/hr_payroll_demo.xml'
--- hr_payroll/hr_payroll_demo.xml	2011-01-14 00:11:01 +0000
+++ hr_payroll/hr_payroll_demo.xml	2011-04-08 10:36:40 +0000
@@ -2,57 +2,59 @@
 <openerp>
     <data>
 
-        <!-- Payroll Structure -->
-        <record id="structure_001" model="hr.payroll.structure">
-            <field name="code">ME</field>
-            <field name="name">Marketing Executive</field>
-            <field name="company_id" ref="base.main_company"/>
-        </record>
+        <!-- Salary Rules -->
 
-        <record id="hr_payslip_line_houserantallowance1" model="hr.payslip.line">
-            <field name="amount_type">per</field>
-            <field eval="5" name="sequence"/>
-            <field eval="0.4" name="amount"/>
+        <record id="hr_payslip_line_houserantallowance1" model="hr.salary.rule">
+            <field name="amount_select">percentage</field>
+            <field eval="40.0" name="amount_percentage"/>
+            <field name="amount_percentage_base">contract.wage</field>
             <field name="code">HRA</field>
-            <field name="type">allowance</field>
+            <field name="type" ref="AL"/>
             <field name="category_id" ref="hr_payroll.HRA"/>
-            <field name="function_id" ref="hr_payroll.structure_001"/>
             <field name="name">House Rent Allowance</field>
+            <field name="sequence" eval="5"/>
         </record>
 
-        <record id="hr_payslip_line_convanceallowance1" model="hr.payslip.line">
-            <field name="amount_type">fix</field>
-            <field eval="10" name="sequence"/>
-            <field eval="800.0" name="amount"/>
+        <record id="hr_payslip_line_convanceallowance1" model="hr.salary.rule">
+            <field name="amount_select">fix</field>
+            <field eval="800.0" name="amount_fix"/>
             <field name="code">CA</field>
-            <field name="type">allowance</field>
+            <field name="type" ref="AL"/>
             <field name="category_id" ref="hr_payroll.CA"/>
-            <field name="function_id" ref="hr_payroll.structure_001"/>
             <field name="name">Conveyance Allowance</field>
+            <field name="sequence" eval="10"/>
         </record>
 
-        <record id="hr_payslip_line_professionaltax1" model="hr.payslip.line">
-            <field name="amount_type">fix</field>
+        <record id="hr_payslip_line_professionaltax1" model="hr.salary.rule">
+            <field name="amount_select">fix</field>
             <field eval="15" name="sequence"/>
-            <field eval="200.0" name="amount"/>
+            <field eval="-200.0" name="amount_fix"/>
             <field name="code">PT</field>
-            <field name="type">deduction</field>
+            <field name="type" ref="DED"/>
             <field name="category_id" ref="hr_payroll.PT"/>
-            <field name="function_id" ref="hr_payroll.structure_001"/>
             <field name="name">Professional Tax</field>
         </record>
 
-        <record id="hr_payslip_line_providentfund1" model="hr.payslip.line">
-            <field name="amount_type">per</field>
+        <record id="hr_payslip_line_providentfund1" model="hr.salary.rule">
+            <field name="amount_select">percentage</field>
             <field eval="20" name="sequence"/>
-            <field eval="0.125" name="amount"/>
+            <field eval="-12.5" name="amount_percentage"/>
+            <field name="amount_percentage_base">contract.wage</field>
             <field name="code">PF</field>
-            <field name="type">deduction</field>
+            <field name="type" ref="DED"/>
             <field name="category_id" ref="hr_payroll.PF"/>
-            <field name="function_id" ref="hr_payroll.structure_001"/>
             <field name="name">Provident Fund</field>
         </record>
 
+        <!-- Salary Structure -->
+
+         <record id="structure_001" model="hr.payroll.structure">
+            <field name="code">ME</field>
+            <field name="name">Marketing Executive</field>
+            <field eval="[(6, 0, [ref('hr_payslip_line_houserantallowance1'), ref('hr_payslip_line_convanceallowance1'),ref('hr_payslip_line_professionaltax1'),ref('hr_payslip_line_providentfund1')])]" name="rule_ids"/>
+            <field name="company_id" ref="base.main_company"/>
+        </record>
+
         <!-- Employee -->
         <record id="hr_employee_bonamy0" model="hr.employee">
             <field eval="0" name="manager"/>
@@ -65,7 +67,6 @@
 
         <!-- Employee Contract -->
         <record id="hr_contract_firstcontract1" model="hr.contract">
-            <field name="wage_type_id" ref="hr_contract.hr_contract_monthly_gross"/>
             <field name="name">First Contract</field>
             <field name="type_id" ref="hr_contract.hr_contract_type_emp"/>
             <field name="date_start" eval="time.strftime('%Y-%m')+'-1'"/>
@@ -77,15 +78,5 @@
             <field eval="5" name="working_days_per_week"/>
         </record>
 
-        <!-- Payslip -->
-        <record id="hr_payslip_salaryslipofbonamyforjune0" model="hr.payslip">
-            <field name="number">SLIP/001</field>
-            <field name="deg_id" ref="hr_payroll.structure_001"/>
-            <field name="employee_id" ref="hr_employee_bonamy0"/>
-            <field name="contract_id" ref="hr_contract_firstcontract1"/>
-            <field name="company_id" ref="base.main_company"/>
-            <field name="date" eval="time.strftime('%Y-%m')+'-5'"/>
-            <field name="name" eval="'Salary Slip of Bonamy for June-'+time.strftime('%Y')"/>
-        </record>
     </data>
 </openerp>

=== renamed file 'hr_payroll/hr_paroll_report.xml' => 'hr_payroll/hr_payroll_report.xml'
--- hr_payroll/hr_paroll_report.xml	2011-01-14 00:11:01 +0000
+++ hr_payroll/hr_payroll_report.xml	2011-04-08 10:36:40 +0000
@@ -9,6 +9,14 @@
           	rml="hr_payroll/report/payslip.rml" 
           	string="Employee PaySlip" />
           	
+      	 <report 
+            auto="False" 
+            id="payslip_report" 
+            model="hr.payslip" 
+            name="test.pdf" 
+            rml="hr_payroll/report/report_payslip.rml" 
+            string="Payslip Report" />
+          	
 	     <report 
           	auto="False" 
           	id="payroll_advice" 

=== modified file 'hr_payroll/hr_payroll_view.xml'
--- hr_payroll/hr_payroll_view.xml	2011-01-27 09:49:39 +0000
+++ hr_payroll/hr_payroll_view.xml	2011-04-08 10:36:40 +0000
@@ -6,83 +6,6 @@
         <menuitem id="payroll_configure" parent="hr.menu_hr_configuration" name="Payroll"/>
         <menuitem id="menu_hr_payroll_reporting" parent="hr.menu_hr_reporting" name="Payroll" groups="base.group_hr_manager"/>
 
-        <!-- Passport Views    -->
-        <record id="hr_passport_form" model="ir.ui.view">
-            <field name="name">hr.passport.form</field>
-            <field name="model">hr.passport</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Passport">
-                    <group col="6" colspan="4">
-                        <field name="name" select="1" colspan="4"/>
-                        <field name="employee_id" />
-                    </group>
-                    <group col="2" colspan="2">
-                        <separator string="Country &amp; Address" colspan="4"/>
-                        <field name="country_id" select="1"/>
-                        <field name="address_id" select="1"/>
-                    </group>
-                    <group col="2" colspan="2">
-                        <separator string="Valid From" colspan="2"/>
-                        <field name="date_issue" select="1"/>
-                        <field name="date_expire" select="1"/>
-                    </group>
-                    <notebook colspan="4">
-                        <page string="Description">
-                            <separator string="Description" colspan="2"/>
-                            <field name="note" colspan="4" nolabel="1"/>
-                        </page>
-                    </notebook>
-                </form>
-            </field>
-        </record>
-        <record id="hr_passport_tree" model="ir.ui.view">
-            <field name="name">hr.passport.tree</field>
-            <field name="model">hr.passport</field>
-            <field name="type">tree</field>
-            <field name="arch" type="xml">
-                <tree string="Passport">
-                    <field name="name" />
-                    <field name="employee_id" />
-                    <field name="address_id"/>
-                    <field name="country_id" />
-                    <field name="date_expire"/>
-                    <field name="date_issue" />
-                </tree>
-            </field>
-        </record>
-
-        <record id="view_hr_passport_filter" model="ir.ui.view">
-            <field name="name">hr.passport.select</field>
-            <field name="model">hr.passport</field>
-            <field name="type">search</field>
-            <field name="arch" type="xml">
-                <search string="Search Passport">
-                    <group col="8" colspan="4">
-                        <field name="name"/>
-                        <field name="employee_id"/>
-                        <field name="country_id"/>
-                        <field name="address_id"/>
-                    </group>
-                    <newline/>
-                    <group col="8" colspan="4" expand="0" string="Group By...">
-                        <filter string="Employees" icon="terp-partner" name="employee_id" context="{'group_by':'employee_id'}"/>
-                        <filter string="Country" name="country_id" icon="terp-go-home" context="{'group_by':'country_id'}"/>
-                        <filter string="Expire" name="date_expire" icon="terp-go-month" context="{'group_by':'date_expire'}"/>
-                        <filter string="Issue" name="date_issue" icon="terp-go-month" context="{'group_by':'date_issue'}"/>
-                    </group>
-                </search>
-            </field>
-        </record>
-        <record id="action_hr_passport_tree" model="ir.actions.act_window">
-            <field name="name">All Passports</field>
-            <field name="res_model">hr.passport</field>
-            <field name="view_type">form</field>
-            <field name="view_id" ref="hr_passport_tree"/>
-            <field name="search_view_id" ref="view_hr_passport_filter"/>
-        </record>
-        <!-- End Passport Views -->
-
         <!-- Employee View -->
         <record id="hr_contract.hr_hr_employee_view_form2" model="ir.ui.view">
             <field name="name">hr.hr.employee.view.form2</field>
@@ -97,6 +20,7 @@
                             <field name="bank_account_id" context="{'display_partner':True, 'partner_id':partner_id}"/>
                             <field name="place_of_birth"/>
                             <field name="children"/>
+                            <!-- <field name="basic" invisible="0"/> -->
                         </group>
                         <group colspan="2" col="2">
                             <separator string="Job Info" colspan="2"/>
@@ -110,75 +34,26 @@
             </data>
             </field>
         </record>
-        <record id="view_employee_passport_form" model="ir.ui.view">
-            <field name="name">hr.employee.passport.form</field>
-            <field name="model">hr.employee</field>
-            <field name="type">form</field>
-            <field name="inherit_id" ref="hr.view_employee_form"/>
-            <field name="arch" type="xml">
-                <field name="passport_id" position="replace">
-                    <field name="passport_id"/>
-                    <field name="otherid"/>
-                </field>
-            </field>
-        </record>
-
         <!-- End Employee View -->
 
         <!-- Contract View -->
-        <record id="hr_contract.hr_contract_view_form" model="ir.ui.view">
-            <field name="name">hr.contract.view.form</field>
+        <record id="hr_contract_form_inherit" model="ir.ui.view">
+            <field name="name">hr.contract.view.form.inherit</field>
             <field name="model">hr.contract</field>
             <field name="type">form</field>
+            <field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
             <field name="arch" type="xml">
-                <form string="Contract">
-                    <group colspan="4" col="6">
-                        <field name="name" select="1"/>
-                        <field name="employee_id" select="1"/>
-                        <field name="job_id"/>
-                        <field name="wage"/>
-                        <field name="wage_type_id" widget="selection"/>
-                        <field name="type_id" widget="selection"/>
-                    </group>
-                    <notebook colspan="4">
-                        <page string="Main Data">
-                            <group col="2" colspan="2">
-                                <separator colspan="2" string="Duration"/>
-                                <field name="date_start" select="1"/>
-                                <field name="date_end" select="1"/>
-                                <field name="working_hours"/>
-                                <field name="working_days_per_week" select="1"/>
-                                <separator colspan="2" string="Trial Period"/>
-                                <field name="trial_date_start" />
-                                <field name="trial_date_end" />
-                            </group>
-                            <group col="2" colspan="2">
-                                <separator colspan="2" string="Advantages"/>
-                                <field name="struct_id" select="1"/>
-                                <field name="advantages_gross"/>
-                                <field name="advantages_net"/>
-                                <field name="advantages" nolabel="1" colspan="2"/>
-                            </group>
-                        </page>
-                        <page string="Work Permit">
-                            <group col="2" colspan="2">
-                                <separator colspan="2" string="Passport"/>
-                                <field name="passport_id" domain="[('employee_id','=',employee_id)]"/>
-                            </group>
-                            <group col="2" colspan="2">
-                                <separator colspan="2" string="Valid for"/>
-                                <field name="visa_no" attrs="{'required': [('passport_id','!=',False), ]}"/>
-                                <field name="permit_no" attrs="{'required': [('passport_id','!=',False), ]}"/>
-                                <field name="visa_expire" attrs="{'required': [('passport_id','!=',False), ]}"/>
-                            </group>
-                        </page>
-                    </notebook>
-                    <separator colspan="4" string="Notes"/>
-                    <field colspan="4" name="notes" nolabel="1"/>
-                </form>
+            <data>
+                <xpath expr="/form/notebook/page/group/field[@name='advantages']" position="before">
+                    <field name="struct_id" select="1"/>
+                </xpath>
+                 <xpath expr="/form/notebook/page/group/field[@name='working_hours']" position="after">
+                    <field name="schedule_pay"/>
+                </xpath>
+            </data>
             </field>
         </record>
-        <!--menuitem action="hr_contract.action_hr_contract" id="hr_menu_contract" parent="payroll_configure" name="Contracts" sequence="4"/-->
+
         <!-- End Contract View-->
 
         <!-- Salary structure -->
@@ -190,7 +65,7 @@
                 <tree string="Employee Function">
                     <field name="name"/>
                     <field name="code"/>
-                    <field name="line_ids"/>
+                    <field name="rule_ids"/>
                     <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                 </tree>
             </field>
@@ -202,59 +77,23 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Employee Function">
-                    <group col="6" colspan="4">
-                        <field name="name" colspan="4" select="1"/>
+                    <group col="6" colspan="6">
+                        <field name="name" select="1"/>
                         <field name="code" select="1"/>
                         <field name="company_id" groups="base.group_multi_company" widget="selection"/>
+                        <field name="parent_id"/>
                     </group>
                     <notebook colspan="4">
-                        <page string="Salary Structure">
-                            <field name="line_ids" nolabel="1" colspan="4">
-                                <form string="Payslip Line">
-                                    <group col="6" colspan="4">
-                                        <field name="name" colspan="4" select="1"/>
-                                        <field name="code" select="1"/>
-                                    </group>
-                                    <group col="2" colspan="2">
-                                        <separator colspan="4" string="Calculations"/>
-                                        <field name="category_id" on_change="onchange_category(category_id)"/>
-                                        <field name="type"/>
-                                        <field name="amount_type"/>
-                                        <field name="amount" on_change="onchange_amount(amount, amount_type)" attrs="{'readonly':[('amount_type','=','func')]}"/>
-                                        <field name="sequence" groups="base.group_extended"/>
-                                    </group>
-                                    <group col="2" colspan="2">
-                                        <separator colspan="4" string="Company contribution"/>
-                                        <field name="company_contrib"/>
-                                    </group>
-                                    <notebook colspan="4">
-                                        <page string="Function">
-                                            <field name="line_ids" colspan="4" nolabel="1" attrs="{'readonly':[('amount_type','!=','func')]}">
-                                                <tree string="Function Arguments" editable="bottom">
-                                                    <field name="name"/>
-                                                    <field name="sequence" groups="base.group_extended"/>
-                                                    <field name="from_val"/>
-                                                    <field name="to_val"/>
-                                                    <field name="amount_type"/>
-                                                    <field name="value"/>
-                                                </tree>
-                                            </field>
-                                        </page>
-                                        <page string="Description">
-                                            <separator colspan="4" string="Description"/>
-                                            <field name="note" colspan="4" nolabel="1"/>
-                                        </page>
-                                    </notebook>
-                                </form>
-                            </field>
-                        </page>
+                         <page string="Salary Rules">
+                           <field colspan="4" name="rule_ids" nolabel="1" />
+                         </page>
                     </notebook>
                 </form>
             </field>
         </record>
 
         <record id="action_view_hr_employee_grade_form" model="ir.actions.act_window">
-            <field name="name">Salary Structure</field>
+            <field name="name">Salary Structures</field>
             <field name="res_model">hr.payroll.structure</field>
             <field name="view_type">form</field>
             <field name="view_id" ref="view_hr_employee_grade_tree"/>
@@ -263,36 +102,10 @@
             id="menu_hr_employee_function"
             action="action_view_hr_employee_grade_form"
             parent="payroll_configure"
+            sequence="13"
         />
         <!-- End Salary structure -->
 
-        <!-- Holiday Status -->
-        <record model="ir.ui.view" id="view_holiday_status_form1">
-            <field name="name">hr.holidays.status.inherit</field>
-            <field name="model">hr.holidays.status</field>
-            <field name="inherit_id" ref="hr_holidays.edit_holiday_status_form"/>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-            <xpath expr="//group[@name='selection']" position="replace">
-                <group colspan="2">
-                            <separator string="Validation" colspan="2"/>
-                                <newline/>
-                            <field name="double_validation"/>
-                                <newline/>
-                            <field name="limit"/>
-                  </group>
-                <group colspan="2">
-                    <separator colspan="2" string="Payroll Configurtion"/><newline/>
-                    <field name="type"/><newline/>
-                    <field name="head_id"/><newline/>
-                    <field name="company_id" groups="base.group_multi_company" widget="selection" select="2"/><newline/>
-                    <field name="code" readonly="True"/>
-                </group>
-            </xpath>
-        </field>
-        </record>
-        <!-- End Holiday Status -->
-
         <!-- Payslip Line -->
         <record id="view_hr_payslip_line_tree" model="ir.ui.view">
             <field name="name">hr.payslip.line.tree</field>
@@ -300,13 +113,13 @@
             <field name="type">tree</field>
             <field name="arch" type="xml">
                 <tree string="Salary Structure" editable="bottom">
-                    <field name="category_id" on_change="onchange_category(category_id)"/>
+                    <field name="category_id"/>
                     <field name="sequence" groups="base.group_extended"/>
                     <field name="name"/>
                     <field name="code"/>
-                    <field name="type"/>
-                    <field name="amount_type"/>
-                    <field name="amount" on_change="onchange_amount(amount, amount_type)"/>
+                    <field name="amount_select"/>
+                    <field name="amount_fix"/>
+                    <field name="amount_percentage"/>
                 </tree>
             </field>
         </record>
@@ -321,14 +134,13 @@
                         <field name="code" select="1"/>
                         <field name="slip_id" select="1"/>
                         <field name="employee_id"/>
-                        <field name="function_id"/>
                     </group>
                     <group col="2" colspan="2">
                         <separator colspan="4" string="Calculations"/>
-                        <field name="category_id" on_change="onchange_category(category_id)"/>
-                        <field name="type"/>
-                        <field name="amount_type"/>
-                        <field name="amount" on_change="onchange_amount(amount, amount_type)" attrs="{'readonly':[('amount_type','=','func')]}"/>
+                        <field name="category_id"/>
+                        <field name="amount_select"/>
+                        <field name="amount_fix"  attrs="{'readonly':[('amount_select','&lt;&gt;','fix')]}"/>
+                        <field name="amount_percentage"  attrs="{'readonly':[('amount_select','&lt;&gt;','percentage')]}"/>
                         <field name="sequence" groups="base.group_extended"/>
                     </group>
                     <group col="2" colspan="2">
@@ -336,18 +148,6 @@
                         <field name="company_contrib"/>
                     </group>
                     <notebook colspan="4">
-                        <page string="Function">
-                            <field name="line_ids" colspan="4" nolabel="1" attrs="{'readonly':[('amount_type','!=','func')]}">
-                                <tree string="Function Arguments" editable="bottom">
-                                    <field name="name"/>
-                                    <field name="sequence" groups="base.group_extended"/>
-                                    <field name="from_val"/>
-                                    <field name="to_val"/>
-                                    <field name="amount_type"/>
-                                    <field name="value"/>
-                                </tree>
-                            </field>
-                        </page>
                         <page string="Description">
                             <separator colspan="4" string="Description"/>
                             <field name="note" colspan="4" nolabel="1"/>
@@ -365,11 +165,9 @@
                 <tree colors="blue:state in ('confirm','hr_check','accont_check');black:state in ('new');gray:state in('cancel')" string="Payslip">
                     <field name="number"/>
                     <field name="employee_id"/>
-                    <field name="register_id" invisible="1"/>
                     <field name="name"/>
-                    <field name="date"/>
-                    <field name="grows"/>
-                    <field name="net"/>
+                    <field name="date_from"/>
+                    <field name="date_to"/>
                     <field name="state"/>
                     <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                 </tree>
@@ -383,22 +181,22 @@
             <field name="arch" type="xml">
                 <form string="Payslip">
                     <group col="6" colspan="4">
-                        <field name="employee_id"/>
-                        <field name="name"/>
-                        <field name="number" select="1"/>
-                        <field name="date"/>
+                        <field name="employee_id" on_change="onchange_employee_id(date_from, date_to, employee_id, contract_id)"/>
+                        <field name="number"/>
+                        <field name="date_from"/>
+                        <field name="contract_id" groups="base.group_extended" domain="[('employee_id','=',employee_id)]" on_change="onchange_contract_id(date_from, date_to, employee_id, contract_id)"/>
+                        <field name="struct_id" groups="base.group_extended" attrs="{'required':[('contract_id','&lt;&gt;',False)]}"/>
+                        <field name="date_to"/>
+                        <field name="name" colspan="4"/>
                     </group>
                     <notebook colspan="4">
-                        <page string="Salary Computation">
+                        <page string="Salary Computation" >
                             <field name="line_ids" colspan="4" nolabel="1">
                                 <tree string="Salary Structure" editable="bottom">
-                                    <field name="category_id" on_change="onchange_category(category_id)"/>
-                                    <field name="sequence" groups="base.group_extended"/>
                                     <field name="name"/>
                                     <field name="code"/>
-                                    <field name="type"/>
-                                    <field name="amount_type"/>
-                                    <field name="amount" on_change="onchange_amount(amount, amount_type)"/>
+                                    <field name="category_id"/>
+                                    <field name="sequence" invisible="1"/>
                                     <field name="total"/>
                                 </tree>
                                 <form string="Payslip Line">
@@ -408,10 +206,10 @@
                                     </group>
                                     <group col="2" colspan="2">
                                         <separator colspan="4" string="Calculations"/>
-                                        <field name="category_id" on_change="onchange_category(category_id)"/>
-                                        <field name="type"/>
-                                        <field name="amount_type"/>
-                                        <field name="amount" on_change="onchange_amount(amount, amount_type)" attrs="{'readonly':[('amount_type','=','func')]}"/>
+                                        <field name="category_id"/>
+                                        <field name="amount_select"/>
+                                        <field name="amount_fix" attrs="{'readonly':[('amount_select','&lt;&gt;','fix')]}"/>
+                                        <field name="amount_percentage" attrs="{'readonly':[('amount_select','=','percentage')]}"/>
                                         <field name="sequence" groups="base.group_extended"/>
                                     </group>
                                     <group col="2" colspan="2">
@@ -419,18 +217,6 @@
                                         <field name="company_contrib"/>
                                     </group>
                                     <notebook colspan="4">
-                                        <page string="Function">
-                                            <field name="line_ids" colspan="4" nolabel="1" attrs="{'readonly':[('amount_type','!=','func')]}">
-                                                <tree string="Function Arguments" editable="bottom">
-                                                    <field name="name"/>
-                                                    <field name="sequence" groups="base.group_extended"/>
-                                                    <field name="from_val"/>
-                                                    <field name="to_val"/>
-                                                    <field name="amount_type"/>
-                                                    <field name="value"/>
-                                                </tree>
-                                            </field>
-                                        </page>
                                         <page string="Description">
                                             <separator colspan="4" string="Description"/>
                                             <field name="note" colspan="4" nolabel="1"/>
@@ -438,45 +224,55 @@
                                     </notebook>
                                 </form>
                             </field>
-                            <group col="6" colspan="4">
-                                <separator string="Computation Overview" colspan="6"/>
-                                <field name="working_days"/>
-                                <field name="holiday_days"/>
-                                <field name="worked_days"/>
-                                <field name="basic_before_leaves"/>
-                                <field name="leaves"/>
-                                <field name="basic"/>
-                                <field name="allounce"/>
-                                <field name="deduction"/>
-                                <field name="other_pay"/>
-                                <field name="grows"/>
-                                <field name="net"/>
-                                <field name="total_pay"/>
-                            </group>
                         </page>
-                        <page string="Other Informations">
-                            <group col="2" colspan="1">
-                                <separator colspan="2" string="Other Informations"/>
+<!-- TODO: put me back -->
+<!--                       <page string="Details By Salary Head">
+                            <field name="details_by_salary_head" nolabel="1">
+                                <tree string="Salary Rules">
+                                    <field name="category_id"/>
+                                    <field name="sequence" groups="base.group_extended"/>
+                                    <field name="name"/>
+                                    <field name="code"/>
+                                   <field name="total"/>
+                                </tree>
+                            </field>
+                       </page>-->
+
+                       <page string="Worked Days">
+                            <field name="input_line_ids" colspan="4" nolabel="1" mode="tree">
+                                <tree editable="bottom">
+                                    <field name="name"/>
+                                    <field name="code"/>
+                                    <field name="number_of_days" sum="Total Working Days"/>
+                                    <field name="number_of_hours"/>
+                                    <field name="contract_id" groups="base.group_extended"/>
+                                    <field name="sequence" invisible="True"/>
+                                </tree>
+                            </field>
+                       </page>
+
+                       <page string="Other Information">
+                            <separator colspan="4" string="Other Information"/>
+                            <group col="5" colspan="2">
+                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                                 <field name="paid" readonly="1"/>
-                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
-                                <field name="register_id" groups="base.group_extended"/>
-                                <field name="deg_id" groups="base.group_extended"/>
-                                <field name="contract_id" groups="base.group_extended" domain="[('employee_id','=',employee_id)]"/>
                             </group>
                             <newline/>
-                            <separator colspan="4" string="Description"/>
+                            <separator colspan="4" string="Notes"/>
                             <field name="note" colspan="4" nolabel="1"/>
-                        </page>
+                       </page>
+
                     </notebook>
+                    <field name='credit_note' />
                     <group col="10" colspan="4">
                         <field name="state"/>
                         <button string="Cancel" icon="terp-dialog-close" name="cancel_sheet" states="draft,hr_check,confirm"/>
-                        <button string="Compute Sheet" icon="terp-stock_format-scientific" name="compute_sheet" states="new"/>
-                        <button string="Recompute Sheet" icon="terp-stock_format-scientific" name="compute_sheet" type="object" states="draft"/>
+                        <button string="Compute Sheet" icon="terp-stock_format-scientific" name="compute_sheet" type="object" states="draft"/>
                         <button string="Verify Sheet" icon="terp-camera_test" name="verify_sheet" states="draft"/>
                         <button string="Approve Sheet" icon="terp-camera_test" name="final_verify_sheet" states="hr_check"/>
                         <button string="Pay Salary" icon="terp-dolar_ok!" name="process_sheet" states="confirm"/>
                         <button string="Set to Draft" icon="terp-stock_effects-object-colorize" name="set_to_draft" states="cancel"/>
+                        <button string="Refund" icon="gtk-execute" name="refund_sheet" states="done" type='object'/>
                     </group>
                 </form>
             </field>
@@ -496,14 +292,12 @@
                         <field name="name"/>
                         <field name="employee_id"/>
                         <field name="number"/>
-                        <field name="date"/>
+                        <field name="date_from"/>
                     </group>
                     <newline/>
                     <group col="8" colspan="4" expand="0" string="Group By...">
                         <filter string="Employees" icon="terp-personal" name="employee_id" context="{'group_by':'employee_id'}"/>
                         <separator orientation="vertical"/>
-                        <filter string="Register" icon="terp-folder-yellow" name="register_id" context="{'group_by':'register_id'}"/>
-                        <separator orientation="vertical"/>
                         <filter string="Companies" name="company_id"  icon="terp-go-home" context="{'group_by':'company_id'}"/>
                         <separator orientation="vertical"/>
                         <filter string="States" name="state" icon="terp-stock_effects-object-colorize" context="{'group_by':'state'}"/>
@@ -512,7 +306,7 @@
             </field>
         </record>
         <record id="action_view_hr_payslip_form" model="ir.actions.act_window">
-            <field name="name">Employee Payslip</field>
+            <field name="name">Employee Payslips</field>
             <field name="res_model">hr.payslip</field>
             <field name="view_type">form</field>
             <field name="view_id" ref="view_hr_payslip_tree"/>
@@ -521,91 +315,40 @@
         <menuitem action="action_view_hr_payslip_form" id="menu_department_tree" parent="menu_hr_root_payroll"/>
 
         <!-- Payment Heads -->
-        <record id="hr_allounce_deduction_categoty_form" model="ir.ui.view">
-            <field name="name">hr.allounce.deduction.categoty.form</field>
-            <field name="model">hr.allounce.deduction.categoty</field>
+        <record id="hr_salary_head_form" model="ir.ui.view">
+            <field name="name">hr.salary.head.form</field>
+            <field name="model">hr.salary.head</field>
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Salary Heads">
-                    <group col="6" colspan="6">
+                    <group col="3" colspan="6">
                         <field name="name" select="1"/>
                         <field name="code" select="1"/>
-                        <field name="type" select="1"/>
-                        <group col="2" colspan="4">
-                            <separator colspan="4" string="Based on"/>
-                            <field name="base" colspan="4" nolabel="1"/>
-                        </group>
-                        <group col="2" colspan="2">
-                            <separator colspan="4" string="Dynamic Computation"/>
-                            <field name="condition"/>
-                            <field name="sequence"/>
-                        </group>
+                        <field name="parent_id" select="1"/>
+                        <field name="sequence" select="1"/>
                     </group>
-                    <notebook colspan="4">
-                        <page string="Description">
-                            <field name="note" colspan="4" nolabel="1"/>
-                        </page>
-                        <page string="Contribution">
-                            <field name="contribute_ids" colspan="4" nolabel="1" height="300">
-                                <form string="Company Contribution">
-                                    <group col="6" colspan="6">
-                                        <field name="name" select="1"/>
-                                        <field name="code" select="1"/>
-                                    </group>
-                                    <group col="2" colspan="2">
-                                        <separator colspan="2" string="Contributions"/>
-                                        <field name="amount_type" attrs="{'required': [('contribute','=',True)]}"/>
-                                        <field name="contribute_per" attrs="{'required': [('contribute','=',True)], 'readonly':[(('amount_type','=','func'))]}"/>
-                                        <field name="register_id" attrs="{'required': [('contribute','=',True)]}"/>
-                                    </group>
-                                    <group col="2" colspan="2">
-                                        <separator colspan="2" string="Other Information"/>
-                                        <field name="company_id" groups="base.group_multi_company" widget="selection" select="1"/>
-                                        <field name="active" select="1"/>
-                                    </group>
-                                    <notebook colspan="4">
-                                        <page string="Function" attrs="{'readonly': [('amount_type','!=','func')]}">
-                                            <field name="line_ids" colspan="4" nolabel="1">
-                                                <tree string="Function Arguments" editable="bottom">
-                                                    <field name="name"/>
-                                                    <field name="sequence"/>
-                                                    <field name="from_val"/>
-                                                    <field name="to_val"/>
-                                                    <field name="amount_type"/>
-                                                    <field name="value"/>
-                                                </tree>
-                                            </field>
-                                        </page>
-                                        <page string="Description">
-                                            <field name="note" colspan="4" nolabel="1"/>
-                                        </page>
-                                    </notebook>
-                                </form>
-                            </field>
-                        </page>
-                    </notebook>
+                    <separator colspan="4" string="Description"/>
+                        <field name="note" colspan="4" nolabel="1"/>
                 </form>
             </field>
         </record>
-        <record id="hr_allounce_deduction_categoty_tree" model="ir.ui.view">
-            <field name="name">hr.allounce.deduction.categoty.tree</field>
-            <field name="model">hr.allounce.deduction.categoty</field>
+        <record id="hr_salary_head_tree" model="ir.ui.view">
+            <field name="name">hr.salary.head.tree</field>
+            <field name="model">hr.salary.head</field>
             <field name="type">tree</field>
             <field name="arch" type="xml">
                 <tree string="Salary Heads">
                     <field name="name"/>
-                    <field name="code"/>
-                    <field name="type"/>
-                    <field name="base"/>
-                    <field name="condition"/>
                     <field name="sequence"/>
+                    <field name="code"/>
+                    <field name="parent_id"/>
                 </tree>
             </field>
         </record>
 
-        <record id="view_allounce_deduction_categoty_filter" model="ir.ui.view">
-            <field name="name">hr.allounce.deduction.categoty.select</field>
-            <field name="model">hr.allounce.deduction.categoty</field>
+        <record id="view_hr_salary_head_filter" model="ir.ui.view">
+            <field name="name">hr.salary.head.select</field>
+            <field name="model">hr.salary.head</field>
             <field name="type">search</field>
             <field name="arch" type="xml">
                 <search string="Salary Heads">
@@ -614,273 +357,29 @@
                     <separator orientation="vertical"/>
                     <field name="name" select="1"/>
                      <field name="code" select="1"/>
-                    <field name="type"/>
                     <newline/>
                     <group expand="0" string="Group By..." colspan="4" col="4" groups="base.group_extended">
-                        <filter string="Based" icon="terp-go-month" domain="[]" context="{'group_by':'base'}"/>
                         <filter string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'type'}"/>
                     </group>
                </search>
             </field>
         </record>
 
-        <record id="hr_allounce_deduction_tree" model="ir.actions.act_window">
+        <record id="action_hr_salary_head" model="ir.actions.act_window">
             <field name="name">Salary Heads</field>
-            <field name="res_model">hr.allounce.deduction.categoty</field>
+            <field name="res_model">hr.salary.head</field>
             <field name="view_type">form</field>
-            <field name="view_id" ref="hr_allounce_deduction_categoty_tree"/>
-           <field name="search_view_id" ref="view_allounce_deduction_categoty_filter"/>
+            <field name="view_id" ref="hr_salary_head_tree"/>
+           <field name="search_view_id" ref="view_hr_salary_head_filter"/>
         </record>
         <menuitem
-            id="menu_hr_allounce_deduction_tree"
-            action="hr_allounce_deduction_tree"
+            id="menu_hr_salary_head"
+            action="action_hr_salary_head"
             parent="payroll_configure"
+            sequence="11"
         />
         <!-- End Payment Heads -->
 
-        <!-- Company Contribution -->
-        <record id="hr_company_contribution_form" model="ir.ui.view">
-            <field name="name">company.contribution.form</field>
-            <field name="model">company.contribution</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Company Contribution">
-                    <group col="6" colspan="6">
-                        <field name="name" select="1"/>
-                        <field name="code" select="1"/>
-                        <field name="category_id"/>
-                    </group>
-                    <group col="2" colspan="2">
-                        <separator colspan="2" string="Contributions"/>
-                        <field name="amount_type" attrs="{'required': [('contribute','=',True)]}"/>
-                        <field name="contribute_per" attrs="{'required': [('contribute','=',True)], 'readonly':[(('amount_type','=','func'))]}"/>
-                        <field name="register_id" attrs="{'required': [('contribute','=',True)]}"/>
-                    </group>
-                    <group col="2" colspan="2">
-                        <separator colspan="2" string="Other Information"/>
-                        <field name="company_id" groups="base.group_multi_company" widget="selection" select="1"/>
-                        <field name="active" select="1"/>
-                    </group>
-                    <notebook colspan="4">
-                        <page string="Function" attrs="{'readonly': [('amount_type','!=','func')]}">
-                            <field name="line_ids" colspan="4" nolabel="1">
-                                <tree string="Function Arguments" editable="bottom">
-                                    <field name="name"/>
-                                    <field name="sequence"/>
-                                    <field name="from_val"/>
-                                    <field name="to_val"/>
-                                    <field name="amount_type"/>
-                                    <field name="value"/>
-                                </tree>
-                            </field>
-                        </page>
-                        <page string="Description">
-                            <field name="note" colspan="4" nolabel="1"/>
-                        </page>
-                    </notebook>
-                </form>
-            </field>
-        </record>
-        <record id="hr_company_contribution_tree" model="ir.ui.view">
-            <field name="name">company.contribution.tree</field>
-            <field name="model">company.contribution</field>
-            <field name="type">tree</field>
-            <field name="arch" type="xml">
-                <tree string="Company Contribution">
-                    <field name="name"/>
-                    <field name="code"/>
-                    <field name="contribute_per"/>
-                    <field name="amount_type"/>
-                    <field name="register_id"/>
-                     <field name="category_id"/>
-                </tree>
-            </field>
-        </record>
-
-        <record id="view_hr_company_contribution_filter" model="ir.ui.view">
-            <field name="name">company.contribution.select</field>
-             <field name="model">company.contribution</field>
-            <field name="type">search</field>
-             <field name="arch" type="xml">
-                <search string="Search Company Contribution">
-                    <group col="8" colspan="4">
-                        <filter icon="terp-document-new" string="Fixed Amount" domain="[('amount_type','=','fix')]" help="Draft Slip"/>
-                        <filter icon="terp-camera_test" string="Function Calculation" domain="[('amount_type','=','func')]" help="Posted Slip"/>
-                        <separator orientation="vertical"/>
-                        <field name="name"/>
-                        <field name="code"/>
-                        <field name="contribute_per"/>
-                        <field name="register_id"/>
-                    </group>
-                    <newline/>
-                    <group col="8" colspan="4" expand="0" string="Group By...">
-                        <filter string="Type" icon="terp-stock_symbol-selection" name="amount_type" context="{'group_by':'amount_type'}"/>
-                        <filter string="Category" name="category_id" icon="terp-stock_symbol-selection"  context="{'group_by':'category_id'}"/>
-                    </group>
-                </search>
-            </field>
-        </record>
-        <record id="action_hr_company_contribution_tree" model="ir.actions.act_window">
-            <field name="name">Company Contributions</field>
-            <field name="res_model">company.contribution</field>
-            <field name="view_type">form</field>
-            <field name="view_id" ref="hr_company_contribution_tree"/>
-             <field name="search_view_id" ref="view_hr_company_contribution_filter"/>
-        </record>
-        <menuitem
-            id="menu_hr_company_contribution_tree"
-            action="action_hr_company_contribution_tree"
-            parent="payroll_configure"
-        />
-        <!-- End Company Contribution -->
-
-        <record id="view_hr_bank_advice_tree" model="ir.ui.view">
-            <field name="name">hr.payroll.advice.tree</field>
-            <field name="model">hr.payroll.advice</field>
-            <field name="type">tree</field>
-            <field name="arch" type="xml">
-                <tree string="Bank Advice">
-                    <field name="number" select="1"/>
-                    <field name="name" select="1"/>
-                    <field name="date" select="1"/>
-                    <field name="company_id" groups="base.group_multi_company" widget="selection"/>
-                </tree>
-            </field>
-        </record>
-
-        <record id="view_hr_bank_advice_form" model="ir.ui.view">
-            <field name="name">hr.payroll.advice.form</field>
-            <field name="model">hr.payroll.advice</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Bank Advice">
-                    <group col="6" colspan="4">
-                        <field name="name" colspan="4" select="1"/>
-                        <field name="number" select="1"/>
-                        <field name="register_id"/>
-                        <field name="bank_id"/>
-                    </group>
-                    <notebook colspan="4">
-                        <page string="Paymeny Lines">
-                            <field name="line_ids" colspan="4" nolabel="1">
-                                <tree string="Payment Lines" editable="bottom">
-                                    <field name="employee_id" on_change="onchange_employee_id(parent.date, employee_id)"/>
-                                    <field name="name"/>
-                                    <field name="amount"/>
-                                    <field name="bysal"/>
-                                    <field name="flag"/>
-                                </tree>
-                            </field>
-                        </page>
-                        <page string="Letter Content">
-                            <group colspan="4" col="6">
-                              <field name="company_id" on_change="onchange_company_id(company_id)" groups="base.group_multi_company" widget="selection"/>
-                              <field name="chaque_nos"/>
-                              <field name="date" select="1"/>
-                            </group>
-                            <separator colspan="4" string="Letter Details"/>
-                            <field name="note" colspan="4" nolabel="1"/>
-                        </page>
-                    </notebook>
-                    <group col="6" colspan="6">
-                        <field name="state"/>
-                        <button name="cancel_sheet" string="Cancel Sheet" states="draft" icon="gtk-cancel"  type="object"/>
-                        <button name="confirm_sheet"  icon="gtk-apply" string="Confirm Sheet" states="draft" type="object"/>
-                        <button name="set_to_draft" string="Set to Draft"  icon="gtk-convert"  states="cancel,confirm" type="object"/>
-                    </group>
-                </form>
-            </field>
-        </record>
-        <record id="action_view_hr_bank_advice_tree" model="ir.actions.act_window">
-            <field name="name">Payment Advice</field>
-            <field name="res_model">hr.payroll.advice</field>
-            <field name="view_type">form</field>
-            <field name="view_mode">tree,form</field>
-            <field name="view_id" ref="view_hr_bank_advice_tree"/>
-        </record>
-        <menuitem
-            action="action_view_hr_bank_advice_tree"
-            id="hr_menu_payment_advice"
-            parent="menu_hr_root_payroll"
-        />
-
-        <record id="view_hr_payroll_register_tree" model="ir.ui.view">
-            <field name="name">hr.payroll.register.tree</field>
-            <field name="model">hr.payroll.register</field>
-            <field name="type">tree</field>
-            <field name="arch" type="xml">
-                <tree  colors="blue:state in ('draft');black:state in ('confirm','new','hr_check','accont_check');gray:state in('done','cancel')" string="Payroll Register">
-                    <field name="number"/>
-                    <field name="name"/>
-                    <field name="date"/>
-                    <field name="state"/>
-                </tree>
-            </field>
-        </record>
-        <record id="view_hr_payroll_register_form" model="ir.ui.view">
-            <field name="name">hr.payroll.register.form</field>
-            <field name="model">hr.payroll.register</field>
-            <field name="type">form</field>
-            <field name="arch" type="xml">
-                <form string="Payroll Register">
-                    <group col="6" colspan="4">
-                        <field name="name" colspan="4" select="1"/>
-                        <field name="number" select="1"/>
-                        <field name="bank_id"/>
-                        <field name="date" select="1"/>
-                    </group>
-                    <notebook colspan="4">
-                        <page string="Payslips">
-                            <field name="line_ids" colspan="4" nolabel="1">
-                                <tree colors="blue:state in ('draft');black:state in ('confirm','new','hr_check','accont_check');gray:state in('done','cancel')" string="Payslip">
-                                    <field name="number"/>
-                                    <field name="employee_id"/>
-                                    <field name="name"/>
-                                    <field name="date"/>
-                                    <field name="basic"/>
-                                    <field name="allounce"/>
-                                    <field name="grows"/>
-                                    <field name="deduction"/>
-                                    <field name="net"/>
-                                    <field name="state"/>
-                                </tree>
-                            </field>
-                            <group col="2" colspan="2">
-                                <separator colspan="4" string="Allowance / Deduction"/>
-                                <field name="allounce"/>
-                                <field name="deduction"/>
-                            </group>
-                            <group col="2" colspan="2">
-                                <separator colspan="4" string="Salary Information"/>
-                                <field name="grows"/>
-                                <field name="net"/>
-                            </group>
-                        </page>
-                    </notebook>
-                    <group col="8" colspan="4">
-                        <field name="state"/>
-                        <button string="Cancel" name="cancel_sheet" icon="gtk-cancel" states="draft,hr_check,accont_check,confirm" type="object"/>
-                        <button string="Compute" name="compute_sheet" states="new" icon="terp-document-new" type="object"/>
-                        <button string="Verify Sheet" icon="gtk-ok" name="verify_sheet" states="draft" type="object"/>
-                        <button string="Complete HR Checking"  icon="gtk-apply" name="final_verify_sheet" type="object" states="hr_check"/>
-                        <button string="Pay Salary" icon="gtk-apply"  name="process_sheet" states="confirm" type="object" />
-                        <button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert" />
-                    </group>
-                </form>
-            </field>
-        </record>
-        <record id="action_view_hr_payroll_register_form" model="ir.actions.act_window">
-            <field name="name">Payroll Register</field>
-            <field name="res_model">hr.payroll.register</field>
-            <field name="view_type">form</field>
-            <field name="view_mode">tree,form</field>
-        </record>
-        <menuitem
-            action="action_view_hr_payroll_register_form"
-            id="hr_menu_payroll_register"
-            parent="menu_hr_root_payroll"
-        />
-
         <!--
         Contribution Register
         -->
@@ -892,8 +391,6 @@
                 <tree string="Contribution Registers">
                     <field name="name" select="1"/>
                     <field name="company_id" select="1" groups="base.group_multi_company" widget="selection"/>
-                    <field name="monthly_total_by_emp"/>
-                    <field name="monthly_total_by_comp"/>
                 </tree>
             </field>
         </record>
@@ -906,33 +403,16 @@
                     <field name="name" select="1"/>
                     <field name="company_id" select="1" groups="base.group_multi_company" widget="selection"/>
                     <notebook colspan="4">
-                        <page string="Contribution Lines">
-                            <field colspan="4" name="register_line_ids" nolabel="1" select="1">
-                                <tree string="Register Lines" editable="top">
-                                    <field name="code"/>
-                                    <field name="name"/>
-                                    <field name="employee_id"/>
-                                    <field name="emp_deduction"/>
-                                    <field name="comp_deduction"/>
-                                    <field name="total"/>
-                                </tree>
-                             </field>
-                         </page>
                          <page string="Description">
                             <separator colspan="4" string="Description"/>
                             <field name="note" colspan="4" nolabel="1"/>
                         </page>
                     </notebook>
-                    <group col="2" colspan="2" name="Month">
-                        <separator colspan="2" string="Month"/>
-                        <field name="monthly_total_by_emp"/>
-                        <field name="monthly_total_by_comp"/>
-                    </group>
                 </form>
             </field>
         </record>
         <record id="action_contibution_register_form" model="ir.actions.act_window">
-            <field name="name">Contribution Register</field>
+            <field name="name">Contribution Registers</field>
             <field name="res_model">hr.contibution.register</field>
             <field name="view_type">form</field>
             <field name="view_id" ref="hr_contibution_register_tree"/>
@@ -941,8 +421,9 @@
             id="menu_action_hr_contibution_register_form"
             action="action_contibution_register_form"
             parent="payroll_configure"
+            sequence="14"
         />
-        <record id="hr_contibution_register_line_form" model="ir.ui.view">
+        <!-- <record id="hr_contibution_register_line_form" model="ir.ui.view">
             <field name="name">hr.contibution.register.line.form</field>
             <field name="model">hr.contibution.register.line</field>
             <field name="type">form</field>
@@ -956,7 +437,7 @@
                       <field name="total"/>
                 </form>
             </field>
-        </record>
+        </record> -->
 
 
 
@@ -970,6 +451,101 @@
             id="act_hr_employee_payslip_list"
             groups="base.group_hr_manager"/>
 
+    <!-- Salary Rules -->
+
+    <record id="hr_salary_rule_tree" model="ir.ui.view">
+            <field name="name">hr.salary.rule.tree</field>
+            <field name="model">hr.salary.rule</field>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <tree string="Salary Rules">
+                    <field name="category_id"/>
+                    <field name="sequence" groups="base.group_extended"/>
+                    <field name="name"/>
+                    <field name="code"/>
+                    <field name="amount_select"/>
+                    <field name="condition_range_min"/>
+                    <field name="condition_range_max"/>
+                </tree>
+            </field>
+        </record>
+    <record id="hr_salary_rule_form" model="ir.ui.view">
+        <field name="name">hr.salary.rule.form</field>
+        <field name="model">hr.salary.rule</field>
+        <field name="type">form</field>
+        <field name="arch" type="xml">
+            <form string="Salary Rules">
+                <group col="6" colspan="6">
+                   <field name="name"/>
+                   <field name="code" select="1"/>
+                   <field name="category_id"/>
+                   <field name="sequence" />
+                   <field name="active"/>
+                   <field name="appears_on_payslip" attrs="{'readonly':[('company_contribution','=', True)]}" />
+                   <field name="company_id" widget="selection" groups="base.group_multi_company"/>
+                </group>
+                <notebook colspan="6">
+                    <page string="General">
+                            <group col="4" colspan="6">
+                                <separator colspan="4" string="Conditions"/>
+                                <field name="condition_select"/><newline/>
+                                <field name="condition_python" attrs="{'invisible':[('condition_select','&lt;&gt;','python')], 'required': [('condition_select','=','python')]}" colspan="4"/> <newline/>
+                                <field name="condition_range" attrs="{'invisible':[('condition_select','&lt;&gt;','range')], 'required':[('condition_select','=','range')]}"/><newline/>
+                                <field name="condition_range_min" colspan="2" attrs="{'invisible':[('condition_select','&lt;&gt;','range')], 'required':[('condition_select','=','range')]}"/>
+                                <field name="condition_range_max" colspan="2" attrs="{'invisible':[('condition_select','&lt;&gt;','range')], 'required':[('condition_select','=','range')]}"/>
+                                <separator colspan="4" string="Computation"/>
+                                <field name="amount_select"/><newline/>
+                                <field name="amount_fix"  attrs="{'invisible':[('amount_select','&lt;&gt;','fix')], 'required':[('amount_select','=','fix')]}"/>
+                                <field colspan="4" name="amount_python_compute" attrs="{'invisible':[('amount_select','&lt;&gt;','code')], 'required':[('amount_select','=','code')]}"/>
+				<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','&lt;&gt;','percentage')], 'required': [('amount_select','=','percentage')]}"/>
+                                <field name="amount_percentage" attrs="{'invisible':[('amount_select','&lt;&gt;','percentage')], 'required':[('amount_select','=','percentage')]}"/>
+                                <separator colspan="4" string="Company contribution"/>
+                                <field name="register_id"/>
+                            </group>
+                    </page>
+                    <page string="Child Rules">
+		       <field name="parent_rule_id"/>
+                       <separator colspan="4" string="Children definition"/>
+                       <field colspan="4" name="child_ids" nolabel="1"/>
+                    </page>
+                    <page string="Description">
+                        <field name="note" colspan="4" nolabel="1"/>
+                    </page>
+                </notebook>
+            </form>
+        </field>
+    </record>
+
+    <record id="view_hr_rule_filter" model="ir.ui.view">
+    <field name="name">hr.salary.rule.select</field>
+    <field name="model">hr.salary.rule</field>
+    <field name="type">search</field>
+    <field name="arch" type="xml">
+        <search string="Search Salary Rule">
+        <group col="8" colspan="4">
+            <field name="name"/>
+            <field name="condition_range_min"/>
+        </group>
+        <newline/>
+
+        <group col="8" colspan="4" expand="0" string="Group By...">
+            <filter string="Name" icon="terp-folder-yellow" name="name" context="{'group_by':'name'}"/>
+        </group>
+        </search>
+    </field>
+    </record>
+
+    <record id="action_salary_rule_form" model="ir.actions.act_window">
+        <field name="name">Salary Rules</field>
+        <field name="res_model">hr.salary.rule</field>
+        <field name="view_type">form</field>
+        <field name="view_id" ref="hr_salary_rule_tree"/>
+        <field name="domain">[('parent_rule_id','=',False)]</field>
+        <field name="search_view_id" ref="view_hr_rule_filter"/>
+    </record>
+
+    <menuitem id="menu_action_hr_salary_rule_form" action="action_salary_rule_form" parent="payroll_configure" sequence="12"/>
+
     </data>
 </openerp>
 

=== modified file 'hr_payroll/hr_payroll_workflow.xml'
--- hr_payroll/hr_payroll_workflow.xml	2011-01-14 00:11:01 +0000
+++ hr_payroll/hr_payroll_workflow.xml	2011-04-08 10:36:40 +0000
@@ -6,42 +6,36 @@
             <field name="osv">hr.payslip</field>
             <field name="on_create">True</field>
         </record>
-        
-        <record id="act_new" model="workflow.activity">
-            <field name="wkf_id" ref="wkf"/>
-            <field name="flow_start">True</field>
-            <field name="name">new</field>
-        </record>
-        
+
         <record id="act_draft" model="workflow.activity">
             <field name="wkf_id" ref="wkf"/>
             <field name="name">draft</field>
-            <field name="action">compute_sheet()</field>
+            <field name="flow_start">True</field>
             <field name="split_mode">OR</field>
-            <field name="kind">function</field>
+            <field name="kind">dummy</field>
         </record>
-        
+
         <record id="act_hr_check" model="workflow.activity">
             <field name="wkf_id" ref="wkf"/>
             <field name="name">hr_check</field>
             <field name="action">hr_check_sheet()</field>
             <field name="kind">function</field>
         </record>
-        
+
         <record id="act_confirm" model="workflow.activity">
             <field name="wkf_id" ref="wkf"/>
             <field name="name">confirm</field>
             <field name="action">verify_sheet()</field>
             <field name="kind">function</field>
         </record>
-        
+
         <record id="act_cancel" model="workflow.activity">
             <field name="wkf_id" ref="wkf"/>
             <field name="name">cancel</field>
             <field name="action">cancel_sheet()</field>
             <field name="kind">function</field>
         </record>
-        
+
         <record id="act_done" model="workflow.activity">
             <field name="wkf_id" ref="wkf"/>
             <field name="name">done</field>
@@ -49,55 +43,49 @@
             <field name="kind">function</field>
             <field name="flow_stop">True</field>
         </record>
-        
-        <record id="t1" model="workflow.transition">
-            <field name="act_from" ref="act_new"/>
-            <field name="act_to" ref="act_draft"/>
-            <field name="signal">compute_sheet</field>
-        </record>
-        
+
         <record id="t2" model="workflow.transition">
             <field name="act_from" ref="act_draft"/>
             <field name="act_to" ref="act_hr_check"/>
             <field name="signal">verify_sheet</field>
         </record>
-        
+
         <record id="t3" model="workflow.transition">
             <field name="act_from" ref="act_hr_check"/>
             <field name="act_to" ref="act_confirm"/>
             <field name="signal">final_verify_sheet</field>
         </record>
-        
+
         <record id="t4" model="workflow.transition">
             <field name="act_from" ref="act_confirm"/>
             <field name="act_to" ref="act_done"/>
             <field name="signal">process_sheet</field>
         </record>
-        
+
         <record id="t7" model="workflow.transition">
             <field name="act_from" ref="act_draft"/>
             <field name="act_to" ref="act_cancel"/>
             <field name="signal">cancel_sheet</field>
         </record>
-        
+
         <record id="t8" model="workflow.transition">
             <field name="act_from" ref="act_hr_check"/>
             <field name="act_to" ref="act_cancel"/>
             <field name="signal">cancel_sheet</field>
         </record>
-        
+
         <record id="t9" model="workflow.transition">
             <field name="act_from" ref="act_confirm"/>
             <field name="act_to" ref="act_cancel"/>
             <field name="signal">cancel_sheet</field>
         </record>
-        
+
         <record id="t11" model="workflow.transition">
             <field name="act_from" ref="act_done"/>
             <field name="act_to" ref="act_cancel"/>
             <field name="signal">cancel_sheet</field>
         </record>
-        
+
         <record id="t12" model="workflow.transition">
             <field name="act_from" ref="act_cancel"/>
             <field name="act_to" ref="act_draft"/>

=== modified file 'hr_payroll/report/payslip.rml'
--- hr_payroll/report/payslip.rml	2011-01-14 00:11:01 +0000
+++ hr_payroll/report/payslip.rml	2011-04-08 10:36:40 +0000
@@ -392,7 +392,7 @@
           <para style="terp_default_Bold_9">Basic Salary</para>
         </td>
         <td>
-          <para style="terp_default_9">[[ formatLang(o.basic_before_leaves, dp='Account') ]] [[ o.company_id.currency_id.symbol ]] </para>
+          <para style="terp_default_9">[[ formatLang(o.contract_id.wage, dp='Account') ]] [[ o.company_id.currency_id.symbol ]] </para>
         </td>
         <td>
           <para style="terp_default_Bold_9">Leaved Deduction</para>
@@ -521,35 +521,7 @@
     <para style="terp_default_space">
       <font color="white"> </font>
     </para>
-    <blockTable colWidths="269.0,134.0,135.0" style="Table21">
-      <tr>
-        <td>
-          <para style="terp_tblheader_Details">Other Lines</para>
-        </td>
-        <td>
-          <para style="terp_tblheader_Details_Right">Payments - [[ get_month(o) ]]</para>
-        </td>
-        <td>
-          <para style="terp_tblheader_Details_Right">Deduction -[[ get_month(o) ]]</para>
-        </td>
-      </tr>
-    </blockTable>
-    <section>
-      <para style="terp_default_9">[[repeatIn(get_others(o.line_ids),'ol') ]]</para>
-      <blockTable colWidths="269.0,134.0,135.0" style="Table22">
-        <tr>
-          <td>
-            <para style="terp_default_9">[[ ol.code or '' ]]</para>
-          </td>
-          <td>
-            <para style="terp_default_Right_9">[[ ol.type in ['advance','loan','otherpay'] and formatLang(ol.total, dp='Account') or '' ]] [[ ol.type in ['advance','loan','otherpay'] and o.company_id and o.company_id.currency_id.symbol or '' ]]</para>
-          </td>
-          <td>
-            <para style="terp_default_Right_9">[[ ol.type in ['otherdeduct','installment'] and formatLang(ol.total, dp='Account') or '' ]] [[ ol.type in ['otherdeduct','installment'] and o.company_id and o.company_id.currency_id.symbol or '' ]]</para>
-          </td>
-        </tr>
-      </blockTable>
-    </section>
+   
     <blockTable colWidths="269.0,177.0,93.0" style="Table5">
       <tr>
         <td>

=== modified file 'hr_payroll/report/payslip.sxw'
Binary files hr_payroll/report/payslip.sxw	2011-01-14 00:11:01 +0000 and hr_payroll/report/payslip.sxw	2011-04-08 10:36:40 +0000 differ
=== modified file 'hr_payroll/report/report_payslip.py'
--- hr_payroll/report/report_payslip.py	2011-01-14 00:11:01 +0000
+++ hr_payroll/report/report_payslip.py	2011-04-08 10:36:40 +0000
@@ -35,34 +35,24 @@
                 'get_month': self.get_month,
                 'get_earnings': self.get_earnings,
                 'get_deductions':self.get_deductions,
-                'get_leave':self.get_leave,
-                'get_others':self.get_others,
+                'get_leave': self.get_leave,
+                'get_payslip_lines': self.get_payslip_lines,
+#                'get_details_by_salary_head': self.get_details_by_salary_head
                 })
 
     def convert(self, amount, cur):
         amt_en = amount_to_text_en.amount_to_text(amount, 'en', cur)
         return amt_en
 
-    def get_others(self, obj):
-        payslip_line = self.pool.get('hr.payslip.line')
-        res = []
-        ids = []
-        for id in range(len(obj)):
-            if obj[id].category_id.type in ('advance', 'loan', 'otherpay', 'otherdeduct', 'installment'):
-                ids.append(obj[id].id)
-        if ids:
-            res = payslip_line.browse(self.cr, self.uid, ids)
-        return res
-
     def get_leave(self, obj):
         payslip_line = self.pool.get('hr.payslip.line')
         res = []
-        ids = []
-        for id in range(len(obj)):
-            if obj[id].type == 'leaves':
-                ids.append(obj[id].id)
-        if ids:
-            res = payslip_line.browse(self.cr, self.uid, ids)
+#        ids = []
+#        for id in range(len(obj)):
+#            if obj[id].type == 'leaves':
+#                ids.append(obj[id].id)
+#        if ids:
+#            res = payslip_line.browse(self.cr, self.uid, ids)
         return res
 
     def get_earnings(self, obj):
@@ -70,7 +60,7 @@
         res = []
         ids = []
         for id in range(len(obj)):
-            if obj[id].category_id.type == 'allowance' and obj[id].type != 'leaves':
+            if obj[id].category_id.parent_id.name == 'Allowance':
                 ids.append(obj[id].id)
         if ids:
             res = payslip_line.browse(self.cr, self.uid, ids)
@@ -81,7 +71,7 @@
         res = []
         ids = []
         for id in range(len(obj)):
-            if obj[id].category_id.type == 'deduction' and obj[id].type != 'leaves':
+            if obj[id].category_id.parent_id.name == 'Deduction':
                 ids.append(obj[id].id)
         if ids:
             res = payslip_line.browse(self.cr, self.uid, ids)
@@ -94,7 +84,19 @@
         date = datetime.strptime(obj.date, '%Y-%m-%d')
         res['mname']= date.strftime('%B')+"-"+date.strftime('%Y')
         return res['mname']
+    
+    def get_payslip_lines(self, obj):
+        payslip_line = self.pool.get('hr.payslip.line')
+        res = []
+        ids = []
+        for id in range(len(obj)):
+            if obj[id].appears_on_payslip == True:
+                ids.append(obj[id].id)
+        if ids:
+            res = payslip_line.browse(self.cr, self.uid, ids)
+        return res
 
 report_sxw.report_sxw('report.payslip.pdf', 'hr.payslip', 'hr_payroll/report/payslip.rml', parser=payslip_report)
+report_sxw.report_sxw('report.test.pdf', 'hr.payslip', 'hr_payroll/report/report_payslip.rml', parser=payslip_report)
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file

=== added file 'hr_payroll/report/report_payslip.rml'
--- hr_payroll/report/report_payslip.rml	1970-01-01 00:00:00 +0000
+++ hr_payroll/report/report_payslip.rml	2011-04-08 10:36:40 +0000
@@ -0,0 +1,345 @@
+<?xml version="1.0"?>
+<document filename="test.pdf">
+  <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
+    <pageTemplate id="first">
+      <frame id="first" x1="28.0" y1="28.0" width="539" height="786"/>
+    </pageTemplate>
+  </template>
+  <stylesheet>
+    <blockTableStyle id="Standard_Outline">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table2">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table15">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="2,0" stop="2,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="2,0" stop="2,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="3,0" stop="3,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="3,-1" stop="3,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table16">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="1,-1" stop="1,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table1">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="2,0" stop="2,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="2,0" stop="2,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="3,0" stop="3,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="3,-1" stop="3,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table17">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="2,0" stop="2,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="2,0" stop="2,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="3,0" stop="3,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="3,-1" stop="3,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table18">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="2,0" stop="2,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="2,0" stop="2,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#cccccc" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#cccccc" start="3,0" stop="3,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#cccccc" start="3,-1" stop="3,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table3">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#000000" start="3,0" stop="3,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,1" stop="0,-1"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,1" stop="1,-1"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,1" stop="2,-1"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
+      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,1" stop="3,-1"/>
+      <lineStyle kind="LINEAFTER" colorName="#000000" start="3,1" stop="3,-1"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table7">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+    </blockTableStyle>
+    <initialize>
+      <paraStyle name="all" alignment="justify"/>
+    </initialize>
+    <paraStyle name="P1" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT"/>
+    <paraStyle name="P2" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT"/>
+    <paraStyle name="P3" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER"/>
+    <paraStyle name="P4" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="P5" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="P6" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="P7" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="P8" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="Standard" fontName="Helvetica"/>
+    <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Caption" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="Index" fontName="Helvetica"/>
+    <paraStyle name="Table Contents" fontName="Helvetica"/>
+    <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER"/>
+    <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_8" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="Footer" fontName="Helvetica"/>
+    <paraStyle name="Horizontal Line" fontName="Helvetica" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/>
+    <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Bold_8" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Right_8" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="12.0" leading="15" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Centre_8" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="14.0" leading="17" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_address" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Bold_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Centre_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Right_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Bold_Right_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_2" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_White_2" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0" textColor="#ffffff"/>
+    <paraStyle name="terp_default_Note" rightIndent="0.0" leftIndent="9.0" fontName="Helvetica-Oblique" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="Table" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_space" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="14.0" leading="17" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <images/>
+  </stylesheet>
+  <story>
+    <para style="terp_default_8">[[repeatIn(objects,'o')]]</para>
+    <blockTable colWidths="539.0" style="Table2">
+      <tr>
+        <td>
+          <para style="terp_header_Centre">Pay Slip </para>
+          <para style="terp_default_Centre_9">
+            <font color="white"> </font>
+          </para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <blockTable colWidths="42.0,207.0,93.0,197.0" style="Table15">
+      <tr>
+        <td>
+          <para style="terp_default_Bold_9">Code</para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.employee_id.sinid or '' ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9">Name </para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9">[[o.employee_id.name]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="42.0,497.0" style="Table16">
+      <tr>
+        <td>
+          <para style="terp_default_Bold_9">Address </para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[o.employee_id.address_home_id and o.employee_id.address_home_id.name or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.street2 or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.zip or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.city or '' ]],[[o.employee_id.address_home_id and o.employee_id.address_home_id.state_id and o.employee_id.address_home_id.state_id.name or '' ]] [[o.employee_id.address_home_id and o.employee_id.address_home_id.country_id and o.employee_id.address_home_id.country_id.name or '' ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="42.0,207.0,93.0,197.0" style="Table1">
+      <tr>
+        <td>
+          <para style="terp_default_Bold_9">Email</para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.employee_id.work_email or '' ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9">Bank Details </para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.employee_id.otherid or '' ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="42.0,208.0,93.0,197.0" style="Table17">
+      <tr>
+        <td>
+          <para style="terp_default_Bold_9">Slip ID</para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.number or '' ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9">Identification No</para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.employee_id.passport_id and o.employee_id.passport_id.name or '' ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="42.0,208.0,93.0,197.0" style="Table18">
+      <tr>
+        <td>
+          <para style="terp_default_Bold_9">Register</para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.register_id and o.register_id.name or '' ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9">Designation </para>
+        </td>
+        <td>
+          <para style="terp_default_9">[[ o.employee_id.contract_id and o.employee_id.contract_id.job_id.name or '' ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="terp_default_space"/>
+    <para style="terp_default_Bold_9">
+      <font face="Helvetica" size="9.0">Payslip Lines </font>
+    </para>
+    <blockTable colWidths="135.0,135.0,135.0,135.0" style="Table3">
+      <tr>
+        <td>
+          <para style="P2">Sequence</para>
+        </td>
+        <td>
+          <para style="P2">Name</para>
+        </td>
+        <td>
+          <para style="P2">Code</para>
+        </td>
+        <td>
+          <para style="P2">Sub Total</para>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <para style="P8"><font face="Helvetica">[[repeatIn(get_payslip_lines(o.line_ids),'p') ]] </font>[[ p.sequence ]]</para>
+        </td>
+        <td>
+          <para style="P8">[[ p.name ]]</para>
+        </td>
+        <td>
+          <para style="P8">[[ p.code ]]</para>
+        </td>
+        <td>
+          <para style="P8">[[ p.total ]] [[ o.company_id and o.company_id.currency_id.symbol or '' ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="P4"/>
+    <para style="P4"/>
+    <para style="P4"/>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <section>
+      <para style="P8">
+        <font color="white"> </font>
+      </para>
+    </section>
+    <para style="terp_default_space">
+      <font color="white"> </font>
+    </para>
+    <section>
+      <para style="P8">
+        <font color="white"> </font>
+      </para>
+    </section>
+    <para style="P7">
+      <font color="white"> </font>
+    </para>
+    <para style="terp_default_9">
+      <font color="white"> </font>
+    </para>
+    <para style="Standard">
+      <font color="white"> </font>
+    </para>
+    <blockTable colWidths="269.0,269.0" style="Table7">
+      <tr>
+        <td>
+          <para style="terp_default_8">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="terp_tblheader_Details_Right">Authorized Signature </para>
+        </td>
+      </tr>
+    </blockTable>
+    <para style="terp_default_space">
+      <font color="white"> </font>
+    </para>
+  </story>
+</document>
+

=== added file 'hr_payroll/report/report_payslip.sxw'
Binary files hr_payroll/report/report_payslip.sxw	1970-01-01 00:00:00 +0000 and hr_payroll/report/report_payslip.sxw	2011-04-08 10:36:40 +0000 differ
=== modified file 'hr_payroll/security/ir.model.access.csv'
--- hr_payroll/security/ir.model.access.csv	2011-01-14 00:11:01 +0000
+++ hr_payroll/security/ir.model.access.csv	2011-04-08 10:36:40 +0000
@@ -1,20 +1,10 @@
 "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
-"access_hr_passport","hr.passport","model_hr_passport","base.group_hr_user",1,1,1,1
 "access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,1,1,1
-"access_hr_payroll_register","hr.payroll.register","model_hr_payroll_register","base.group_hr_user",1,1,1,1
-"access_hr_payroll_advice","hr.payroll.advice","model_hr_payroll_advice","base.group_hr_user",1,1,1,1
-"access_hr_payroll_advice_line","hr.payroll.advice.line","model_hr_payroll_advice_line","base.group_hr_user",1,1,1,1
 "access_hr_contibution_register","hr.contibution.register","model_hr_contibution_register","base.group_hr_user",1,1,1,1
-"access_hr_contibution_register_line","hr.contibution.register.line","model_hr_contibution_register_line","base.group_hr_user",1,1,1,1
-"access_hr_allounce_deduction_category","hr.allounce.deduction.category","model_hr_allounce_deduction_categoty","base.group_hr_user",1,1,1,1
-"access_company_contribution","company.contribution","model_company_contribution","base.group_hr_user",1,1,1,1
-"access_company_contribution_line","company.contribution.line","model_company_contribution_line","base.group_hr_user",1,1,1,1
+"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,1,1,1
 "access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,1,1,1
 "access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,1,1,1
-"access_hr_payslip_line_line","hr.payslip.line.line","model_hr_payslip_line_line","base.group_hr_user",1,1,1,1
 "access_res_partner_payroll","res.partner.payroll","base.model_res_partner","base.group_hr_user",1,1,1,1
 "access_hr_payslip_manager","hr.payslip.manager","model_hr_payslip","base.group_hr_manager",1,1,1,1
 "access_hr_payslip_line_manager","hr.payslip.line.manager","model_hr_payslip_line","base.group_hr_manager",1,1,1,1
 "access_hr_payroll_structure_manager","hr.payroll.structure.manager","model_hr_payroll_structure","base.group_hr_manager",1,1,1,1
-"access_hr_passport_manager","hr.passport.manager","model_hr_passport","base.group_hr_manager",1,1,1,1
-"access_hr_contract_wage_type","hr.contract.wage.type user","hr_contract.model_hr_contract_wage_type","base.group_hr_user",1,1,1,1

=== modified file 'resource/resource.py'
--- resource/resource.py	2011-03-21 13:06:45 +0000
+++ resource/resource.py	2011-04-08 10:36:40 +0000
@@ -43,6 +43,18 @@
         'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', context=context)
     }
 
+    def working_hours_on_day(self, cr, uid, resource_calendar_id, day, context=None):
+        """
+        @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
+        for working_day in resource_calendar_id.attendance_ids:
+            if (int(working_day.dayofweek) + 1) == day.isoweekday():
+                res += working_day.hour_to - working_day.hour_from
+        return res 
+
     def _get_leaves(self, cr, uid, id, resource):
         resource_cal_leaves = self.pool.get('resource.calendar.leaves')
         dt_leave = []