~openerp-community/eficent-openerp-project-management/nerviaconsultores-openerp-7.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2011 Eficent (<http://www.eficent.com/>)
#              <contact@eficent.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from lxml import etree
import time
from datetime import datetime, date, timedelta
import decimal_precision as dp
from tools.translate import _
from osv import fields, osv
import netsvc
import tools

class account_analytic_account(osv.osv):
    
    def _categories_name_calc(self, cr, uid, ids, name, args, context=None):
        
        if not ids:
            return []
        res = []            
            
        accounts_br = self.browse(cr, uid, ids, context=context)   
                
        for account in accounts_br:
            data =[]
            categories_br = account.category_id
            if categories_br:                    
                for category_br in categories_br:
                    cat_name = category_br.complete_name or ''
                    data.insert(0, cat_name)
                data.sort(cmp=None, key=None, reverse=False)
                data_str = ', '.join(map(tools.ustr,data))     
                
            else:
                data_str = ''
                                

            res.append((account.id, data_str))
                                   
        return dict(res)     
    
    _inherit = 'account.analytic.account'
    _columns = {   
            
        'category_id': fields.many2many('analytic.account.category', 'analytic_account_category_rel', 'account_id', 'category_id', 'Categories'),
        'categories_name_str': fields.function(_categories_name_calc, method=True, type='text', string='Categories', help='Analytic account categories'), 
                                               
     }
                
account_analytic_account()