2
# -*- coding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
# Developer: Olivier DOSSMANN
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
25
from osv import fields
26
from time import strftime
27
from lxml import etree
29
class account_bank_statement_line(osv.osv):
30
_name = 'account.bank.statement.line'
31
_inherit = 'account.bank.statement.line'
33
def _get_output(self, cr, uid, ids, field_name, arg, context=None):
35
Get an amount regarding currency in context (from 'output' and 'output_currency_id' values)
40
if isinstance(ids, (int, long)):
42
# Return nothing if no 'output_currency_id' in context
43
if not context or not context.get('output_currency_id', False):
45
res[id] = {'output_currency': False, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
48
currency_id = context.get('output_currency_id')
49
currency_obj = self.pool.get('res.currency')
50
rate = currency_obj.read(cr, uid, currency_id, ['rate'], context=context).get('rate', False)
54
res[id] = {'output_currency': currency_id, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
56
for absl in self.browse(cr, uid, ids, context=context):
57
res[absl.id] = {'output_currency': False, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
60
context.update({'date': absl.date or strftime('%Y-%m-%d')})
61
mnt = self.pool.get('res.currency').compute(cr, uid, absl.currency_id.id, currency_id, absl.amount, round=True, context=context)
62
res[absl.id]['output_amount'] = mnt or 0.0
64
res[absl.id]['output_amount_debit'] = 0.0
65
res[absl.id]['output_amount_credit'] = abs(mnt) or 0.0
67
res[absl.id]['output_amount_debit'] = abs(mnt) or 0.0
68
res[absl.id]['output_amount_credit'] = 0.0
69
# or output_currency field
70
res[absl.id]['output_currency'] = currency_id
74
'output_amount': fields.function(_get_output, string="Output amount", type='float', method=True, store=False, multi="statement_output_currency"),
75
'output_amount_debit': fields.function(_get_output, string="Output debit", type='float', method=True, store=False, multi="statement_output_currency"),
76
'output_amount_credit': fields.function(_get_output, string="Output credit", type='float', method=True, store=False, multi="statement_output_currency"),
77
'output_currency': fields.function(_get_output, string="Output curr.", type='many2one', relation='res.currency', method=True, store=False,
78
multi="statement_output_currency"),
81
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
83
Remove output_amount and output_currency field if context doesn't have 'output_currency_id'
86
view = super(account_bank_statement_line, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
87
if view_type == 'tree' and (not context or not context.get('output_currency_id', False)):
88
tree = etree.fromstring(view['arch'])
89
for element in ['output_currency', 'output_amount']:
90
element_fields = tree.xpath('/tree/field[@name="' + element + '"]')
91
for field in element_fields:
93
view['arch'] = etree.tostring(tree)
96
def copy(self, cr, uid, id, default=None, context=None):
102
'output_currency': False,
103
'output_amount': 0.0,
105
return super(account_bank_statement_line, self).copy(cr, uid, id, default, context=context)
107
account_bank_statement_line()
108
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: