← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-payroll-payslip-on-payslip-mtr into lp:~openerp-dev/openobject-addons/trunk-payroll

 

Meera Trambadia (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-payroll-payslip-on-payslip-mtr into lp:~openerp-dev/openobject-addons/trunk-payroll.

Requested reviews:
  qdp (OpenERP) (qdp)
  Mustufa Rangwala (Open ERP) (mra-tinyerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-payslip-on-payslip-mtr/+merge/61921

*Added following methods to compute 'payslip' on 'other payslip'(based on some criteria) through a rule.
- payslip_sum()
- worked_days_sum()

-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-payslip-on-payslip-mtr/+merge/61921
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-05-12 11:57:19 +0000
+++ hr_payroll/hr_payroll.py	2011-05-23 07:17:25 +0000
@@ -473,18 +473,84 @@
             localdict['categories'][category.code] = category.code in localdict['categories'] and localdict['categories'][category.code] + amount or amount
             return localdict
 
+        class InputLine(object):
+            """a class that will be used into the python code, mainly for usability purposes"""
+            def __init__(self, pool, cr, uid, employee_id, dict):
+                self.pool = pool
+                self.cr = cr
+                self.uid = uid
+                self.employee_id = employee_id
+                self.dict = dict
+
+            def __getattr__(self, attr):
+                return self.dict.__getitem__(attr)
+
+            def sum(self, code, from_date, to_date=None):
+                if to_date is None:
+                    to_date = datetime.now().strftime('%Y-%m-%d')
+                result = 0.0
+                self.cr.execute("SELECT sum(quantity) as sum\
+                            FROM hr_payslip as hp, hr_payslip_input as pi \
+                            WHERE hp.employee_id = %s AND hp.state in ('confirm','done') \
+                            AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s",
+                           (self.employee_id, from_date, to_date, code))
+                res = self.cr.fetchone()[0]
+                return res or 0.0
+
+        class WorkedDays(InputLine):
+            """a class that will be used into the python code, mainly for usability purposes"""
+            def _sum(self, code, from_date, to_date=None):
+                if to_date is None:
+                    to_date = datetime.now().strftime('%Y-%m-%d')
+                result = 0.0
+                self.cr.execute("SELECT sum(number_of_days) as number_of_days, sum(number_of_hours) as number_of_hours\
+                            FROM hr_payslip as hp, hr_payslip_worked_days as pi \
+                            WHERE hp.employee_id = %s AND hp.state in ('confirm','done') \
+                            AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s",
+                           (self.employee_id, from_date, to_date, code))
+                return self.cr.fetchone()
+
+            def sum(self, code, from_date, to_date=None):
+                res = self._sum(code, from_date, to_date)
+                return res and res[0] or 0.0
+
+            def sum_hours(self, code, from_date, to_date=None):
+                res = self._sum(code, from_date, to_date)
+                return res and res[1] or 0.0
+
+        class Payslips(InputLine):
+            """a class that will be used into the python code, mainly for usability purposes"""
+
+            def sum(self, code, from_date, to_date=None):
+                if to_date is None:
+                    to_date = datetime.now().strftime('%Y-%m-%d')
+                self.cr.execute("SELECT sum(case when hp.credit_note = False then (pl.total) else (-pl.total) end)\
+                            FROM hr_payslip as hp, hr_payslip_line as pl \
+                            WHERE hp.employee_id = %s AND hp.state in ('confirm','done') \
+                            AND hp.date_from >= %s AND hp.date_to <= %s AND hp.id = pl.slip_id AND pl.code = %s",
+                            (self.employee_id, from_date, to_date, code))
+                res = self.cr.fetchone()
+                return res and res[0] or 0.0
+
         #we keep a dict with the result because a value can be overwritten by another rule with the same code
         result_dict = {}
         blacklist = []
+        payslip_obj = self.pool.get('hr.payslip')
+        inputs_obj = self.pool.get('hr.payslip.worked_days')
         obj_rule = self.pool.get('hr.salary.rule')
-        payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context)
+        payslip = payslip_obj.browse(cr, uid, payslip_id, context=context)
         worked_days = {}
         for worked_days_line in payslip.worked_days_line_ids:
             worked_days[worked_days_line.code] = worked_days_line
         inputs = {}
         for input_line in payslip.input_line_ids:
             inputs[input_line.code] = input_line
-        localdict = {'categories': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs}
+
+        input_obj = InputLine(self.pool, cr, uid, payslip.employee_id.id, inputs)
+        worked_days_obj = WorkedDays(self.pool, cr, uid, payslip.employee_id.id, worked_days)
+        payslip_obj = Payslips(self.pool, cr, uid, payslip.employee_id.id, payslip)
+
+        localdict = {'categories': {}, 'payslip': payslip_obj, 'worked_days': worked_days_obj, 'inputs': input_obj}
         #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
@@ -660,7 +726,7 @@
         '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"),
-        'quantity': fields.float('Quantity', help="It is used in computation. For e.g. A rule for sales having 1% commission of basic salary for per product can defined in expression like result = inputs['S-ASUS']['qunatity']*contract.wage*0.01."),
+        'quantity': fields.float('Quantity', help="It is used in computation. For e.g. A rule for sales having 1% commission of basic salary for per product can defined in expression like result = inputs.SASUS.qunatity * contract.wage*0.01."),
         'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"),
     }
     _order = 'payslip_id, sequence'
