From c3f2dda9c9a871108599d4eb287d8864957ecfa5 Mon Sep 17 00:00:00 2001 From: jcoux Date: Fri, 12 Aug 2016 14:58:29 +0200 Subject: [PATCH] Add missing unaffected earnings account into reports --- .../i18n/account_financial_report_qweb.pot | 61 +++++-- account_financial_report_qweb/i18n/fr.po | 42 ++++- .../report/general_ledger.py | 170 ++++++++++++++++++ .../wizard/general_ledger_wizard.py | 16 ++ .../wizard/general_ledger_wizard_view.xml | 69 ++++--- .../wizard/trial_balance_wizard.py | 16 ++ .../wizard/trial_balance_wizard_view.xml | 63 ++++--- 7 files changed, 366 insertions(+), 71 deletions(-) diff --git a/account_financial_report_qweb/i18n/account_financial_report_qweb.pot b/account_financial_report_qweb/i18n/account_financial_report_qweb.pot index bdf0471c..4094b0c4 100644 --- a/account_financial_report_qweb/i18n/account_financial_report_qweb.pot +++ b/account_financial_report_qweb/i18n/account_financial_report_qweb.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 9.0c\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-07-29 07:38+0000\n" -"PO-Revision-Date: 2016-07-29 07:38+0000\n" +"POT-Creation-Date: 2016-08-12 12:17+0000\n" +"PO-Revision-Date: 2016-08-12 12:17+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -262,6 +262,22 @@ msgstr "" msgid "Code" msgstr "" +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_aged_partner_balance_wizard_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_open_items_report_wizard_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_company_id +msgid "Company" +msgstr "" + +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_aged_partner_balance_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_open_items_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_trial_balance_qweb_company_id +msgid "Company id" +msgstr "" + #. module: account_financial_report_qweb #: code:addons/account_financial_report_qweb/report/general_ledger_xlsx.py:30 #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_move_line_cost_center @@ -463,6 +479,12 @@ msgstr "" msgid "Date from" msgstr "" +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_date_range_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_date_range_id +msgid "Date range" +msgstr "" + #. module: account_financial_report_qweb #: code:addons/account_financial_report_qweb/report/general_ledger_xlsx.py:61 #: code:addons/account_financial_report_qweb/report/trial_balance_xlsx.py:66 @@ -472,12 +494,6 @@ msgstr "" msgid "Date range filter" msgstr "" -#. module: account_financial_report_qweb -#: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_date_range_id -#: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_date_range_id -msgid "Date range id" -msgstr "" - #. module: account_financial_report_qweb #: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_date_to #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_date_to @@ -683,6 +699,11 @@ msgstr "" msgid "General Ledger XLSX" msgstr "" +#. module: account_financial_report_qweb +#: model:ir.ui.view,arch_db:account_financial_report_qweb.general_ledger_wizard +msgid "General Ledger can be computed only if selected company have only one unaffected earnings account." +msgstr "" + #. module: account_financial_report_qweb #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_trial_balance_qweb_general_ledger_id msgid "General ledger id" @@ -918,14 +939,20 @@ msgid "No" msgstr "" #. module: account_financial_report_qweb -#: code:addons/account_financial_report_qweb/report/general_ledger.py:457 -#: code:addons/account_financial_report_qweb/report/general_ledger.py:673 -#: code:addons/account_financial_report_qweb/report/open_items.py:275 -#: code:addons/account_financial_report_qweb/report/open_items.py:491 +#: code:addons/account_financial_report_qweb/report/general_ledger.py:491 +#: code:addons/account_financial_report_qweb/report/general_ledger.py:707 +#: code:addons/account_financial_report_qweb/report/open_items.py:277 +#: code:addons/account_financial_report_qweb/report/open_items.py:493 #, python-format msgid "No partner allocated" msgstr "" +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_not_only_one_unaffected_earnings_account +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_not_only_one_unaffected_earnings_account +msgid "Not only one unaffected earnings account" +msgstr "" + #. module: account_financial_report_qweb #: model:ir.ui.menu,name:account_financial_report_qweb.menu_oca_reports msgid "OCA accounting reports" @@ -1224,6 +1251,16 @@ msgstr "" msgid "Trial Balance XLSX" msgstr "" +#. module: account_financial_report_qweb +#: model:ir.ui.view,arch_db:account_financial_report_qweb.trial_balance_wizard +msgid "Trial Balance can be computed only if selected company have only one unaffected earnings account." +msgstr "" + +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_unaffected_earnings_account +msgid "Unaffected earnings account" +msgstr "" + #. module: account_financial_report_qweb #: model:ir.model.fields,help:account_financial_report_qweb.field_general_ledger_report_wizard_hide_account_balance_at_0 #: model:ir.model.fields,help:account_financial_report_qweb.field_open_items_report_wizard_hide_account_balance_at_0 diff --git a/account_financial_report_qweb/i18n/fr.po b/account_financial_report_qweb/i18n/fr.po index 8cbe1bde..3d0f886d 100644 --- a/account_financial_report_qweb/i18n/fr.po +++ b/account_financial_report_qweb/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 9.0c\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-08-11 09:11+0000\n" -"PO-Revision-Date: 2016-08-11 09:11+0000\n" +"POT-Creation-Date: 2016-08-12 12:18+0000\n" +"PO-Revision-Date: 2016-08-12 12:18+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -246,7 +246,7 @@ msgid "Centralized" msgstr "Centralisé" #. module: account_financial_report_qweb -#: code:addons/account_financial_report_qweb/report/general_ledger.py:901 +#: code:addons/account_financial_report_qweb/report/general_ledger.py:933 #, python-format msgid "Centralized Entries" msgstr "Écritures centralisées" @@ -270,6 +270,14 @@ msgstr "Code" msgid "Company" msgstr "Société" +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_aged_partner_balance_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_open_items_qweb_company_id +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_trial_balance_qweb_company_id +msgid "Company id" +msgstr "Société" + #. module: account_financial_report_qweb #: code:addons/account_financial_report_qweb/report/general_ledger_xlsx.py:30 #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_move_line_cost_center @@ -529,7 +537,7 @@ msgstr "Débit" #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_trial_balance_qweb_partner_display_name #: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_display_name msgid "Display Name" -msgstr "Afficher le nom" +msgstr "Nom affiché" #. module: account_financial_report_qweb #: code:addons/account_financial_report_qweb/report/aged_partner_balance_xlsx.py:75 @@ -691,6 +699,11 @@ msgstr "General Ledger Report Wizard" msgid "General Ledger XLSX" msgstr "Grand livre en XLSX" +#. module: account_financial_report_qweb +#: model:ir.ui.view,arch_db:account_financial_report_qweb.general_ledger_wizard +msgid "General Ledger can be computed only if selected company have only one unaffected earnings account." +msgstr "Le Grand Livre ne peut être calculé que si la société sélectionnée a un seul compte de résultat non affecté." + #. module: account_financial_report_qweb #: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_trial_balance_qweb_general_ledger_id msgid "General ledger id" @@ -926,14 +939,20 @@ msgid "No" msgstr "Non" #. module: account_financial_report_qweb -#: code:addons/account_financial_report_qweb/report/general_ledger.py:459 -#: code:addons/account_financial_report_qweb/report/general_ledger.py:675 +#: code:addons/account_financial_report_qweb/report/general_ledger.py:491 +#: code:addons/account_financial_report_qweb/report/general_ledger.py:707 #: code:addons/account_financial_report_qweb/report/open_items.py:277 #: code:addons/account_financial_report_qweb/report/open_items.py:493 #, python-format msgid "No partner allocated" msgstr "Écritures sans partenaire" +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_general_ledger_report_wizard_not_only_one_unaffected_earnings_account +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_trial_balance_report_wizard_not_only_one_unaffected_earnings_account +msgid "Not only one unaffected earnings account" +msgstr "Pas un seul compte de résultat non affecté" + #. module: account_financial_report_qweb #: model:ir.ui.menu,name:account_financial_report_qweb.menu_oca_reports msgid "OCA accounting reports" @@ -1232,6 +1251,16 @@ msgstr "Trial Balance Report Wizard" msgid "Trial Balance XLSX" msgstr "Balance générale XLSX" +#. module: account_financial_report_qweb +#: model:ir.ui.view,arch_db:account_financial_report_qweb.trial_balance_wizard +msgid "Trial Balance can be computed only if selected company have only one unaffected earnings account." +msgstr "La Balance Générale ne peut être calculée que si la société sélectionnée a un seul compte de résultat non affecté." + +#. module: account_financial_report_qweb +#: model:ir.model.fields,field_description:account_financial_report_qweb.field_report_general_ledger_qweb_unaffected_earnings_account +msgid "Unaffected earnings account" +msgstr "Compte de résultat non affecté" + #. module: account_financial_report_qweb #: model:ir.model.fields,help:account_financial_report_qweb.field_general_ledger_report_wizard_hide_account_balance_at_0 #: model:ir.model.fields,help:account_financial_report_qweb.field_open_items_report_wizard_hide_account_balance_at_0 @@ -1333,3 +1362,4 @@ msgstr "report_trial_balance_qweb_account" #: model:ir.model,name:account_financial_report_qweb.model_report_trial_balance_qweb_partner msgid "report_trial_balance_qweb_partner" msgstr "report_trial_balance_qweb_partner" + diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index 035cc4de..b93b9f16 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -51,6 +51,22 @@ class GeneralLedgerReport(models.TransientModel): inverse_name='report_id' ) + # Compute of unaffected earnings account + @api.depends('company_id') + def _compute_unaffected_earnings_account(self): + account_type = self.env.ref('account.data_unaffected_earnings') + self.unaffected_earnings_account = self.env['account.account'].search( + [ + ('user_type_id', '=', account_type.id), + ('company_id', '=', self.company_id.id) + ]) + + unaffected_earnings_account = fields.Many2one( + comodel_name='account.account', + compute='_compute_unaffected_earnings_account', + store=True + ) + class GeneralLedgerReportAccount(models.TransientModel): @@ -198,6 +214,13 @@ class GeneralLedgerReportCompute(models.TransientModel): # Compute report data self._inject_account_values() self._inject_partner_values() + + # Add unaffected earnings account + if (not self.filter_account_ids or + self.unaffected_earnings_account.id in + self.filter_account_ids.ids): + self._inject_unaffected_earnings_account_values() + self._inject_line_not_centralized_values() self._inject_line_not_centralized_values(is_account_line=False, is_partner_line=True) @@ -206,6 +229,13 @@ class GeneralLedgerReportCompute(models.TransientModel): only_empty_partner_line=True) if self.centralize: self._inject_line_centralized_values() + + # Complete unaffected earnings account + if (not self.filter_account_ids or + self.unaffected_earnings_account.id in + self.filter_account_ids.ids): + self._complete_unaffected_earnings_account_values() + # Compute display flag self._compute_has_second_currency() # Refresh cache because all data are computed with SQL requests @@ -285,6 +315,7 @@ WITH query_inject_account += """ WHERE a.company_id = %s + AND a.id != %s """ if self.filter_account_ids: query_inject_account += """ @@ -364,6 +395,7 @@ AND ) query_inject_account_params += ( self.company_id.id, + self.unaffected_earnings_account.id, ) if self.filter_account_ids: query_inject_account_params += ( @@ -979,3 +1011,141 @@ WHERE id = %s """ params = (self.id,) * 3 self.env.cr.execute(query_update_has_second_currency, params) + + def _inject_unaffected_earnings_account_values(self): + """Inject the report values of the unaffected earnings account + for report_general_ledger_qweb_account.""" + subquery_sum_amounts = """ + SELECT + SUM(ml.balance) AS balance + FROM + account_account a + INNER JOIN + account_account_type at ON a.user_type_id = at.id + INNER JOIN + account_move_line ml + ON a.id = ml.account_id + AND ml.date <= %s + AND + NOT( + at.include_initial_balance != TRUE AND ml.date >= %s + OR at.include_initial_balance = TRUE + ) + """ + if self.only_posted_moves: + subquery_sum_amounts += """ + INNER JOIN + account_move m ON ml.move_id = m.id AND m.state = 'posted' + """ + if self.filter_cost_center_ids: + subquery_sum_amounts += """ + INNER JOIN + account_analytic_account aa + ON + ml.analytic_account_id = aa.id + AND aa.id IN %s + """ + subquery_sum_amounts += """ + WHERE + a.company_id =%s + AND a.id != %s + """ + query_inject_account = """ + WITH + initial_sum_amounts AS ( """ + subquery_sum_amounts + """ ) + INSERT INTO + report_general_ledger_qweb_account + ( + report_id, + create_uid, + create_date, + account_id, + code, + name, + is_partner_account, + initial_balance + ) + SELECT + %s AS report_id, + %s AS create_uid, + NOW() AS create_date, + a.id AS account_id, + a.code, + a.name, + False AS is_partner_account, + COALESCE(i.balance, 0.0) AS initial_balance + FROM + account_account a, + initial_sum_amounts i + WHERE + a.company_id = %s + AND a.id = %s + """ + query_inject_account_params = ( + self.date_from, + self.fy_start_date, + ) + if self.filter_cost_center_ids: + query_inject_account_params += ( + tuple(self.filter_cost_center_ids.ids), + ) + query_inject_account_params += ( + self.company_id.id, + self.unaffected_earnings_account.id, + self.id, + self.env.uid, + self.company_id.id, + self.unaffected_earnings_account.id, + ) + self.env.cr.execute(query_inject_account, + query_inject_account_params) + + def _complete_unaffected_earnings_account_values(self): + """Complete the report values of the unaffected earnings account + for report_general_ledger_qweb_account.""" + query_update_unaffected_earnings_account_values = """ + WITH + sum_amounts AS + ( + SELECT + SUM(COALESCE(rml.debit, 0.0)) AS debit, + SUM(COALESCE(rml.credit, 0.0)) AS credit, + SUM( + COALESCE(rml.debit, 0.0) - + COALESCE(rml.credit, 0.0) + ) + ra.initial_balance AS balance + FROM + report_general_ledger_qweb_account ra + LEFT JOIN + report_general_ledger_qweb_move_line rml + ON ra.id = rml.report_account_id + WHERE + ra.report_id = %s + AND ra.account_id = %s + GROUP BY + ra.id + ) + UPDATE + report_general_ledger_qweb_account ra + SET + initial_debit = 0.0, + initial_credit = 0.0, + final_debit = sum_amounts.debit, + final_credit = sum_amounts.credit, + final_balance = sum_amounts.balance + FROM + sum_amounts + WHERE + ra.report_id = %s + AND ra.account_id = %s + """ + params = ( + self.id, + self.unaffected_earnings_account.id, + self.id, + self.unaffected_earnings_account.id, + ) + self.env.cr.execute( + query_update_unaffected_earnings_account_values, + params + ) diff --git a/account_financial_report_qweb/wizard/general_ledger_wizard.py b/account_financial_report_qweb/wizard/general_ledger_wizard.py index 6dec0e2b..c066cba0 100644 --- a/account_financial_report_qweb/wizard/general_ledger_wizard.py +++ b/account_financial_report_qweb/wizard/general_ledger_wizard.py @@ -55,6 +55,22 @@ class GeneralLedgerReportWizard(models.TransientModel): string='Filter cost centers', ) + not_only_one_unaffected_earnings_account = fields.Boolean( + readonly=True, + string='Not only one unaffected earnings account' + ) + + @api.onchange('company_id') + def onchange_company_id(self): + """Handle company change.""" + account_type = self.env.ref('account.data_unaffected_earnings') + count = self.env['account.account'].search_count( + [ + ('user_type_id', '=', account_type.id), + ('company_id', '=', self.company_id.id) + ]) + self.not_only_one_unaffected_earnings_account = count != 1 + @api.onchange('date_range_id') def onchange_date_range_id(self): """Handle date range change.""" diff --git a/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml b/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml index dff93e5a..6c608753 100644 --- a/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml +++ b/account_financial_report_qweb/wizard/general_ledger_wizard_view.xml @@ -10,37 +10,50 @@ - - - - - - +
+ + + + + + + + + + + + - - - - +
+
+ + +

General Ledger can be computed only if selected company have only one unaffected earnings account.

+ +
-
diff --git a/account_financial_report_qweb/wizard/trial_balance_wizard.py b/account_financial_report_qweb/wizard/trial_balance_wizard.py index bd05233c..17abdfdd 100644 --- a/account_financial_report_qweb/wizard/trial_balance_wizard.py +++ b/account_financial_report_qweb/wizard/trial_balance_wizard.py @@ -49,6 +49,22 @@ class TrialBalanceReportWizard(models.TransientModel): string='Filter partners', ) + not_only_one_unaffected_earnings_account = fields.Boolean( + readonly=True, + string='Not only one unaffected earnings account' + ) + + @api.onchange('company_id') + def onchange_company_id(self): + """Handle company change.""" + account_type = self.env.ref('account.data_unaffected_earnings') + count = self.env['account.account'].search_count( + [ + ('user_type_id', '=', account_type.id), + ('company_id', '=', self.company_id.id) + ]) + self.not_only_one_unaffected_earnings_account = count != 1 + @api.onchange('date_range_id') def onchange_date_range_id(self): """Handle date range change.""" diff --git a/account_financial_report_qweb/wizard/trial_balance_wizard_view.xml b/account_financial_report_qweb/wizard/trial_balance_wizard_view.xml index db7be23e..ba2ceb9e 100644 --- a/account_financial_report_qweb/wizard/trial_balance_wizard_view.xml +++ b/account_financial_report_qweb/wizard/trial_balance_wizard_view.xml @@ -10,34 +10,47 @@ - - - - - - +
+ + + + + + + + + + + + - - - - +
+
+ + +

Trial Balance can be computed only if selected company have only one unaffected earnings account.

+ +