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

« back to all changes in this revision

Viewing changes to financing_contract/format.py

  • Committer: Quentin THEURET
  • Date: 2011-12-19 18:17:59 UTC
  • mto: (451.4.7 test_uf_631)
  • mto: This revision was merged to the branch mainline in revision 523.
  • Revision ID: qt@tempo-consulting.fr-20111219181759-coktzw4gwaygpfdx
UF-631 [ADD] Added documents_done module

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 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'),
 
49
    }
 
50
    
 
51
    _defaults = {
 
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,
 
68
    }
 
69
    
 
70
    def name_get(self, cr, uid, ids, context=None):
 
71
        result = self.browse(cr, uid, ids, context=context)
 
72
        res = []
 
73
        for rs in result:
 
74
            format_name = rs.format_name
 
75
            res += [(rs.id, format_name)]
 
76
        return res
 
77
    
 
78
financing_contract_format()
 
79
 
 
80
class financing_contract_actual_line(osv.osv):
 
81
    
 
82
    _name = "financing.contract.actual.line"
 
83
 
 
84
    def _get_number_of_childs(self, cr, uid, ids, field_name=None, arg=None, context={}):
 
85
        # Verifications
 
86
        if not context:
 
87
            context = {}
 
88
        if isinstance(ids, (int, long)):
 
89
            ids = [ids]
 
90
        # Prepare some values
 
91
        res = {}
 
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
 
94
        return res
 
95
    
 
96
    def _get_parent_ids(self, cr, uid, ids, context=None):
 
97
        res = []
 
98
        for line in self.browse(cr, uid, ids, context=context):
 
99
            if line.parent_id:
 
100
                res.append(line.parent_id.id)
 
101
        return res
 
102
    
 
103
    _columns = {
 
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'),
 
114
    }
 
115
    
 
116
    _defaults = {
 
117
        'line_type': 'normal',
 
118
    }
 
119
    
 
120
    def create(self, cr, uid, vals, context=None):
 
121
        if not context:
 
122
            context={}
 
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)
 
129
    
 
130
    def write(self, cr, uid, ids, vals, context=None):
 
131
        if not context:
 
132
            context={}
 
133
        if isinstance(ids, (int, long)):
 
134
            ids = [ids]
 
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)
 
141
    
 
142
    def copy_format_line(self, cr, uid, browse_source_line, destination_format_id, parent_id=None, context=None):
 
143
        if destination_format_id:
 
144
            format_line_vals = {
 
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,
 
152
            }
 
153
            account_ids = []
 
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)
 
160
        return
 
161
            
 
162
financing_contract_actual_line()
 
163
 
 
164
class financing_contract_format(osv.osv):
 
165
    
 
166
    _name = "financing.contract.format"
 
167
    _inherit = "financing.contract.format"
 
168
    
 
169
    _columns = {
 
170
        'actual_line_ids': fields.one2many('financing.contract.actual.line', 'format_id', 'Actual lines'),
 
171
    }
 
172
    
 
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
 
180
        # copy format lines
 
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,
 
184
                                                                                 uid,
 
185
                                                                                 source_line,
 
186
                                                                                 destination_id,
 
187
                                                                                 parent_id=None,
 
188
                                                                                 context=context)
 
189
        return
 
190
        
 
191
financing_contract_format()
 
192
 
 
193
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: