← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-payroll-details_by_salary_head-psi into lp:~openerp-dev/openobject-addons/trunk-payroll

 

Purnendu Singh (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-payroll-details_by_salary_head-psi into lp:~openerp-dev/openobject-addons/trunk-payroll.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-details_by_salary_head-psi/+merge/56886

Hello sir,

put back the tab with rules grouped by head. On Payslip

Thanks
Purnendu Singh 
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-details_by_salary_head-psi/+merge/56886
Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-addons/trunk-payroll-details_by_salary_head-psi into lp:~openerp-dev/openobject-addons/trunk-payroll.
=== modified file 'hr_payroll/hr_payroll.py'
--- hr_payroll/hr_payroll.py	2011-04-07 12:40:50 +0000
+++ hr_payroll/hr_payroll.py	2011-04-08 07:17:45 +0000
@@ -191,37 +191,27 @@
     _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
+    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 = {}
+        for payslip in self.browse(cr, uid, ids, context=context):
+            if payslip.contract_id:
+                contract_ids = [payslip.contract_id.id]
+            else:
+                contract_ids = self.get_contract(cr, uid, payslip.employee_id, payslip.date_from, payslip.date_to, context=context)
+            structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context)
+            rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, structure_ids, context=context)
+            sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])]
+            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(sorted_rule_ids),))
+
+            sorted_salary_heads = [id[0] for id in cr.fetchall()]
+            for field in field_names:
+               if field == 'details_by_salary_head':
+                   res[payslip.id] = {field: 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'),
@@ -250,8 +240,7 @@
         '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)]}),
-       #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'),
+        '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'),
@@ -503,7 +492,7 @@
         #defaults
         res = {'value':{
                       'line_ids':[],
-                      #'details_by_salary_head':[], TODO put me back
+                      'details_by_salary_head':[],
                       'name':'',
                       'contract_id': False,
                       'struct_id': False,

=== modified file 'hr_payroll/hr_payroll_view.xml'
--- hr_payroll/hr_payroll_view.xml	2011-04-07 13:06:34 +0000
+++ hr_payroll/hr_payroll_view.xml	2011-04-08 07:17:45 +0000
@@ -225,18 +225,17 @@
                                 </form>
                             </field>
                         </page>
-<!-- TODO: put me back -->
-<!--                       <page string="Details By Salary Head">
+                       <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"/>
+                                    <field name="amount_select"/>
                                 </tree>
                             </field>
-                       </page>-->
+                       </page>
 
                        <page string="Worked Days">
                             <field name="input_line_ids" colspan="4" nolabel="1" mode="tree">
@@ -495,14 +494,14 @@
                                 <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_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"/>
+               <field name="parent_rule_id"/>
                        <separator colspan="4" string="Children definition"/>
                        <field colspan="4" name="child_ids" nolabel="1"/>
                     </page>


Follow ups