22
22
from osv import fields, osv
24
24
class financing_contract_format(osv.osv):
26
26
_name = "financing.contract.format"
27
_rec_name = 'format_name'
29
30
'format_name': fields.char('Name', size=64, required=True),
30
31
'reporting_type': fields.selection([('project','Total project only'),
32
33
('all', 'Earmarked and total project')], 'Reporting type', required=True),
33
34
# For contract only, but needed for line domain;
34
35
# we need to keep them available
36
'overhead_percentage': fields.float('Overhead percentage'),
37
'overhead_type': fields.selection([('cost_percentage','Percentage of direct costs'),
38
('grant_percentage','Percentage of grant')], 'Overhead calculation mode'),
35
39
'eligibility_from_date': fields.date('Eligibility date from'),
36
40
'eligibility_to_date': fields.date('Eligibility date to'),
37
41
'funding_pool_ids': fields.one2many('financing.contract.funding.pool.line', 'contract_id', 'Funding Pools'),
38
42
'cost_center_ids': fields.many2many('account.analytic.account', 'financing_contract_cost_center', 'contract_id', 'cost_center_id', string='Cost Centers'),
44
'hidden_instance_id': fields.many2one('msf.instance','Proprietary Instance'),
42
48
'format_name': 'Format',
43
49
'reporting_type': 'all',
50
'overhead_type': 'cost_percentage',
46
53
def name_get(self, cr, uid, ids, context=None):
47
54
result = self.browse(cr, uid, ids, context=context)
50
57
format_name = rs.format_name
51
58
res += [(rs.id, format_name)]
62
('date_overlap', 'check(eligibility_from_date < eligibility_to_date)', 'The "Eligibility Date From" should be sooner than the "Eligibility Date To".'),
54
66
financing_contract_format()
56
class account_account(osv.osv):
57
_name = 'account.account'
58
_inherit = 'account.account'
68
class account_destination_link(osv.osv):
69
_name = 'account.destination.link'
70
_inherit = 'account.destination.link'
60
def _get_used(self, cr, uid, ids, field_name, arg, context=None):
72
def _get_used_in_contract(self, cr, uid, ids, field_name, arg, context=None):
62
74
if context is None:
66
78
if not context.get('contract_id') and not context.get('donor_id'):
80
ids_to_exclude[id] = False
71
83
if context.get('contract_id'):
72
84
ctr_obj = self.pool.get('financing.contract.contract')
75
87
ctr_obj = self.pool.get('financing.contract.donor')
76
88
id_toread = context['donor_id']
90
active_id = context.get('active_id', False)
79
91
for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
80
for acc in line.account_ids:
81
exclude[acc.id] = True
92
if not active_id or line.id != active_id:
93
for account_destination in line.account_destination_ids: # exclude from other duplet format lines
94
exclude[account_destination.id] = True
95
for account_quadruplet in line.account_quadruplet_ids: # exclude from other quadruplet format lines
96
# UFTP-16: The list of all duplet acc/destination needs to be grey if one line of combination in the quad has been selected
97
duplet_ids_to_exclude = self.search(cr, uid, [('account_id', '=', account_quadruplet.account_id.id),('destination_id','=',account_quadruplet.account_destination_id.id)])
98
for item in duplet_ids_to_exclude:
83
res[id] = id in exclude
102
ids_to_exclude[id] = id in exclude
103
return ids_to_exclude
86
def _search_used(self, cr, uid, obj, name, args, context=None):
105
def _search_used_in_contract(self, cr, uid, obj, name, args, context=None):
89
108
if context is None:
103
122
for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
104
for acc in line.account_ids:
105
exclude[acc.id] = True
123
if not context.get('active_id', False) or line.id != context['active_id']:
124
for account_destination in line.account_destination_ids:
125
exclude[account_destination.id] = True
126
for account_quadruplet in line.account_quadruplet_ids:
127
exclude[account_quadruplet.account_destination_id.id] = True
107
129
return [('id', 'not in', exclude.keys())]
110
'used': fields.function(_get_used, method=True, type='boolean', string='Used', fnct_search=_search_used),
132
'used_in_contract': fields.function(_get_used_in_contract, method=True, type='boolean', string='Used', fnct_search=_search_used_in_contract),
113
135
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
114
136
if context is None:
116
138
if view_type == 'tree' and (context.get('contract_id') or context.get('donor_id')) :
117
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'financing_contract', 'view_account_for_contract_tree')[1]
118
return super(account_account, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
139
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'financing_contract', 'view_account_destination_link_for_contract_tree')[1]
140
return super(account_destination_link, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
144
account_destination_link()
121
145
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: