26
26
class analytic_line(osv.osv):
27
27
_inherit = "account.analytic.line"
29
def _get_amount_currency(self, cr, uid, ids, field_name=None, arg=None, context={}):
32
Get amount currency given in move attached to analytic line or default stored amount if no move_id exists.
37
if isinstance(ids, (int, long)):
41
for aal in self.browse(cr, uid, ids, context=context):
43
res[aal.id] = aal.move_id.amount_currency
45
sql = "SELECT amount_currency FROM %s WHERE id = %s" % (self._table, aal.id)
47
sql_result = cr.fetchone()
48
res[aal.id] = sql_result and sql_result[0] or None
51
def _set_amount_currency(self, cr, uid, id, name=None, value=None, fnct_inv_arg=None, context={}):
53
Set amount currency if no move_id in value
56
sql = "UPDATE %s SET %s = %s WHERE id = %s" % (self._table, name, value, id)
61
'reversal_origin': fields.many2one('account.analytic.line', string="Reversal origin", readonly=True, help="Line that have been reversed."),
62
'invoice_line_id': fields.many2one('account.invoice.line', string="Invoice line", readonly=True, help="Invoice line from which this line is linked."),
63
'source_date': fields.date('Source date', help="Date used for FX rate re-evaluation"),
64
'amount_currency': fields.function(_get_amount_currency, fnct_inv=_set_amount_currency, method=True, store=True, string="Amount currency", type="float", readonly="True", help=""),
65
30
"distribution_id": fields.many2one('analytic.distribution', 'Analytic Distribution'),
104
69
self._check_date(cr, uid, vals, context=context)
105
70
return super(analytic_line, self).write(cr, uid, ids, vals, context=context)
107
def copy(self, cr, uid, defaults, context={}):
109
Update amount_currency from previous element
111
amt = self.read(cr, uid, defaults, ['amount_currency'], context=context).get('amount_currency', False)
112
res = super(account_analytic_line, self).copy(cr, uid, defaults, context=context)
113
self.write(cr, uid, [res], {'amount_currency': amt}, context=context)
117
73
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: