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 costs'),
31
('allocated','Funded costs'),
32
('all', 'Total project and funded costs')], 'Reporting type', required=True),
33
'overhead_type': fields.selection([('cost_percentage','Percentage of total costs'),
34
('grant_percentage','Percentage of direct costs'),
35
('amount', 'Lump sum')], 'Overhead type', required=True),
36
'overhead_percentage': fields.float('Percentage overhead'),
37
'budget_allocated_overhead': fields.float('Funded overhead - Budget'),
38
'budget_project_overhead': fields.float('Total project overhead - Budget'),
39
'allocated_overhead': fields.float('Funded overhead - Actuals'),
40
'project_overhead': fields.float('Total project overhead - Actuals'),
41
'budget_allocated_lump_sum': fields.float('Funded lump sum - Budget'),
42
'budget_project_lump_sum': fields.float('Total project lump sum - Budget'),
43
'allocated_lump_sum': fields.float('Funded lump sum - Actuals'),
44
'project_lump_sum': fields.float('Total project lump sum - Actuals'),
45
'budget_allocated_consumption': fields.float('Funded consumption - Budget'),
46
'budget_project_consumption': fields.float('Total project consumption - Budget'),
47
'allocated_consumption': fields.float('Funded consumption - Actuals'),
48
'project_consumption': fields.float('Total project consumption - Actuals'),
52
'format_name': 'Format',
53
'reporting_type': 'all',
54
'overhead_type': 'cost_percentage',
55
'overhead_percentage': 0.0,
56
'budget_allocated_overhead': 0.0,
57
'budget_project_overhead': 0.0,
58
'allocated_overhead': 0.0,
59
'project_overhead': 0.0,
60
'budget_allocated_lump_sum': 0.0,
61
'budget_project_lump_sum': 0.0,
62
'allocated_lump_sum': 0.0,
63
'project_lump_sum': 0.0,
64
'budget_allocated_consumption': 0.0,
65
'budget_project_consumption': 0.0,
66
'allocated_consumption': 0.0,
67
'project_consumption': 0.0,
70
def name_get(self, cr, uid, ids, context=None):
71
result = self.browse(cr, uid, ids, context=context)
74
format_name = rs.format_name
75
res += [(rs.id, format_name)]
78
financing_contract_format()
80
class financing_contract_actual_line(osv.osv):
82
_name = "financing.contract.actual.line"
84
def _get_number_of_childs(self, cr, uid, ids, field_name=None, arg=None, context={}):
88
if isinstance(ids, (int, long)):
92
for line in self.browse(cr, uid, ids, context=context):
93
res[line.id] = line.child_ids and len(line.child_ids) or 0
96
def _get_parent_ids(self, cr, uid, ids, context=None):
98
for line in self.browse(cr, uid, ids, context=context):
100
res.append(line.parent_id.id)
104
'name': fields.char('Name', size=64, required=True),
105
'code': fields.char('Code', size=16, required=True),
106
'format_id': fields.many2one('financing.contract.format', 'Format'),
107
'account_ids': fields.many2many('account.account', 'financing_contract_actual_accounts', 'actual_line_id', 'account_id', string='Accounts'),
108
'parent_id': fields.many2one('financing.contract.actual.line', 'Parent line', ondelete='cascade'),
109
'child_ids': fields.one2many('financing.contract.actual.line', 'parent_id', 'Child lines'),
110
'line_type': fields.selection([('view','View'),
111
('normal','Normal')], 'Line type', required=True),
112
'allocated_amount': fields.float('Funded amount - Budget'),
113
'project_amount': fields.float('Total project amount - Budget'),
117
'line_type': 'normal',
120
def create(self, cr, uid, vals, context=None):
123
# if the account is set as view, remove budget and account values
124
if 'line_type' in vals and vals['line_type'] == 'view':
125
vals['allocated_amount'] = 0.0
126
vals['project_amount'] = 0.0
127
vals['account_ids'] = []
128
return super(financing_contract_actual_line, self).create(cr, uid, vals, context=context)
130
def write(self, cr, uid, ids, vals, context=None):
133
if isinstance(ids, (int, long)):
135
# if the account is set as view, remove budget and account values
136
if 'line_type' in vals and vals['line_type'] == 'view':
137
vals['allocated_amount'] = 0.0
138
vals['project_amount'] = 0.0
139
vals['account_ids'] = [(6, 0, [])]
140
return super(financing_contract_actual_line, self).write(cr, uid, ids, vals, context=context)
142
def copy_format_line(self, cr, uid, browse_source_line, destination_format_id, parent_id=None, context=None):
143
if destination_format_id:
145
'name': browse_source_line.name,
146
'code': browse_source_line.code,
147
'format_id': destination_format_id,
148
'parent_id': parent_id,
149
'line_type': browse_source_line.line_type,
150
'allocated_amount': browse_source_line.allocated_amount,
151
'project_amount': browse_source_line.project_amount,
154
for account in browse_source_line.account_ids:
155
account_ids.append(account.id)
156
format_line_vals['account_ids'] = [(6, 0, account_ids)]
157
parent_line_id = self.pool.get('financing.contract.actual.line').create(cr, uid, format_line_vals, context=context)
158
for child_line in browse_source_line.child_ids:
159
self.copy_format_line(cr, uid, child_line, destination_format_id, parent_line_id, context=context)
162
financing_contract_actual_line()
164
class financing_contract_format(osv.osv):
166
_name = "financing.contract.format"
167
_inherit = "financing.contract.format"
170
'actual_line_ids': fields.one2many('financing.contract.actual.line', 'format_id', 'Actual lines'),
173
def copy_format_lines(self, cr, uid, source_id, destination_id, context=None):
174
# remove all old report lines
175
destination_obj = self.browse(cr, uid, destination_id, context=context)
176
for to_remove_line in destination_obj.actual_line_ids:
177
self.pool.get('financing.contract.actual.line').unlink(cr, uid, to_remove_line.id, context=context)
178
source_obj = self.browse(cr, uid, source_id, context=context)
179
# Method to copy a format
181
for source_line in source_obj.actual_line_ids:
182
if not source_line.parent_id:
183
self.pool.get('financing.contract.actual.line').copy_format_line(cr,
191
financing_contract_format()
193
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: