1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
5
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
6
# Copyright (C) 2012 Associazione OpenERP Italia
7
# (<http://www.openerp-italia.org>).
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU Affero General Public License as published
12
# by the Free Software Foundation, either version 3 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU Affero General Public License for more details.
20
# You should have received a copy of the GNU Affero General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
##############################################################################
25
from osv import fields,osv
26
from tools.translate import _
29
class riba_accreditation(osv.osv_memory):
31
def _get_accreditation_journal_id(self, cr, uid, context=None):
32
return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'accreditation_journal_id', context=context)
34
def _get_accreditation_account_id(self, cr, uid, context=None):
35
return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'accreditation_account_id', context=context)
37
def _get_bank_account_id(self, cr, uid, context=None):
38
return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'bank_account_id', context=context)
40
def _get_bank_expense_account_id(self, cr, uid, context=None):
41
return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'bank_expense_account_id', context=context)
43
def _get_accreditation_amount(self, cr, uid, context=None):
46
if not context.get('active_id', False):
48
distinta_pool = self.pool.get('riba.distinta')
49
distinta = distinta_pool.browse(cr, uid, context['active_id'], context=context)
51
for line in distinta.line_ids:
55
_name = "riba.accreditation"
56
_description = "Bank accreditation"
58
'accreditation_journal_id' : fields.many2one('account.journal', "Accreditation journal",
59
domain=[('type', '=', 'bank')]),
60
'accreditation_account_id' : fields.many2one('account.account', "Ri.Ba. bank account"),
61
'accreditation_amount': fields.float('Credit amount'),
62
'bank_account_id' : fields.many2one('account.account', "Bank account",
63
domain=[('type', '=', 'liquidity')]),
64
'bank_amount': fields.float('Versed amount'),
65
'bank_expense_account_id' : fields.many2one('account.account', "Bank Expenses account"),
66
'expense_amount': fields.float('Expenses amount'),
70
'accreditation_journal_id': _get_accreditation_journal_id,
71
'accreditation_account_id': _get_accreditation_account_id,
72
'bank_account_id': _get_bank_account_id,
73
'bank_expense_account_id': _get_bank_expense_account_id,
74
'accreditation_amount': _get_accreditation_amount,
77
def skip(self, cr, uid, ids, context=None):
80
wf_service = netsvc.LocalService("workflow")
81
active_id = context and context.get('active_id', False) or False
83
raise osv.except_osv(_('Error'), _('No active ID found'))
84
wf_service.trg_validate(
85
uid, 'riba.distinta', active_id, 'accredited', cr)
86
return {'type': 'ir.actions.act_window_close'}
88
def create_move(self, cr, uid, ids, context=None):
91
wf_service = netsvc.LocalService("workflow")
92
active_id = context and context.get('active_id', False) or False
94
raise osv.except_osv(_('Error'), _('No active ID found'))
95
move_pool = self.pool.get('account.move')
96
move_line_pool = self.pool.get('account.move.line')
97
distinta_pool = self.pool.get('riba.distinta')
98
distinta = distinta_pool.browse(cr, uid, active_id, context=context)
99
wizard = self.browse(cr,uid,ids)[0]
100
if not wizard.accreditation_journal_id or not wizard.accreditation_account_id or not wizard.bank_account_id or not wizard.bank_expense_account_id:
101
raise osv.except_osv(_('Error'), _('Every account is mandatory'))
103
'ref': _('Accreditation Ri.Ba. %s') % distinta.name,
104
'journal_id': wizard.accreditation_journal_id.id,
108
'account_id': wizard.accreditation_account_id.id,
109
'credit': wizard.accreditation_amount,
114
'account_id': wizard.bank_account_id.id,
115
'debit': wizard.bank_amount,
120
'account_id': wizard.bank_expense_account_id.id,
121
'debit': wizard.expense_amount,
126
move_id = move_pool.create(cr, uid, move_vals, context=context)
127
distinta.write({'accreditation_move_id': move_id})
128
wf_service.trg_validate(
129
uid, 'riba.distinta', active_id, 'accredited', cr)
131
'name': _('Accreditation Entry'),
134
'res_model': 'account.move',
135
'type': 'ir.actions.act_window',
137
'res_id': move_id or False,