← 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:
  Purnendu Singh (OpenERP) (psi-tinyerp)
  Mustufa Rangwala (Open ERP) (mra-tinyerp)

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

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/56935
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-payroll.
=== modified file 'hr_payroll/hr_payroll.py'
--- hr_payroll/hr_payroll.py	2011-04-08 13:04:34 +0000
+++ hr_payroll/hr_payroll.py	2011-04-08 13:25:46 +0000
@@ -185,38 +185,6 @@
     _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)]}),
@@ -238,14 +206,13 @@
             \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)]}),
+        'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', domain=[('type','=','payslip_line')], context={'default_type':'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)]}),
-       #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.one2many('hr.payslip.line', 'slip_id', 'Payslip', domain=[('type','=','payslip_by_head')], context={'default_type':'payslip_by_head'}, required=False, readonly=True, states={'draft': [('readonly', False)]}),
     }
     _defaults = {
         'date_from': lambda *a: time.strftime('%Y-%m-01'),
@@ -374,6 +341,21 @@
                 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)
+            line_ids = self.get_salary_rules(cr, uid, lines, payslip.id, context=context)
+            res = []
+            for line in slip_line_pool.read(cr, uid, line_ids, {}, context=context):
+                vals = {
+                    'code': line['code'],
+                    'name': line['name'],
+                    'sequence': line['sequence'],
+                    'amount_select': line['amount_select'],
+                    'category_id': line['category_id'][0],
+                    'employee_id': line['employee_id'][0],
+                    'type': 'payslip_by_head',
+                }
+                res.append(vals)
+            res = [(0,0,item) for item in res]
+            self.write(cr, uid, [payslip.id], {'details_by_salary_head': res}, context=context)
         return True
 
     def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None):
@@ -433,6 +415,14 @@
             res += [attendances] + leaves
         return res
 
+    def get_salary_rules(self, cr, uid, lines, payslip_id, context=None):
+        category_ids = [line[2]['category_id'] for line in lines]
+        cr.execute('''SELECT sl.id FROM hr_payslip_line AS sl \
+                LEFT JOIN hr_salary_head AS sh on (sl.category_id = sh.id) \
+                WHERE sl.slip_id = %s \
+                AND sh.id IN %s ORDER BY sh.sequence''',(payslip_id, tuple(category_ids),))
+        return [id[0] for id in cr.fetchall()]
+
     def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context):
         result = []
         blacklist = []
@@ -478,6 +468,7 @@
                         'register_id': rule.register_id.id,
                         'total': amount,
                         'employee_id': contract.employee_id.id,
+                        'type': 'payslip_line',
                     }
                     result.append(vals)
                 else:
@@ -500,7 +491,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,
@@ -540,6 +531,11 @@
         res['value'].update({
                     'input_line_ids': input_line_ids,
             })
+#        #computation of the detail by salary heads
+#        details_by_head = self.get_salary_rules(cr, uid, contract_ids, 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):
@@ -729,7 +725,11 @@
 
     _columns = {
         'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=True),
-        'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
+        'type':  fields.selection([
+            ('payslip_line', 'a'),
+            ('payslip_by_head', 'b'),
+            ], 'Test'),
+        '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')),
     }

=== modified file 'hr_payroll/hr_payroll_view.xml'
--- hr_payroll/hr_payroll_view.xml	2011-04-08 13:03:13 +0000
+++ hr_payroll/hr_payroll_view.xml	2011-04-08 13:25:46 +0000
@@ -233,18 +233,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">
@@ -501,14 +500,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