Browse Source

Currency from account instead of move lines

pull/390/head
jbeficient 7 years ago
committed by Simone Rubino
parent
commit
29bd9645c3
  1. 2
      account_financial_report_qweb/__manifest__.py
  2. 68
      account_financial_report_qweb/report/general_ledger.py
  3. 12
      account_financial_report_qweb/report/templates/general_ledger.xml
  4. 24
      account_financial_report_qweb/report/templates/trial_balance.xml
  5. 13
      account_financial_report_qweb/report/trial_balance.py

2
account_financial_report_qweb/__manifest__.py

@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'QWeb Financial Reports', 'name': 'QWeb Financial Reports',
'version': '10.0.1.3.0',
'version': '10.0.1.4.0',
'category': 'Reporting', 'category': 'Reporting',
'summary': 'OCA Financial Reports', 'summary': 'OCA Financial Reports',
'author': 'Camptocamp SA,' 'author': 'Camptocamp SA,'

68
account_financial_report_qweb/report/general_ledger.py

@ -91,12 +91,11 @@ class GeneralLedgerReportAccount(models.TransientModel):
initial_debit = fields.Float(digits=(16, 2)) initial_debit = fields.Float(digits=(16, 2))
initial_credit = fields.Float(digits=(16, 2)) initial_credit = fields.Float(digits=(16, 2))
initial_balance = 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)) initial_balance_foreign_currency = fields.Float(digits=(16, 2))
final_debit = fields.Float(digits=(16, 2)) final_debit = fields.Float(digits=(16, 2))
final_credit = fields.Float(digits=(16, 2)) final_credit = fields.Float(digits=(16, 2))
final_balance = 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)) final_balance_foreign_currency = fields.Float(digits=(16, 2))
# Flag fields, used for report display and for data computation # 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_debit = fields.Float(digits=(16, 2))
initial_credit = fields.Float(digits=(16, 2)) initial_credit = fields.Float(digits=(16, 2))
initial_balance = 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)) initial_balance_foreign_currency = fields.Float(digits=(16, 2))
final_debit = fields.Float(digits=(16, 2)) final_debit = fields.Float(digits=(16, 2))
final_credit = fields.Float(digits=(16, 2)) final_credit = fields.Float(digits=(16, 2))
final_balance = 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)) final_balance_foreign_currency = fields.Float(digits=(16, 2))
# Data fields, used to browse report data # Data fields, used to browse report data
@ -280,14 +278,8 @@ class GeneralLedgerReportCompute(models.TransientModel):
SUM(ml.debit) AS debit, SUM(ml.debit) AS debit,
SUM(ml.credit) AS credit, SUM(ml.credit) AS credit,
SUM(ml.balance) AS balance, 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 FROM
accounts a accounts a
INNER JOIN INNER JOIN
@ -330,11 +322,11 @@ class GeneralLedgerReportCompute(models.TransientModel):
""" """
sub_subquery_sum_amounts += """ sub_subquery_sum_amounts += """
LEFT JOIN LEFT JOIN
res_currency c ON ml.currency_id = c.id
res_currency c ON a.currency_id = c.id
""" """
sub_subquery_sum_amounts += """ sub_subquery_sum_amounts += """
GROUP BY GROUP BY
a.id
a.id, c.name
""" """
return sub_subquery_sum_amounts return sub_subquery_sum_amounts
@ -379,7 +371,8 @@ WITH
a.name, a.name,
a.internal_type IN ('payable', 'receivable') a.internal_type IN ('payable', 'receivable')
AS is_partner_account, AS is_partner_account,
a.user_type_id
a.user_type_id,
a.currency_id
FROM FROM
account_account a account_account a
""" """
@ -445,12 +438,11 @@ INSERT INTO
initial_debit, initial_debit,
initial_credit, initial_credit,
initial_balance, initial_balance,
initial_currency_name,
currency_name,
initial_balance_foreign_currency, initial_balance_foreign_currency,
final_debit, final_debit,
final_credit, final_credit,
final_balance, final_balance,
final_currency_name,
final_balance_foreign_currency, final_balance_foreign_currency,
is_partner_account is_partner_account
) )
@ -464,12 +456,11 @@ SELECT
COALESCE(i.debit, 0.0) AS initial_debit, COALESCE(i.debit, 0.0) AS initial_debit,
COALESCE(i.credit, 0.0) AS initial_credit, COALESCE(i.credit, 0.0) AS initial_credit,
COALESCE(i.balance, 0.0) AS initial_balance, 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(i.balance_currency, 0.0) AS initial_balance_foreign_currency,
COALESCE(f.debit, 0.0) AS final_debit, COALESCE(f.debit, 0.0) AS final_debit,
COALESCE(f.credit, 0.0) AS final_credit, COALESCE(f.credit, 0.0) AS final_credit,
COALESCE(f.balance, 0.0) AS final_balance, 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, COALESCE(f.balance_currency, 0.0) AS final_balance_foreign_currency,
a.is_partner_account a.is_partner_account
FROM FROM
@ -478,6 +469,8 @@ LEFT JOIN
initial_sum_amounts i ON a.id = i.account_id initial_sum_amounts i ON a.id = i.account_id
LEFT JOIN LEFT JOIN
final_sum_amounts f ON a.id = f.account_id final_sum_amounts f ON a.id = f.account_id
LEFT JOIN
res_currency c ON c.id = a.currency_id
WHERE WHERE
( (
i.debit IS NOT NULL AND i.debit != 0 i.debit IS NOT NULL AND i.debit != 0
@ -557,16 +550,14 @@ AND
SUM(ml.debit) AS debit, SUM(ml.debit) AS debit,
SUM(ml.credit) AS credit, SUM(ml.credit) AS credit,
SUM(ml.balance) AS balance, 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 FROM
accounts_partners ap 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 INNER JOIN
account_move_line ml account_move_line ml
ON ap.account_id = ml.account_id ON ap.account_id = ml.account_id
@ -608,13 +599,9 @@ AND
ml.analytic_account_id = aa.id ml.analytic_account_id = aa.id
AND aa.id IN %s AND aa.id IN %s
""" """
sub_subquery_sum_amounts += """
LEFT JOIN
res_currency c ON ml.currency_id = c.id
"""
sub_subquery_sum_amounts += """ sub_subquery_sum_amounts += """
GROUP BY GROUP BY
ap.account_id, ap.partner_id
ap.account_id, ap.partner_id, c.name
""" """
return sub_subquery_sum_amounts return sub_subquery_sum_amounts
@ -756,12 +743,11 @@ INSERT INTO
initial_debit, initial_debit,
initial_credit, initial_credit,
initial_balance, initial_balance,
initial_currency_name,
currency_name,
initial_balance_foreign_currency, initial_balance_foreign_currency,
final_debit, final_debit,
final_credit, final_credit,
final_balance, final_balance,
final_currency_name,
final_balance_foreign_currency final_balance_foreign_currency
) )
SELECT SELECT
@ -773,12 +759,11 @@ SELECT
COALESCE(i.debit, 0.0) AS initial_debit, COALESCE(i.debit, 0.0) AS initial_debit,
COALESCE(i.credit, 0.0) AS initial_credit, COALESCE(i.credit, 0.0) AS initial_credit,
COALESCE(i.balance, 0.0) AS initial_balance, 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(i.balance_currency, 0.0) AS initial_balance_foreign_currency,
COALESCE(f.debit, 0.0) AS final_debit, COALESCE(f.debit, 0.0) AS final_debit,
COALESCE(f.credit, 0.0) AS final_credit, COALESCE(f.credit, 0.0) AS final_credit,
COALESCE(f.balance, 0.0) AS final_balance, 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 COALESCE(f.balance_currency, 0.0) AS final_balance_foreign_currency
FROM FROM
accounts_partners ap accounts_partners ap
@ -1365,7 +1350,8 @@ WHERE id = %s
code, code,
name, name,
is_partner_account, is_partner_account,
initial_balance
initial_balance,
currency_name
) )
SELECT SELECT
%s AS report_id, %s AS report_id,
@ -1375,7 +1361,8 @@ WHERE id = %s
a.code, a.code,
a.name, a.name,
False AS is_partner_account, False AS is_partner_account,
COALESCE(i.balance, 0.0) AS initial_balance
COALESCE(i.balance, 0.0) AS initial_balance,
''
FROM FROM
account_account a, account_account a,
initial_sum_amounts i initial_sum_amounts i
@ -1412,6 +1399,7 @@ WHERE id = %s
self.company_id.id, self.company_id.id,
self.unaffected_earnings_account.id, self.unaffected_earnings_account.id,
) )
self.env.cr.execute(query_inject_account, self.env.cr.execute(query_inject_account,
query_inject_account_params) query_inject_account_params)
@ -1447,7 +1435,9 @@ WHERE id = %s
initial_credit = 0.0, initial_credit = 0.0,
final_debit = sum_amounts.debit, final_debit = sum_amounts.debit,
final_credit = sum_amounts.credit, 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 FROM
sum_amounts sum_amounts
WHERE WHERE

12
account_financial_report_qweb/report/templates/general_ledger.xml

@ -160,12 +160,12 @@
<!--## balance cumulated--> <!--## balance cumulated-->
<div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance"/></div> <div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell"><span t-field="account_or_partner_object.initial_currency_name"/></div>
<t t-if="account_or_partner_object.initial_currency_name">
<div class="act_as_cell"><span t-field="account_or_partner_object.currency_name"/></div>
<t t-if="account_or_partner_object.currency_name">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance_foreign_currency"/></div> <div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance_foreign_currency"/></div>
</t> </t>
<t t-if="not account_or_partner_object.initial_currency_name">
<t t-if="not account_or_partner_object.currency_name">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell"></div> <div class="act_as_cell"></div>
</t> </t>
@ -240,12 +240,12 @@
<!--## balance cumulated--> <!--## balance cumulated-->
<div class="act_as_cell amount" style="width: 75px; padding-right: 1px;"><span t-field="account_or_partner_object.final_balance"/></div> <div class="act_as_cell amount" style="width: 75px; padding-right: 1px;"><span t-field="account_or_partner_object.final_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell" style="width: 35px;"><span t-field="account_or_partner_object.final_currency_name"/></div>
<t t-if="account_or_partner_object.final_currency_name">
<div class="act_as_cell" style="width: 35px;"><span t-field="account_or_partner_object.currency_name"/></div>
<t t-if="account_or_partner_object.currency_name">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_balance_foreign_currency"/></div> <div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_balance_foreign_currency"/></div>
</t> </t>
<t t-if="not account_or_partner_object.final_currency_name">
<t t-if="not account_or_partner_object.currency_name">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell" style="width: 75px;"/> <div class="act_as_cell" style="width: 75px;"/>
</t> </t>

24
account_financial_report_qweb/report/templates/trial_balance.xml

@ -19,7 +19,7 @@
<!-- Display account lines --> <!-- Display account lines -->
<t t-if="not show_partner_details"> <t t-if="not show_partner_details">
<div class="act_as_table data_table" style="width: 1140px !important;">
<div class="act_as_table data_table" style="width: 1325px !important;">
<!-- Display account header --> <!-- Display account header -->
<t t-call="account_financial_report_qweb.report_trial_balance_qweb_lines_header"/> <t t-call="account_financial_report_qweb.report_trial_balance_qweb_lines_header"/>
@ -41,7 +41,7 @@
<span t-field="account.code"/> - <span t-field="account.name"/> <span t-field="account.code"/> - <span t-field="account.name"/>
</div> </div>
<div class="act_as_table data_table" style="width: 1140px !important;">
<div class="act_as_table data_table" style="width: 1325px !important;">
<!-- Display account/partner header --> <!-- Display account/partner header -->
<t t-call="account_financial_report_qweb.report_trial_balance_qweb_lines_header"/> <t t-call="account_financial_report_qweb.report_trial_balance_qweb_lines_header"/>
@ -65,7 +65,7 @@
</template> </template>
<template id="account_financial_report_qweb.report_trial_balance_qweb_filters"> <template id="account_financial_report_qweb.report_trial_balance_qweb_filters">
<div class="act_as_table data_table" style="width: 1140px !important;">
<div class="act_as_table data_table" style="width: 1325px !important;">
<div class="act_as_row labels"> <div class="act_as_row labels">
<div class="act_as_cell">Date range filter</div> <div class="act_as_cell">Date range filter</div>
<div class="act_as_cell">Target moves filter</div> <div class="act_as_cell">Target moves filter</div>
@ -109,6 +109,11 @@
<div class="act_as_cell" style="width: 110px;">Credit</div> <div class="act_as_cell" style="width: 110px;">Credit</div>
<!--## Ending balance--> <!--## Ending balance-->
<div class="act_as_cell" style="width: 110px;">Ending balance</div> <div class="act_as_cell" style="width: 110px;">Ending balance</div>
<!--## currency_name-->
<div class="act_as_cell" style="width: 35px;">Cur.</div>
<!--## amount_currency-->
<div class="act_as_cell" style="width: 75px;">Initial blance cur.</div>
<div class="act_as_cell" style="width: 75px;">Ending blance cur.</div>
</div> </div>
</div> </div>
</template> </template>
@ -130,6 +135,19 @@
<div class="act_as_cell amount"><span t-field="line.credit"/></div> <div class="act_as_cell amount"><span t-field="line.credit"/></div>
<!--## Ending balance--> <!--## Ending balance-->
<div class="act_as_cell amount"><span t-field="line.final_balance"/></div> <div class="act_as_cell amount"><span t-field="line.final_balance"/></div>
<!--## currency_name-->
<div class="act_as_cell"><span t-field="line.currency_name"/></div>
<t t-if="line.currency_name">
<!--## balance_currency-->
<div class="act_as_cell amount"><span t-field="line.initial_balance_foreign_currency"/></div>
<div class="act_as_cell amount"><span
t-field="line.final_balance_foreign_currency"/></div>
</t>
<t t-if="not line.currency_name">
<!--## balance_currency-->
<div class="act_as_cell"/>
<div class="act_as_cell"/>
</t>
</div> </div>
</template> </template>

