~camptocamp/account-analytic/analytic_multicurrency_different_currency_vre

« back to all changes in this revision

Viewing changes to analytic_multicurrency/analytic.py

  • Committer: Vincent Renaville
  • Date: 2013-09-20 09:29:21 UTC
  • Revision ID: vincent.renaville@camptocamp.com-20130920092921-4dhp6jurw58ly3sq
[FIx] Allow to set an different currency from the one specified in the company

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
                                         'balance', 'quantity'],
80
80
                                        context)
81
81
 
 
82
    def _set_company_currency(self, cr, uid, ids, name, value, arg, context=None):
 
83
        if isinstance(ids, (int, long)):
 
84
            ids = [ids]
 
85
        if value:
 
86
            return cr.execute("""update account_analytic_account set currency_id=%s
 
87
                                 where id in %s""",
 
88
                              (value, (tuple(ids)), ))
 
89
 
 
90
    def _currency(self, cr, uid, ids, field_name, arg, context=None):
 
91
        result = {}
 
92
        for rec in self.browse(cr, uid, ids, context=context):
 
93
            result[rec.id] = rec.currency_id.id
 
94
        return result
 
95
 
 
96
    def _get_analytic_account(self, cr, uid, ids, context=None):
 
97
        return super(account_analytic_account, self)._get_analytic_account(
 
98
            cr, uid, ids, context=context)
 
99
 
82
100
    _columns = {
83
101
        'balance': fields.function(_debit_credit_bal_qtty,
84
102
                                   type='float',
99
117
                                    type='float',
100
118
                                    string='Quantity',
101
119
                                    multi='debit_credit_bal_qtty'),
 
120
        # We overwrite function field currency_id to set a currency different
 
121
        # from the one specified in the company
 
122
        'currency_id': fields.function(_currency, fnct_inv=_set_company_currency,
 
123
            store={
 
124
                'res.company': (_get_analytic_account, ['currency_id'], 10),
 
125
            }, string='Currency', type='many2one', relation='res.currency'),
 
126
 
102
127
    }
103
128
 
104
129
    # We remove the currency constraint cause we want to let the user