1
# -*- encoding: utf-8 -*-
3
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/
7
# info Vauxoo (info@vauxoo.com)
9
# Coded by: Luis Torres (luis_t@vauxoo.com)
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as
14
# published by the Free Software Foundation, either version 3 of the
15
# License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
26
from openerp.osv import fields, osv
27
from openerp import netsvc
29
class hr_payslip(osv.osv):
30
_inherit = 'hr.payslip'
32
def _compute_lines(self, cr, uid, ids, name, args, context=None):
34
for payslip in self.browse(cr, uid, ids, context=context):
38
for p in payslip.move_id.line_id:
41
temp_lines = map(lambda x: x.id, p.reconcile_id.line_id)
42
elif p.reconcile_partial_id:
43
temp_lines = map(lambda x: x.id, p.reconcile_partial_id.line_partial_ids)
44
lines += [x for x in temp_lines if x not in lines]
47
lines = filter(lambda x: x not in src, lines)
48
result[payslip.id] = lines
51
def _reconciled(self, cr, uid, ids, name, args, context=None):
53
wf_service = netsvc.LocalService("workflow")
54
for pay in self.browse(cr, uid, ids, context=context):
55
res[pay.id] = self.test_paid(cr, uid, [pay.id])
56
if not res[pay.id] and pay.state == 'paid':
57
wf_service.trg_validate(uid, 'hr.payslip', pay.id, 'open_test', cr)
60
def action_done_paid(self, cr, uid, ids, context=None):
61
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
63
def _get_payslip_from_line(self, cr, uid, ids, context=None):
65
for line in self.pool.get('account.move.line').browse(cr, uid, ids, context=context):
66
if line.reconcile_partial_id:
67
for line2 in line.reconcile_partial_id.line_partial_ids:
68
move[line2.move_id.id] = True
70
for line2 in line.reconcile_id.line_id:
71
move[line2.move_id.id] = True
74
payslip_ids = self.pool.get('hr.payslip').search(cr, uid, [('move_id', 'in', move.keys())], context=context)
77
def _get_payslip_from_reconcile(self, cr, uid, ids, context=None):
79
for r in self.pool.get('account.move.reconcile').browse(cr, uid, ids, context=context):
80
for line in r.line_partial_ids:
81
move[line.move_id.id] = True
82
for line in r.line_id:
83
move[line.move_id.id] = True
87
payslip_ids = self.pool.get('hr.payslip').search(cr, uid, [('move_id', 'in', move.keys())], context=context)
91
'state': fields.selection([
93
('verify', 'Waiting'),
95
('cancel', 'Rejected'),
97
], 'Status', select=True, readonly=True,
98
help='* When the payslip is created the status is \'Draft\'.\
99
\n* If the payslip is under verification, the status is \'Waiting\'. \
100
\n* If the payslip is confirmed then status is set to \'Done\'.\
101
\n* When user cancel payslip the status is \'Rejected\'.\
102
\n* When the payment is done the status id \'Paid\'.'),
103
'payment_ids': fields.function(_compute_lines, relation='account.move.line',
104
type="many2many", string='Payments'),
105
'reconciled': fields.function(_reconciled, string='Paid/Reconciled', type='boolean',
107
'hr.payslip': (lambda self, cr, uid, ids, c={}: ids, [], 50),
108
'account.move.line': (_get_payslip_from_line, None, 50),
109
'account.move.reconcile': (_get_payslip_from_reconcile, None, 50),},
110
help="It indicates that the payslip has been paid and the journal entry of the payslip has been reconciled with one or several journal entries of payment."),
113
def move_line_id_payment_get(self, cr, uid, ids, *args):
114
if not ids: return []
115
result = self.move_line_id_payment_gets(cr, uid, ids, *args)
116
return result.get(ids[0], [])
118
def move_line_id_payment_gets(self, cr, uid, ids, *args):
120
if not ids: return res
121
payslip_bwr = self.browse(cr, uid, ids[0])
123
for x in payslip_bwr.details_by_salary_rule_category:
124
if x.salary_rule_id.account_credit.id:
125
account_ids.append(x.salary_rule_id.account_credit.id)
126
if not account_ids: return res
127
cr.execute('SELECT i.id, l.id '\
128
'FROM account_move_line l '\
129
'LEFT JOIN hr_payslip i ON (i.move_id=l.move_id) '\
131
'AND l.account_id=%s',
132
(tuple(ids), account_ids[0]))
133
for r in cr.fetchall():
134
res.setdefault(r[0], [])
135
res[r[0]].append( r[1] )
138
def test_paid(self, cr, uid, ids, *args):
139
res = self.move_line_id_payment_get(cr, uid, ids)
144
cr.execute('select reconcile_id from account_move_line where id=%s', (id,))
145
ok = ok and bool(cr.fetchone()[0])
148
def done_paid(self, cr, uid, ids, context=None):
150
This function is called by a webservice for update the payslip that were created
151
before to added the state paid.
153
wf_service = netsvc.LocalService("workflow")
155
wf_service.trg_write(uid, 'hr.payslip', id_, cr)