~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to funding_pool/analytic_line.py

UF-359 [ADD] Account override module integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
class analytic_line(osv.osv):
27
27
    _inherit = "account.analytic.line"
28
28
 
29
 
    def _get_amount_currency(self, cr, uid, ids, field_name=None, arg=None, context={}):
30
 
        """
31
 
        Get amount currency.
32
 
        Get amount currency given in move attached to analytic line or default stored amount if no move_id exists.
33
 
        """
34
 
        # Verifications
35
 
        if not context:
36
 
            context = {}
37
 
        if isinstance(ids, (int, long)):
38
 
            ids = [ids]
39
 
        # Prepare some values
40
 
        res = {}
41
 
        for aal in self.browse(cr, uid, ids, context=context):
42
 
            if aal.move_id:
43
 
                res[aal.id] = aal.move_id.amount_currency
44
 
            else:
45
 
                sql = "SELECT amount_currency FROM %s WHERE id = %s" % (self._table, aal.id)
46
 
                cr.execute(sql)
47
 
                sql_result = cr.fetchone()
48
 
                res[aal.id] = sql_result and sql_result[0] or None
49
 
        return res
50
 
 
51
 
    def _set_amount_currency(self, cr, uid, id, name=None, value=None, fnct_inv_arg=None, context={}):
52
 
        """
53
 
        Set amount currency if no move_id in value
54
 
        """
55
 
        if name and value:
56
 
            sql = "UPDATE %s SET %s = %s WHERE id = %s" % (self._table, name, value, id)
57
 
            cr.execute(sql)
58
 
        return True
59
 
 
60
29
    _columns = {
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'),
66
31
    }
67
32
 
104
69
            self._check_date(cr, uid, vals, context=context)
105
70
        return super(analytic_line, self).write(cr, uid, ids, vals, context=context)
106
71
 
107
 
    def copy(self, cr, uid, defaults, context={}):
108
 
        """
109
 
        Update amount_currency from previous element
110
 
        """
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)
114
 
        return res
115
 
 
116
72
analytic_line()
117
73
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: