From 5867601b5e5af92ee36ad5cece452cb4ec949c4b Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Fri, 27 Oct 2017 16:56:20 +0200 Subject: [PATCH 1/3] [ADD] Add taxes description in general ledger report --- .../report/general_ledger.py | 30 +++++++++++++++++-- .../report/general_ledger_xlsx.py | 21 +++++++------ .../report/templates/general_ledger.xml | 8 ++++- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index 8bd8fc25..560b6d89 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -177,6 +177,7 @@ class GeneralLedgerReportMoveLine(models.TransientModel): entry = fields.Char() journal = fields.Char() account = fields.Char() + taxes_description = fields.Char() partner = fields.Char() label = fields.Char() cost_center = fields.Char() @@ -252,8 +253,8 @@ class GeneralLedgerReportCompute(models.TransientModel): # Complete unaffected earnings account if (not self.filter_account_ids or - self.unaffected_earnings_account.id in - self.filter_account_ids.ids): + self.unaffected_earnings_account.id in + self.filter_account_ids.ids): self._complete_unaffected_earnings_account_values() if with_line_details: @@ -862,6 +863,7 @@ INSERT INTO entry, journal, account, + taxes_description, partner, label, cost_center, @@ -890,6 +892,28 @@ SELECT m.name AS entry, j.code AS journal, a.code AS account, + CASE + WHEN + ml.tax_line_id is not null + THEN + at.name + WHEN + (SELECT count(*) + FROM account_move_line_account_tax_rel aml_at_rel + WHERE aml_at_rel.account_move_line_id = ml.id + LIMIT 1) > 0 + THEN + (SELECT + array_to_string(array_agg(at.name), ', ') + FROM + account_move_line_account_tax_rel aml_at_rel + LEFT JOIN + account_tax at on (at.id = aml_at_rel.account_tax_id) + WHERE + aml_at_rel.account_move_line_id = ml.id) + ELSE + '' + END as taxes_description, """ if not only_empty_partner_line: query_inject_move_line += """ @@ -960,6 +984,8 @@ INNER JOIN account_journal j ON ml.journal_id = j.id INNER JOIN account_account a ON ml.account_id = a.id +LEFT JOIN + account_tax at ON ml.tax_line_id = at.id """ if is_account_line: query_inject_move_line += """ diff --git a/account_financial_report_qweb/report/general_ledger_xlsx.py b/account_financial_report_qweb/report/general_ledger_xlsx.py index e7b99cf0..2f547bb8 100644 --- a/account_financial_report_qweb/report/general_ledger_xlsx.py +++ b/account_financial_report_qweb/report/general_ledger_xlsx.py @@ -25,32 +25,35 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): 1: {'header': _('Entry'), 'field': 'entry', 'width': 18}, 2: {'header': _('Journal'), 'field': 'journal', 'width': 8}, 3: {'header': _('Account'), 'field': 'account', 'width': 9}, - 4: {'header': _('Partner'), 'field': 'partner', 'width': 25}, - 5: {'header': _('Ref - Label'), 'field': 'label', 'width': 40}, - 6: {'header': _('Cost center'), + 4: {'header': _('Taxes'), + 'field': 'taxes_description', + 'width': 15}, + 5: {'header': _('Partner'), 'field': 'partner', 'width': 25}, + 6: {'header': _('Ref - Label'), 'field': 'label', 'width': 40}, + 7: {'header': _('Cost center'), 'field': 'cost_center', 'width': 15}, - 7: {'header': _('Rec.'), 'field': 'matching_number', 'width': 5}, - 8: {'header': _('Debit'), + 8: {'header': _('Rec.'), 'field': 'matching_number', 'width': 5}, + 9: {'header': _('Debit'), 'field': 'debit', 'field_initial_balance': 'initial_debit', 'field_final_balance': 'final_debit', 'type': 'amount', 'width': 14}, - 9: {'header': _('Credit'), + 10: {'header': _('Credit'), 'field': 'credit', 'field_initial_balance': 'initial_credit', 'field_final_balance': 'final_credit', 'type': 'amount', 'width': 14}, - 10: {'header': _('Cumul. Bal.'), + 11: {'header': _('Cumul. Bal.'), 'field': 'cumul_balance', 'field_initial_balance': 'initial_balance', 'field_final_balance': 'final_balance', 'type': 'amount', 'width': 14}, - 11: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7}, - 12: {'header': _('Amount cur.'), + 12: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7}, + 13: {'header': _('Amount cur.'), 'field': 'amount_currency', 'type': 'amount', 'width': 14}, diff --git a/account_financial_report_qweb/report/templates/general_ledger.xml b/account_financial_report_qweb/report/templates/general_ledger.xml index 0cb91502..4656eb67 100644 --- a/account_financial_report_qweb/report/templates/general_ledger.xml +++ b/account_financial_report_qweb/report/templates/general_ledger.xml @@ -110,10 +110,12 @@
Journal
Account
+ +
Taxes
Partner
-
Ref - Label
+
Ref - Label
Cost center
@@ -145,6 +147,8 @@
+ +
@@ -181,6 +185,8 @@
+ +
From 1e1bf2a301a7bd839ffcfff5d014f460a34a4bf0 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Mon, 30 Oct 2017 07:54:27 +0100 Subject: [PATCH 2/3] [CHG] Use tax description if it exists. Removed useless when condition --- .../report/general_ledger.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index 560b6d89..010b0d7b 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -896,15 +896,14 @@ SELECT WHEN ml.tax_line_id is not null THEN - at.name + COALESCE(at.description, at.name) WHEN - (SELECT count(*) - FROM account_move_line_account_tax_rel aml_at_rel - WHERE aml_at_rel.account_move_line_id = ml.id - LIMIT 1) > 0 + ml.tax_line_id is null THEN (SELECT - array_to_string(array_agg(at.name), ', ') + array_to_string( + array_agg(COALESCE(at.description, at.name) + ), ', ') FROM account_move_line_account_tax_rel aml_at_rel LEFT JOIN From 1cfb51f0ae46b16af19fb91dd9ae407d9eb56cba Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Mon, 30 Oct 2017 08:03:56 +0100 Subject: [PATCH 3/3] [FIX] pylint/pep8 --- account_financial_report_qweb/README.rst | 1 + .../report/general_ledger.py | 13 ++++---- .../report/general_ledger_xlsx.py | 30 ++++++++++++------- .../report/open_items.py | 1 + .../report/open_items_xlsx.py | 17 +++++++---- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/account_financial_report_qweb/README.rst b/account_financial_report_qweb/README.rst index 7836ebbb..b127e61d 100644 --- a/account_financial_report_qweb/README.rst +++ b/account_financial_report_qweb/README.rst @@ -52,6 +52,7 @@ Contributors * Julien Coux * Akim Juillerat * Alexis de Lattre +* Benjamin Willig Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index 010b0d7b..b943b367 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -210,10 +210,8 @@ class GeneralLedgerReportCompute(models.TransientModel): report_name=report_name) @api.multi - def compute_data_for_report(self, - with_line_details=True, - with_partners=True - ): + def compute_data_for_report( + self, with_line_details=True, with_partners=True): self.ensure_one() # Compute report data self._inject_account_values() @@ -253,8 +251,8 @@ class GeneralLedgerReportCompute(models.TransientModel): # Complete unaffected earnings account if (not self.filter_account_ids or - self.unaffected_earnings_account.id in - self.filter_account_ids.ids): + self.unaffected_earnings_account.id in + self.filter_account_ids.ids): self._complete_unaffected_earnings_account_values() if with_line_details: @@ -617,7 +615,7 @@ AND Only for "partner" accounts (payable and receivable). """ - + # pylint: disable=sql-injection query_inject_partner = """ WITH accounts_partners AS @@ -1324,6 +1322,7 @@ WHERE id = %s subquery_sum_amounts += """ ) sub """ + # pylint: disable=sql-injection query_inject_account = """ WITH initial_sum_amounts AS ( """ + subquery_sum_amounts + """ ) diff --git a/account_financial_report_qweb/report/general_ledger_xlsx.py b/account_financial_report_qweb/report/general_ledger_xlsx.py index 2f547bb8..a52f0ee9 100644 --- a/account_financial_report_qweb/report/general_ledger_xlsx.py +++ b/account_financial_report_qweb/report/general_ledger_xlsx.py @@ -40,12 +40,14 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): 'field_final_balance': 'final_debit', 'type': 'amount', 'width': 14}, - 10: {'header': _('Credit'), + 10: { + 'header': _('Credit'), 'field': 'credit', 'field_initial_balance': 'initial_credit', 'field_final_balance': 'final_credit', 'type': 'amount', - 'width': 14}, + 'width': 14 + }, 11: {'header': _('Cumul. Bal.'), 'field': 'cumul_balance', 'field_initial_balance': 'initial_balance', @@ -61,15 +63,23 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx): def _get_report_filters(self, report): return [ - [_('Date range filter'), - _('From: %s To: %s') % (report.date_from, report.date_to)], - [_('Target moves filter'), + [ + _('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')], + 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'), + ], ] def _get_col_count_filter_name(self): diff --git a/account_financial_report_qweb/report/open_items.py b/account_financial_report_qweb/report/open_items.py index 5265fd00..3128d6f1 100644 --- a/account_financial_report_qweb/report/open_items.py +++ b/account_financial_report_qweb/report/open_items.py @@ -257,6 +257,7 @@ FROM def _inject_partner_values(self): """ Inject report values for report_open_items_qweb_partner. """ + # pylint: disable=sql-injection query_inject_partner = """ WITH accounts_partners AS diff --git a/account_financial_report_qweb/report/open_items_xlsx.py b/account_financial_report_qweb/report/open_items_xlsx.py index 63bd02fb..1d75c752 100644 --- a/account_financial_report_qweb/report/open_items_xlsx.py +++ b/account_financial_report_qweb/report/open_items_xlsx.py @@ -49,12 +49,19 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx): def _get_report_filters(self, report): return [ - [_('Date at filter'), report.date_at], - [_('Target moves filter'), + [ + _('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')], + else _('All entries'), + ], + [ + _('Account balance at 0 filter'), + _('Hide') if report.hide_account_balance_at_0 else _('Show'), + ], ] def _get_col_count_filter_name(self):