@@ -668,6 +734,7 @@
         'sequence': 10,
         'quantity': 0.0,
     }
+
 hr_payslip_input()
 
 class hr_salary_rule(osv.osv):
@@ -677,7 +744,7 @@
         'name':fields.char('Name', size=256, required=True, readonly=False),
         'code':fields.char('Code', size=64, required=True, help="The code of salary rules can be used as reference in computation of other rules. In that case, it is case sensitive."),
         'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'),
-        'quantity': fields.char('Quantity', size=256, help="It is used in computation for percentage and fixed amount.For e.g. A rule for Meal Voucher having fixed amount of 1€ per worked day can have its quantity defined in expression like worked_days['WORK100']['number_of_days']."),
+        'quantity': fields.char('Quantity', size=256, help="It is used in computation for percentage and fixed amount.For e.g. A rule for Meal Voucher having fixed amount of 1€ per worked day can have its quantity defined in expression like worked_days.WORK100.number_of_days."),
         'category_id':fields.many2one('hr.salary.rule.category', 'Category', 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"),
@@ -715,13 +782,13 @@
         'amount_python_compute': '''
 # Available variables:
 #----------------------
-# payslip: hr.payslip object
+# payslip: object containing the payslips
 # employee: hr.employee object
 # contract: hr.contract object
 # rules: rules code (previously computed)
 # categories: dictionary containing the computed salary rule categories (sum of amount of all rules belonging to that category). Keys are the category codes.
-# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
-# inputs: dictionary containing the computed inputs. Keys are the inputs codes.
+# worked_days: object containing the computed worked days.
+# inputs: object containing the computed inputs.
 
 # Note: returned value have to be set in the variable 'result'
 
@@ -730,13 +797,13 @@
 '''
 # Available variables:
 #----------------------
-# payslip: hr.payslip object
+# payslip: object containing the payslips
 # employee: hr.employee object
 # contract: hr.contract object
 # rules: rules code (previously computed)
 # categories: dictionary containing the computed salary rule categories (sum of amount of all rules belonging to that category). Keys are the category codes.
-# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
-# inputs: dictionary containing the computed inputs. Keys are the inputs codes.
+# worked_days: object containing the computed worked days
+# inputs: object containing the computed inputs
 
 # Note: returned value have to be set in the variable 'result'
 

=== modified file 'hr_payroll/hr_payroll_demo.xml'
--- hr_payroll/hr_payroll_demo.xml	2011-05-10 11:19:31 +0000
+++ hr_payroll/hr_payroll_demo.xml	2011-05-23 07:17:25 +0000
@@ -53,8 +53,8 @@
 
         <record id="hr_salary_rule_meal_voucher" model="hr.salary.rule">
             <field name="amount_select">fix</field>
-            <field eval="1" name="amount_fix"/>
-            <field name="quantity">worked_days['WORK100']['number_of_days']</field>
+            <field eval="10" name="amount_fix"/>
+            <field name="quantity">worked_days.WORK100.number_of_days</field>
             <field name="code">MA</field>
             <field name="category_id" ref="hr_payroll.ALW"/>
             <field name="name">Meal Voucher</field>
@@ -67,19 +67,19 @@
             <field name="category_id" ref="hr_payroll.ALW"/>
             <field name="name">Get 1% of sales</field>
             <field name="sequence" eval="17"/>
-            <field name="amount_python_compute">result = (inputs['S-ASUS']['quantity'] + inputs['S-CHINA']['quantity']) * contract.wage * 0.01</field>
+            <field name="amount_python_compute">result = (inputs.SASUS.quantity + inputs.SCHINA.quantity) * contract.wage * 0.01</field>
          </record>
 
         <!-- Rule Inputs -->
 
         <record id="hr_rule_input_sale_a" model="hr.rule.input">
-            <field name="code">S-ASUS</field>
+            <field name="code">SASUS</field>
             <field name="name">Sale to ASUStek</field>
             <field name="input_id" ref="hr_salary_rule_sales_commission"/>
         </record>
 
         <record id="hr_rule_input_sale_b" model="hr.rule.input">
-            <field name="code">S-CHINA</field>
+            <field name="code">SCHINA</field>
             <field name="name">Sale to China Export</field>
             <field name="input_id" ref="hr_salary_rule_sales_commission"/>
         </record>


Follow ups