33
33
'funding_pool_id': fields.many2one('account.analytic.account', 'Funding pool name', required=True),
34
34
'funded': fields.boolean('Earmarked'),
35
35
'total_project': fields.boolean('Total project'),
36
'instance_id': fields.many2one('msf.instance','Proprietary Instance'),
60
61
def create(self, cr, uid, vals, context=None):
62
# US-113: Check if the call is from sync update
63
if context.get('sync_update_execution') and vals.get('contract_id', False):
64
# US-113: and if there is any financing contract existed for this format, if no, then ignore this call
65
exist = self.pool.get('financing.contract.contract').search(cr, uid, [('format_id', '=', vals['contract_id'])])
61
69
result = super(financing_contract_funding_pool_line, self).create(cr, uid, vals, context=context)
62
70
# when a new funding pool is added to contract, then add all of the cost centers to the cost center tab, unless
63
71
# the cost center is already there. No action is taken when a cost center is deleted
94
102
if context is None:
105
# US-180: Check if it comes from the sync update, and if any contract
106
if context.get('sync_update_execution') and vals.get('format_id', False):
107
# Check if this format line belongs to any financing contract/format
108
ctr_obj = self.pool.get('financing.contract.contract')
109
exist = ctr_obj.search(cr, uid, [('format_id', '=', vals['format_id'])])
96
113
res = super(financing_contract_funding_pool_line, self).write(cr, uid, ids, vals, context=context)
97
114
self.check_fp(cr, uid, ids)
592
609
if 'funding_pool_ids' in vals: # When the FP is added into the contract, then set this flag into the database
593
610
vals['fp_added_flag'] = True
597
612
# check if the flag has been set TRUE in the previous save
598
613
fp_added_flag = self.browse(cr, uid, ids[0], context=context).fp_added_flag
599
614
if 'format_id' in vals and fp_added_flag: # if the flag is TRUE, and there is a format
631
646
format_obj = self.pool.get('financing.contract.format')
632
647
format_line_obj = self.pool.get('financing.contract.format.line')
633
648
format_browse = format_obj.browse(cr, uid, format.id, context=context)
649
fcfpl_line_obj = self.pool.get('financing.contract.funding.pool.line')
651
# US-113: Populate the instance_id down to format, format line and also funding pool line
652
instance_id = vals.get('instance_id', False)
654
if not format.hidden_instance_id or format.hidden_instance_id.id != instance_id:
655
format_obj.write(cr, uid, format.id, {'hidden_instance_id': instance_id}, context=context)
634
657
for format_line in format_browse.actual_line_ids:
635
658
account_quadruplet_ids = [account_quadruplet.id for account_quadruplet in format_line.account_quadruplet_ids]
636
659
filtered_quads = [x for x in account_quadruplet_ids if x in valid_quad_ids]
637
660
list_diff = set(account_quadruplet_ids).symmetric_difference(set(filtered_quads))
639
ret = format_line_obj.write(cr, uid, format_line.id, {'account_quadruplet_ids': [(6, 0, filtered_quads)]}, context=context)
663
list_to_update['account_quadruplet_ids'] = [(6, 0, filtered_quads)]
665
if not format_line.instance_id or format_line.instance_id.id != instance_id:
666
list_to_update['instance_id'] = instance_id
667
if len(list_to_update) > 0:
668
format_line_obj.write(cr, uid, format_line.id, list_to_update, context=context)
670
# populate the instance_id to the funding pool lines
672
for fpid in format.funding_pool_ids:
674
if not fpid.instance_id or fpid.instance_id.id != instance_id:
675
list_to_update['instance_id'] = instance_id
676
if len(list_to_update) > 0:
677
fcfpl_line_obj.write(cr, uid, fpid.id, list_to_update, context=context)
642
681
def _check_grant_amount_proxy(self, cr, uid, ids, signal, context=None):
741
# US-113: unlink all relevant objects of this FC, because it's not automatic and would left orphan data, also impact to the sync
742
def unlink(self, cr, uid, ids, context=None):
743
format_obj = self.pool.get('financing.contract.format')
744
format_line_obj = self.pool.get('financing.contract.format.line')
745
fcfpl_line_obj = self.pool.get('financing.contract.funding.pool.line')
748
for fcc in self.browse(cr,uid,ids,context=context):
749
format_to_del.append(fcc.format_id.id)
750
for format_line in fcc.format_id.actual_line_ids:
751
format_line_obj.unlink(cr, uid, format_line.id, context)
753
for fpid in fcc.format_id.funding_pool_ids:
754
fcfpl_line_obj.unlink(cr, uid, fpid.id, context)
757
res = super(financing_contract_contract, self).unlink(cr, uid, ids, context)
759
# then finally the format line attached to this FC
761
format_obj.unlink(cr, uid, format_to_del, context)
702
765
financing_contract_contract()
704
767
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: