1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO Consulting.
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.
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.
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/>.
20
##############################################################################
22
from osv import fields, osv
24
class financing_contract_format(osv.osv):
26
_name = "financing.contract.format"
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'),
45
'format_name': 'Format',
46
'reporting_type': 'all',
47
'overhead_type': 'cost_percentage',
50
def name_get(self, cr, uid, ids, context=None):
51
result = self.browse(cr, uid, ids, context=context)
54
format_name = rs.format_name
55
res += [(rs.id, format_name)]
58
financing_contract_format()
60
class account_account(osv.osv):
61
_name = 'account.account'
62
_inherit = 'account.account'
64
def _get_used(self, cr, uid, ids, field_name, arg, context=None):
70
if not context.get('contract_id') and not context.get('donor_id'):
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']
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
87
res[id] = id in exclude
90
def _search_used(self, cr, uid, obj, name, args, context=None):
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'):
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']
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
111
return [('id', 'not in', exclude.keys())]
114
'used': fields.function(_get_used, method=True, type='boolean', string='Used', fnct_search=_search_used),
117
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
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)
125
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: