1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
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
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
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.
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/>.
21
##############################################################################
23
from osv import fields, osv
24
from tools.translate import _
26
_logger = logging.getLogger(__name__)
28
class account_bank_statement(osv.osv):
29
_inherit = 'account.bank.statement'
31
def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, st_line_number, context=None):
34
res_currency_obj = self.pool.get('res.currency')
35
account_move_obj = self.pool.get('account.move')
36
account_move_line_obj = self.pool.get('account.move.line')
37
account_bank_statement_line_obj = self.pool.get('account.bank.statement.line')
38
st_line = account_bank_statement_line_obj.browse(cr, uid, st_line_id, context=context)
39
st = st_line.statement_id
41
context.update({'date': st_line.date})
43
move_id = account_move_obj.create(cr, uid, {
44
'journal_id': st.journal_id.id,
45
'period_id': st.period_id.id,
47
'name': st_line_number,
50
account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
51
'move_ids': [(4, move_id, False)]
54
# torec = [] # FIX by Noviat; remove obsolete code
55
if st_line.amount >= 0:
56
account = st.journal_id.default_credit_account_id
58
account = st.journal_id.default_debit_account_id
60
acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id
62
'res.currency.compute.account': acc_cur,
64
amount = res_currency_obj.compute(cr, uid, st.currency.id,
65
company_currency_id, st_line.amount, context=context)
72
'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False,
73
'account_id': (st_line.account_id) and st_line.account_id.id,
74
'credit': ((amount>0) and amount) or 0.0,
75
'debit': ((amount<0) and -amount) or 0.0,
76
'statement_id': st.id,
77
'journal_id': st.journal_id.id,
78
'period_id': st.period_id.id,
79
'currency_id': st.currency.id,
80
'analytic_account_id': st_line.analytic_account_id and st_line.analytic_account_id.id or False
83
if st.currency.id <> company_currency_id:
84
amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
85
st.currency.id, amount, context=context)
86
val['amount_currency'] = -amount_cur
88
if st_line.account_id and st_line.account_id.currency_id: # FIX by Noviat
89
val['currency_id'] = st_line.account_id.currency_id.id
90
amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
91
st_line.account_id.currency_id.id, amount, context=context)
92
val['amount_currency'] = -amount_cur
94
move_line_id = account_move_line_obj.create(cr, uid, val, context=context)
95
#torec.append(move_line_id) # FIX by Noviat; remove obsolete code
97
# Fill the secondary amount/currency
98
# if currency is not the same than the company
99
amount_currency = False
101
if account.currency_id: # FIX by Noviat
102
amount_currency = st_line.amount
103
currency_id = st.currency.id
105
account_move_line_obj.create(cr, uid, {
106
'name': st_line.name,
107
'date': st_line.date,
110
'partner_id': ((st_line.partner_id) and st_line.partner_id.id) or False,
111
'account_id': account.id,
112
'credit': ((amount < 0) and -amount) or 0.0,
113
'debit': ((amount > 0) and amount) or 0.0,
114
'statement_id': st.id,
115
'journal_id': st.journal_id.id,
116
'period_id': st.period_id.id,
117
'amount_currency': amount_currency,
118
'currency_id': currency_id,
121
for line in account_move_line_obj.browse(cr, uid, [x.id for x in
122
account_move_obj.browse(cr, uid, move_id,
123
context=context).line_id],
125
if line.state <> 'valid':
126
raise osv.except_osv(_('Error !'),
127
_('Journal item "%s" is not valid.') % line.name)
129
# Bank statements will not consider boolean on journal entry_posted
130
account_move_obj.post(cr, uid, [move_id], context=context)
133
account_bank_statement()
135
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: