diff --git a/account_financial_report/report/account_balance.py b/account_financial_report/report/account_balance.py index 94d1d1b3..82fa5e65 100644 --- a/account_financial_report/report/account_balance.py +++ b/account_financial_report/report/account_balance.py @@ -55,6 +55,7 @@ class account_balance(report_sxw.rml_parse): 'get_periods_and_date_text': self.get_periods_and_date_text, 'get_informe_text': self.get_informe_text, 'get_month':self.get_month, + 'exchange_name':self.exchange_name, }) self.context = context @@ -121,6 +122,24 @@ class account_balance(report_sxw.rml_parse): return {'periods':periods_str, 'date':dates_str} + def exchange_name(self, form): + self.from_currency_id = self.get_company_currency(form['company_id'] and form['company_id'][0]) + if not form['currency_id']: + self.to_currency_id = self.from_currency_id + else: + self.to_currency_id = form['currency_id'] and form['currency_id'][0] + return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name + + def exchange(self, from_amount): + if self.from_currency_id == self.to_currency_id: + return from_amount + curr_obj = self.pool.get('res.currency') + return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount) + + def get_company_currency(self, company_id): + rc_obj = self.pool.get('res.company') + return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id + def lines(self, form, ids={}, done=None, level=0): """ @@ -128,6 +147,13 @@ class account_balance(report_sxw.rml_parse): (account info plus debit/credit/balance in the selected period and the full year) """ + + self.from_currency_id = self.get_company_currency(form['company_id'] and form['company_id'][0]) + if not form['currency_id']: + self.to_currency_id = self.from_currency_id + else: + self.to_currency_id = form['currency_id'] and form['currency_id'][0] + tot_eje = 0.0 if not ids: ids = self.ids @@ -265,7 +291,7 @@ class account_balance(report_sxw.rml_parse): 'code': account['code'], 'name': (account['total'] and not account['label']) and 'TOTAL %s'%(account['name'].upper()) or account['name'], 'level': account['level'], - 'balance': account['balance'], + 'balance': self.exchange(account['balance']), 'parent_id': account['parent_id'], 'bal_type': '', 'label': account['label'], @@ -302,7 +328,7 @@ class account_balance(report_sxw.rml_parse): res2 = { 'type' : 'view', 'name': 'TOTAL %s'%(str_label), - 'balance': tot_eje, + 'balance': self.exchange(tot_eje), 'label': False, 'total': True, } diff --git a/account_financial_report/report/account_balance_2_cols.py b/account_financial_report/report/account_balance_2_cols.py index 2c140904..6f00642f 100644 --- a/account_financial_report/report/account_balance_2_cols.py +++ b/account_financial_report/report/account_balance_2_cols.py @@ -55,6 +55,7 @@ class account_balance(report_sxw.rml_parse): 'get_periods_and_date_text': self.get_periods_and_date_text, 'get_informe_text': self.get_informe_text, 'get_month':self.get_month, + 'exchange_name':self.exchange_name, }) self.context = context @@ -122,12 +123,41 @@ class account_balance(report_sxw.rml_parse): return {'periods':periods_str, 'date':dates_str} + + def exchange_name(self, form): + self.from_currency_id = self.get_company_currency(form['company_id'] and form['company_id'][0]) + if not form['currency_id']: + self.to_currency_id = self.from_currency_id + else: + self.to_currency_id = form['currency_id'] and form['currency_id'][0] + return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name + + def exchange(self, from_amount): + if self.from_currency_id == self.to_currency_id: + return from_amount + curr_obj = self.pool.get('res.currency') + return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount) + + def get_company_currency(self, company_id): + rc_obj = self.pool.get('res.company') + return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id + + + def lines(self, form, ids={}, done=None, level=0): """ Returns all the data needed for the report lines (account info plus debit/credit/balance in the selected period and the full year) """ + + + self.from_currency_id = self.get_company_currency(form['company_id'] and form['company_id'][0]) + if not form['currency_id']: + self.to_currency_id = self.from_currency_id + else: + self.to_currency_id = form['currency_id'] and form['currency_id'][0] + tot_bin = 0.0 tot_deb = 0.0 tot_crd = 0.0 @@ -280,10 +310,10 @@ class account_balance(report_sxw.rml_parse): 'code': account['code'], 'name': (account['total'] and not account['label']) and 'TOTAL %s'%(account['name'].upper()) or account['name'], 'level': account['level'], - 'balanceinit': period_balanceinit[account_id], - 'debit': account['debit'], - 'credit': account['credit'], - 'balance': period_balanceinit[account_id]+account['debit']-account['credit'], + 'balanceinit': self.exchange(period_balanceinit[account_id]), + 'debit': self.exchange(account['debit']), + 'credit': self.exchange(account['credit']), + 'balance': self.exchange(period_balanceinit[account_id]+account['debit']-account['credit']), 'parent_id': account['parent_id'], 'bal_type': '', 'label': account['label'], diff --git a/account_financial_report/report/balance_full.rml b/account_financial_report/report/balance_full.rml index d75a846e..83513f0f 100644 --- a/account_financial_report/report/balance_full.rml +++ b/account_financial_report/report/balance_full.rml @@ -16,7 +16,7 @@ - [[ get_informe_text(data['form']) ]][[data['form'] and (' (Expresado en %s)'%( company.currency_id.name)) or '']] + [[data['form'] and (' (Expresado en %s)'%( exchange_name(data['form']))) or '']] diff --git a/account_financial_report/report/balance_full_2_cols.rml b/account_financial_report/report/balance_full_2_cols.rml index 55bc336d..5e3f3adb 100644 --- a/account_financial_report/report/balance_full_2_cols.rml +++ b/account_financial_report/report/balance_full_2_cols.rml @@ -20,7 +20,7 @@ - [[data['form'] and (' (Expresado en %s)'%( company.currency_id.name)) or '']] + [[data['form'] and (' (Expresado en %s)'%( exchange_name(data['form']))) or '']] diff --git a/account_financial_report/wizard/account_report_wizard.xml b/account_financial_report/wizard/account_report_wizard.xml index ba5ae4ec..2b27d638 100644 --- a/account_financial_report/wizard/account_report_wizard.xml +++ b/account_financial_report/wizard/account_report_wizard.xml @@ -78,8 +78,11 @@ form
- + + + + @@ -141,8 +144,12 @@ form - + + + + + diff --git a/account_financial_report/wizard/wizard_account_balance_2_report.py b/account_financial_report/wizard/wizard_account_balance_2_report.py index 439463f3..2b809de4 100644 --- a/account_financial_report/wizard/wizard_account_balance_2_report.py +++ b/account_financial_report/wizard/wizard_account_balance_2_report.py @@ -48,6 +48,7 @@ class wizard_account_balance_gene_2(osv.osv_memory): 'lab_str': fields.char('Description', size= 128), 'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas'),('bdl','Diario Legal')],'Tipo Informe',required=True), #~ 'type_report': fields.selection([('un_col','Una Columna'),('dos_col','Dos Columnas'),('cuatro_col','Cuatro Columnas')],'Tipo Informe',required=True), + 'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all values for this report to be expressed in this secondary currency."), } _defaults = { diff --git a/account_financial_report/wizard/wizard_account_balance_report.py b/account_financial_report/wizard/wizard_account_balance_report.py index 8b3ecfd4..9088adc5 100644 --- a/account_financial_report/wizard/wizard_account_balance_report.py +++ b/account_financial_report/wizard/wizard_account_balance_report.py @@ -48,6 +48,7 @@ class wizard_account_balance_gene(osv.osv_memory): 'lab_str': fields.char('Description', size= 128), 'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas')],'Tipo Informe',required=True), #~ 'type_report': fields.selection([('un_col','Una Columna'),('dos_col','Dos Columnas'),('cuatro_col','Cuatro Columnas')],'Tipo Informe',required=True), + 'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all values for this report to be expressed in this secondary currency."), } _defaults = {