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

« back to all changes in this revision

Viewing changes to analytic_distribution/account_bank_statement.py

  • Committer: jf
  • Date: 2011-12-30 09:08:24 UTC
  • mfrom: (395.8.8 UF-661)
  • Revision ID: jf@tempo4-20111230090824-4zbrgeyqqu4z4so3
UF-661 [MERGE] Financing contracts: Export CSV File

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        """
59
59
        Launch analytic distribution wizard from a statement line
60
60
        """
 
61
        # Some verifications
61
62
        if not context:
62
63
            context = {}
63
64
        if isinstance(ids, (int, long)):
64
65
            ids = [ids]
65
 
        # we get the analytical distribution object linked to this line
66
 
        distrib_id = False
67
 
        statement_line_obj = self.browse(cr, uid, ids[0], context=context)
68
 
        amount = statement_line_obj.amount * -1 or 0.0
 
66
        # Prepare some values
 
67
        absl = self.browse(cr, uid, ids[0], context=context)
 
68
        amount = absl.amount * -1 or 0.0
69
69
        # Search elements for currency
70
70
        company_currency = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
71
 
        currency = statement_line_obj.statement_id.journal_id.currency and statement_line_obj.statement_id.journal_id.currency.id or company_currency
72
 
        if statement_line_obj.analytic_distribution_id:
73
 
            distrib_id = statement_line_obj.analytic_distribution_id.id
74
 
        else:
75
 
            distrib_id = self.pool.get('analytic.distribution').create(cr, uid, {}, context=context)
76
 
            newvals={'analytic_distribution_id': distrib_id}
77
 
            super(account_bank_statement_line, self).write(cr, uid, ids, newvals, context=context)
78
 
        wiz_obj = self.pool.get('wizard.costcenter.distribution')
79
 
        wiz_id = wiz_obj.create(cr, uid, {'total_amount': amount, 'distribution_id': distrib_id, 'currency_id': currency}, context=context)
80
 
        # we open a wizard
 
71
        currency = absl.statement_id.journal_id.currency and absl.statement_id.journal_id.currency.id or company_currency
 
72
        # Get analytic distribution id from this line
 
73
        distrib_id = absl.analytic_distribution_id and absl.analytic_distribution_id.id or False
 
74
        # Prepare values for wizard
 
75
        vals = {
 
76
            'total_amount': amount,
 
77
            'register_line_id': absl.id,
 
78
            'currency_id': currency or False,
 
79
            'state': 'dispatch',
 
80
            'account_id': absl.account_id and absl.account_id.id or False,
 
81
        }
 
82
        if distrib_id:
 
83
            vals.update({'distribution_id': distrib_id,})
 
84
        # Create the wizard
 
85
        wiz_obj = self.pool.get('analytic.distribution.wizard')
 
86
        wiz_id = wiz_obj.create(cr, uid, vals, context=context)
 
87
        # Update some context values
81
88
        context.update({
82
89
            'active_id': ids[0],
83
90
            'active_ids': ids,
84
 
            'wizard_ids': {'cost_center': wiz_id},
85
91
        })
 
92
        # Open it!
86
93
        return {
87
94
                'type': 'ir.actions.act_window',
88
 
                'res_model': 'wizard.costcenter.distribution',
 
95
                'res_model': 'analytic.distribution.wizard',
89
96
                'view_type': 'form',
90
97
                'view_mode': 'form',
91
98
                'target': 'new',