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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 MSF, TeMPO Consulting.
#
# 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 osv import fields, osv
class financing_contract_format(osv.osv):
_name = "financing.contract.format"
_columns = {
'format_name': fields.char('Name', size=64, required=True),
'reporting_type': fields.selection([('project','Total project costs'),
('allocated','Funded costs'),
('all', 'Total project and funded costs')], 'Reporting type', required=True),
'overhead_type': fields.selection([('cost_percentage','Percentage of total costs'),
('grant_percentage','Percentage of direct costs'),
('amount', 'Lump sum')], 'Overhead type', required=True),
'overhead_percentage': fields.float('Percentage overhead'),
'budget_allocated_overhead': fields.float('Funded overhead - Budget'),
'budget_project_overhead': fields.float('Total project overhead - Budget'),
'allocated_overhead': fields.float('Funded overhead - Actuals'),
'project_overhead': fields.float('Total project overhead - Actuals'),
'budget_allocated_lump_sum': fields.float('Funded lump sum - Budget'),
'budget_project_lump_sum': fields.float('Total project lump sum - Budget'),
'allocated_lump_sum': fields.float('Funded lump sum - Actuals'),
'project_lump_sum': fields.float('Total project lump sum - Actuals'),
'budget_allocated_consumption': fields.float('Funded consumption - Budget'),
'budget_project_consumption': fields.float('Total project consumption - Budget'),
'allocated_consumption': fields.float('Funded consumption - Actuals'),
'project_consumption': fields.float('Total project consumption - Actuals'),
}
_defaults = {
'format_name': 'Format',
'reporting_type': 'all',
'overhead_type': 'cost_percentage',
'overhead_percentage': 0.0,
'budget_allocated_overhead': 0.0,
'budget_project_overhead': 0.0,
'allocated_overhead': 0.0,
'project_overhead': 0.0,
'budget_allocated_lump_sum': 0.0,
'budget_project_lump_sum': 0.0,
'allocated_lump_sum': 0.0,
'project_lump_sum': 0.0,
'budget_allocated_consumption': 0.0,
'budget_project_consumption': 0.0,
'allocated_consumption': 0.0,
'project_consumption': 0.0,
}
def name_get(self, cr, uid, ids, context=None):
result = self.browse(cr, uid, ids, context=context)
res = []
for rs in result:
format_name = rs.format_name
res += [(rs.id, format_name)]
return res
financing_contract_format()
class financing_contract_actual_line(osv.osv):
_name = "financing.contract.actual.line"
def _get_number_of_childs(self, cr, uid, ids, field_name=None, arg=None, context={}):
# Verifications
if not context:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
# Prepare some values
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.child_ids and len(line.child_ids) or 0
return res
def _get_parent_ids(self, cr, uid, ids, context=None):
res = []
for line in self.browse(cr, uid, ids, context=context):
if line.parent_id:
res.append(line.parent_id.id)
return res
_columns = {
'name': fields.char('Name', size=64, required=True),
'code': fields.char('Code', size=16, required=True),
'format_id': fields.many2one('financing.contract.format', 'Format'),
'account_ids': fields.many2many('account.account', 'financing_contract_actual_accounts', 'actual_line_id', 'account_id', string='Accounts'),
'parent_id': fields.many2one('financing.contract.actual.line', 'Parent line', ondelete='cascade'),
'child_ids': fields.one2many('financing.contract.actual.line', 'parent_id', 'Child lines'),
'line_type': fields.selection([('view','View'),
('normal','Normal')], 'Line type', required=True),
'allocated_amount': fields.float('Funded amount - Budget'),
'project_amount': fields.float('Total project amount - Budget'),
}
_defaults = {
'line_type': 'normal',
}
def create(self, cr, uid, vals, context=None):
if not context:
context={}
# if the account is set as view, remove budget and account values
if 'line_type' in vals and vals['line_type'] == 'view':
vals['allocated_amount'] = 0.0
vals['project_amount'] = 0.0
vals['account_ids'] = []
return super(financing_contract_actual_line, self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
if not context:
context={}
if isinstance(ids, (int, long)):
ids = [ids]
# if the account is set as view, remove budget and account values
if 'line_type' in vals and vals['line_type'] == 'view':
vals['allocated_amount'] = 0.0
vals['project_amount'] = 0.0
vals['account_ids'] = [(6, 0, [])]
return super(financing_contract_actual_line, self).write(cr, uid, ids, vals, context=context)
def copy_format_line(self, cr, uid, browse_source_line, destination_format_id, parent_id=None, context=None):
if destination_format_id:
format_line_vals = {
'name': browse_source_line.name,
'code': browse_source_line.code,
'format_id': destination_format_id,
'parent_id': parent_id,
'line_type': browse_source_line.line_type,
'allocated_amount': browse_source_line.allocated_amount,
'project_amount': browse_source_line.project_amount,
}
account_ids = []
for account in browse_source_line.account_ids:
account_ids.append(account.id)
format_line_vals['account_ids'] = [(6, 0, account_ids)]
parent_line_id = self.pool.get('financing.contract.actual.line').create(cr, uid, format_line_vals, context=context)
for child_line in browse_source_line.child_ids:
self.copy_format_line(cr, uid, child_line, destination_format_id, parent_line_id, context=context)
return
financing_contract_actual_line()
class financing_contract_format(osv.osv):
_name = "financing.contract.format"
_inherit = "financing.contract.format"
_columns = {
'actual_line_ids': fields.one2many('financing.contract.actual.line', 'format_id', 'Actual lines'),
}
def copy_format_lines(self, cr, uid, source_id, destination_id, context=None):
# remove all old report lines
destination_obj = self.browse(cr, uid, destination_id, context=context)
for to_remove_line in destination_obj.actual_line_ids:
self.pool.get('financing.contract.actual.line').unlink(cr, uid, to_remove_line.id, context=context)
source_obj = self.browse(cr, uid, source_id, context=context)
# Method to copy a format
# copy format lines
for source_line in source_obj.actual_line_ids:
if not source_line.parent_id:
self.pool.get('financing.contract.actual.line').copy_format_line(cr,
uid,
source_line,
destination_id,
parent_id=None,
context=context)
return
financing_contract_format()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|