From 29bd9645c3ce93dab7368485f93f1a98d1b1fffe Mon Sep 17 00:00:00 2001 From: jbeficient Date: Thu, 1 Mar 2018 17:10:51 +0100 Subject: [PATCH] Currency from account instead of move lines --- account_financial_report_qweb/__manifest__.py | 2 +- .../report/general_ledger.py | 68 ++++++++----------- .../report/templates/general_ledger.xml | 12 ++-- .../report/templates/trial_balance.xml | 24 ++++++- .../report/trial_balance.py | 13 +++- 5 files changed, 68 insertions(+), 51 deletions(-) diff --git a/account_financial_report_qweb/__manifest__.py b/account_financial_report_qweb/__manifest__.py index e3ae53df..b3326eb4 100644 --- a/account_financial_report_qweb/__manifest__.py +++ b/account_financial_report_qweb/__manifest__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'QWeb Financial Reports', - 'version': '10.0.1.3.0', + 'version': '10.0.1.4.0', 'category': 'Reporting', 'summary': 'OCA Financial Reports', 'author': 'Camptocamp SA,' diff --git a/account_financial_report_qweb/report/general_ledger.py b/account_financial_report_qweb/report/general_ledger.py index f0bb7ab3..b1f65a61 100644 --- a/account_financial_report_qweb/report/general_ledger.py +++ b/account_financial_report_qweb/report/general_ledger.py @@ -91,12 +91,11 @@ class GeneralLedgerReportAccount(models.TransientModel): initial_debit = fields.Float(digits=(16, 2)) initial_credit = fields.Float(digits=(16, 2)) initial_balance = fields.Float(digits=(16, 2)) - initial_currency_name = fields.Char() + currency_name = fields.Char() initial_balance_foreign_currency = fields.Float(digits=(16, 2)) final_debit = fields.Float(digits=(16, 2)) final_credit = fields.Float(digits=(16, 2)) final_balance = fields.Float(digits=(16, 2)) - final_currency_name = fields.Char() final_balance_foreign_currency = fields.Float(digits=(16, 2)) # Flag fields, used for report display and for data computation @@ -134,12 +133,11 @@ class GeneralLedgerReportPartner(models.TransientModel): initial_debit = fields.Float(digits=(16, 2)) initial_credit = fields.Float(digits=(16, 2)) initial_balance = fields.Float(digits=(16, 2)) - initial_currency_name = fields.Char() + currency_name = fields.Char() initial_balance_foreign_currency = fields.Float(digits=(16, 2)) final_debit = fields.Float(digits=(16, 2)) final_credit = fields.Float(digits=(16, 2)) final_balance = fields.Float(digits=(16, 2)) - final_currency_name = fields.Char() final_balance_foreign_currency = fields.Float(digits=(16, 2)) # Data fields, used to browse report data @@ -280,14 +278,8 @@ class GeneralLedgerReportCompute(models.TransientModel): SUM(ml.debit) AS debit, SUM(ml.credit) AS credit, SUM(ml.balance) AS balance, - CASE - WHEN COUNT(c.name) = COUNT(1) - AND MIN(c.name) = MAX(c.name) - THEN MAX(c.name) END AS currency_name, - CASE - WHEN COUNT(c.name) = COUNT(1) - AND MIN(c.name) = MAX(c.name) - THEN SUM(ml.amount_currency) END AS balance_currency + c.name AS currency_name, + SUM(ml.amount_currency) AS balance_currency FROM accounts a INNER JOIN @@ -330,11 +322,11 @@ class GeneralLedgerReportCompute(models.TransientModel): """ sub_subquery_sum_amounts += """ LEFT JOIN - res_currency c ON ml.currency_id = c.id + res_currency c ON a.currency_id = c.id """ sub_subquery_sum_amounts += """ GROUP BY - a.id + a.id, c.name """ return sub_subquery_sum_amounts @@ -379,7 +371,8 @@ WITH a.name, a.internal_type IN ('payable', 'receivable') AS is_partner_account, - a.user_type_id + a.user_type_id, + a.currency_id FROM account_account a """ @@ -445,12 +438,11 @@ INSERT INTO initial_debit, initial_credit, initial_balance, - initial_currency_name, + currency_name, initial_balance_foreign_currency, final_debit, final_credit, final_balance, - final_currency_name, final_balance_foreign_currency, is_partner_account ) @@ -464,12 +456,11 @@ 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, - i.currency_name AS initial_currency_name, + c.name AS currency_name, 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, COALESCE(f.balance, 0.0) AS final_balance, - f.currency_name AS final_currency_name, COALESCE(f.balance_currency, 0.0) AS final_balance_foreign_currency, a.is_partner_account FROM @@ -478,6 +469,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 @@ -557,16 +550,14 @@ AND SUM(ml.debit) AS debit, SUM(ml.credit) AS credit, SUM(ml.balance) AS balance, - CASE - WHEN COUNT(c.name) = COUNT(1) - AND MIN(c.name) = MAX(c.name) - THEN MAX(c.name) END AS currency_name, - CASE - WHEN COUNT(c.name) = COUNT(1) - AND MIN(c.name) = MAX(c.name) - THEN SUM(ml.amount_currency) END AS balance_currency + c.name as currency_name, + SUM(ml.amount_currency) AS balance_currency FROM accounts_partners ap + INNER JOIN account_account ac + ON ac.id = ap.account_id + LEFT JOIN + res_currency c ON ap.account_id = c.id INNER JOIN account_move_line ml ON ap.account_id = ml.account_id @@ -608,13 +599,9 @@ AND ml.analytic_account_id = aa.id AND aa.id IN %s """ - sub_subquery_sum_amounts += """ - LEFT JOIN - res_currency c ON ml.currency_id = c.id - """ sub_subquery_sum_amounts += """ GROUP BY - ap.account_id, ap.partner_id + ap.account_id, ap.partner_id, c.name """ return sub_subquery_sum_amounts @@ -756,12 +743,11 @@ INSERT INTO initial_debit, initial_credit, initial_balance, - initial_currency_name, + currency_name, initial_balance_foreign_currency, final_debit, final_credit, final_balance, - final_currency_name, final_balance_foreign_currency ) SELECT @@ -773,12 +759,11 @@ 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, - i.currency_name AS initial_currency_name, + i.currency_name AS currency_name, 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, COALESCE(f.balance, 0.0) AS final_balance, - f.currency_name AS final_currency_name, COALESCE(f.balance_currency, 0.0) AS final_balance_foreign_currency FROM accounts_partners ap @@ -1365,7 +1350,8 @@ WHERE id = %s code, name, is_partner_account, - initial_balance + initial_balance, + currency_name ) SELECT %s AS report_id, @@ -1375,7 +1361,8 @@ WHERE id = %s a.code, a.name, False AS is_partner_account, - COALESCE(i.balance, 0.0) AS initial_balance + COALESCE(i.balance, 0.0) AS initial_balance, + '' FROM account_account a, initial_sum_amounts i @@ -1412,6 +1399,7 @@ WHERE id = %s self.company_id.id, self.unaffected_earnings_account.id, ) + self.env.cr.execute(query_inject_account, query_inject_account_params) @@ -1447,7 +1435,9 @@ WHERE id = %s initial_credit = 0.0, final_debit = sum_amounts.debit, final_credit = sum_amounts.credit, - final_balance = sum_amounts.balance + final_balance = sum_amounts.balance, + initial_balance_foreign_currency = 0.0, + final_balance_foreign_currency = 0.0 FROM sum_amounts WHERE diff --git a/account_financial_report_qweb/report/templates/general_ledger.xml b/account_financial_report_qweb/report/templates/general_ledger.xml index 9ce61218..a706181f 100644 --- a/account_financial_report_qweb/report/templates/general_ledger.xml +++ b/account_financial_report_qweb/report/templates/general_ledger.xml @@ -160,12 +160,12 @@
-
- +
+
- +
@@ -240,12 +240,12 @@
-
- +
+
- +
diff --git a/account_financial_report_qweb/report/templates/trial_balance.xml b/account_financial_report_qweb/report/templates/trial_balance.xml index 54fc9f3c..27ab6003 100644 --- a/account_financial_report_qweb/report/templates/trial_balance.xml +++ b/account_financial_report_qweb/report/templates/trial_balance.xml @@ -19,7 +19,7 @@ -
+
@@ -41,7 +41,7 @@ -
-
+
@@ -65,7 +65,7 @@ @@ -130,6 +135,19 @@
+ +
+ + +
+
+
+ + +
+
+
diff --git a/account_financial_report_qweb/report/trial_balance.py b/account_financial_report_qweb/report/trial_balance.py index 558db8ef..50e5b29c 100644 --- a/account_financial_report_qweb/report/trial_balance.py +++ b/account_financial_report_qweb/report/trial_balance.py @@ -64,9 +64,12 @@ class TrialBalanceReportAccount(models.TransientModel): name = fields.Char() initial_balance = fields.Float(digits=(16, 2)) + initial_balance_foreign_currency = fields.Float(digits=(16, 2)) debit = fields.Float(digits=(16, 2)) credit = fields.Float(digits=(16, 2)) + currency_name = fields.Char() final_balance = fields.Float(digits=(16, 2)) + final_balance_foreign_currency = fields.Float(digits=(16, 2)) # Data fields, used to browse report data partner_ids = fields.One2many( @@ -182,7 +185,10 @@ INSERT INTO initial_balance, debit, credit, - final_balance + final_balance, + currency_name, + initial_balance_foreign_currency, + final_balance_foreign_currency ) SELECT %s AS report_id, @@ -194,7 +200,10 @@ SELECT rag.initial_balance AS initial_balance, rag.final_debit - rag.initial_debit AS debit, rag.final_credit - rag.initial_credit AS credit, - rag.final_balance AS final_balance + rag.final_balance AS final_balance, + rag.currency_name AS currency_name, + rag.initial_balance_foreign_currency AS initial_balance_foreign_currency, + rag.final_balance_foreign_currency AS final_balance_foreign_currency FROM report_general_ledger_qweb_account rag WHERE