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

« back to all changes in this revision

Viewing changes to account_override/account_analytic_line.py

  • Committer: chloups208
  • Date: 2011-06-30 14:54:26 UTC
  • mto: (307.2.1 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: chloups208@chloups208-laptop-20110630145426-qsj5j0pp3e5b23bc
[UF-53][UF-58][UF-63] initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#-*- encoding:utf-8 -*-
3
 
##############################################################################
4
 
#
5
 
#    OpenERP, Open Source Management Solution
6
 
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
 
#    Developer: Olivier DOSSMANN
8
 
#
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.
13
 
#
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.
18
 
#
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/>.
21
 
#
22
 
##############################################################################
23
 
 
24
 
from osv import osv
25
 
from osv import fields
26
 
import decimal_precision as dp
27
 
 
28
 
class account_analytic_line(osv.osv):
29
 
    _inherit = 'account.analytic.line'
30
 
 
31
 
    def __init__(self, pool, cr):
32
 
        """
33
 
        Permits to OpenERP not attempt to update DB field with the old field_function
34
 
        """
35
 
        super(account_analytic_line, self).__init__(pool, cr)
36
 
        if self.pool._store_function.get(self._name, []):
37
 
            newstore = []
38
 
            for fct in self.pool._store_function[self._name]:
39
 
                if fct[1] not in ['currency_id', 'amount_currency']:
40
 
                    newstore.append(fct)
41
 
            self.pool._store_function[self._name] = newstore
42
 
 
43
 
    def join_without_redundancy(self, text='', string=''):
44
 
        return self.pool.get('account.move.line').join_without_redundancy(text, string)
45
 
 
46
 
    _columns = {
47
 
        'reversal_origin': fields.many2one('account.analytic.line', string="Reversal origin", readonly=True, help="Line that have been reversed."),
48
 
        'invoice_line_id': fields.many2one('account.invoice.line', string="Invoice line", readonly=True, help="Invoice line from which this line is linked.", ondelete='cascade'),
49
 
        'source_date': fields.date('Source date', help="Date used for FX rate re-evaluation"),
50
 
        'amount_currency': fields.float(string="Amount currency", digits_compute=dp.get_precision('Account'), readonly="True", required=True, help="The amount expressed in an optional other currency."),
51
 
        'currency_id': fields.many2one('res.currency', string="Currency", required=True),
52
 
    }
53
 
 
54
 
    def reverse(self, cr, uid, ids, context={}):
55
 
        """
56
 
        Reverse an analytic line
57
 
        """
58
 
        if not context:
59
 
            context = {}
60
 
        if isinstance(ids, (int, long)):
61
 
            ids = [ids]
62
 
        res = []
63
 
        for al in self.browse(cr, uid, ids, context=context):
64
 
            vals = {
65
 
                'name': self.join_without_redundancy(al.name, 'REV'),
66
 
                'amount': al.amount * -1,
67
 
                'date': al.source_date or al.date,
68
 
                'reversal_origin': al.id,
69
 
                'amount_currency': al.amount_currency * -1,
70
 
                'currency_id': al.currency_id.id,
71
 
            }
72
 
            new_al = self.copy(cr, uid, al.id, vals, context=context)
73
 
            res.append(new_al)
74
 
        return res
75
 
 
76
 
account_analytic_line()
77
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: