2
#-*- encoding: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
27
class account_analytic_line(osv.osv):
28
_inherit = 'account.analytic.line'
30
def _get_amount_currency(self, cr, uid, ids, field_name=None, arg=None, context={}):
33
Get amount currency given in move attached to analytic line or default stored amount if no move_id exists.
38
if isinstance(ids, (int, long)):
42
for aal in self.browse(cr, uid, ids, context=context):
44
res[aal.id] = aal.move_id.amount_currency
46
sql = "SELECT amount_currency FROM %s WHERE id = %s" % (self._table, aal.id)
48
sql_result = cr.fetchone()
49
res[aal.id] = sql_result and sql_result[0] or None
52
def _set_amount_currency(self, cr, uid, id, name=None, value=None, fnct_inv_arg=None, context={}):
54
Set amount currency if no move_id in value
57
sql = "UPDATE %s SET %s = %s WHERE id = %s" % (self._table, name, value, id)
62
'reversal_origin': fields.many2one('account.analytic.line', string="Reversal origin", readonly=True, help="Line that have been reversed."),
63
'invoice_line_id': fields.many2one('account.invoice.line', string="Invoice line", readonly=True, help="Invoice line from which this line is linked."),
64
'source_date': fields.date('Source date', help="Date used for FX rate re-evaluation"),
65
'amount_currency': fields.function(_get_amount_currency, fnct_inv=_set_amount_currency, method=True, store=True, string="Amount currency", type="float", readonly="True", help="")
68
def copy(self, cr, uid, defaults, context={}):
70
Update amount_currency from previous element
72
amt = self.read(cr, uid, defaults, ['amount_currency'], context=context).get('amount_currency', False)
73
res = super(account_analytic_line, self).copy(cr, uid, defaults, context=context)
74
self.write(cr, uid, [res], {'amount_currency': amt}, context=context)
77
account_analytic_line()
78
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: