=== modified file 'account/invoice.py' --- account/invoice.py 2010-11-04 18:33:33 +0000 +++ account/invoice.py 2010-11-23 11:44:27 +0000 @@ -1214,24 +1214,43 @@ 'tax_amount': fields.float('Tax Code Amount', digits=(16,int(config['price_accuracy']))), } + def _calculate_factor(self, cr, uid, ids, factor_name): + factor = 1 + invoice_tax_obj = self.browse(cr, uid, ids[0]) + if factor_name == 'factor_base': + if invoice_tax_obj.base <> 0.0: + factor = invoice_tax_obj.base_amount / invoice_tax_obj.base + + elif factor_name == 'factor_amount': + if invoice_tax_obj.amount <> 0.0: + factor = invoice_tax_obj.tax_amount / invoice_tax_obj.amount + + return factor + def base_change(self, cr, uid, ids, base,currency_id=False,company_id=False,date_invoice=False): cur_obj = self.pool.get('res.currency') company_obj = self.pool.get('res.company') - company_currency=False + company_currency = False + factor = 1 + if ids: + factor = self._calculate_factor(cr, uid, ids, 'factor_base') if company_id: company_currency = company_obj.read(cr,uid,[company_id],['currency_id'])[0]['currency_id'][0] if currency_id and company_currency: - base = cur_obj.compute(cr, uid, currency_id, company_currency, base, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) + base = cur_obj.compute(cr, uid, currency_id, company_currency, base*factor, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'base_amount':base}} def amount_change(self, cr, uid, ids, amount,currency_id=False,company_id=False,date_invoice=False): cur_obj = self.pool.get('res.currency') company_obj = self.pool.get('res.company') - company_currency=False + company_currency = False + factor = 1 + if ids: + factor = self._calculate_factor(cr, uid, ids, 'factor_amount') if company_id: company_currency = company_obj.read(cr,uid,[company_id],['currency_id'])[0]['currency_id'][0] if currency_id and company_currency: - amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) + amount = cur_obj.compute(cr, uid, currency_id, company_currency, amount*factor, context={'date': date_invoice or time.strftime('%Y-%m-%d')}, round=False) return {'value': {'tax_amount':amount}} _order = 'sequence'