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
2010-10-28 06:54:18 +00:00
# it under the terms of the GNU Affero General Public License as published by
2010-06-18 20:30:58 +00:00
# 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
2010-10-28 06:54:18 +00:00
# GNU Affero General Public License for more details.
2010-06-18 20:30:58 +00:00
#
2010-10-28 06:54:18 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-06-18 20:30:58 +00:00
# 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-10-14 12:06:38 +00:00
class contrib_register ( osv . osv ) :
2011-04-13 13:16:28 +00:00
_inherit = ' hr.contribution.register '
2010-10-14 12:06:38 +00:00
_description = ' Contribution Register '
_columns = {
' account_id ' : fields . many2one ( ' account.account ' , ' Account ' ) ,
' analytic_account_id ' : fields . many2one ( ' account.analytic.account ' , ' Analytic Account ' ) ,
}
contrib_register ( )
2010-06-18 20:30:58 +00:00
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 = {
2011-04-21 07:22:56 +00:00
' period_id ' : fields . many2one ( ' account.period ' , ' Force Period ' , states = { ' draft ' : [ ( ' readonly ' , False ) ] } , readonly = True , domain = [ ( ' state ' , ' <> ' , ' done ' ) ] , help = " Keep empty to use the period of the validation(Payslip) date. " ) ,
2011-05-12 08:01:47 +00:00
' journal_id ' : fields . many2one ( ' account.journal ' , ' Expense Journal ' , states = { ' draft ' : [ ( ' readonly ' , False ) ] } , readonly = True ) ,
#TOCHECK: should we have a link to account.move or account.move.line?
#'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True),
2011-04-20 10:38:11 +00:00
' account_move_ids ' : fields . many2many ( ' account.move ' , ' payslip_move_rel ' , ' slip_id ' , ' move_id ' , ' Accounting Entries ' , readonly = True ) ,
2010-06-18 20:30:58 +00:00
}
2011-04-21 07:22:56 +00:00
2011-04-20 13:25:08 +00:00
def onchange_contract_id ( self , cr , uid , ids , date_from , date_to , employee_id = False , contract_id = False , context = None ) :
contract_obj = self . pool . get ( ' hr.contract ' )
res = super ( hr_payslip , self ) . onchange_contract_id ( cr , uid , ids , date_from = date_from , date_to = date_to , employee_id = employee_id , contract_id = contract_id , context = context )
journal_id = contract_obj . browse ( cr , uid , contract_id , context = context ) . journal_id . id
res [ ' value ' ] . update ( { ' journal_id ' : journal_id } )
return res
2011-04-20 11:22:22 +00:00
2011-05-12 08:01:47 +00:00
#FIXME: we need to overwrite a smaller code
2011-04-14 13:33:15 +00:00
def get_payslip_lines ( self , cr , uid , contract_ids , payslip_id , context ) :
2011-04-19 07:02:04 +00:00
journal_obj = self . pool . get ( ' account.journal ' )
rule_obj = self . pool . get ( ' hr.salary.rule ' )
contract_obj = self . pool . get ( ' hr.contract ' )
structure_obj = self . pool . get ( ' hr.payroll.structure ' )
vals_account = { }
2011-04-14 13:33:15 +00:00
result = super ( hr_payslip , self ) . get_payslip_lines ( cr , uid , contract_ids , payslip_id , context )
2011-04-19 07:02:04 +00:00
structure_ids = contract_obj . get_all_structures ( cr , uid , contract_ids , context = context )
2011-04-14 13:33:15 +00:00
#get the rules of the structure and thier children
2011-04-19 07:02:04 +00:00
rule_ids = structure_obj . get_all_rules ( cr , uid , structure_ids , context = context )
2011-04-14 13:33:15 +00:00
sorted_rule_ids = [ id for id , sequence in sorted ( rule_ids , key = lambda x : x [ 1 ] ) ]
2011-05-12 05:19:49 +00:00
#Fetching Debit/Credit account of the payslip journal.
2011-04-20 13:30:58 +00:00
journal = self . browse ( cr , uid , payslip_id , context = context ) . journal_id
2011-04-20 11:22:22 +00:00
credit_account = journal . default_credit_account_id and journal . default_credit_account_id . id or False
debit_account = journal . default_debit_account_id and journal . default_debit_account_id . id or False
2011-05-12 05:19:49 +00:00
# Assigning above fetched Debit/Credit account on salary rules if not specified
2011-04-19 07:02:04 +00:00
for rule in rule_obj . browse ( cr , uid , sorted_rule_ids , context = context ) :
if not rule . account_debit . id :
2011-04-19 12:44:01 +00:00
rule_obj . write ( cr , uid , [ rule . id ] , { ' account_debit ' : debit_account } )
2011-04-19 07:02:04 +00:00
if not rule . account_credit . id :
2011-04-19 12:44:01 +00:00
rule_obj . write ( cr , uid , [ rule . id ] , { ' account_credit ' : credit_account } )
2011-05-12 05:19:49 +00:00
#Assigning Debit/Credit account on payslip lines
2011-04-14 13:33:15 +00:00
for value in result :
if value [ ' salary_rule_id ' ] == rule . id :
2011-04-19 12:44:01 +00:00
if rule . category_id . name == ' Deduction ' :
if not rule . account_debit . id :
value [ ' account_id ' ] = debit_account
else :
value [ ' account_id ' ] = rule . account_debit . id
elif rule . category_id . name == ' Allowance ' :
if not rule . account_credit . id :
value [ ' account_id ' ] = credit_account
else :
value [ ' account_id ' ] = rule . account_credit . id
2011-04-19 07:02:04 +00:00
else :
2011-04-20 13:30:58 +00:00
emp_account_id = self . browse ( cr , uid , payslip_id , context = context ) . employee_id . employee_account . id
value [ ' account_id ' ] = emp_account_id
2011-04-20 08:55:19 +00:00
if rule . analytic_account_id :
value [ ' analytic_account_id ' ] = rule . analytic_account_id . id
2011-04-14 13:33:15 +00:00
return result
2011-04-20 11:22:22 +00:00
2011-05-12 08:01:47 +00:00
#TODO: to correct
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 ' )
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 )
2011-04-20 11:38:47 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } , context = context )
2010-07-27 07:11:45 +00:00
2011-05-12 08:01:47 +00:00
#TODO: to correct
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 ' )
for slip in self . browse ( cr , uid , ids , context = context ) :
2010-12-29 11:16:31 +00:00
if not slip . bank_journal_id or not slip . journal_id :
# Call super method to process sheet if journal_id or bank_journal_id are not specified.
super ( hr_payslip , self ) . process_sheet ( cr , uid , [ slip . id ] , context = context )
continue
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
2011-04-20 11:22:22 +00:00
2011-04-18 12:27:08 +00:00
for line in slip . line_ids :
if line . category_id . name == ' Net ' :
amt = line . total
2011-04-20 11:22:22 +00:00
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 :
2011-04-18 12:27:08 +00:00
if ( ( fiscal_year [ ' date_start ' ] < = slip . date_from ) and ( fiscal_year [ ' date_stop ' ] > = slip . date_to ) ) :
2010-06-18 20:30:58 +00:00
year_exist = True
if not year_exist :
2010-11-18 16:21:31 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Fiscal Year is not defined for slip date %s ' ) % slip . date )
2011-04-18 12:27:08 +00:00
search_periods = period_pool . search ( cr , uid , [ ( ' date_start ' , ' <= ' , slip . date_from ) , ( ' date_stop ' , ' >= ' , slip . date_to ) ] , context = context )
2010-07-27 07:11:45 +00:00
if not search_periods :
2010-11-18 16:21:31 +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 ,
2011-04-18 12:27:08 +00:00
' date ' : slip . date_from ,
2010-06-18 20:30:58 +00:00
' 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 )
2011-02-28 09:01:20 +00:00
if not slip . employee_id . property_bank_account . id :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Employee Bank Account is not defined for %s ' ) % slip . employee_id . name )
2010-06-18 20:30:58 +00:00
ded_rec = {
2010-10-27 12:49:59 +00:00
' move_id ' : move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
2011-04-18 12:27:08 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : slip . employee_id . property_bank_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
2011-04-18 12:27:08 +00:00
' credit ' : amt ,
2010-10-27 12:49:59 +00:00
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
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 = {
2010-10-27 12:49:59 +00:00
' move_id ' : move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
' partner_id ' : partner_id ,
2011-04-18 12:27:08 +00:00
' date ' : slip . date_from ,
2010-06-18 20:30:58 +00:00
' account_id ' : partner . property_account_payable . id ,
2011-04-18 12:27:08 +00:00
' debit ' : amt ,
2010-10-27 12:49:59 +00:00
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
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 ) ] ,
2011-04-20 10:38:11 +00:00
' paid ' : True ,
' account_move_ids ' : [ ( 4 , move_id ) ] ,
2010-06-18 20:30:58 +00:00
}
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
2011-05-12 08:01:47 +00:00
#TODO: to clean
2010-07-27 07:11:45 +00:00
def account_check_sheet ( self , cr , uid , ids , context = None ) :
2011-04-20 11:38:47 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' accont_check ' } , context = context )
2011-05-12 08:01:47 +00:00
#TODO: to clean
2010-07-27 07:11:45 +00:00
def hr_check_sheet ( self , cr , uid , ids , context = None ) :
2011-04-20 11:38:47 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' hr_check ' } , context = context )
2010-07-27 07:11:45 +00:00
2011-05-12 08:01:47 +00:00
#TODO: to clean
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 ' )
for slip in self . browse ( cr , uid , ids , context = context ) :
2011-04-14 13:33:15 +00:00
for line in slip . line_ids :
if line . category_id . name == ' Basic ' :
basic_amt = line . total
2010-12-29 11:16:31 +00:00
if not slip . journal_id :
# Call super method to verify sheet if journal_id is not specified.
super ( hr_payslip , self ) . verify_sheet ( cr , uid , [ slip . id ] , context = context )
continue
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 = [ ]
2011-04-20 10:38:11 +00:00
move_ids = [ ]
2010-06-18 20:30:58 +00:00
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 :
2011-02-28 09:01:20 +00:00
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please define 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 :
2011-02-28 09:01:20 +00:00
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please define 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 :
2011-04-13 13:16:28 +00:00
if ( ( fiscal_year [ ' date_start ' ] < = slip . date_from ) and ( fiscal_year [ ' date_stop ' ] > = slip . date_to ) ) :
2010-06-18 20:30:58 +00:00
year_exist = True
if not year_exist :
2010-11-18 16:21:31 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Fiscal Year is not defined for slip date %s ' ) % slip . date )
2011-04-13 13:16:28 +00:00
search_periods = period_pool . search ( cr , uid , [ ( ' date_start ' , ' = ' , slip . date_from ) , ( ' date_stop ' , ' = ' , slip . date_to ) ] , context = context )
2010-07-27 07:11:45 +00:00
if not search_periods :
2010-11-18 16:21:31 +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 = {
' journal_id ' : slip . journal_id . id ,
2010-07-27 07:11:45 +00:00
' period_id ' : period_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-06-18 20:30:58 +00:00
' ref ' : slip . number ,
' narration ' : slip . name
}
2010-07-27 07:11:45 +00:00
move_id = move_pool . create ( cr , uid , move , context = context )
2011-04-20 10:38:11 +00:00
move_ids + = [ move_id ]
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
2011-02-28 09:01:20 +00:00
if not slip . employee_id . salary_account . id :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Please define Salary Account for %s . ' ) % slip . employee_id . name )
2010-06-18 20:30:58 +00:00
line = {
' move_id ' : move_id ,
' name ' : " By Basic Salary / " + slip . employee_id . name ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : slip . employee_id . salary_account . id ,
2011-04-14 13:33:15 +00:00
' debit ' : basic_amt ,
2010-06-18 20:30:58 +00:00
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' analytic_account_id ' : False ,
' ref ' : slip . number
}
#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
2011-02-28 09:01:20 +00:00
if not slip . employee_id . employee_account . id :
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' Please define Employee Payable Account for %s . ' ) % slip . employee_id . name )
2010-06-18 20:30:58 +00:00
line = {
' move_id ' : move_id ,
2011-03-02 10:44:41 +00:00
' name ' : " To Basic Payble Salary / " + slip . employee_id . name ,
2010-06-18 20:30:58 +00:00
' partner_id ' : partner_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : slip . employee_id . employee_account . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
2011-04-14 13:33:15 +00:00
' credit ' : basic_amt ,
2010-06-18 20:30:58 +00:00
' 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 :
2011-04-18 12:27:08 +00:00
if line . name == ' Net ' or line . name == ' Gross ' or line . name == ' Basic ' :
continue
2010-06-18 20:30:58 +00:00
name = " [ %s ] - %s / %s " % ( line . code , line . name , slip . employee_id . name )
amount = line . total
rec = {
2010-10-27 12:49:59 +00:00
' move_id ' : move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : line . account_id . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
2010-10-27 12:49:59 +00:00
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' analytic_account_id ' : False ,
' ref ' : slip . number ,
' quantity ' : 1
2010-06-18 20:30:58 +00:00
}
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
2011-04-14 13:33:15 +00:00
if line . category_id . name == ' Allowance ' :
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 = {
2010-10-27 12:49:59 +00:00
' move_id ' : move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
' partner_id ' : partner_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : partner . property_account_payable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
2010-10-27 12:49:59 +00:00
' quantity ' : 1 ,
' credit ' : amount ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
2010-07-27 07:11:45 +00:00
line_ids + = [ movel_pool . create ( cr , uid , ded_rec , context = context ) ]
2011-04-14 13:33:15 +00:00
elif line . category_id . name == ' Deduction ' :
2010-06-18 20:30:58 +00:00
if not partner . property_account_receivable :
raise osv . except_osv ( _ ( ' Integrity Error ! ' ) , _ ( ' Please Configure Partners Receivable Account!! ' ) )
2011-04-18 12:27:08 +00:00
amount = - ( amount )
2010-06-18 20:30:58 +00:00
rec [ ' credit ' ] = amount
total_deduct + = amount
ded_rec = {
2010-10-27 12:49:59 +00:00
' move_id ' : move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
' partner_id ' : partner_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-10-27 12:49:59 +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 ,
2010-10-27 12:49:59 +00:00
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
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-06-18 20:30:58 +00:00
adj_move_id = False
if total_deduct > 0 :
move = {
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-06-18 20:30:58 +00:00
' ref ' : slip . number ,
2010-10-27 12:49:59 +00:00
' narration ' : ' Adjustment: %s ' % ( slip . name )
2010-06-18 20:30:58 +00:00
}
2010-07-27 07:11:45 +00:00
adj_move_id = move_pool . create ( cr , uid , move , context = context )
2011-04-20 10:38:11 +00:00
move_ids + = [ adj_move_id ]
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 = {
2010-10-27 12:49:59 +00:00
' move_id ' : adj_move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
' partner_id ' : partner_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
2010-07-27 07:11:45 +00:00
' account_id ' : partner . property_account_receivable . id ,
2010-06-18 20:30:58 +00:00
' debit ' : 0.0 ,
2010-10-27 12:49:59 +00:00
' quantity ' : 1 ,
' credit ' : total_deduct ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
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 = {
2010-10-27 12:49:59 +00:00
' move_id ' : adj_move_id ,
2010-06-18 20:30:58 +00:00
' name ' : name ,
' partner_id ' : partner_id ,
2011-04-14 13:33:15 +00:00
' date ' : slip . date_from ,
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 ,
2010-10-27 12:49:59 +00:00
' quantity ' : 1 ,
' credit ' : 0.0 ,
' journal_id ' : slip . journal_id . id ,
' period_id ' : period_id ,
' ref ' : slip . number
2010-06-18 20:30:58 +00:00
}
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 ) ] ,
2011-04-20 10:38:11 +00:00
' account_move_ids ' : [ ( 6 , 0 , move_ids ) ]
2010-06-18 20:30:58 +00:00
}
if not slip . period_id :
rec [ ' period_id ' ] = period_id
2010-07-27 07:11:45 +00:00
2011-04-14 13:33:15 +00:00
exp_ids = exp_pool . search ( cr , uid , [ ( ' date_valid ' , ' >= ' , slip . date_from ) , ( ' date_valid ' , ' <= ' , slip . date_to ) , ( ' state ' , ' = ' , ' invoiced ' ) ] , context = context )
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
return True
2010-07-27 07:11:45 +00:00
2010-06-18 20:30:58 +00:00
hr_payslip ( )
2011-05-12 08:01:47 +00:00
#TODO: remove, i don't think it's worth having that information on the payslip line rather than on the salary rule
#class hr_payslip_line(osv.osv):
# _inherit = 'hr.payslip.line'
# _columns = {
# 'account_id': fields.many2one('account.account', 'General Account'),
# 'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
# }
#hr_payslip_line()
2010-10-14 12:06:38 +00:00
2011-04-13 13:16:28 +00:00
class hr_salary_rule ( osv . osv ) :
_inherit = ' hr.salary.rule '
_columns = {
' analytic_account_id ' : fields . many2one ( ' account.analytic.account ' , ' Analytic Account ' ) ,
' account_tax_id ' : fields . many2one ( ' account.tax.code ' , ' Tax Code ' ) ,
' account_debit ' : fields . many2one ( ' account.account ' , ' Debit Account ' ) ,
' account_credit ' : fields . many2one ( ' account.account ' , ' Credit Account ' ) ,
}
hr_salary_rule ( )
class hr_contract ( osv . osv ) :
2011-04-20 11:22:22 +00:00
2011-04-13 13:16:28 +00:00
_inherit = ' hr.contract '
_description = ' Employee Contract '
_columns = {
' analytic_account_id ' : fields . many2one ( ' account.analytic.account ' , ' Analytic Account ' ) ,
2011-05-12 08:01:47 +00:00
' journal_id ' : fields . many2one ( ' account.journal ' , ' Salary Journal ' ) ,
2011-04-13 13:16:28 +00:00
}
hr_contract ( )
2010-11-18 16:21:31 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: