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_move_line(osv.osv):
30
_name = 'account.move.line'
31
_inherit = 'account.move.line'
33
def _get_output(self, cr, uid, ids, field_name, arg, context={}):
35
Get an amount regarding currency in context (from 'output' and 'output_currency_id' values).
36
NB: Pay attention to 'currency_table_id' field in context. It compute amounts regarding another rates.
41
if isinstance(ids, (int, long)):
43
# Return nothing if no 'output_currency_id' in context
44
if not context or not context.get('output_currency_id', False):
46
res[id] = {'output_currency': False, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
49
currency_id = context.get('output_currency_id')
50
currency_obj = self.pool.get('res.currency')
51
rate = currency_obj.read(cr, uid, currency_id, ['rate'], context=context).get('rate', False)
55
res[id] = {'output_currency': currency_id, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
57
for ml in self.browse(cr, uid, ids, context=context):
58
res[ml.id] = {'output_currency': False, 'output_amount': 0.0, 'output_amount_debit': 0.0, 'output_amount_credit': 0.0}
61
context.update({'date': ml.source_date or ml.date or strftime('%Y-%m-%d')})
62
mnt = self.pool.get('res.currency').compute(cr, uid, ml.currency_id.id, currency_id, ml.amount_currency, round=True, context=context)
63
res[ml.id]['output_amount'] = mnt or 0.0
65
res[ml.id]['output_amount_debit'] = 0.0
66
res[ml.id]['output_amount_credit'] = abs(mnt) or 0.0
68
res[ml.id]['output_amount_debit'] = abs(mnt) or 0.0
69
res[ml.id]['output_amount_credit'] = 0.0
70
# or output_currency field
71
res[ml.id]['output_currency'] = currency_id
75
'output_amount': fields.function(_get_output, string="Output amount", type='float', method=True, store=False, multi="output_currency"),
76
'output_amount_debit': fields.function(_get_output, string="Output debit", type='float', method=True, store=False, multi="output_currency"),
77
'output_amount_credit': fields.function(_get_output, string="Output credit", type='float', method=True, store=False, multi="output_currency"),
78
'output_currency': fields.function(_get_output, string="Output curr.", type='many2one', relation='res.currency', method=True, store=False,
79
multi="output_currency"),
82
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
84
Remove output_amount and output_currency field if context doesn't have 'output_currency_id'
87
view = super(account_move_line, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
88
if view_type == 'tree' and (not context or not context.get('output_currency_id', False)):
89
tree = etree.fromstring(view['arch'])
90
for element in ['output_currency', 'output_amount_debit', 'output_amount_credit']:
91
element_fields = tree.xpath('/tree/field[@name="' + element + '"]')
92
for field in element_fields:
94
view['arch'] = etree.tostring(tree)
98
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: