From 0a886af6d6fafd229c1ce21bfb881e78cb443af4 Mon Sep 17 00:00:00 2001 From: hveficent Date: Mon, 28 May 2018 09:16:03 +0200 Subject: [PATCH] [10.0] [BACKPORT] foreign currencies + dynamic reports --- account_financial_report_qweb/__manifest__.py | 8 +- .../report/abstract_report_xlsx.py | 87 ++- .../report/aged_partner_balance.py | 23 +- .../report/general_ledger.py | 75 +-- .../report/general_ledger_xlsx.py | 84 +-- .../report/journal_report.py | 73 ++- .../report/journal_report_xlsx.py | 2 +- .../report/open_items.py | 65 ++- .../report/open_items_xlsx.py | 57 +- .../report/templates/aged_partner_balance.xml | 535 +++++++++++++----- .../report/templates/general_ledger.xml | 527 ++++++++++++----- .../report/templates/journal.xml | 52 +- .../report/templates/open_items.xml | 237 +++++--- .../report/templates/trial_balance.xml | 502 +++++++++++++--- .../report/trial_balance.py | 82 ++- .../report/trial_balance_xlsx.py | 67 ++- account_financial_report_qweb/reports.xml | 47 +- .../static/src/css/report.css | 14 +- .../account_financial_report_qweb_backend.js | 95 ++++ .../account_financial_report_qweb_widgets.js | 69 +++ .../tests/__init__.py | 1 + .../tests/abstract_test.py | 305 +++++++--- .../tests/abstract_test_foreign_currency.py | 79 +++ .../tests/test_aged_partner_balance.py | 2 +- .../tests/test_general_ledger.py | 14 +- .../tests/test_journal.py | 45 ++ .../tests/test_open_items.py | 7 +- .../tests/test_trial_balance.py | 7 +- .../view/report_aged_partner_balance.xml | 9 + .../view/report_general_ledger.xml | 9 + .../view/report_journal_ledger.xml | 9 + .../view/report_open_items.xml | 9 + .../view/report_template.xml | 57 ++ .../view/report_trial_balance.xml | 11 + .../wizard/aged_partner_balance_wizard.py | 29 +- .../aged_partner_balance_wizard_view.xml | 3 + .../wizard/general_ledger_wizard.py | 36 +- .../wizard/general_ledger_wizard_view.xml | 4 + .../wizard/journal_report_wizard.py | 38 +- .../wizard/journal_report_wizard.xml | 19 +- .../wizard/open_items_wizard.py | 36 +- .../wizard/open_items_wizard_view.xml | 4 + .../wizard/trial_balance_wizard.py | 39 +- .../wizard/trial_balance_wizard_view.xml | 4 + 44 files changed, 2686 insertions(+), 791 deletions(-) create mode 100644 account_financial_report_qweb/static/src/js/account_financial_report_qweb_backend.js create mode 100644 account_financial_report_qweb/static/src/js/account_financial_report_qweb_widgets.js create mode 100644 account_financial_report_qweb/tests/abstract_test_foreign_currency.py create mode 100644 account_financial_report_qweb/view/report_aged_partner_balance.xml create mode 100644 account_financial_report_qweb/view/report_general_ledger.xml create mode 100644 account_financial_report_qweb/view/report_journal_ledger.xml create mode 100644 account_financial_report_qweb/view/report_open_items.xml create mode 100644 account_financial_report_qweb/view/report_template.xml create mode 100644 account_financial_report_qweb/view/report_trial_balance.xml diff --git a/account_financial_report_qweb/__manifest__.py b/account_financial_report_qweb/__manifest__.py index d22f3521..aa3c181b 100644 --- a/account_financial_report_qweb/__manifest__.py +++ b/account_financial_report_qweb/__manifest__.py @@ -34,7 +34,13 @@ 'report/templates/layouts.xml', 'report/templates/open_items.xml', 'report/templates/trial_balance.xml', - 'view/account_view.xml' + 'view/account_view.xml', + 'view/report_template.xml', + 'view/report_general_ledger.xml', + 'view/report_journal_ledger.xml', + 'view/report_trial_balance.xml', + 'view/report_open_items.xml', + 'view/report_aged_partner_balance.xml', ], 'installable': True, 'application': True, diff --git a/account_financial_report_qweb/report/abstract_report_xlsx.py b/account_financial_report_qweb/report/abstract_report_xlsx.py index adc6661d..16114503 100644 --- a/account_financial_report_qweb/report/abstract_report_xlsx.py +++ b/account_financial_report_qweb/report/abstract_report_xlsx.py @@ -46,6 +46,7 @@ class AbstractReportXslx(ReportXlsx): filters = self._get_report_filters(report) self.columns = self._get_report_columns(report) + self.workbook = workbook self.set_sheet(self.add_sheet(workbook, report_name[:31])) self._set_column_width() @@ -100,30 +101,17 @@ class AbstractReportXslx(ReportXlsx): {'bold': True, 'border': True, 'bg_color': '#FFFFCC'}) - self.format_header_amount.set_num_format('#,##0.00') + currency_id = self.env['res.company']._get_user_currency() + self.format_header_amount.set_num_format( + '#,##0.'+'0'*currency_id.decimal_places) self.format_amount = workbook.add_format() - self.format_amount.set_num_format('#,##0.00') + self.format_amount.set_num_format( + '#,##0.'+'0'*currency_id.decimal_places) self.format_percent_bold_italic = workbook.add_format( {'bold': True, 'italic': True} ) self.format_percent_bold_italic.set_num_format('#,##0.00%') - def _get_currency_amt_format(self, line_object): - """ Return amount format specific for each currency. """ - format_amt = getattr(self, 'format_amount') - if line_object.currency_id: - field_name = \ - 'format_amount_%s' % line_object.currency_id.name - if hasattr(self, field_name): - format_amt = getattr(self, field_name) - else: - format_amt = self.workbook.add_format() - setattr(self, 'field_name', format_amt) - format_amount = \ - '#,##0.' + ('0' * line_object.currency_id.decimal_places) - format_amt.set_num_format(format_amount) - return format_amt - def _set_column_width(self): """Set width for all defined columns. Columns are defined with `_get_report_columns` method. @@ -241,11 +229,15 @@ class AbstractReportXslx(ReportXlsx): self.row_pos, col_pos, float(value), format_amt ) - elif cell_type == 'many2one': - self.sheet.write_string( - self.row_pos, col_pos, value.name or '', - self.format_header_right) - + elif column.get('field_currency_balance'): + value = getattr(my_object, column['field_currency_balance']) + cell_type = column.get('type', 'string') + if cell_type == 'many2one': + if my_object.currency_id: + self.sheet.write_string( + self.row_pos, col_pos, value.name or '', + self.format_right + ) self.row_pos += 1 def write_ending_balance(self, my_object, name, label): @@ -278,18 +270,57 @@ class AbstractReportXslx(ReportXlsx): ) elif cell_type == 'amount_currency': if my_object.currency_id: - format_amt = self._get_currency_amt_format( + format_amt = self._get_currency_amt_header_format( my_object) self.sheet.write_number( self.row_pos, col_pos, float(value), format_amt ) - elif cell_type == 'many2one': - self.sheet.write_string( - self.row_pos, col_pos, value.name or '', - self.format_header_right) + elif column.get('field_currency_balance'): + value = getattr(my_object, column['field_currency_balance']) + cell_type = column.get('type', 'string') + if cell_type == 'many2one': + if my_object.currency_id: + self.sheet.write_string( + self.row_pos, col_pos, value.name or '', + self.format_header_right) self.row_pos += 1 + def _get_currency_amt_format(self, line_object): + """ Return amount format specific for each currency. """ + format_amt = getattr(self, 'format_amount') + if line_object.currency_id: + field_name = \ + 'format_amount_%s' % line_object.currency_id.name + if hasattr(self, field_name): + format_amt = getattr(self, field_name) + else: + format_amt = self.workbook.add_format() + setattr(self, 'field_name', format_amt) + format_amount = \ + '#,##0.' + ('0' * line_object.currency_id.decimal_places) + format_amt.set_num_format(format_amount) + return format_amt + + def _get_currency_amt_header_format(self, line_object): + """ Return amount header format for each currency. """ + format_amt = getattr(self, 'format_header_amount') + if line_object.currency_id: + field_name = \ + 'format_header_amount_%s' % line_object.currency_id.name + if hasattr(self, field_name): + format_amt = getattr(self, field_name) + else: + format_amt = self.workbook.add_format( + {'bold': True, + 'border': True, + 'bg_color': '#FFFFCC'}) + setattr(self, 'field_name', format_amt) + format_amount = \ + '#,##0.' + ('0' * line_object.currency_id.decimal_places) + format_amt.set_num_format(format_amount) + return format_amt + def _generate_report_content(self, workbook, report): pass diff --git a/account_financial_report_qweb/report/aged_partner_balance.py b/account_financial_report_qweb/report/aged_partner_balance.py index aabf09ec..d6f1a81c 100644 --- a/account_financial_report_qweb/report/aged_partner_balance.py +++ b/account_financial_report_qweb/report/aged_partner_balance.py @@ -185,10 +185,9 @@ class AgedPartnerBalanceReportCompute(models.TransientModel): _inherit = 'report_aged_partner_balance_qweb' @api.multi - def print_report(self, xlsx_report=False): + def print_report(self, report_type): self.ensure_one() - self.compute_data_for_report() - if xlsx_report: + if report_type == 'xlsx': report_name = 'account_financial_report_qweb.' \ 'report_aged_partner_balance_xlsx' else: @@ -197,6 +196,22 @@ class AgedPartnerBalanceReportCompute(models.TransientModel): return self.env['report'].get_action(docids=self.ids, report_name=report_name) + def _get_html(self): + result = {} + rcontext = {} + context = dict(self.env.context) + report = self.browse(context.get('active_id')) + if report: + rcontext['o'] = report + result['html'] = self.env.ref( + 'account_financial_report_qweb.' + 'report_aged_partner_balance_html').render(rcontext) + return result + + @api.model + def get_html(self, given_context=None): + return self._get_html() + def _prepare_report_open_items(self): self.ensure_one() return { @@ -439,6 +454,7 @@ INSERT INTO report_partner_id, create_uid, create_date, + move_line_id, date, date_due, entry, @@ -458,6 +474,7 @@ SELECT rp.id AS report_partner_id, %s AS create_uid, NOW() AS create_date, + rlo.move_line_id, rlo.date, rlo.date_due, rlo.entry, diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index 8ebb2151..f633f4d7 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -29,6 +29,7 @@ class GeneralLedgerReport(models.TransientModel): fy_start_date = fields.Date() only_posted_moves = fields.Boolean() hide_account_balance_at_0 = fields.Boolean() + foreign_currency = fields.Boolean() company_id = fields.Many2one(comodel_name='res.company') filter_account_ids = fields.Many2many(comodel_name='account.account') filter_partner_ids = fields.Many2many(comodel_name='res.partner') @@ -38,7 +39,6 @@ class GeneralLedgerReport(models.TransientModel): centralize = fields.Boolean() # Flag fields, used for report display - has_second_currency = fields.Boolean() show_cost_center = fields.Boolean( default=lambda self: self.env.user.has_group( 'analytic.group_analytic_accounting' @@ -203,10 +203,9 @@ class GeneralLedgerReportCompute(models.TransientModel): _inherit = 'report_general_ledger_qweb' @api.multi - def print_report(self, xlsx_report=False): + def print_report(self, report_type): self.ensure_one() - self.compute_data_for_report() - if xlsx_report: + if report_type == 'xlsx': report_name = 'account_financial_report_qweb.' \ 'report_general_ledger_xlsx' else: @@ -215,6 +214,22 @@ class GeneralLedgerReportCompute(models.TransientModel): return self.env['report'].get_action(docids=self.ids, report_name=report_name) + def _get_html(self): + result = {} + rcontext = {} + context = dict(self.env.context) + report = self.browse(context.get('active_id')) + if report: + rcontext['o'] = report + result['html'] = self.env.ref( + 'account_financial_report_qweb.' + 'report_general_ledger_html').render(rcontext) + return result + + @api.model + def get_html(self, given_context=None): + return self._get_html() + @api.multi def compute_data_for_report( self, with_line_details=True, with_partners=True): @@ -255,10 +270,6 @@ class GeneralLedgerReportCompute(models.TransientModel): if self.centralize: self._inject_line_centralized_values() - if with_line_details: - # Compute display flag - self._compute_has_second_currency() - # Refresh cache because all data are computed with SQL requests self.invalidate_cache() @@ -453,7 +464,7 @@ SELECT COALESCE(i.debit, 0.0) AS initial_debit, COALESCE(i.credit, 0.0) AS initial_credit, COALESCE(i.balance, 0.0) AS initial_balance, - a.currency_id, + c.id AS currency_id, COALESCE(i.balance_currency, 0.0) AS initial_balance_foreign_currency, COALESCE(f.debit, 0.0) AS final_debit, COALESCE(f.credit, 0.0) AS final_credit, @@ -466,6 +477,8 @@ LEFT JOIN initial_sum_amounts i ON a.id = i.account_id LEFT JOIN final_sum_amounts f ON a.id = f.account_id +LEFT JOIN + res_currency c ON c.id = a.currency_id WHERE ( i.debit IS NOT NULL AND i.debit != 0 @@ -529,7 +542,7 @@ AND tuple(self.filter_cost_center_ids.ids), ) query_inject_account_params += ( - self.id, + self.id or 'NULL', self.env.uid, ) self.env.cr.execute(query_inject_account, query_inject_account_params) @@ -1241,48 +1254,6 @@ ORDER BY query_inject_move_line_centralized_params ) - def _compute_has_second_currency(self): - """ Compute "has_second_currency" flag which will used for display.""" - query_update_has_second_currency = """ -UPDATE - report_general_ledger_qweb -SET - has_second_currency = - ( - SELECT - TRUE - FROM - report_general_ledger_qweb_move_line l - INNER JOIN - report_general_ledger_qweb_account a - ON l.report_account_id = a.id - WHERE - a.report_id = %s - AND l.currency_id IS NOT NULL - LIMIT 1 - ) - OR - ( - SELECT - TRUE - FROM - report_general_ledger_qweb_move_line l - INNER JOIN - report_general_ledger_qweb_partner p - ON l.report_partner_id = p.id - INNER JOIN - report_general_ledger_qweb_account a - ON p.report_account_id = a.id - WHERE - a.report_id = %s - AND l.currency_id IS NOT NULL - LIMIT 1 - ) -WHERE id = %s - """ - params = (self.id,) * 3 - self.env.cr.execute(query_update_has_second_currency, params) - def _get_unaffected_earnings_account_sub_subquery_sum_initial( self ): diff --git a/account_financial_report_qweb/report/general_ledger_xlsx.py b/account_financial_report_qweb/report/general_ledger_xlsx.py index 9a97ba5a..2b7ac916 100644 --- a/account_financial_report_qweb/report/general_ledger_xlsx.py +++ b/account_financial_report_qweb/report/general_ledger_xlsx.py @@ -20,7 +20,7 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): return _('General Ledger') def _get_report_columns(self, report): - return { + res = { 0: {'header': _('Date'), 'field': 'date', 'width': 11}, 1: {'header': _('Entry'), 'field': 'entry', 'width': 18}, 2: {'header': _('Journal'), 'field': 'journal', 'width': 8}, @@ -54,39 +54,38 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): 'field_final_balance': 'final_balance', 'type': 'amount', 'width': 14}, - 12: {'header': _('Cur.'), - 'field': 'currency_id', - 'field_initial_balance': 'currency_id', - 'field_final_balance': 'currency_id', - 'type': 'many2one', - 'width': 7}, - 13: {'header': _('Amount cur.'), - 'field': 'amount_currency', - 'field_initial_balance': 'initial_balance_foreign_currency', - 'field_final_balance': 'final_balance_foreign_currency', - 'type': 'amount', - 'width': 14}, } + if report.foreign_currency: + foreign_currency = { + 12: {'header': _('Cur.'), + 'field': 'currency_id', + 'field_currency_balance': 'currency_id', + 'type': 'many2one', + 'width': 7}, + 13: {'header': _('Amount cur.'), + 'field': 'amount_currency', + 'field_initial_balance': + 'initial_balance_foreign_currency', + 'field_final_balance': 'final_balance_foreign_currency', + 'type': 'amount_currency', + 'width': 14}, + } + res = dict(res.items() + foreign_currency.items()) + return res def _get_report_filters(self, report): return [ - [ - _('Date range filter'), - _('From: %s To: %s') % (report.date_from, report.date_to), - ], - [ - _('Target moves filter'), - _('All posted entries') if report.only_posted_moves - else _('All entries'), - ], - [ - _('Account balance at 0 filter'), - _('Hide') if report.hide_account_balance_at_0 else _('Show'), - ], - [ - _('Centralize filter'), - _('Yes') if report.centralize else _('No'), - ], + [_('Date range filter'), + _('From: %s To: %s') % (report.date_from, report.date_to)], + [_('Target moves filter'), + _('All posted entries') if report.only_posted_moves else _( + 'All entries')], + [_('Account balance at 0 filter'), + _('Hide') if report.hide_account_balance_at_0 else _('Show')], + [_('Centralize filter'), + _('Yes') if report.centralize else _('No')], + [_('Show foreign currency'), + _('Yes') if report.foreign_currency else _('No')], ] def _get_col_count_filter_name(self): @@ -115,7 +114,7 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): self.write_array_header() # Display initial balance line for account - self.write_initial_balance(account, _('Initial balance')) + self.write_initial_balance(account) # Display account move lines for line in account.move_line_ids: @@ -131,30 +130,41 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): self.write_array_header() # Display initial balance line for partner - self.write_initial_balance(partner, _('Initial balance')) + self.write_initial_balance(partner) # Display account move lines for line in partner.move_line_ids: self.write_line(line) # Display ending balance line for partner - self.write_ending_balance(partner, 'partner') + self.write_ending_balance(partner) # Line break self.row_pos += 1 # Display ending balance line for account - self.write_ending_balance(account, 'account') + self.write_ending_balance(account) # 2 lines break self.row_pos += 2 - def write_ending_balance(self, my_object, type_object): + def write_initial_balance(self, my_object): + """Specific function to write initial balance for General Ledger""" + if 'partner' in my_object._name: + label = _('Partner Initial balance') + my_object.currency_id = my_object.report_account_id.currency_id + elif 'account' in my_object._name: + label = _('Initial balance') + super(GeneralLedgerXslx, self).write_initial_balance( + my_object, label + ) + + def write_ending_balance(self, my_object): """Specific function to write ending balance for General Ledger""" - if type_object == 'partner': + if 'partner' in my_object._name: name = my_object.name label = _('Partner ending balance') - elif type_object == 'account': + elif 'account' in my_object._name: name = my_object.code + ' - ' + my_object.name label = _('Ending balance') super(GeneralLedgerXslx, self).write_ending_balance( diff --git a/account_financial_report_qweb/report/journal_report.py b/account_financial_report_qweb/report/journal_report.py index c70cc0ba..5f873a78 100644 --- a/account_financial_report_qweb/report/journal_report.py +++ b/account_financial_report_qweb/report/journal_report.py @@ -61,7 +61,7 @@ class ReportJournalQweb(models.TransientModel): comodel_name='report_journal_qweb_report_tax_line', inverse_name='report_id', ) - with_currency = fields.Boolean() + foreign_currency = fields.Boolean() with_account_name = fields.Boolean() @api.model @@ -76,6 +76,12 @@ class ReportJournalQweb(models.TransientModel): def _get_group_options(self): return self.env['journal.report.wizard']._get_group_options() + @api.multi + def refresh(self): + self.ensure_one() + self.report_journal_ids.unlink() + self.compute_data_for_report() + @api.multi def compute_data_for_report(self): self.ensure_one() @@ -88,15 +94,21 @@ class ReportJournalQweb(models.TransientModel): if self.group_option == 'none': self._inject_report_tax_values() - @api.multi - def refresh(self): - self.ensure_one() - self.report_journal_ids.unlink() - self.compute_data_for_report() + # Refresh cache because all data are computed with SQL requests + self.invalidate_cache() @api.multi def _inject_journal_values(self): self.ensure_one() + sql = """ + DELETE + FROM report_journal_qweb_journal + WHERE report_id = %s + """ + params = ( + self.id, + ) + self.env.cr.execute(sql, params) sql = """ INSERT INTO report_journal_qweb_journal ( create_uid, @@ -139,6 +151,15 @@ class ReportJournalQweb(models.TransientModel): @api.multi def _inject_move_values(self): self.ensure_one() + sql = """ + DELETE + FROM report_journal_qweb_move + WHERE report_id = %s + """ + params = ( + self.id, + ) + self.env.cr.execute(sql, params) sql = self._get_inject_move_insert() sql += self._get_inject_move_select() sql += self._get_inject_move_where_clause() @@ -225,6 +246,15 @@ class ReportJournalQweb(models.TransientModel): @api.multi def _inject_move_line_values(self): self.ensure_one() + sql = """ + DELETE + FROM report_journal_qweb_move_line + WHERE report_id = %s + """ + params = ( + self.id, + ) + self.env.cr.execute(sql, params) sql = """ INSERT INTO report_journal_qweb_move_line ( create_uid, @@ -414,7 +444,15 @@ class ReportJournalQweb(models.TransientModel): @api.multi def _inject_journal_tax_values(self): self.ensure_one() - + sql = """ + DELETE + FROM report_journal_qweb_journal_tax_line + WHERE report_id = %s + """ + params = ( + self.id, + ) + self.env.cr.execute(sql, params) sql_distinct_tax_id = """ SELECT distinct(jrqml.tax_id) @@ -553,10 +591,9 @@ class ReportJournalQweb(models.TransientModel): self.env.cr.execute(sql, (self.id,)) @api.multi - def print_report(self, xlsx_report=False): + def print_report(self, report_type): self.ensure_one() - self.compute_data_for_report() - if xlsx_report: + if report_type == 'xlsx': report_name = 'account_financial_report_qweb.' \ 'report_journal_xlsx' else: @@ -565,6 +602,22 @@ class ReportJournalQweb(models.TransientModel): return self.env['report'].get_action( docids=self.ids, report_name=report_name) + def _get_html(self): + result = {} + rcontext = {} + context = dict(self.env.context) + report = self.browse(context.get('active_id')) + if report: + rcontext['o'] = report + result['html'] = self.env.ref( + 'account_financial_report_qweb.' + 'report_journal_html').render(rcontext) + return result + + @api.model + def get_html(self, given_context=None): + return self._get_html() + class ReportJournalQwebJournal(models.TransientModel): diff --git a/account_financial_report_qweb/report/journal_report_xlsx.py b/account_financial_report_qweb/report/journal_report_xlsx.py index 7a36204c..0ed64ad3 100644 --- a/account_financial_report_qweb/report/journal_report_xlsx.py +++ b/account_financial_report_qweb/report/journal_report_xlsx.py @@ -76,7 +76,7 @@ class JournalXslx(abstract_report_xlsx.AbstractReportXslx): } ] - if report.with_currency: + if report.foreign_currency: columns += [ { 'header': _('Amount Currency'), diff --git a/account_financial_report_qweb/report/open_items.py b/account_financial_report_qweb/report/open_items.py index 21ac0cec..2c52f559 100644 --- a/account_financial_report_qweb/report/open_items.py +++ b/account_financial_report_qweb/report/open_items.py @@ -22,6 +22,7 @@ class OpenItemsReport(models.TransientModel): date_at = fields.Date() only_posted_moves = fields.Boolean() hide_account_balance_at_0 = fields.Boolean() + foreign_currency = fields.Boolean() company_id = fields.Many2one(comodel_name='res.company') filter_account_ids = fields.Many2many(comodel_name='account.account') filter_partner_ids = fields.Many2many(comodel_name='res.partner') @@ -53,7 +54,7 @@ class OpenItemsReportAccount(models.TransientModel): # Data fields, used for report display code = fields.Char() name = fields.Char() - currency_name = fields.Char() + currency_id = fields.Many2one(comodel_name='res.currency') final_amount_residual = fields.Float(digits=(16, 2)) final_amount_total_due = fields.Float(digits=(16, 2)) final_amount_residual_currency = fields.Float(digits=(16, 2)) @@ -84,7 +85,7 @@ class OpenItemsReportPartner(models.TransientModel): # Data fields, used for report display name = fields.Char() - currency_name = fields.Char() + currency_id = fields.Many2one(comodel_name='res.currency') final_amount_residual = fields.Float(digits=(16, 2)) final_amount_total_due = fields.Float(digits=(16, 2)) final_amount_residual_currency = fields.Float(digits=(16, 2)) @@ -133,7 +134,7 @@ class OpenItemsReportMoveLine(models.TransientModel): label = fields.Char() amount_total_due = fields.Float(digits=(16, 2)) amount_residual = fields.Float(digits=(16, 2)) - currency_name = fields.Char() + currency_id = fields.Many2one(comodel_name='res.currency') amount_total_due_currency = fields.Float(digits=(16, 2)) amount_residual_currency = fields.Float(digits=(16, 2)) @@ -146,10 +147,9 @@ class OpenItemsReportCompute(models.TransientModel): _inherit = 'report_open_items_qweb' @api.multi - def print_report(self, xlsx_report=False): + def print_report(self, report_type): self.ensure_one() - self.compute_data_for_report() - if xlsx_report: + if report_type == 'xlsx': report_name = 'account_financial_report_qweb.' \ 'report_open_items_xlsx' else: @@ -158,6 +158,22 @@ class OpenItemsReportCompute(models.TransientModel): return self.env['report'].get_action(docids=self.ids, report_name=report_name) + def _get_html(self): + result = {} + rcontext = {} + context = dict(self.env.context) + report = self.browse(context.get('active_id')) + if report: + rcontext['o'] = report + result['html'] = self.env.ref( + 'account_financial_report_qweb.' + 'report_open_items_html').render(rcontext) + return result + + @api.model + def get_html(self, given_context=None): + return self._get_html() + @api.multi def compute_data_for_report(self): self.ensure_one() @@ -186,7 +202,7 @@ WITH a.code, a.name, a.user_type_id, - c.name as currency_name + c.id as currency_id FROM account_account a INNER JOIN @@ -221,7 +237,7 @@ WITH """ query_inject_account += """ GROUP BY - a.id, c.name + a.id, c.id ) INSERT INTO report_open_items_qweb_account @@ -230,7 +246,7 @@ INSERT INTO create_uid, create_date, account_id, - currency_name, + currency_id, code, name ) @@ -239,7 +255,7 @@ SELECT %s AS create_uid, NOW() AS create_date, a.id AS account_id, - a.currency_name, + a.currency_id, a.code, a.name FROM @@ -505,7 +521,7 @@ INSERT INTO label, amount_total_due, amount_residual, - currency_name, + currency_id, amount_total_due_currency, amount_residual_currency ) @@ -538,7 +554,7 @@ SELECT CONCAT_WS(' - ', NULLIF(ml.ref, ''), NULLIF(ml.name, '')) AS label, ml.balance, ml2.amount_residual, - c.name AS currency_name, + c.id AS currency_id, ml.amount_currency, ml2.amount_residual_currency FROM @@ -632,7 +648,7 @@ WHERE WHERE ra.report_id = %s )""" - query_compute_partners_residual_cumul = """ + query_computer_partner_residual_cumul = """ UPDATE report_open_items_qweb_partner SET @@ -647,7 +663,7 @@ SET ) """ + where_condition_partner_by_account params_compute_partners_residual_cumul = (self.id,) - self.env.cr.execute(query_compute_partners_residual_cumul, + self.env.cr.execute(query_computer_partner_residual_cumul, params_compute_partners_residual_cumul) query_compute_partners_due_cumul = """ @@ -664,9 +680,9 @@ SET rml.report_partner_id = report_open_items_qweb_partner.id ) """ + where_condition_partner_by_account - params_compute_partners_due_cumul = (self.id,) + params_compute_partner_due_cumul = (self.id,) self.env.cr.execute(query_compute_partners_due_cumul, - params_compute_partners_due_cumul) + params_compute_partner_due_cumul) # Manage currency in partner where_condition_partner_by_account_cur = """ @@ -681,25 +697,26 @@ WHERE report_open_items_qweb_partner rp ON ra.id = rp.report_account_id WHERE - ra.report_id = %s AND ra.currency_name IS NOT NULL - )""" - query_compute_partners_cur_name_cumul = """ + ra.report_id = %s AND ra.currency_id IS NOT NULL + ) + """ + query_compute_partners_cur_id_cumul = """ UPDATE report_open_items_qweb_partner SET - currency_name = + currency_id = ( SELECT - MAX(currency_name) as currency_name + MAX(currency_id) as currency_id FROM report_open_items_qweb_move_line rml WHERE rml.report_partner_id = report_open_items_qweb_partner.id ) """ + where_condition_partner_by_account_cur - params_compute_partners_cur_name_cumul = (self.id,) - self.env.cr.execute(query_compute_partners_cur_name_cumul, - params_compute_partners_cur_name_cumul) + params_compute_partners_cur_id_cumul = (self.id,) + self.env.cr.execute(query_compute_partners_cur_id_cumul, + params_compute_partners_cur_id_cumul) query_compute_partners_cur_residual_cumul = """ UPDATE diff --git a/account_financial_report_qweb/report/open_items_xlsx.py b/account_financial_report_qweb/report/open_items_xlsx.py index ca5f261b..9f6c645d 100644 --- a/account_financial_report_qweb/report/open_items_xlsx.py +++ b/account_financial_report_qweb/report/open_items_xlsx.py @@ -19,7 +19,7 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx): return _('Open Items') def _get_report_columns(self, report): - return { + res = { 0: {'header': _('Date'), 'field': 'date', 'width': 11}, 1: {'header': _('Entry'), 'field': 'entry', 'width': 18}, 2: {'header': _('Journal'), 'field': 'journal', 'width': 8}, @@ -29,7 +29,6 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx): 6: {'header': _('Due date'), 'field': 'date_due', 'width': 11}, 7: {'header': _('Original'), 'field': 'amount_total_due', - 'field_final_balance': 'final_amount_total_due', 'type': 'amount', 'width': 14}, 8: {'header': _('Residual'), @@ -37,37 +36,36 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx): 'field_final_balance': 'final_amount_residual', 'type': 'amount', 'width': 14}, - 9: {'header': _('Cur.'), - 'field': 'currency_name', - 'field_final_balance': 'currency_name', - 'width': 7}, - 10: {'header': _('Cur. Original'), - 'field': 'amount_total_due_currency', - 'field_final_balance': 'final_amount_total_due_currency', - 'type': 'amount', - 'width': 14}, - 11: {'header': _('Cur. Residual'), - 'field': 'amount_residual_currency', - 'field_final_balance': 'final_amount_residual_currency', - 'type': 'amount', - 'width': 14}, } + if report.foreign_currency: + foreign_currency = { + 9: {'header': _('Cur.'), 'field': 'currency_id', + 'field_currency_balance': 'currency_id', + 'type': 'many2one', 'width': 7}, + 10: {'header': _('Cur. Original'), + 'field': 'amount_total_due_currency', + 'field_final_balance': 'final_amount_total_due_currency', + 'type': 'amount_currency', + 'width': 14}, + 11: {'header': _('Cur. Residual'), + 'field': 'amount_residual_currency', + 'field_final_balance': 'final_amount_residual_currency', + 'type': 'amount_currency', + 'width': 14}, + } + res = dict(res.items() + foreign_currency.items()) + return res def _get_report_filters(self, report): return [ - [ - _('Date at filter'), - report.date_at - ], - [ - _('Target moves filter'), - _('All posted entries') if report.only_posted_moves - else _('All entries'), - ], - [ - _('Account balance at 0 filter'), - _('Hide') if report.hide_account_balance_at_0 else _('Show'), - ], + [_('Date at filter'), report.date_at], + [_('Target moves filter'), + _('All posted entries') if report.only_posted_moves else _( + 'All entries')], + [_('Account balance at 0 filter'), + _('Hide') if report.hide_account_balance_at_0 else _('Show')], + [_('Show foreign currency'), + _('Yes') if report.foreign_currency else _('No')], ] def _get_col_count_filter_name(self): @@ -117,6 +115,7 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx): if type_object == 'partner': name = my_object.name label = _('Partner ending balance') + my_object.currency_id = my_object.report_account_id.currency_id elif type_object == 'account': name = my_object.code + ' - ' + my_object.name label = _('Ending balance') diff --git a/account_financial_report_qweb/report/templates/aged_partner_balance.xml b/account_financial_report_qweb/report/templates/aged_partner_balance.xml index b146731d..7b35a28d 100644 --- a/account_financial_report_qweb/report/templates/aged_partner_balance.xml +++ b/account_financial_report_qweb/report/templates/aged_partner_balance.xml @@ -1,80 +1,88 @@ -