13
account_financial_report_qweb/report/trial_balance.py

@ -64,9 +64,12 @@ class TrialBalanceReportAccount(models.TransientModel):
name = fields.Char() name = fields.Char()
initial_balance = fields.Float(digits=(16, 2)) initial_balance = fields.Float(digits=(16, 2))
initial_balance_foreign_currency = fields.Float(digits=(16, 2))
debit = fields.Float(digits=(16, 2)) debit = fields.Float(digits=(16, 2))
credit = fields.Float(digits=(16, 2)) credit = fields.Float(digits=(16, 2))
currency_name = fields.Char()
final_balance = fields.Float(digits=(16, 2)) final_balance = fields.Float(digits=(16, 2))
final_balance_foreign_currency = fields.Float(digits=(16, 2))
# Data fields, used to browse report data # Data fields, used to browse report data
partner_ids = fields.One2many( partner_ids = fields.One2many(
@ -182,7 +185,10 @@ INSERT INTO
initial_balance, initial_balance,
debit, debit,
credit, credit,
final_balance
final_balance,
currency_name,
initial_balance_foreign_currency,
final_balance_foreign_currency
) )
SELECT SELECT
%s AS report_id, %s AS report_id,
@ -194,7 +200,10 @@ SELECT
rag.initial_balance AS initial_balance, rag.initial_balance AS initial_balance,
rag.final_debit - rag.initial_debit AS debit, rag.final_debit - rag.initial_debit AS debit,
rag.final_credit - rag.initial_credit AS credit, 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 FROM
report_general_ledger_qweb_account rag report_general_ledger_qweb_account rag
WHERE WHERE

Loading…
Cancel
Save