[IMP] Changed all module categories, limited number of categories
[odoo/odoo.git] / addons / hr_payroll_account / hr_payroll_account.py
1 #-*- coding:utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    d$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22 import time
23 import netsvc
24 from datetime import date, datetime, timedelta
25
26 from osv import fields, osv
27 from tools import config
28 from tools.translate import _
29
30 def prev_bounds(cdate=False):
31     when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d")))
32     this_first = date(when.year, when.month, 1)
33     month = when.month + 1
34     year = when.year
35     if month > 12:
36         month = 1
37         year += 1
38     next_month = date(year, month, 1)
39     prev_end = next_month - timedelta(days=1)
40     return this_first, prev_end
41
42 class hr_payroll_structure(osv.osv):
43     _inherit = 'hr.payroll.structure'
44     _description = 'Salary Structure'
45
46     _columns = {
47         'account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
48     }
49 hr_payroll_structure()
50
51 class hr_employee(osv.osv):
52     '''
53     Employee
54     '''
55     _inherit = 'hr.employee'
56     _description = 'Employee'
57
58     _columns = {
59         'property_bank_account': fields.property(
60             'account.account',
61             type='many2one',
62             relation='account.account',
63             string="Bank Account",
64             method=True,
65             domain="[('type', '=', 'liquidity')]",
66             view_load=True,
67             help="Select Bank Account from where Salary Expense will be Paid"),
68         'salary_account':fields.property(
69             'account.account',
70             type='many2one',
71             relation='account.account',
72             string="Salary Account",
73             method=True,
74             domain="[('type', '=', 'other')]",
75             view_load=True,
76             help="Expense account when Salary Expense will be recorded"),
77         'employee_account':fields.property(
78             'account.account',
79             type='many2one',
80             relation='account.account',
81             string="Employee Account",
82             method=True,
83             domain="[('type', '=', 'other')]",
84             view_load=True,
85             help="Employee Payable Account"),
86         'analytic_account':fields.property(
87             'account.analytic.account',
88             type='many2one',
89             relation='account.analytic.account',
90             string="Analytic Account",
91             method=True,
92             view_load=True,
93             help="Analytic Account for Salary Analysis"),
94     }
95 hr_employee()
96
97 class payroll_register(osv.osv):
98     _inherit = 'hr.payroll.register'
99     _description = 'Payroll Register'
100
101     _columns = {
102         'journal_id': fields.many2one('account.journal', 'Expense Journal'),
103         'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'),
104         'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."),
105     }
106
107     def compute_sheet(self, cr, uid, ids, context=None):
108         emp_pool = self.pool.get('hr.employee')
109         slip_pool = self.pool.get('hr.payslip')
110         func_pool = self.pool.get('hr.payroll.structure')
111         slip_line_pool = self.pool.get('hr.payslip.line')
112         wf_service = netsvc.LocalService("workflow")
113         vals = self.browse(cr, uid, ids, context=context)[0]
114         emp_ids = emp_pool.search(cr, uid, [])
115
116         for emp in emp_pool.browse(cr, uid, emp_ids, context=context):
117             old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)])
118             if old_slips:
119                 slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]})
120                 for sid in old_slips:
121                     wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr)
122             else:
123                 res = {
124                     'employee_id':emp.id,
125                     'basic':0.0,
126                     'register_id':ids[0],
127                     'name':vals.name,
128                     'date':vals.date,
129                     'journal_id':vals.journal_id.id,
130                     'bank_journal_id':vals.bank_journal_id.id
131                 }
132                 slip_id = slip_pool.create(cr, uid, res)
133                 wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr)
134
135         number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register')
136         self.write(cr, uid, ids, {'state':'draft', 'number':number})
137         return True
138
139 payroll_register()
140
141 class payroll_advice(osv.osv):
142     _inherit = 'hr.payroll.advice'
143     _description = 'Bank Advice Note'
144
145     _columns = {
146         'account_id': fields.many2one('account.account', 'Account'),
147     }
148 payroll_advice()
149
150 class contrib_register(osv.osv):
151     _inherit = 'hr.contibution.register'
152     _description = 'Contribution Register'
153
154     def _total_contrib(self, cr, uid, ids, field_names, arg, context=None):
155         line_pool = self.pool.get('hr.contibution.register.line')
156         period_id = self.pool.get('account.period').search(cr,uid,[('date_start','<=',time.strftime('%Y-%m-%d')),('date_stop','>=',time.strftime('%Y-%m-%d'))])[0]
157         fiscalyear_id = self.pool.get('account.period').browse(cr, uid, period_id, context=context).fiscalyear_id
158         res = {}
159         for cur in self.browse(cr, uid, ids, context=context):
160             current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)])
161             years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)])
162
163             e_month = 0.0
164             c_month = 0.0
165             for i in line_pool.browse(cr, uid, current, context=context):
166                 e_month += i.emp_deduction
167                 c_month += i.comp_deduction
168
169             e_year = 0.0
170             c_year = 0.0
171             for j in line_pool.browse(cr, uid, years, context=context):
172                 e_year += i.emp_deduction
173                 c_year += i.comp_deduction
174
175             res[cur.id]={
176                 'monthly_total_by_emp':e_month,
177                 'monthly_total_by_comp':c_month,
178                 'yearly_total_by_emp':e_year,
179                 'yearly_total_by_comp':c_year
180             }
181         return res
182
183     _columns = {
184         'account_id': fields.many2one('account.account', 'Account'),
185         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
186         'yearly_total_by_emp': fields.function(_total_contrib, method=True, multi='dc', store=True, string='Total By Employee', digits=(16, 4)),
187         'yearly_total_by_comp': fields.function(_total_contrib, method=True, multi='dc', store=True,  string='Total By Company', digits=(16, 4)),
188     }
189 contrib_register()
190
191 class contrib_register_line(osv.osv):
192     _inherit = 'hr.contibution.register.line'
193     _description = 'Contribution Register Line'
194
195     _columns = {
196         'period_id': fields.many2one('account.period', 'Period'),
197     }
198 contrib_register_line()
199
200 class hr_holidays_status(osv.osv):
201     _inherit = 'hr.holidays.status'
202     _columns = {
203         'account_id': fields.many2one('account.account', 'Account'),
204         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
205     }
206 hr_holidays_status()
207
208 class hr_payslip(osv.osv):
209     '''
210     Pay Slip
211     '''
212     _inherit = 'hr.payslip'
213     _description = 'Pay Slip'
214
215     _columns = {
216         'journal_id': fields.many2one('account.journal', 'Expense Journal'),
217         'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'),
218         'move_ids':fields.one2many('hr.payslip.account.move', 'slip_id', 'Accounting vouchers'),
219         'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True),
220         'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True),
221         'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."),
222     }
223
224     def create_voucher(self, cr, uid, ids, name, voucher, sequence=5):
225         slip_move = self.pool.get('hr.payslip.account.move')
226         for slip in ids:
227             res = {
228                 'slip_id':slip,
229                 'move_id':voucher,
230                 'sequence':sequence,
231                 'name':name
232             }
233             slip_move.create(cr, uid, res)
234
235     def cancel_sheet(self, cr, uid, ids, context=None):
236         move_pool = self.pool.get('account.move')
237         slip_move = self.pool.get('hr.payslip.account.move')
238         move_ids = []
239         for slip in self.browse(cr, uid, ids, context=context):
240             for line in slip.move_ids:
241                 move_ids.append(line.id)
242                 if line.move_id:
243                     if line.move_id.state == 'posted':
244                         move_pool.button_cancel(cr, uid [line.move_id.id], context)
245                     move_pool.unlink(cr, uid, [line.move_id.id], context=context)
246
247         slip_move.unlink(cr, uid, move_ids, context=context)
248         self.write(cr, uid, ids, {'state':'cancel'}, context=context)
249         return True
250
251     def process_sheet(self, cr, uid, ids, context=None):
252         move_pool = self.pool.get('account.move')
253         movel_pool = self.pool.get('account.move.line')
254         invoice_pool = self.pool.get('account.invoice')
255         fiscalyear_pool = self.pool.get('account.fiscalyear')
256         period_pool = self.pool.get('account.period')
257
258         for slip in self.browse(cr, uid, ids, context=context):
259             if not slip.bank_journal_id or not slip.journal_id:
260                 # Call super method to process sheet if journal_id or bank_journal_id are not specified.
261                 super(hr_payslip, self).process_sheet(cr, uid, [slip.id], context=context)
262                 continue
263             line_ids = []
264             partner = False
265             partner_id = False
266             exp_ids = []
267
268             partner = slip.employee_id.bank_account_id.partner_id
269             partner_id = partner.id
270
271             fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context)
272             if not fiscal_year_ids:
273                 raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract'))
274             fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context)
275             year_exist = False
276             for fiscal_year in fiscal_year_objs:
277                 if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)):
278                     year_exist = True
279             if not year_exist:
280                 raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date)
281             search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context)
282             if not search_periods:
283                 raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date)
284             period_id = search_periods[0]
285             name = 'Payment of Salary to %s' % (slip.employee_id.name)
286             move = {
287                 'journal_id': slip.bank_journal_id.id,
288                 'period_id': period_id,
289                 'date': slip.date,
290                 'type':'bank_pay_voucher',
291                 'ref':slip.number,
292                 'narration': name
293             }
294             move_id = move_pool.create(cr, uid, move, context=context)
295             self.create_voucher(cr, uid, [slip.id], name, move_id)
296
297             name = "To %s account" % (slip.employee_id.name)
298             ded_rec = {
299                 'move_id': move_id,
300                 'name': name,
301                 'date': slip.date,
302                 'account_id': slip.employee_id.property_bank_account.id,
303                 'debit': 0.0,
304                 'credit': slip.total_pay,
305                 'journal_id': slip.journal_id.id,
306                 'period_id': period_id,
307                 'ref': slip.number
308             }
309             line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
310             name = "By %s account" % (slip.employee_id.property_bank_account.name)
311             cre_rec = {
312                 'move_id': move_id,
313                 'name': name,
314                 'partner_id': partner_id,
315                 'date': slip.date,
316                 'account_id': partner.property_account_payable.id,
317                 'debit': slip.total_pay,
318                 'credit': 0.0,
319                 'journal_id': slip.journal_id.id,
320                 'period_id': period_id,
321                 'ref': slip.number
322             }
323             line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)]
324
325             other_pay = slip.other_pay
326             #Process all Reambuse Entries
327             for line in slip.line_ids:
328                 if line.type == 'otherpay' and line.expanse_id.invoice_id:
329                     if not line.expanse_id.invoice_id.move_id:
330                         raise osv.except_osv(_('Warning !'), _('Please Confirm all Expense Invoice appear for Reimbursement'))
331                     invids = [line.expanse_id.invoice_id.id]
332                     amount = line.total
333                     acc_id = slip.bank_journal_id.default_credit_account_id and slip.bank_journal_id.default_credit_account_id.id
334                     period_id = slip.period_id.id
335                     journal_id = slip.bank_journal_id.id
336                     name = '[%s]-%s' % (slip.number, line.name)
337                     invoice_pool.pay_and_reconcile(cr, uid, invids, amount, acc_id, period_id, journal_id, False, period_id, False, context, name)
338                     other_pay -= amount
339                     #TODO: link this account entries to the Payment Lines also Expense Entries to Account Lines
340                     l_ids = movel_pool.search(cr, uid, [('name','=',name)], context=context)
341                     line_ids += l_ids
342
343                     l_ids = movel_pool.search(cr, uid, [('invoice','=',line.expanse_id.invoice_id.id)], context=context)
344                     exp_ids += l_ids
345
346             #Process for Other payment if any
347             other_move_id = False
348             if slip.other_pay > 0:
349                 narration = 'Payment of Other Payeble amounts to %s' % (slip.employee_id.name)
350                 move = {
351                     'journal_id': slip.bank_journal_id.id,
352                     'period_id': period_id,
353                     'date': slip.date,
354                     'type':'bank_pay_voucher',
355                     'ref':slip.number,
356                     'narration': narration
357                 }
358                 other_move_id = move_pool.create(cr, uid, move, context=context)
359                 self.create_voucher(cr, uid, [slip.id], narration, move_id)
360
361                 name = "To %s account" % (slip.employee_id.name)
362                 ded_rec = {
363                     'move_id':other_move_id,
364                     'name':name,
365                     'date':slip.date,
366                     'account_id':slip.employee_id.property_bank_account.id,
367                     'debit': 0.0,
368                     'credit': other_pay,
369                     'journal_id':slip.journal_id.id,
370                     'period_id':period_id,
371                     'ref':slip.number
372                 }
373                 line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
374                 name = "By %s account" % (slip.employee_id.property_bank_account.name)
375                 cre_rec = {
376                     'move_id':other_move_id,
377                     'name':name,
378                     'partner_id':partner_id,
379                     'date':slip.date,
380                     'account_id':partner.property_account_payable.id,
381                     'debit': other_pay,
382                     'credit':0.0,
383                     'journal_id':slip.journal_id.id,
384                     'period_id':period_id,
385                     'ref':slip.number
386                 }
387                 line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)]
388
389             rec = {
390                 'state':'done',
391                 'move_payment_ids':[(6, 0, line_ids)],
392                 'paid':True
393             }
394             self.write(cr, uid, [slip.id], rec, context=context)
395             for exp_id in exp_ids:
396                 self.write(cr, uid, [slip.id], {'move_line_ids':[(4, exp_id)]}, context=context)
397
398         return True
399
400     def account_check_sheet(self, cr, uid, ids, context=None):
401         self.write(cr, uid, ids, {'state':'accont_check'}, context=context)
402         return True
403
404     def hr_check_sheet(self, cr, uid, ids, context=None):
405         self.write(cr, uid, ids, {'state':'hr_check'}, context=context)
406         return True
407
408     def verify_sheet(self, cr, uid, ids, context=None):
409         move_pool = self.pool.get('account.move')
410         movel_pool = self.pool.get('account.move.line')
411         exp_pool = self.pool.get('hr.expense.expense')
412         fiscalyear_pool = self.pool.get('account.fiscalyear')
413         period_pool = self.pool.get('account.period')
414         property_pool = self.pool.get('ir.property')
415         payslip_pool = self.pool.get('hr.payslip.line')
416
417         for slip in self.browse(cr, uid, ids, context=context):
418             if not slip.journal_id:
419                 # Call super method to verify sheet if journal_id is not specified.
420                 super(hr_payslip, self).verify_sheet(cr, uid, [slip.id], context=context)
421                 continue
422             total_deduct = 0.0
423
424             line_ids = []
425             partner = False
426             partner_id = False
427
428             if not slip.employee_id.bank_account_id:
429                 raise osv.except_osv(_('Integrity Error !'), _('Please defined bank account for %s !') % (slip.employee_id.name))
430
431             if not slip.employee_id.bank_account_id.partner_id:
432                 raise osv.except_osv(_('Integrity Error !'), _('Please defined partner in bank account for %s !') % (slip.employee_id.name))
433
434             partner = slip.employee_id.bank_account_id.partner_id
435             partner_id = slip.employee_id.bank_account_id.partner_id.id
436
437             period_id = False
438
439             if slip.period_id:
440                 period_id = slip.period_id.id
441             else:
442                 fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context)
443                 if not fiscal_year_ids:
444                     raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract'))
445                 fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context)
446                 year_exist = False
447                 for fiscal_year in fiscal_year_objs:
448                     if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)):
449                         year_exist = True
450                 if not year_exist:
451                     raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date)
452                 search_periods = period_pool.search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context)
453                 if not search_periods:
454                     raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date)
455                 period_id = search_periods[0]
456
457             move = {
458                 'journal_id': slip.journal_id.id,
459                 'period_id': period_id,
460                 'date': slip.date,
461                 'ref':slip.number,
462                 'narration': slip.name
463             }
464             move_id = move_pool.create(cr, uid, move, context=context)
465             self.create_voucher(cr, uid, [slip.id], slip.name, move_id)
466
467             line = {
468                 'move_id':move_id,
469                 'name': "By Basic Salary / " + slip.employee_id.name,
470                 'date': slip.date,
471                 'account_id': slip.employee_id.salary_account.id,
472                 'debit': slip.basic,
473                 'credit': 0.0,
474                 'quantity':slip.working_days,
475                 'journal_id': slip.journal_id.id,
476                 'period_id': period_id,
477                 'analytic_account_id': False,
478                 'ref':slip.number
479             }
480
481             #Setting Analysis Account for Basic Salary
482             if slip.employee_id.analytic_account:
483                 line['analytic_account_id'] = slip.employee_id.analytic_account.id
484
485             move_line_id = movel_pool.create(cr, uid, line, context=context)
486             line_ids += [move_line_id]
487
488             line = {
489                 'move_id':move_id,
490                 'name': "To Basic Paysble Salary / " + slip.employee_id.name,
491                 'partner_id': partner_id,
492                 'date': slip.date,
493                 'account_id': slip.employee_id.employee_account.id,
494                 'debit': 0.0,
495                 'quantity':slip.working_days,
496                 'credit': slip.basic,
497                 'journal_id': slip.journal_id.id,
498                 'period_id': period_id,
499                 'ref':slip.number
500             }
501             line_ids += [movel_pool.create(cr, uid, line, context=context)]
502
503             for line in slip.line_ids:
504                 name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name)
505                 amount = line.total
506
507                 if line.type == 'leaves':
508                     continue
509
510                 rec = {
511                     'move_id': move_id,
512                     'name': name,
513                     'date': slip.date,
514                     'account_id': line.account_id.id,
515                     'debit': 0.0,
516                     'credit': 0.0,
517                     'journal_id': slip.journal_id.id,
518                     'period_id': period_id,
519                     'analytic_account_id': False,
520                     'ref': slip.number,
521                     'quantity': 1
522                 }
523
524                 #Setting Analysis Account for Salary Slip Lines
525                 if line.analytic_account_id:
526                     rec['analytic_account_id'] = line.analytic_account_id.id
527                 else:
528                     rec['analytic_account_id'] = slip.deg_id.account_id.id
529
530                 if line.type == 'allowance' or line.type == 'otherpay':
531                     rec['debit'] = amount
532                     if not partner.property_account_payable:
533                         raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Payable Account!!'))
534                     ded_rec = {
535                         'move_id': move_id,
536                         'name': name,
537                         'partner_id': partner_id,
538                         'date': slip.date,
539                         'account_id': partner.property_account_payable.id,
540                         'debit': 0.0,
541                         'quantity': 1,
542                         'credit': amount,
543                         'journal_id': slip.journal_id.id,
544                         'period_id': period_id,
545                         'ref': slip.number
546                     }
547                     line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
548                 elif line.type == 'deduction' or line.type == 'otherdeduct':
549                     if not partner.property_account_receivable:
550                         raise osv.except_osv(_('Integrity Error !'), _('Please Configure Partners Receivable Account!!'))
551                     rec['credit'] = amount
552                     total_deduct += amount
553                     ded_rec = {
554                         'move_id': move_id,
555                         'name': name,
556                         'partner_id': partner_id,
557                         'date': slip.date,
558                         'quantity': 1,
559                         'account_id': partner.property_account_receivable.id,
560                         'debit': amount,
561                         'credit': 0.0,
562                         'journal_id': slip.journal_id.id,
563                         'period_id': period_id,
564                         'ref': slip.number
565                     }
566                     line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
567
568                 line_ids += [movel_pool.create(cr, uid, rec, context=context)]
569
570                 # if self._debug:
571                 #    for contrib in line.category_id.contribute_ids:
572                 #       _log.debug("%s %s %s %s %s",  contrib.name, contrub.code, contrub.amount_type, contrib.contribute_per, line.total)
573
574             adj_move_id = False
575             if total_deduct > 0:
576                 move = {
577                     'journal_id': slip.journal_id.id,
578                     'period_id': period_id,
579                     'date': slip.date,
580                     'ref':slip.number,
581                     'narration': 'Adjustment: %s' % (slip.name)
582                 }
583                 adj_move_id = move_pool.create(cr, uid, move, context=context)
584                 name = "Adjustment Entry - %s" % (slip.employee_id.name)
585                 self.create_voucher(cr, uid, [slip.id], name, adj_move_id)
586
587                 ded_rec = {
588                     'move_id': adj_move_id,
589                     'name': name,
590                     'partner_id': partner_id,
591                     'date': slip.date,
592                     'account_id': partner.property_account_receivable.id,
593                     'debit': 0.0,
594                     'quantity': 1,
595                     'credit': total_deduct,
596                     'journal_id': slip.journal_id.id,
597                     'period_id': period_id,
598                     'ref': slip.number
599                 }
600                 line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
601                 cre_rec = {
602                     'move_id': adj_move_id,
603                     'name': name,
604                     'partner_id': partner_id,
605                     'date': slip.date,
606                     'account_id': partner.property_account_payable.id,
607                     'debit': total_deduct,
608                     'quantity': 1,
609                     'credit': 0.0,
610                     'journal_id': slip.journal_id.id,
611                     'period_id': period_id,
612                     'ref': slip.number
613                 }
614                 line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)]
615
616             rec = {
617                 'state':'confirm',
618                 'move_line_ids':[(6, 0,line_ids)],
619             }
620             if not slip.period_id:
621                 rec['period_id'] = period_id
622
623             dates = prev_bounds(slip.date)
624             exp_ids = exp_pool.search(cr, uid, [('date_valid','>=',dates[0]), ('date_valid','<=',dates[1]), ('state','=','invoiced')], context=context)
625             if exp_ids:
626                 acc = property_pool.get(cr, uid, 'property_account_expense_categ', 'product.category')
627                 for exp in exp_pool.browse(cr, uid, exp_ids, context=context):
628                     exp_res = {
629                         'name':exp.name,
630                         'amount_type':'fix',
631                         'type':'otherpay',
632                         'category_id':exp.category_id.id,
633                         'amount':exp.amount,
634                         'slip_id':slip.id,
635                         'expanse_id':exp.id,
636                         'account_id':acc
637                     }
638                     payslip_pool.create(cr, uid, exp_res, context=context)
639
640             self.write(cr, uid, [slip.id], rec, context=context)
641
642         return True
643
644 hr_payslip()
645
646 class hr_payslip_line(osv.osv):
647     _inherit = 'hr.payslip.line'
648     _columns = {
649         'account_id': fields.many2one('account.account', 'General Account'),
650         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
651     }
652 hr_payslip_line()
653
654 class account_move_link_slip(osv.osv):
655     '''
656     Account Move Link to Pay Slip
657     '''
658     _name = 'hr.payslip.account.move'
659     _description = 'Account Move Link to Pay Slip'
660     _columns = {
661         'name':fields.char('Name', size=256, required=True, readonly=False),
662         'move_id':fields.many2one('account.move', 'Expense Entries', required=False, readonly=True),
663         'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=False),
664         'sequence': fields.integer('Sequence'),
665     }
666 account_move_link_slip()
667
668 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: