~julie-w/unifield-wm/UTP-925

« back to all changes in this revision

Viewing changes to funding_pool/wizard/wizard_fundingpool_distribution.py

UF-359 [MERGE] Merge UF_358_engagement_journal because it adds some improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        "cost_center_id": fields.many2one('account.analytic.account', 'Cost Center', required=True),
37
37
        "percentage": fields.float('Percentage'),
38
38
        "amount": fields.float('Amount'),
 
39
        'currency_id': fields.many2one('res.currency', string="Currency"),
39
40
    }
40
41
    
41
42
    _defaults ={
70
71
    def _get_initial_lines(self, cr, uid, wizard_id, context=None):
71
72
        wizard_obj = self.browse(cr, uid, wizard_id, context=context)
72
73
        distrib_obj = self.pool.get('analytic.distribution').browse(cr, uid, wizard_obj.distribution_id.id, context=context)
 
74
        company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
73
75
        if 'cost_center_updated' in context and context['cost_center_updated']:
74
76
            # create funding pool lines from cost center lines
75
77
            private_funds_ids = self.pool.get('account.analytic.account').search(cr, uid, [('code', '=', 'PF')])
82
84
                    'cost_center_id': cc_wizard_line.analytic_id.id,
83
85
                    'amount': cc_wizard_line.amount,
84
86
                    'percentage': cc_wizard_line.percentage,
 
87
                    'currency_id': cc_wizard_line.currency_id and cc_wizard_line.currency_id.id or company_currency,
85
88
                }
86
89
                self.pool.get('wizard.fundingpool.distribution.line').create(cr, uid, wizard_line_vals, context=context)
87
90
            # lines were created, flag is set to true
131
134
        allocated_amount = 0.0
132
135
        allocated_percentage = 0.0
133
136
        wizard_obj = self.browse(cr, uid, wizard_id, context=context)
 
137
        company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
 
138
        currency = wizard_obj.currency_id and wizard_obj.currency_id.id or company_currency
134
139
        # Something was written; we modify the flag in the wizard
135
140
        self.write(cr, uid, [wizard_id], vals={'modified_line': True}, context={})
136
141
        # Create a temporary object to keep track of values
182
187
                                                                        uid,
183
188
                                                                        [wizard_line['id']],
184
189
                                                                        vals={'amount': wizard_line['amount'],
185
 
                                                                              'percentage': wizard_line['percentage']},
 
190
                                                                              'percentage': wizard_line['percentage'],
 
191
                                                                              'currency_id': currency},
186
192
                                                                        context={'skip_validation': True})
187
193
        return
188
194
            
206
212
        # check if the allocation is fully done
207
213
        allocated_percentage = 0.0
208
214
        wizard_obj = self.browse(cr, uid, ids[0], context=context)
 
215
        company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
 
216
        currency = wizard_obj.currency_id and wizard_obj.currency_id.id or company_currency
209
217
        for wizard_line in wizard_obj.wizard_distribution_lines:
210
218
            allocated_percentage += wizard_line.percentage
211
219
        if abs(allocated_percentage - 100.0) > 10**-4:
212
220
            raise osv.except_osv(_('Not fully allocated !'),_("You have to allocate the whole amount!"))
213
221
        if 'free_1' not in context['wizard_ids']:
214
222
            newwiz_obj = self.pool.get('wizard.free1.distribution')
215
 
            newwiz_id = newwiz_obj.create(cr, uid, {'total_amount': wizard_obj.total_amount, 'distribution_id': wizard_obj.distribution_id.id}, context=context)
 
223
            newwiz_id = newwiz_obj.create(cr, uid, {'total_amount': wizard_obj.total_amount, 'distribution_id': wizard_obj.distribution_id.id, 
 
224
                'currency_id': currency}, context=context)
216
225
            context['wizard_ids']['free_1'] = newwiz_id
217
226
        # we open a wizard
218
227
        return {