2012-05-15 08:41:29 +00:00
#-*- coding:utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>). All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2012-05-21 07:06:43 +00:00
import time
2012-06-04 06:18:28 +00:00
from datetime import date
2012-05-24 11:24:12 +00:00
from datetime import datetime
2012-06-04 06:18:28 +00:00
from datetime import timedelta
2012-05-21 07:06:43 +00:00
from dateutil . relativedelta import relativedelta
2012-05-23 12:12:10 +00:00
2012-06-04 06:18:28 +00:00
from tools . translate import _
from calendar import isleap
2012-05-23 09:03:31 +00:00
from osv import fields , osv
import decimal_precision as dp
2012-05-21 07:06:43 +00:00
2012-05-15 08:41:29 +00:00
class hr_contract_in ( osv . osv ) :
_inherit = ' hr.contract '
2012-05-23 12:12:10 +00:00
_description = ' contract '
2012-05-23 07:29:45 +00:00
_columns = {
' tds ' : fields . float ( ' TDS ' , digits_compute = dp . get_precision ( ' Payroll ' ) ) ,
2012-05-23 12:12:10 +00:00
' house_rent_income ' : fields . float ( ' House Rent Income ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Income from house property. " ) ,
' saving_bank_account ' : fields . float ( ' Saving Bank Account Income ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Saving income for bank account. " ) ,
' other_income ' : fields . float ( ' Other Income ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Other income of employee. " ) ,
' short_term_gain ' : fields . float ( ' Short Term Gain from Share Trading/Equity MFs ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Stocks/equity mutual funds are sold before one year. " ) ,
' long_term_gain ' : fields . float ( ' Long Term Gain from Share Trading/Equity MFs ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Stocks/equity mutual funds are kept for more than a year. " ) ,
' food_coupon_amount ' : fields . float ( ' Food Coupons ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Amount of food coupon per day. " ) ,
' driver_salay ' : fields . boolean ( ' Driver Salary ' , help = " Allowance for company provided driver. " ) ,
' professional_tax ' : fields . float ( ' Professional Tax ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Professional tax deducted from salary " ) ,
' leave_avail_dedution ' : fields . float ( ' Leave Availed Deduction ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Deduction for emergency leave of employee. " ) ,
' medical_insurance ' : fields . float ( ' Medical Insurance ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Deduction towards company provided medical insurance. " ) ,
' voluntary_provident_fund ' : fields . float ( ' Voluntary Provident Fund ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " VPF computed as percentage.( % ) " ) ,
' company_transport ' : fields . float ( ' Company Provided Transport ' , digits_compute = dp . get_precision ( ' Payroll ' ) , help = " Deduction for company provided transport. " ) ,
2012-05-23 07:29:45 +00:00
}
hr_contract_in ( )
class hr_employee ( osv . osv ) :
_inherit = ' hr.employee '
2012-05-23 12:12:10 +00:00
_description = ' employee '
2012-05-21 07:06:43 +00:00
def _compute_year ( self , cr , uid , ids , fields , args , context = None ) :
"""
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
2012-05-24 11:24:12 +00:00
@param ids : List of employee ’ s IDs
2012-05-21 07:06:43 +00:00
@return : No . of years of experience .
@param context : A standard dictionary for contextual values
"""
res = { }
2012-05-23 05:45:19 +00:00
DATETIME_FORMAT = " % Y- % m- %d "
2012-05-24 11:24:12 +00:00
c_date = time . strftime ( DATETIME_FORMAT )
2012-05-23 05:45:19 +00:00
current_date = datetime . strptime ( c_date , DATETIME_FORMAT )
2012-05-23 12:12:10 +00:00
for employee in self . browse ( cr , uid , ids , context = context ) :
2012-05-23 05:45:19 +00:00
if employee . join_date :
date_start = datetime . strptime ( employee . join_date , DATETIME_FORMAT )
diffyears = current_date . year - date_start . year
difference = current_date - date_start . replace ( current_date . year )
days_in_year = isleap ( current_date . year ) and 366 or 365
difference_in_years = diffyears + ( difference . days + difference . seconds / 86400.0 ) / days_in_year
total_years = relativedelta ( current_date , date_start ) . years
total_months = relativedelta ( current_date , date_start ) . months
if total_months < 10 :
2012-05-23 12:12:10 +00:00
year_month = float ( total_months ) / 10 + total_years
2012-05-23 05:45:19 +00:00
else :
2012-05-23 12:12:10 +00:00
year_month = float ( total_months ) / 100 + total_years
2012-05-23 09:03:31 +00:00
res [ employee . id ] = year_month
2012-05-23 13:35:05 +00:00
else :
res [ employee . id ] = 0.0
2012-05-21 07:06:43 +00:00
return res
2012-05-23 07:29:45 +00:00
2012-05-23 05:45:19 +00:00
_columns = {
2012-05-23 12:12:10 +00:00
' join_date ' : fields . date ( ' Join Date ' , help = " joining date of employee " ) ,
2012-05-24 11:24:12 +00:00
' number_of_year ' : fields . function ( _compute_year , string = ' No. of Years of Service ' , type = " float " , store = True , help = " Total years of work experience. " ) ,
2012-05-23 05:45:19 +00:00
}
hr_employee ( )
2012-06-04 06:18:28 +00:00
class payroll_advice ( osv . osv ) :
'''
Bank Advice Note
'''
_name = ' hr.payroll.advice '
_description = ' Bank Advice Note '
_columns = {
' 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 . 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 : ' draft ' ,
' company_id ' : lambda self , cr , uid , context : \
self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid ,
context = context ) . company_id . id ,
}
def compute_advice ( self , cr , uid , ids , context = None ) :
payslip_pool = self . pool . get ( ' hr.payslip ' )
advice_line_pool = self . pool . get ( ' hr.payroll.advice.line ' )
sequence_pool = self . pool . get ( ' ir.sequence ' )
payslip_line_pool = self . pool . get ( ' hr.payslip.line ' )
2012-06-06 09:55:08 +00:00
DATETIME_FORMAT = " % Y- % m- %d "
2012-06-04 06:18:28 +00:00
for advice in self . browse ( cr , uid , ids , context = context ) :
2012-06-06 09:55:08 +00:00
old_line_ids = advice_line_pool . search ( cr , uid , [ ( ' advice_id ' , ' = ' , advice . id ) ] , context = context )
if old_line_ids :
advice_line_pool . unlink ( cr , uid , old_line_ids , context = context )
slip_ids = payslip_pool . search ( cr , uid , [ ( ' date_from ' , ' <= ' , advice . date ) , ( ' date_to ' , ' >= ' , advice . date ) ] , context = context )
2012-06-04 06:18:28 +00:00
if not slip_ids :
2012-06-06 09:55:08 +00:00
advice_date = datetime . strptime ( advice . date , DATETIME_FORMAT )
a_date = advice_date . strftime ( ' % B ' ) + ' - ' + advice_date . strftime ( ' % Y ' )
raise osv . except_osv ( _ ( ' Error ! ' ) , _ ( ' No payslips for %s ' ) % ( a_date ) )
for slip in payslip_pool . browse ( cr , uid , slip_ids , context = context ) :
line_ids = payslip_line_pool . search ( cr , uid , [ ( ' slip_id ' , ' in ' , slip_ids ) , ( ' code ' , ' = ' , " NET " ) ] , context = context )
for line in slip . 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 ) )
advice_line = {
' advice_id ' : advice . id ,
' name ' : slip . employee_id . bank_account_id . acc_number ,
' employee_id ' : slip . employee_id . id ,
' bysal ' : line . total
}
id = advice_line_pool . create ( cr , uid , advice_line , context = context )
number = self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' payment.advice ' )
self . write ( cr , uid , ids , { ' number ' : number } , context = context )
2012-06-04 06:18:28 +00:00
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 ) ,
2012-06-06 09:55:08 +00:00
' name ' : fields . char ( ' Bank Account No. ' , size = 64 , required = True , readonly = False ) ,
2012-06-04 06:18:28 +00:00
' employee_id ' : fields . many2one ( ' hr.employee ' , ' Employee ' , required = True ) ,
' bysal ' : fields . float ( ' By Salary ' , digits_compute = dp . get_precision ( ' Payroll ' ) ) ,
}
payroll_advice_line ( )
2012-05-15 08:41:29 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: