Launchpad automatic translations update.
[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, timedelta
25
26 from osv import fields, osv
27 from tools.translate import _
28
29 def prev_bounds(cdate=False):
30     when = date.fromtimestamp(time.mktime(time.strptime(cdate,"%Y-%m-%d")))
31     this_first = date(when.year, when.month, 1)
32     month = when.month + 1
33     year = when.year
34     if month > 12:
35         month = 1
36         year += 1
37     next_month = date(year, month, 1)
38     prev_end = next_month - timedelta(days=1)
39     return this_first, prev_end
40
41 class hr_payroll_structure(osv.osv):
42     _inherit = 'hr.payroll.structure'
43     _description = 'Salary Structure'
44
45     _columns = {
46         'account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
47     }
48 hr_payroll_structure()
49
50 class hr_employee(osv.osv):
51     '''
52     Employee
53     '''
54     _inherit = 'hr.employee'
55     _description = 'Employee'
56
57     _columns = {
58         'property_bank_account': fields.property(
59             'account.account',
60             type='many2one',
61             relation='account.account',
62             string="Bank Account",
63             method=True,
64             domain="[('type', '=', 'liquidity')]",
65             view_load=True,
66             help="Select Bank Account from where Salary Expense will be Paid, to be used for payslip verification."),
67         'salary_account':fields.property(
68             'account.account',
69             type='many2one',
70             relation='account.account',
71             string="Salary Account",
72             method=True,
73             domain="[('type', '=', 'other')]",
74             view_load=True,
75             help="Expense account when Salary Expense will be recorded"),
76         'employee_account':fields.property(
77             'account.account',
78             type='many2one',
79             relation='account.account',
80             string="Employee Account",
81             method=True,
82             domain="[('type', '=', 'other')]",
83             view_load=True,
84             help="Employee Payable Account"),
85         'analytic_account':fields.property(
86             'account.analytic.account',
87             type='many2one',
88             relation='account.analytic.account',
89             string="Analytic Account",
90             method=True,
91             view_load=True,
92             help="Analytic Account for Salary Analysis"),
93     }
94 hr_employee()
95
96 class payroll_register(osv.osv):
97     _inherit = 'hr.payroll.register'
98     _description = 'Payroll Register'
99
100     _columns = {
101         'journal_id': fields.many2one('account.journal', 'Expense Journal'),
102         'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'),
103         'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."),
104     }
105
106     def compute_sheet(self, cr, uid, ids, context=None):
107         emp_pool = self.pool.get('hr.employee')
108         slip_pool = self.pool.get('hr.payslip')
109         wf_service = netsvc.LocalService("workflow")
110         vals = self.browse(cr, uid, ids, context=context)[0]
111         emp_ids = emp_pool.search(cr, uid, [])
112
113         for emp in emp_pool.browse(cr, uid, emp_ids, context=context):
114             old_slips = slip_pool.search(cr, uid, [('employee_id','=', emp.id), ('date','=',vals.date)])
115             if old_slips:
116                 slip_pool.write(cr, uid, old_slips, {'register_id':ids[0]})
117                 for sid in old_slips:
118                     wf_service.trg_validate(uid, 'hr.payslip', sid, 'compute_sheet', cr)
119             else:
120                 res = {
121                     'employee_id':emp.id,
122                     'basic':0.0,
123                     'register_id':ids[0],
124                     'name':vals.name,
125                     'date':vals.date,
126                     'journal_id':vals.journal_id.id,
127                     'bank_journal_id':vals.bank_journal_id.id
128                 }
129                 slip_id = slip_pool.create(cr, uid, res)
130                 wf_service.trg_validate(uid, 'hr.payslip', slip_id, 'compute_sheet', cr)
131
132         number = self.pool.get('ir.sequence').get(cr, uid, 'salary.register')
133         self.write(cr, uid, ids, {'state':'draft', 'number':number})
134         return True
135
136 payroll_register()
137
138 class payroll_advice(osv.osv):
139     _inherit = 'hr.payroll.advice'
140     _description = 'Bank Advice Note'
141
142     _columns = {
143         'account_id': fields.many2one('account.account', 'Account'),
144     }
145 payroll_advice()
146
147 class contrib_register(osv.osv):
148     _inherit = 'hr.contibution.register'
149     _description = 'Contribution Register'
150
151     def _total_contrib(self, cr, uid, ids, field_names, arg, context=None):
152         line_pool = self.pool.get('hr.contibution.register.line')
153         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]
154         fiscalyear_id = self.pool.get('account.period').browse(cr, uid, period_id, context=context).fiscalyear_id
155         res = {}
156         for cur in self.browse(cr, uid, ids, context=context):
157             current = line_pool.search(cr, uid, [('period_id','=',period_id),('register_id','=',cur.id)])
158             years = line_pool.search(cr, uid, [('period_id.fiscalyear_id','=',fiscalyear_id.id), ('register_id','=',cur.id)])
159
160             e_month = 0.0
161             c_month = 0.0
162             for i in line_pool.browse(cr, uid, current, context=context):
163                 e_month += i.emp_deduction
164                 c_month += i.comp_deduction
165
166             e_year = 0.0
167             c_year = 0.0
168             for j in line_pool.browse(cr, uid, years, context=context):
169                 e_year += i.emp_deduction
170                 c_year += i.comp_deduction
171
172             res[cur.id]={
173                 'monthly_total_by_emp':e_month,
174                 'monthly_total_by_comp':c_month,
175                 'yearly_total_by_emp':e_year,
176                 'yearly_total_by_comp':c_year
177             }
178         return res
179
180     _columns = {
181         'account_id': fields.many2one('account.account', 'Account'),
182         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
183         'yearly_total_by_emp': fields.function(_total_contrib, method=True, multi='dc', store=True, string='Total By Employee', digits=(16, 4)),
184         'yearly_total_by_comp': fields.function(_total_contrib, method=True, multi='dc', store=True,  string='Total By Company', digits=(16, 4)),
185     }
186 contrib_register()
187
188 class contrib_register_line(osv.osv):
189     _inherit = 'hr.contibution.register.line'
190     _description = 'Contribution Register Line'
191
192     _columns = {
193         'period_id': fields.many2one('account.period', 'Period'),
194     }
195 contrib_register_line()
196
197 class hr_holidays_status(osv.osv):
198     _inherit = 'hr.holidays.status'
199     _columns = {
200         'account_id': fields.many2one('account.account', 'Account'),
201         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
202     }
203 hr_holidays_status()
204
205 class hr_payslip(osv.osv):
206     '''
207     Pay Slip
208     '''
209     _inherit = 'hr.payslip'
210     _description = 'Pay Slip'
211
212     _columns = {
213         'journal_id': fields.many2one('account.journal', 'Expense Journal'),
214         'bank_journal_id': fields.many2one('account.journal', 'Bank Journal'),
215         'move_ids':fields.one2many('hr.payslip.account.move', 'slip_id', 'Accounting vouchers'),
216         'move_line_ids':fields.many2many('account.move.line', 'payslip_lines_rel', 'slip_id', 'line_id', 'Accounting Lines', readonly=True),
217         'move_payment_ids':fields.many2many('account.move.line', 'payslip_payment_rel', 'slip_id', 'payment_id', 'Payment Lines', readonly=True),
218         'period_id': fields.many2one('account.period', 'Force Period', domain=[('state','<>','done')], help="Keep empty to use the period of the validation(Payslip) date."),
219     }
220
221     def create_voucher(self, cr, uid, ids, name, voucher, sequence=5):
222         slip_move = self.pool.get('hr.payslip.account.move')
223         for slip in ids:
224             res = {
225                 'slip_id':slip,
226                 'move_id':voucher,
227                 'sequence':sequence,
228                 'name':name
229             }
230             slip_move.create(cr, uid, res)
231
232     def cancel_sheet(self, cr, uid, ids, context=None):
233         move_pool = self.pool.get('account.move')
234         slip_move = self.pool.get('hr.payslip.account.move')
235         move_ids = []
236         for slip in self.browse(cr, uid, ids, context=context):
237             for line in slip.move_ids:
238                 move_ids.append(line.id)
239                 if line.move_id:
240                     if line.move_id.state == 'posted':
241                         move_pool.button_cancel(cr, uid [line.move_id.id], context)
242                     move_pool.unlink(cr, uid, [line.move_id.id], context=context)
243
244         slip_move.unlink(cr, uid, move_ids, context=context)
245         self.write(cr, uid, ids, {'state':'cancel'}, context=context)
246         return True
247
248     def process_sheet(self, cr, uid, ids, context=None):
249         move_pool = self.pool.get('account.move')
250         movel_pool = self.pool.get('account.move.line')
251         invoice_pool = self.pool.get('account.invoice')
252         fiscalyear_pool = self.pool.get('account.fiscalyear')
253         period_pool = self.pool.get('account.period')
254
255         for slip in self.browse(cr, uid, ids, context=context):
256             if not slip.bank_journal_id or not slip.journal_id:
257                 # Call super method to process sheet if journal_id or bank_journal_id are not specified.
258                 super(hr_payslip, self).process_sheet(cr, uid, [slip.id], context=context)
259                 continue
260             line_ids = []
261             partner = False
262             partner_id = False
263             exp_ids = []
264
265             partner = slip.employee_id.bank_account_id.partner_id
266             partner_id = partner.id
267
268             fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context)
269             if not fiscal_year_ids:
270                 raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract'))
271             fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context)
272             year_exist = False
273             for fiscal_year in fiscal_year_objs:
274                 if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)):
275                     year_exist = True
276             if not year_exist:
277                 raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date)
278             search_periods = period_pool.search(cr, uid, [('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context)
279             if not search_periods:
280                 raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date)
281             period_id = search_periods[0]
282             name = 'Payment of Salary to %s' % (slip.employee_id.name)
283             move = {
284                 'journal_id': slip.bank_journal_id.id,
285                 'period_id': period_id,
286                 'date': slip.date,
287                 'type':'bank_pay_voucher',
288                 'ref':slip.number,
289                 'narration': name
290             }
291             move_id = move_pool.create(cr, uid, move, context=context)
292             self.create_voucher(cr, uid, [slip.id], name, move_id)
293
294             name = "To %s account" % (slip.employee_id.name)
295             
296             if not slip.employee_id.property_bank_account.id:
297                 raise osv.except_osv(_('Warning !'), _('Employee Bank Account is not defined for %s') % slip.employee_id.name)
298             
299             ded_rec = {
300                 'move_id': move_id,
301                 'name': name,
302                 'date': slip.date,
303                 'account_id': slip.employee_id.property_bank_account.id,
304                 'debit': 0.0,
305                 'credit': slip.total_pay,
306                 'journal_id': slip.journal_id.id,
307                 'period_id': period_id,
308                 'ref': slip.number
309             }
310             line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
311             name = "By %s account" % (slip.employee_id.property_bank_account.name)
312             cre_rec = {
313                 'move_id': move_id,
314                 'name': name,
315                 'partner_id': partner_id,
316                 'date': slip.date,
317                 'account_id': partner.property_account_payable.id,
318                 'debit': slip.total_pay,
319                 'credit': 0.0,
320                 'journal_id': slip.journal_id.id,
321                 'period_id': period_id,
322                 'ref': slip.number
323             }
324             line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)]
325
326             other_pay = slip.other_pay
327             #Process all Reambuse Entries
328             for line in slip.line_ids:
329                 if line.type == 'otherpay':
330                     amount = line.total
331                     acc_id = slip.bank_journal_id.default_credit_account_id and slip.bank_journal_id.default_credit_account_id.id
332                     period_id = slip.period_id.id
333                     journal_id = slip.bank_journal_id.id
334                     name = '[%s]-%s' % (slip.number, line.name)
335                     other_pay -= amount
336                     #TODO: link this account entries to the Payment Lines also Expense Entries to Account Lines
337                     l_ids = movel_pool.search(cr, uid, [('name','=',name)], context=context)
338                     line_ids += l_ids
339
340             #Process for Other payment if any
341             other_move_id = False
342             if slip.other_pay > 0:
343                 narration = 'Payment of Other Payeble amounts to %s' % (slip.employee_id.name)
344                 move = {
345                     'journal_id': slip.bank_journal_id.id,
346                     'period_id': period_id,
347                     'date': slip.date,
348                     'type':'bank_pay_voucher',
349                     'ref':slip.number,
350                     'narration': narration
351                 }
352                 other_move_id = move_pool.create(cr, uid, move, context=context)
353                 self.create_voucher(cr, uid, [slip.id], narration, move_id)
354
355                 name = "To %s account" % (slip.employee_id.name)
356                 ded_rec = {
357                     'move_id':other_move_id,
358                     'name':name,
359                     'date':slip.date,
360                     'account_id':slip.employee_id.property_bank_account.id,
361                     'debit': 0.0,
362                     'credit': other_pay,
363                     'journal_id':slip.journal_id.id,
364                     'period_id':period_id,
365                     'ref':slip.number
366                 }
367                 line_ids += [movel_pool.create(cr, uid, ded_rec, context=context)]
368                 name = "By %s account" % (slip.employee_id.property_bank_account.name)
369                 cre_rec = {
370                     'move_id':other_move_id,
371                     'name':name,
372                     'partner_id':partner_id,
373                     'date':slip.date,
374                     'account_id':partner.property_account_payable.id,
375                     'debit': other_pay,
376                     'credit':0.0,
377                     'journal_id':slip.journal_id.id,
378                     'period_id':period_id,
379                     'ref':slip.number
380                 }
381                 line_ids += [movel_pool.create(cr, uid, cre_rec, context=context)]
382
383             rec = {
384                 'state':'done',
385                 'move_payment_ids':[(6, 0, line_ids)],
386                 'paid':True
387             }
388             self.write(cr, uid, [slip.id], rec, context=context)
389             for exp_id in exp_ids:
390                 self.write(cr, uid, [slip.id], {'move_line_ids':[(4, exp_id)]}, context=context)
391
392         return True
393
394     def account_check_sheet(self, cr, uid, ids, context=None):
395         self.write(cr, uid, ids, {'state':'accont_check'}, context=context)
396         return True
397
398     def hr_check_sheet(self, cr, uid, ids, context=None):
399         self.write(cr, uid, ids, {'state':'hr_check'}, context=context)
400         return True
401
402     def verify_sheet(self, cr, uid, ids, context=None):
403         move_pool = self.pool.get('account.move')
404         movel_pool = self.pool.get('account.move.line')
405         fiscalyear_pool = self.pool.get('account.fiscalyear')
406         period_pool = self.pool.get('account.period')
407
408         for slip in self.browse(cr, uid, ids, context=context):
409             if not slip.journal_id:
410                 # Call super method to verify sheet if journal_id is not specified.
411                 super(hr_payslip, self).verify_sheet(cr, uid, [slip.id], context=context)
412                 continue
413             total_deduct = 0.0
414
415             line_ids = []
416             partner = False
417             partner_id = False
418
419             if not slip.employee_id.bank_account_id:
420                 raise osv.except_osv(_('Configuration Error !'), _('Please define bank account for %s !') % (slip.employee_id.name))
421
422             if not slip.employee_id.bank_account_id.partner_id:
423                 raise osv.except_osv(_('Configuration Error !'), _('Please define partner in bank account for %s !') % (slip.employee_id.name))
424
425             partner = slip.employee_id.bank_account_id.partner_id
426             partner_id = slip.employee_id.bank_account_id.partner_id.id
427
428             period_id = False
429
430             if slip.period_id:
431                 period_id = slip.period_id.id
432             else:
433                 fiscal_year_ids = fiscalyear_pool.search(cr, uid, [], context=context)
434                 if not fiscal_year_ids:
435                     raise osv.except_osv(_('Warning !'), _('Please define fiscal year for perticular contract'))
436                 fiscal_year_objs = fiscalyear_pool.read(cr, uid, fiscal_year_ids, ['date_start','date_stop'], context=context)
437                 year_exist = False
438                 for fiscal_year in fiscal_year_objs:
439                     if ((fiscal_year['date_start'] <= slip.date) and (fiscal_year['date_stop'] >= slip.date)):
440                         year_exist = True
441                 if not year_exist:
442                     raise osv.except_osv(_('Warning !'), _('Fiscal Year is not defined for slip date %s') % slip.date)
443                 search_periods = period_pool.search(cr,uid,[('date_start','<=',slip.date),('date_stop','>=',slip.date)], context=context)
444                 if not search_periods:
445                     raise osv.except_osv(_('Warning !'), _('Period is not defined for slip date %s') % slip.date)
446                 period_id = search_periods[0]
447
448             move = {
449                 'journal_id': slip.journal_id.id,
450                 'period_id': period_id,
451                 'date': slip.date,
452                 'ref':slip.number,
453                 'narration': slip.name
454             }
455             move_id = move_pool.create(cr, uid, move, context=context)
456             self.create_voucher(cr, uid, [slip.id], slip.name, move_id)
457             
458             if not slip.employee_id.salary_account.id:
459                 raise osv.except_osv(_('Warning !'), _('Please define Salary Account for %s.') % slip.employee_id.name)
460             
461             line = {
462                 'move_id':move_id,
463                 'name': "By Basic Salary / " + slip.employee_id.name,
464                 'date': slip.date,
465                 'account_id': slip.employee_id.salary_account.id,
466                 'debit': slip.basic,
467                 'credit': 0.0,
468                 'quantity':slip.working_days,
469                 'journal_id': slip.journal_id.id,
470                 'period_id': period_id,
471                 'analytic_account_id': False,
472                 'ref':slip.number
473             }
474             #Setting Analysis Account for Basic Salary
475             if slip.employee_id.analytic_account:
476                 line['analytic_account_id'] = slip.employee_id.analytic_account.id
477
478             move_line_id = movel_pool.create(cr, uid, line, context=context)
479             line_ids += [move_line_id]
480
481             if not slip.employee_id.employee_account.id:
482                 raise osv.except_osv(_('Warning !'), _('Please define Employee Payable Account for %s.') % slip.employee_id.name)
483             
484             line = {
485                 'move_id':move_id,
486                 'name': "To Basic Payable Salary / " + slip.employee_id.name,
487                 'partner_id': partner_id,
488                 'date': slip.date,
489                 'account_id': slip.employee_id.employee_account.id,
490                 'debit': 0.0,
491                 'quantity':slip.working_days,
492                 'credit': slip.basic,
493                 'journal_id': slip.journal_id.id,
494                 'period_id': period_id,
495                 'ref':slip.number
496             }
497             
498             line_ids += [movel_pool.create(cr, uid, line, context=context)]
499
500             for line in slip.line_ids:
501                 name = "[%s] - %s / %s" % (line.code, line.name, slip.employee_id.name)
502                 amount = line.total
503
504                 if line.type == 'leaves':
505                     continue
506
507                 rec = {
508                     'move_id': move_id,
509                     'name': name,
510                     'date': slip.date,
511                     'account_id': line.account_id.id,
512                     'debit': 0.0,
513                     'credit': 0.0,
514                     'journal_id': slip.journal_id.id,
515                     'period_id': period_id,
516                     'analytic_account_id': False,
517                     'ref': slip.number,
518                     'quantity': 1
519                 }
520
521                 #Setting Analysis Account for Salary Slip Lines
522                 if line.analytic_account_id:
523                     rec['analytic_account_id'] = line.analytic_account_id.id
524                 else:
525                     if not slip.deg_id:
526                         raise osv.except_osv(_('Configuration Error !'), _("Payslip cannot be approved due to one of the following reasons: \n 1. The Structure line %s has not been linked with an analytic account. \n Or \n 2. Payslip for %s is missing the configuration of Designation from 'Accounting Details") % (line.name, slip.employee_id.name))
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(_('Configuration 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(_('Configuration 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             self.write(cr, uid, [slip.id], rec, context=context)
624         return True
625
626 hr_payslip()
627
628 class hr_payslip_line(osv.osv):
629     _inherit = 'hr.payslip.line'
630     _columns = {
631         'account_id': fields.many2one('account.account', 'General Account'),
632         'analytic_account_id':fields.many2one('account.analytic.account', 'Analytic Account'),
633     }
634 hr_payslip_line()
635
636 class account_move_link_slip(osv.osv):
637     '''
638     Account Move Link to Pay Slip
639     '''
640     _name = 'hr.payslip.account.move'
641     _description = 'Account Move Link to Pay Slip'
642     _columns = {
643         'name':fields.char('Name', size=256, required=True, readonly=False),
644         'move_id':fields.many2one('account.move', 'Expense Entries', required=False, readonly=True),
645         'slip_id':fields.many2one('hr.payslip', 'Pay Slip', required=False),
646         'sequence': fields.integer('Sequence'),
647     }
648 account_move_link_slip()
649
650 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: