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="")
30
"distribution_id": fields.many2one('analytic.distribution', 'Analytic Distribution'),
67
33
def _check_date(self, cr, uid, vals, context={}):
62
if isinstance(ids, (int, long)):
97
65
if not 'account_id' in vals:
98
66
line = self.browse(cr, uid, [id], context=context)
101
69
self._check_date(cr, uid, vals, context=context)
102
70
return super(analytic_line, self).write(cr, uid, ids, vals, context=context)
104
def copy(self, cr, uid, defaults, context={}):
106
Update amount_currency from previous element
108
amt = self.read(cr, uid, defaults, ['amount_currency'], context=context).get('amount_currency', False)
109
res = super(analytic_line, self).copy(cr, uid, defaults, context=context)
110
self.write(cr, uid, [res], {'amount_currency': amt}, context=context)
114
73
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: