39
39
'total_project': True,
42
def create(self, cr, uid, vals, context=None):
43
result = super(financing_contract_funding_pool_line, self).create(cr, uid, vals, context=context)
44
# Add the corresponding quadruplets (one for each CC in the format and all A/D)
45
if 'contract_id' in vals and 'funding_pool_id' in vals:
46
# Create quadruplets accordingly
47
quad_obj = self.pool.get('financing.contract.account.quadruplet')
48
format_obj = self.pool.get('financing.contract.format')
49
data = format_obj.get_data_for_quadruplets(cr, vals['contract_id'])
50
# for each funding pool, add all quadruplets
51
for cost_center_id in data['cost_center_ids']:
52
for account_destination_id in data['account_destination_ids']:
53
quad_obj.create(cr, uid,
54
{'format_id': vals['contract_id'],
55
'account_destination_id': account_destination_id,
56
'cost_center_id': cost_center_id,
57
'funding_pool_id': vals['funding_pool_id']}, context=context)
60
def write(self, cr, uid, ids, vals, context=None):
61
if 'funding_pool_id' in vals:
62
# if the funding pool changes, add/remove accordingly
63
quad_obj = self.pool.get('financing.contract.account.quadruplet')
64
format_obj = self.pool.get('financing.contract.format')
66
funding_pool_line = self.browse(cr, uid, id, context=context)
67
format_id = funding_pool_line.contract_id.id
68
data = format_obj.get_data_for_quadruplets(cr, format_id)
69
old_funding_pool_id = funding_pool_line.funding_pool_id.id
70
new_funding_pool_id = vals['funding_pool_id']
72
quads_to_delete = quad_obj.search(cr, uid, [('funding_pool_id', '=', old_funding_pool_id)], context=context)
73
quad_obj.unlink(cr, uid, quads_to_delete, context=context)
74
# add missing quadruplets
75
for cost_center_id in data['cost_center_ids']:
76
for account_destination_id in data['account_destination_ids']:
77
quad_obj.create(cr, uid,
78
{'format_id': format_id,
79
'account_destination_id': account_destination_id,
80
'cost_center_id': cost_center_id,
81
'funding_pool_id': new_funding_pool_id}, context=context)
83
return super(financing_contract_funding_pool_line, self).write(cr, uid, ids, vals, context=context)
85
def unlink(self, cr, uid, ids, context=None):
86
# for unlink, simple: remove all lines for those funding pools
87
quad_obj = self.pool.get('financing.contract.account.quadruplet')
88
for funding_pool_line in self.browse(cr, uid, ids, context=context):
89
quads_to_delete = quad_obj.search(cr, uid, [('funding_pool_id', '=', funding_pool_line.funding_pool_id.id)], context=context)
90
quad_obj.unlink(cr, uid, quads_to_delete, context=context)
92
return super(financing_contract_funding_pool_line, self).unlink(cr, uid, ids, context=context)
42
94
financing_contract_funding_pool_line()
44
96
class financing_contract_contract(osv.osv):
122
174
account_destination_ids = []
123
175
if reporting_type is None:
124
176
reporting_type = browse_contract.reporting_type
126
general_domain = format_line_obj._get_general_domain(cr,
128
browse_contract.format_id,
132
179
# parse parent lines (either value or sum of children's values)
133
180
for line in browse_contract.actual_line_ids:
134
181
if not line.parent_id:
135
account_destination_ids += format_line_obj._get_account_destination_ids(line, general_domain['funding_pool_account_destination_ids'])
139
account_domain = format_line_obj._create_account_destination_domain(account_destination_ids)
140
date_domain = eval(general_domain['date_domain'])
141
analytic_domain = [date_domain[0],
143
('is_reallocated', '=', False),
144
('is_reversal', '=', False),
145
eval(general_domain['funding_pool_domain']),
146
eval(general_domain['cost_center_domain'])]
147
analytic_domain += account_domain
182
account_destination_ids += format_line_obj._get_analytic_domain(cr, uid, line, reporting_type, context=context)
149
184
return analytic_domain
166
201
'name': fields.char('Financing contract name', size=64, required=True),
167
202
'code': fields.char('Financing contract code', size=16, required=True),
168
'donor_id': fields.many2one('financing.contract.donor', 'Donor', required=True),
203
'donor_id': fields.many2one('financing.contract.donor', 'Donor', required=True, domain="[('active', '=', True)]"),
169
204
'donor_grant_reference': fields.char('Donor grant reference', size=64),
170
205
'hq_grant_reference': fields.char('HQ grant reference', size=64),
171
206
'grant_amount': fields.float('Grant amount', required=True),
180
215
('soft_closed', 'Soft-closed'),
181
216
('hard_closed', 'Hard-closed')], 'State'),
182
217
'currency_table_id': fields.many2one('res.currency.table', 'Currency Table'),
218
'instance_id': fields.many2one('msf.instance','Proprietary Instance', required=True),
183
219
# Define for _inherits
184
'format_id': fields.many2one('financing.contract.format', 'Format', ondelete="cascade", required=True),
220
'format_id': fields.many2one('financing.contract.format', 'Format', ondelete="cascade"),
188
224
'state': 'draft',
189
225
'reporting_currency': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
190
'format_id': lambda self,cr,uid,context: self.pool.get('financing.contract.format').create(cr, uid, {}, context=context)
193
228
def _check_unicity(self, cr, uid, ids, context=None):
210
245
default = default.copy()
211
246
default['code'] = (contract['code'] or '') + '(copy)'
212
247
default['name'] = (contract['name'] or '') + '(copy)'
213
# Copy lines manually
248
# Copy lines manually but remove CCs and FPs
249
default['funding_pool_ids'] = []
250
default['cost_center_ids'] = []
214
251
default['actual_line_ids'] = []
215
252
copy_id = super(financing_contract_contract, self).copy(cr, uid, id, default, context=context)
216
253
copy = self.browse(cr, uid, copy_id, context=context)
328
364
# create "real" lines
329
365
for line in contract.actual_line_ids:
330
366
if not line.parent_id:
331
allocated_budget += line.allocated_budget
332
project_budget += line.project_budget
333
allocated_real += line.allocated_real
334
project_real += line.project_real
367
# UTP-853: self.create_reporting_line rounds each line
368
# (int value) so we add a round for sums equivalence
369
allocated_budget += round(line.allocated_budget)
370
project_budget += round(line.project_budget)
371
allocated_real += round(line.allocated_real)
372
project_real += round(line.project_real)
335
373
reporting_line_id = self.create_reporting_line(cr, uid, contract, line, contract_line_id, context=context)
337
375
# Refresh contract line with general infos
422
460
'res_id': [wiz_id],
423
461
'context': context,
464
def create(self, cr, uid, vals, context=None):
465
# Do not copy lines from the Donor on create if coming from the sync server
468
result = super(financing_contract_contract, self).create(cr, uid, vals, context=context)
469
if not context.get('sync_update_execution'):
470
contract = self.browse(cr, uid, result, context=context)
471
if contract.donor_id and contract.donor_id.format_id and contract.format_id:
472
self.pool.get('financing.contract.format').copy_format_lines(cr, uid, contract.donor_id.format_id.id, contract.format_id.id, context=context)
476
def write(self, cr, uid, ids, vals, context=None):
477
if 'donor_id' in vals:
478
donor = self.pool.get('financing.contract.donor').browse(cr, uid, vals['donor_id'], context=context)
479
for contract in self.browse(cr, uid, ids, context=context):
480
if contract.donor_id and contract.format_id and vals['donor_id'] != contract.donor_id.id:
481
self.pool.get('financing.contract.format').copy_format_lines(cr, uid, donor.format_id.id, contract.format_id.id, context=context)
483
return super(financing_contract_contract, self).write(cr, uid, ids, vals, context=context)
426
485
financing_contract_contract()
428
487
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: