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

« back to all changes in this revision

Viewing changes to financing_contract/format.py

  • Committer: jf
  • Date: 2012-06-13 12:43:21 UTC
  • mfrom: (827.5.11 uf-635)
  • Revision ID: jf@tempo4-20120613124321-2b8cwgl86gyy2tb7
UF-635 [DEV] Documents workflow: Graphic representation
lp:~unifield-team/unifield-wm/uf-635 revno 838

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 MSF, TeMPO Consulting.
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
 
 
24
class financing_contract_format(osv.osv):
 
25
    
 
26
    _name = "financing.contract.format"
 
27
    
 
28
    _columns = {
 
29
        'format_name': fields.char('Name', size=64, required=True),
 
30
        'reporting_type': fields.selection([('project','Total project only'),
 
31
                                            ('allocated','Earmarked only'),
 
32
                                            ('all', 'Earmarked and total project')], 'Reporting type', required=True),
 
33
        # For contract only, but needed for line domain;
 
34
        # we need to keep them available
 
35
        'overhead_percentage': fields.float('Overhead percentage'),
 
36
        'overhead_type': fields.selection([('cost_percentage','Percentage of direct costs'),
 
37
                                           ('grant_percentage','Percentage of grant')], 'Overhead calculation mode'),
 
38
        'eligibility_from_date': fields.date('Eligibility date from'),
 
39
        'eligibility_to_date': fields.date('Eligibility date to'),
 
40
        'funding_pool_ids': fields.one2many('financing.contract.funding.pool.line', 'contract_id', 'Funding Pools'),
 
41
        'cost_center_ids': fields.many2many('account.analytic.account', 'financing_contract_cost_center', 'contract_id', 'cost_center_id', string='Cost Centers'),
 
42
    }
 
43
    
 
44
    _defaults = {
 
45
        'format_name': 'Format',
 
46
        'reporting_type': 'all',
 
47
        'overhead_type': 'cost_percentage',
 
48
    }
 
49
    
 
50
    def name_get(self, cr, uid, ids, context=None):
 
51
        result = self.browse(cr, uid, ids, context=context)
 
52
        res = []
 
53
        for rs in result:
 
54
            format_name = rs.format_name
 
55
            res += [(rs.id, format_name)]
 
56
        return res
 
57
        
 
58
financing_contract_format()
 
59
 
 
60
class account_account(osv.osv):
 
61
    _name = 'account.account'
 
62
    _inherit = 'account.account'
 
63
 
 
64
    def _get_used(self, cr, uid, ids, field_name, arg, context=None):
 
65
        res = {}
 
66
        if context is None:
 
67
            context = {}
 
68
        exclude = {}
 
69
 
 
70
        if not context.get('contract_id') and not context.get('donor_id'):
 
71
            for id in ids:
 
72
                res[id] = False
 
73
            return res
 
74
 
 
75
        if context.get('contract_id'):
 
76
            ctr_obj = self.pool.get('financing.contract.contract')
 
77
            id_toread = context['contract_id']
 
78
        elif context.get('donor_id'):
 
79
            ctr_obj = self.pool.get('financing.contract.donor')
 
80
            id_toread = context['donor_id']
 
81
 
 
82
        exclude = {}
 
83
        for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
 
84
            for acc in line.account_ids:
 
85
                exclude[acc.id] = True
 
86
        for id in ids:
 
87
            res[id] = id in exclude
 
88
        return res
 
89
 
 
90
    def _search_used(self, cr, uid, obj, name, args, context=None):
 
91
        if not args:
 
92
            return []
 
93
        if context is None:
 
94
            context = {}
 
95
        assert args[0][1] == '=' and args[0][2], 'Filter not implemented'
 
96
        if not context.get('contract_id') and not context.get('donor_id'):
 
97
            return []
 
98
 
 
99
        if context.get('contract_id'):
 
100
            ctr_obj = self.pool.get('financing.contract.contract')
 
101
            id_toread = context['contract_id']
 
102
        elif context.get('donor_id'):
 
103
            ctr_obj = self.pool.get('financing.contract.donor')
 
104
            id_toread = context['donor_id']
 
105
 
 
106
        exclude = {}
 
107
        for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
 
108
            for acc in line.account_ids:
 
109
                exclude[acc.id] = True
 
110
 
 
111
        return [('id', 'not in', exclude.keys())]
 
112
 
 
113
    _columns = {
 
114
        'used': fields.function(_get_used, method=True, type='boolean', string='Used', fnct_search=_search_used),
 
115
    }
 
116
 
 
117
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
 
118
        if context is None:
 
119
            context = {}
 
120
        if view_type == 'tree' and (context.get('contract_id') or context.get('donor_id')) :
 
121
            view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'financing_contract', 'view_account_for_contract_tree')[1]
 
122
        return super(account_account, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
 
123
 
 
124
account_account()
 
125
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: