2010-06-18 20:30:58 +00:00
#-*- coding:utf-8 -*-
##############################################################################
#
2010-07-27 07:11:45 +00:00
# OpenERP, Open Source Management Solution
2010-06-18 20:30:58 +00:00
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# d$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import netsvc
2010-07-27 07:11:45 +00:00
from datetime import date , datetime , timedelta
from osv import fields , osv
2010-06-18 20:30:58 +00:00
from tools import config
from tools . translate import _
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
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_payslip ( osv . osv ) :
'''
Pay Slip
'''
_inherit = ' hr.payslip '
_description = ' Pay Slip '
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
_columns = {
' move_ids ' : fields . one2many ( ' hr.payslip.account.move ' , ' slip_id ' , ' Accounting vouchers ' , required = False ) ,
' move_line_ids ' : fields . many2many ( ' account.move.line ' , ' payslip_lines_rel ' , ' slip_id ' , ' line_id ' , ' Accounting Lines ' , readonly = True ) ,
' move_payment_ids ' : fields . many2many ( ' account.move.line ' , ' payslip_payment_rel ' , ' slip_id ' , ' payment_id ' , ' Payment Lines ' , readonly = True ) ,
' period_id ' : fields . many2one ( ' account.period ' , ' Force Period ' , domain = [ ( ' state ' , ' <> ' , ' done ' ) ] , help = " Keep empty to use the period of the validation(Payslip) date. " ) ,
}
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
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 )
2010-07-27 07:11:45 +00:00
def cancel_sheet ( self , cr , uid , ids , context = None ) :
2010-06-18 20:30:58 +00:00
move_pool = self . pool . get ( ' account.move ' )
2010-07-02 10:37:15 +00:00
slip_move = self . pool . get ( ' hr.payslip.account.move ' )
2010-07-27 07:11:45 +00:00
if context is None :
context = { }
2010-07-02 10:37:15 +00:00
move_ids = [ ]
2010-07-27 07:11:45 +00:00
for slip in self . browse ( cr , uid , ids , context = context ) :
2010-07-02 10:37:15 +00:00
for line in slip . move_ids :
move_ids . append ( line . id )
if line . move_id :
if line . move_id . state == ' posted ' :
move_pool . button_cancel ( cr , uid [ line . move_id . id ] , context )
2010-07-27 07:11:45 +00:00
move_pool . unlink ( cr , uid , [ line . move_id . id ] , context = context )
slip_move . unlink ( cr , uid , move_ids , context = context )
self . write ( cr , uid , ids , { ' state ' : ' cancel ' } , context = context )
2010-06-18 20:30:58 +00:00
return True
2010-07-27 07:11:45 +00:00
def process_sheet ( self , cr , uid , ids , context = None ) :
2010-06-18 20:30:58 +00:00
move_pool = self . pool . get ( ' account.move ' )
movel_pool = self . pool . get ( ' account.move.line ' )
invoice_pool = self . pool . get ( ' account.invoice ' )
2010-07-27 07:11:45 +00:00
fiscalyear_pool = self . pool . get ( ' account.fiscalyear ' )
period_pool = self . pool . get ( ' account.period ' )
if context is None :
context = { }
for slip in self . browse ( cr , uid , ids , context = context ) :
2010-06-18 20:30:58 +00:00
line_ids = [ ]
partner = False
partner_id = False
exp_ids = [ ]
2010-07-27 07:11:45 +00:00
2010-06-19 15:04:13 +00:00
partner = slip . employee_id . bank_account_id . partner_id
2010-06-18 20:30:58 +00:00
partner_id = partner . id
2010-07-27 07:11:45 +00:00
fiscal_year_ids = fiscalyear_pool . search ( cr , uid , [ ] , context = context )
2010-06-18 20:30:58 +00:00
if not fiscal_year_ids :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Please define fiscal year for perticular contract ' ) )
2010-07-27 07:11:45 +00:00
fiscal_year_objs = fiscalyear_pool . read ( cr , uid , fiscal_year_ids , [ ' date_start ' , ' date_stop ' ] , context = context )
2010-06-18 20:30:58 +00:00
year_exist = False
for fiscal_year in fiscal_year_objs :
if ( ( fiscal_year [ ' date_start ' ] < = slip . date ) and ( fiscal_year [ ' date_stop ' ] > = slip . date ) ) :
year_exist = True
if not year_exist :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Fiscal Year is not defined for slip date %s ' % slip . date ) )
2010-07-27 07:11:45 +00:00
search_periods = period_pool . search ( cr , uid , [ ( ' date_start ' , ' <= ' , slip . date ) , ( ' date_stop ' , ' >= ' , slip . date ) ] , context = context )
if not search_periods :
2010-06-18 20:30:58 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Period is not defined for slip date %s ' % slip . date ) )
2010-07-27 07:11:45 +00:00
period_id = search_periods [ 0 ]
2010-06-18 20:30:58 +00:00
name = ' Payment of Salary to %s ' % ( slip . employee_id . name )
move = {
' journal_id ' : slip . bank_journal_id . id ,
2010-07-27 07:11:45 +00:00
' period_id ' : period_id ,
2010-06-18 20:30:58 +00:00
' date ' : slip . date ,
' type ' : ' bank_pay_voucher ' ,
' ref ' : slip . number ,
' narration ' : name
}
2010-07-27 07:11:45 +00:00
move_id = move_pool . create ( cr , uid , move , context = context )
2010-06-18 20:30:58 +00:00
self . create_voucher ( cr , uid , [ slip . id ] , name , move_id )
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
name = " To %s account " % ( slip . employee_id . name )
ded_rec = {
' move_id ' : move_id ,
' name ' : name ,
#'partner_id': partner_id,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : slip . employee_id . property_bank_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' credit ' : slip . total_pay ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
name = " By %s account " % ( slip . employee_id . property_bank_account . name )
cre_rec = {
' move_id ' : move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
' date ' : slip . date ,
' account_id ' : partner . property_account_payable . id ,
' debit ' : slip . total_pay ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , cre_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
other_pay = slip . other_pay
#Process all Reambuse Entries
for line in slip . line_ids :
if line . type == ' otherpay ' and line . expanse_id . invoice_id :
if not line . expanse_id . invoice_id . move_id :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Please Confirm all Expanse Invoice appear for Reimbursement ' ) )
invids = [ line . expanse_id . invoice_id . id ]
amount = line . total
acc_id = slip . bank_journal_id . default_credit_account_id and slip . bank_journal_id . default_credit_account_id . id
period_id = slip . period_id . id
journal_id = slip . bank_journal_id . id
name = ' [ %s ]- %s ' % ( slip . number , line . name )
invoice_pool . pay_and_reconcile ( cr , uid , invids , amount , acc_id , period_id , journal_id , False , period_id , False , context , name )
other_pay - = amount
#TODO: link this account entries to the Payment Lines also Expanse Entries to Account Lines
2010-07-27 07:11:45 +00:00
l_ids = movel_pool . search ( cr , uid , [ ( ' name ' , ' = ' , name ) ] , context = context )
2010-06-18 20:30:58 +00:00
line_ids + = l_ids
2010-07-27 07:11:45 +00:00
l_ids = movel_pool . search ( cr , uid , [ ( ' invoice ' , ' = ' , line . expanse_id . invoice_id . id ) ] , context = context )
2010-06-18 20:30:58 +00:00
exp_ids + = l_ids
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
#Process for Other payment if any
other_move_id = False
if slip . other_pay > 0 :
narration = ' Payment of Other Payeble amounts to %s ' % ( slip . employee_id . name )
move = {
' journal_id ' : slip . bank_journal_id . id ,
2010-07-27 07:11:45 +00:00
' period_id ' : period_id ,
2010-06-18 20:30:58 +00:00
' date ' : slip . date ,
' type ' : ' bank_pay_voucher ' ,
' ref ' : slip . number ,
' narration ' : narration
}
2010-07-27 07:11:45 +00:00
other_move_id = move_pool . create ( cr , uid , move , context = context )
2010-06-18 20:30:58 +00:00
self . create_voucher ( cr , uid , [ slip . id ] , narration , move_id )
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
name = " To %s account " % ( slip . employee_id . name )
ded_rec = {
' move_id ' : other_move_id ,
' name ' : name ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : slip . employee_id . property_bank_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' credit ' : other_pay ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
name = " By %s account " % ( slip . employee_id . property_bank_account . name )
cre_rec = {
' move_id ' : other_move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
' date ' : slip . date ,
' account_id ' : partner . property_account_payable . id ,
' debit ' : other_pay ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , cre_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
rec = {
' state ' : ' done ' ,
' move_payment_ids ' : [ ( 6 , 0 , line_ids ) ] ,
' paid ' : True
}
2010-07-27 07:11:45 +00:00
self . write ( cr , uid , [ slip . id ] , rec , context = context )
2010-06-18 20:30:58 +00:00
for exp_id in exp_ids :
2010-07-27 07:11:45 +00:00
self . write ( cr , uid , [ slip . id ] , { ' move_line_ids ' : [ ( 4 , exp_id ) ] } , context = context )
2010-06-18 20:30:58 +00:00
return True
2010-07-27 07:11:45 +00:00
def account_check_sheet ( self , cr , uid , ids , context = None ) :
if context is None :
context = { }
self . write ( cr , uid , ids , { ' state ' : ' accont_check ' } , context = context )
2010-06-18 20:30:58 +00:00
return True
2010-07-27 07:11:45 +00:00
def hr_check_sheet ( self , cr , uid , ids , context = None ) :
if context is None :
context = { }
self . write ( cr , uid , ids , { ' state ' : ' hr_check ' } , context = context )
2010-06-18 20:30:58 +00:00
return True
2010-07-27 07:11:45 +00:00
def verify_sheet ( self , cr , uid , ids , context = None ) :
2010-06-18 20:30:58 +00:00
move_pool = self . pool . get ( ' account.move ' )
movel_pool = self . pool . get ( ' account.move.line ' )
exp_pool = self . pool . get ( ' hr.expense.expense ' )
2010-07-27 07:11:45 +00:00
fiscalyear_pool = self . pool . get ( ' account.fiscalyear ' )
period_pool = self . pool . get ( ' account.period ' )
property_pool = self . pool . get ( ' ir.property ' )
payslip_pool = self . pool . get ( ' hr.payslip.line ' )
if context is None :
context = { }
for slip in self . browse ( cr , uid , ids , context = context ) :
2010-06-18 20:30:58 +00:00
total_deduct = 0.0
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
line_ids = [ ]
partner = False
partner_id = False
2010-07-27 07:11:45 +00:00
2010-06-19 15:04:13 +00:00
if not slip . employee_id . bank_account_id :
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please defined bank account for %s ! ' % ( slip . employee_id . name ) ) )
2010-07-27 07:11:45 +00:00
2010-06-19 15:04:13 +00:00
if not slip . employee_id . bank_account_id . partner_id :
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please defined partner in bank account for %s ! ' % ( slip . employee_id . name ) ) )
2010-07-27 07:11:45 +00:00
2010-06-19 15:04:13 +00:00
partner = slip . employee_id . bank_account_id . partner_id
partner_id = slip . employee_id . bank_account_id . partner_id . id
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
period_id = False
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
if slip . period_id :
period_id = slip . period_id . id
else :
2010-07-27 07:11:45 +00:00
fiscal_year_ids = fiscalyear_pool . search ( cr , uid , [ ] , context = context )
2010-06-18 20:30:58 +00:00
if not fiscal_year_ids :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Please define fiscal year for perticular contract ' ) )
2010-07-27 07:11:45 +00:00
fiscal_year_objs = fiscalyear_pool . read ( cr , uid , fiscal_year_ids , [ ' date_start ' , ' date_stop ' ] , context = context )
2010-06-18 20:30:58 +00:00
year_exist = False
for fiscal_year in fiscal_year_objs :
if ( ( fiscal_year [ ' date_start ' ] < = slip . date ) and ( fiscal_year [ ' date_stop ' ] > = slip . date ) ) :
year_exist = True
if not year_exist :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Fiscal Year is not defined for slip date %s ' % slip . date ) )
2010-07-27 07:11:45 +00:00
search_periods = period_pool . search ( cr , uid , [ ( ' date_start ' , ' <= ' , slip . date ) , ( ' date_stop ' , ' >= ' , slip . date ) ] , context = context )
if not search_periods :
2010-06-18 20:30:58 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Period is not defined for slip date %s ' % slip . date ) )
2010-07-27 07:11:45 +00:00
period_id = search_periods [ 0 ]
2010-06-18 20:30:58 +00:00
move = {
2010-07-27 07:11:45 +00:00
#'name': slip.name,
2010-06-18 20:30:58 +00:00
' journal_id ' : slip . journal_id . id ,
2010-07-27 07:11:45 +00:00
' period_id ' : period_id ,
2010-06-18 20:30:58 +00:00
' date ' : slip . date ,
' ref ' : slip . number ,
' narration ' : slip . name
}
2010-07-27 07:11:45 +00:00
move_id = move_pool . create ( cr , uid , move , context = context )
2010-06-18 20:30:58 +00:00
self . create_voucher ( cr , uid , [ slip . id ] , slip . name , move_id )
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
line = {
' move_id ' : move_id ,
' name ' : " By Basic Salary / " + slip . employee_id . name ,
' date ' : slip . date ,
2010-07-27 07:11:45 +00:00
' account_id ' : slip . employee_id . salary_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : slip . basic ,
' credit ' : 0.0 ,
' quantity ' : slip . working_days ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' analytic_account_id ' : False ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
#Setting Analysis Account for Basic Salary
if slip . employee_id . analytic_account :
line [ ' analytic_account_id ' ] = slip . employee_id . analytic_account . id
2010-07-27 07:11:45 +00:00
move_line_id = movel_pool . create ( cr , uid , line , context = context )
2010-06-18 20:30:58 +00:00
line_ids + = [ move_line_id ]
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
line = {
' move_id ' : move_id ,
' name ' : " To Basic Paysble Salary / " + slip . employee_id . name ,
' partner_id ' : partner_id ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : slip . employee_id . employee_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' quantity ' : slip . working_days ,
' credit ' : slip . basic ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , line , context = context ) ]
2010-06-18 20:30:58 +00:00
for line in slip . line_ids :
name = " [ %s ] - %s / %s " % ( line . code , line . name , slip . employee_id . name )
amount = line . total
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
if line . type == ' leaves ' :
continue
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
rec = {
' move_id ' : move_id ,
' name ' : name ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : line . account_id . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' analytic_account_id ' : False ,
' ref ' : slip . number ,
' quantity ' : 1
}
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
#Setting Analysis Account for Salary Slip Lines
if line . analytic_account_id :
rec [ ' analytic_account_id ' ] = line . analytic_account_id . id
2010-07-27 07:11:45 +00:00
else :
2010-06-18 20:30:58 +00:00
rec [ ' analytic_account_id ' ] = slip . deg_id . account_id . id
2010-07-27 07:11:45 +00:00
2010-07-02 10:37:15 +00:00
if line . type == ' allowance ' or line . type == ' otherpay ' :
2010-06-18 20:30:58 +00:00
rec [ ' debit ' ] = amount
if not partner . property_account_payable :
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please Configure Partners Payable Account!! ' ) )
ded_rec = {
' move_id ' : move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : partner . property_account_payable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' quantity ' : 1 ,
' credit ' : amount ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
elif line . type == ' deduction ' or line . type == ' otherdeduct ' :
if not partner . property_account_receivable :
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please Configure Partners Receivable Account!! ' ) )
rec [ ' credit ' ] = amount
total_deduct + = amount
ded_rec = {
' move_id ' : move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
2010-06-18 20:30:58 +00:00
' quantity ' : 1 ,
2010-07-27 07:11:45 +00:00
' account_id ' : partner . property_account_receivable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : amount ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
line_ids + = [ movel_pool . create ( cr , uid , rec , context = context ) ]
2010-07-07 13:03:47 +00:00
for contrub in line . category_id . contribute_ids :
print contrib . name , contrub . code , contrub . amount_type , contrib . contribute_per , line . total
2010-07-27 07:11:45 +00:00
2010-07-02 10:37:15 +00:00
# if line.company_contrib > 0:
# company_contrib = line.company_contrib
## if line.category_id.amount_type == 'per':
## company_contrib = (amount * line.category_id.contribute_per)
2010-06-18 20:30:58 +00:00
2010-07-02 10:37:15 +00:00
# narration = """Company Contribution of %s Encode same as a Company Expanse @ %s""" % (line.name, company_contrib)
# move = {
2010-07-27 07:11:45 +00:00
# #'name': slip.name,
2010-07-02 10:37:15 +00:00
# 'journal_id': slip.journal_id.id,
2010-07-27 07:11:45 +00:00
# 'period_id': period_id,
2010-07-02 10:37:15 +00:00
# 'date': slip.date,
# 'ref':slip.number,
# 'narration': narration
# }
# company_contrib_move_id = move_pool.create(cr, uid, move)
# name = "[%s] - %s / %s - Company Contribution" % (line.code, line.name, slip.employee_id.name)
# self.create_voucher(cr, uid, [slip.id], name, company_contrib_move_id)
2010-07-27 07:11:45 +00:00
#
2010-07-02 10:37:15 +00:00
# ded_deb = {
# 'move_id':company_contrib_move_id,
# 'name': name,
2010-07-27 07:11:45 +00:00
# 'date': slip.date,
2010-07-02 10:37:15 +00:00
# 'quantity':1,
# 'account_id': line.category_id.account_id.id,
# 'debit': company_contrib,
# 'credit' : 0.0,
# 'journal_id': slip.journal_id.id,
# 'period_id': period_id,
# 'ref':slip.number
# }
# line_ids += [movel_pool.create(cr, uid, ded_deb)]
# ded_cre = {
# 'move_id':company_contrib_move_id,
# 'name': name,
2010-07-27 07:11:45 +00:00
# 'date': slip.date,
2010-07-02 10:37:15 +00:00
# 'quantity':1,
# 'account_id': line.category_id.register_id.account_id.id,
# 'debit': 0.0,
# 'credit' : company_contrib,
# 'journal_id': slip.journal_id.id,
# 'period_id': period_id,
# 'ref':slip.number
# }
# line_ids += [movel_pool.create(cr, uid, ded_cre)]
2010-07-27 07:11:45 +00:00
#
2010-07-02 10:37:15 +00:00
# if line.category_id.include_in_salary:
# narration = """Company Contribution of %s Deducted from Employee %s""" % (line.name, company_contrib)
# move = {
2010-07-27 07:11:45 +00:00
# #'name': slip.name,
2010-07-02 10:37:15 +00:00
# 'journal_id': slip.journal_id.id,
2010-07-27 07:11:45 +00:00
# 'period_id': period_id,
2010-07-02 10:37:15 +00:00
# 'date': slip.date,
# 'ref':slip.number,
# 'narration': narration
# }
# include_in_salary_move_id = move_pool.create(cr, uid, move)
# self.create_voucher(cr, uid, [slip.id], narration, include_in_salary_move_id)
2010-07-27 07:11:45 +00:00
#
2010-07-02 10:37:15 +00:00
# total_deduct += company_contrib
# ded_deb = {
# 'move_id':include_in_salary_move_id,
# 'name': name,
# 'partner_id': partner_id,
2010-07-27 07:11:45 +00:00
# 'date': slip.date,
2010-07-02 10:37:15 +00:00
# 'quantity':1,
# 'account_id': partner.property_account_receivable.id,
# 'debit': company_contrib,
# 'credit' : 0.0,
# 'journal_id': slip.journal_id.id,
# 'period_id': period_id,
# 'ref':slip.number
# }
# line_ids += [movel_pool.create(cr, uid, ded_deb)]
# ded_cre = {
# 'move_id':include_in_salary_move_id,
# 'name': name,
2010-07-27 07:11:45 +00:00
# 'date': slip.date,
2010-07-02 10:37:15 +00:00
# 'quantity':1,
# 'account_id': line.category_id.account_id.id,
# 'debit': 0.0,
# 'credit' : company_contrib,
# 'journal_id': slip.journal_id.id,
# 'period_id': period_id,
# 'ref':slip.number
# }
# line_ids += [movel_pool.create(cr, uid, ded_cre)]
2010-06-18 20:30:58 +00:00
#make an entry line to contribution register
# if line.category_id.register_id:
# ctr = {
# 'register_id':line.category_id.register_id.id,
# 'name':line.name,
# 'code':line.code,
# 'employee_id':slip.employee_id.id,
# 'period_id':period_id,
# 'emp_deduction':amount,
# }
# if line.category_id.contribute:
# ctr['comp_deduction'] = amount
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# company = 0.0
# employee = 0.0
# if line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'per':
# new_amount = (amount * (line.category_id.contribute_per / (1+line.category_id.contribute_per)))
# company = new_amount
# employee = amount - company
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# elif line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'fix':
# company = line.category_id.contribute_per
# employee = amount - company
# elif line.category_id.contribute and line.category_id.include_in_salary and line.category_id.amount_type == 'func':
# company = self.pool.get('hr.allounce.deduction.categoty').execute_function(cr, uid, line.category_id.id, line.slip_id.basic, context)
# employee = amount
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'per':
# company = amount * line.category_id.contribute_per
# employee = amount
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'fix':
# company = line.category_id.contribute_per
# employee = amount
# elif line.category_id.contribute and not line.category_id.include_in_salary and line.category_id.amount_type == 'func':
# company = self.pool.get('hr.allounce.deduction.categoty').execute_function(cr, uid, line.category_id.id, line.slip_id.basic, context)
# employee = amount
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# ctr['emp_deduction'] = employee
# ctr['comp_deduction'] = company
2010-07-27 07:11:45 +00:00
#
2010-06-18 20:30:58 +00:00
# self.pool.get('hr.contibution.register.line').create(cr, uid, ctr)
adj_move_id = False
if total_deduct > 0 :
move = {
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' date ' : slip . date ,
' ref ' : slip . number ,
' narration ' : ' Adjustment : %s ' % ( slip . name )
}
2010-07-27 07:11:45 +00:00
adj_move_id = move_pool . create ( cr , uid , move , context = context )
2010-06-18 20:30:58 +00:00
name = " Adjustment Entry - %s " % ( slip . employee_id . name )
self . create_voucher ( cr , uid , [ slip . id ] , name , adj_move_id )
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
ded_rec = {
' move_id ' : adj_move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
2010-07-27 07:11:45 +00:00
' date ' : slip . date ,
' account_id ' : partner . property_account_receivable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
' quantity ' : 1 ,
' credit ' : total_deduct ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
cre_rec = {
' move_id ' : adj_move_id ,
' name ' : name ,
' partner_id ' : partner_id ,
' date ' : slip . date ,
2010-07-27 07:11:45 +00:00
' account_id ' : partner . property_account_payable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : total_deduct ,
' quantity ' : 1 ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , cre_rec , context = context ) ]
2010-06-18 20:30:58 +00:00
rec = {
' state ' : ' confirm ' ,
' move_line_ids ' : [ ( 6 , 0 , line_ids ) ] ,
}
if not slip . period_id :
rec [ ' period_id ' ] = period_id
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
dates = prev_bounds ( slip . date )
2010-07-27 07:11:45 +00:00
exp_ids = exp_pool . search ( cr , uid , [ ( ' date_valid ' , ' >= ' , dates [ 0 ] ) , ( ' date_valid ' , ' <= ' , dates [ 1 ] ) , ( ' state ' , ' = ' , ' invoiced ' ) ] , context = context )
2010-06-18 20:30:58 +00:00
if exp_ids :
2010-07-27 07:11:45 +00:00
acc = property_pool . get ( cr , uid , ' property_account_expense_categ ' , ' product.category ' )
for exp in exp_pool . browse ( cr , uid , exp_ids , context = context ) :
2010-06-18 20:30:58 +00:00
exp_res = {
' name ' : exp . name ,
' amount_type ' : ' fix ' ,
' type ' : ' otherpay ' ,
' category_id ' : exp . category_id . id ,
' amount ' : exp . amount ,
' slip_id ' : slip . id ,
' expanse_id ' : exp . id ,
' account_id ' : acc
}
2010-07-27 07:11:45 +00:00
payslip_pool . create ( cr , uid , exp_res , context = context )
self . write ( cr , uid , [ slip . id ] , rec , context = context )
2010-06-18 20:30:58 +00:00
return True
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
hr_payslip ( )
class account_move_link_slip ( osv . osv ) :
'''
Account Move Link to Pay Slip
'''
_name = ' hr.payslip.account.move '
_description = ' Account Move Link to Pay Slip '
_columns = {
' name ' : fields . char ( ' Name ' , size = 256 , required = True , readonly = False ) ,
' move_id ' : fields . many2one ( ' account.move ' , ' Expanse Entries ' , required = False , readonly = True ) ,
' slip_id ' : fields . many2one ( ' hr.payslip ' , ' Pay Slip ' , required = False ) ,
' sequence ' : fields . integer ( ' Sequence ' ) ,
}
account_move_link_slip ( )