Browse Source

Refactor account_financial_report - journal ledger

pull/639/head
Jordi Ballester Alomar 5 years ago
parent
commit
efc69cdc48
  1. 70
      account_financial_report/report/abstract_report_xlsx.py
  2. 6
      account_financial_report/report/aged_partner_balance_xlsx.py
  3. 7
      account_financial_report/report/general_ledger.py
  4. 6
      account_financial_report/report/general_ledger_xlsx.py
  5. 1162
      account_financial_report/report/journal_ledger.py
  6. 103
      account_financial_report/report/journal_ledger_xlsx.py
  7. 6
      account_financial_report/report/open_items_xlsx.py
  8. 99
      account_financial_report/report/templates/journal_ledger.xml
  9. 6
      account_financial_report/report/trial_balance_xlsx.py
  10. 6
      account_financial_report/report/vat_report_xlsx.py
  11. 26
      account_financial_report/reports.xml
  12. 171
      account_financial_report/tests/test_journal_ledger.py
  13. 60
      account_financial_report/wizard/journal_ledger_wizard.py

70
account_financial_report/report/abstract_report_xlsx.py

@ -41,7 +41,7 @@ class AbstractReportXslx(models.AbstractModel):
self._define_formats(workbook)
report_name = self._get_report_name(report)
report_name = self._get_report_name(report, data=data)
report_footer = self._get_report_footer()
filters = self._get_report_filters(report)
self.columns = self._get_report_columns(report)
@ -54,7 +54,7 @@ class AbstractReportXslx(models.AbstractModel):
self._write_filters(filters)
self._generate_report_content(workbook, report)
self._generate_report_content(workbook, report, data)
self._write_report_footer(report_footer)
@ -216,6 +216,42 @@ class AbstractReportXslx(models.AbstractModel):
)
self.row_pos += 1
def write_line_from_dict(self, line_dict):
"""Write a line on current line
"""
for col_pos, column in self.columns.items():
value = line_dict.get(column['field'], False)
cell_type = column.get('type', 'string')
if cell_type == 'string':
if (line_dict.get('account_group_id', False) and
line_dict['account_group_id']):
self.sheet.write_string(
self.row_pos, col_pos, value or '',
self.format_bold)
else:
self.sheet.write_string(
self.row_pos, col_pos, value or '')
elif cell_type == 'amount':
if line_dict.get('account_group_id', False) and \
line_dict['account_group_id']:
cell_format = self.format_amount_bold
else:
cell_format = self.format_amount
self.sheet.write_number(
self.row_pos, col_pos, float(value), cell_format
)
elif cell_type == 'amount_currency':
if line_dict.get('currency_id', False):
format_amt = self._get_currency_amt_format_dict(
line_dict)
self.sheet.write_number(
self.row_pos, col_pos, float(value), format_amt
)
elif cell_type == 'currency_name':
self.sheet.write_string(
self.row_pos, col_pos, value or '', self.format_right)
self.row_pos += 1
def write_initial_balance(self, my_object, label):
"""Write a specific initial balance line on current line
using defined columns field_initial_balance name.
@ -324,6 +360,30 @@ class AbstractReportXslx(models.AbstractModel):
format_amt.set_num_format(format_amount)
return format_amt
def _get_currency_amt_format_dict(self, line_dict):
""" Return amount format specific for each currency. """
if line_dict.get('account_group_id', False) and \
line_dict['account_group_id']:
format_amt = getattr(self, 'format_amount_bold')
field_prefix = 'format_amount_bold'
else:
format_amt = getattr(self, 'format_amount')
field_prefix = 'format_amount'
if line_dict.get('currency_id', False) and line_dict['currency_id']:
currency = self.env['res.currency'].browse(
line_dict['currency_id'])
field_name = \
'%s_%s' % (field_prefix, currency.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' * currency.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')
@ -343,20 +403,20 @@ class AbstractReportXslx(models.AbstractModel):
format_amt.set_num_format(format_amount)
return format_amt
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
"""
Allow to fetch report content to be displayed.
"""
raise NotImplementedError()
def _get_report_complete_name(self, report, prefix):
def _get_report_complete_name(self, report, prefix, data=None):
if report.company_id:
suffix = ' - %s - %s' % (
report.company_id.name, report.company_id.currency_id.name)
return prefix + suffix
return prefix
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
"""
Allow to define the report name.
Report name will be used as sheet name and as report title.

6
account_financial_report/report/aged_partner_balance_xlsx.py

@ -10,9 +10,9 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
_name = 'report.a_f_r.report_aged_partner_balance_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
report_name = _('Aged Partner Balance')
return self._get_report_complete_name(report, report_name)
return self._get_report_complete_name(report, report_name, data=data)
def _get_report_columns(self, report):
if not report.show_move_line_details:
@ -141,7 +141,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
def _get_col_pos_final_balance_label(self):
return 5
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
if not report.show_move_line_details:
# For each account
for account in report.account_ids:

7
account_financial_report/report/general_ledger.py

@ -8,7 +8,6 @@ from odoo import models, fields, api, _
class GeneralLedgerReport(models.TransientModel):
""" Here, we just define class fields.
For methods, go more bottom at this file.
The class hierarchy is :
* GeneralLedgerReport
** GeneralLedgerReportAccount
@ -699,7 +698,6 @@ AND
"""Return final subquery used to compute sum amounts on partners"""
subquery_sum_amounts = """
SELECT
sub.account_id AS account_id,
sub.partner_id AS partner_id,
@ -733,7 +731,6 @@ AND
def _inject_partner_values(self, only_empty_partner=False):
""" Inject report values for report_general_ledger_partner.
Only for "partner" accounts (payable and receivable).
"""
# pylint: disable=sql-injection
@ -1001,13 +998,10 @@ AND
only_empty_partner_line=False,
only_unaffected_earnings_account=False):
""" Inject report values for report_general_ledger_move_line.
If centralized option have been chosen,
only non centralized accounts are computed.
In function of `is_account_line` and `is_partner_line` values,
the move_line link is made either with account or either with partner.
The "only_empty_partner_line" value is used
to compute data without partner.
"""
@ -1323,7 +1317,6 @@ ORDER BY
def _inject_line_centralized_values(self):
""" Inject report values for report_general_ledger_move_line.
Only centralized accounts are computed.
"""
if self.filter_analytic_tag_ids:

6
account_financial_report/report/general_ledger_xlsx.py

@ -11,9 +11,9 @@ class GeneralLedgerXslx(models.AbstractModel):
_name = 'report.a_f_r.report_general_ledger_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
report_name = _('General Ledger')
return self._get_report_complete_name(report, report_name)
return self._get_report_complete_name(report, report_name, data=data)
def _get_report_columns(self, report):
res = {
@ -114,7 +114,7 @@ class GeneralLedgerXslx(models.AbstractModel):
def _get_col_pos_final_balance_label(self):
return 5
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
# For each account
for account in report.account_ids:
# Write account title

1162
account_financial_report/report/journal_ledger.py
File diff suppressed because it is too large
View File

103
account_financial_report/report/journal_ledger_xlsx.py

@ -10,9 +10,15 @@ class JournalLedgerXslx(models.AbstractModel):
_name = 'report.a_f_r.report_journal_ledger_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
company_id = data.get('company_id', False)
report_name = _('Journal Ledger')
return self._get_report_complete_name(report, report_name)
if company_id:
company = self.env['res.company'].browse(company_id)
suffix = ' - %s - %s' % (
company.name, company.currency_id.name)
report_name = report_name + suffix
return report_name
def _get_report_columns(self, report):
columns = [
@ -36,7 +42,7 @@ class JournalLedgerXslx(models.AbstractModel):
if report.with_account_name:
columns.append({
'header': _('Account Name'),
'field': 'account',
'field': 'account_name',
'width': 15
})
@ -74,9 +80,9 @@ class JournalLedgerXslx(models.AbstractModel):
columns += [
{
'header': _('Currency'),
'field': 'currency_id',
'type': 'many2one',
'width': 14
'field': 'currency_name',
'width': 14,
'type': 'currency_name',
},
{
'header': _('Amount Currency'),
@ -181,51 +187,61 @@ class JournalLedgerXslx(models.AbstractModel):
_('Journals'),
', '.join([
"%s - %s" % (report_journal.code, report_journal.name)
for report_journal in report.report_journal_ledger_ids
for report_journal in report.journal_ids
])
]
]
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
res_data = self.env[
'report.account_financial_report.journal_ledger'
].get_report_values(report, data)
group_option = report.group_option
if group_option == 'journal':
for report_journal in report.report_journal_ledger_ids:
self._generate_journal_content(workbook, report_journal)
for ledger in res_data['Journal_Ledgers']:
self._generate_journal_content(workbook, report, res_data,
ledger)
elif group_option == 'none':
self._generate_no_group_content(workbook, report)
self._generate_no_group_content(workbook, report,
res_data)
def _generate_no_group_content(self, workbook, report):
def _generate_no_group_content(self, workbook, report, res_data):
self._generate_moves_content(
workbook, report, "Report", report.report_move_ids)
self._generate_no_group_taxes_summary(workbook, report)
workbook, "Report", report, res_data, res_data['Moves'])
self._generate_no_group_taxes_summary(workbook, report, res_data)
def _generate_journal_content(self, workbook, report_journal):
def _generate_journal_content(self, workbook, report, res_data, ledger):
journal = self.env['account.journal'].browse(ledger['id'])
currency_name = journal.currency_id and journal.currency_id.name or \
journal.company_id.currency_id.name
sheet_name = "%s (%s) - %s" % (
report_journal.code,
report_journal.currency_id.name,
report_journal.name,
journal.code,
currency_name,
journal.name,
)
self._generate_moves_content(
workbook, report_journal.report_id, sheet_name,
report_journal.report_move_ids)
self._generate_journal_taxes_summary(workbook, report_journal)
workbook, sheet_name, report, res_data, ledger['report_moves'])
self._generate_journal_taxes_summary(workbook, ledger)
def _generate_no_group_taxes_summary(self, workbook, report):
def _generate_no_group_taxes_summary(self, workbook, report, res_data):
self._generate_taxes_summary(
workbook, report, "Tax Report", report.report_tax_line_ids)
workbook, "Tax Report", res_data['tax_line_data'])
def _generate_journal_taxes_summary(self, workbook, report_journal):
def _generate_journal_taxes_summary(self, workbook, ledger):
journal = self.env['account.journal'].browse(ledger['id'])
currency_name = journal.currency_id and journal.currency_id.name or \
journal.company_id.currency_id.name
sheet_name = "Tax - %s (%s) - %s" % (
report_journal.code,
report_journal.currency_id.name,
report_journal.name,
journal.code,
currency_name,
journal.name,
)
report = report_journal.report_id
self._generate_taxes_summary(
workbook, report, sheet_name, report_journal.report_tax_line_ids)
workbook, sheet_name, ledger['tax_lines'])
def _generate_moves_content(self, workbook, report, sheet_name, moves):
def _generate_moves_content(self, workbook, sheet_name, report, res_data,
moves):
self.workbook = workbook
self.sheet = workbook.add_worksheet(sheet_name)
self._set_column_width()
@ -236,12 +252,33 @@ class JournalLedgerXslx(models.AbstractModel):
self.row_pos += 2
self.write_array_header()
account_ids_data = res_data['account_ids_data']
currency_ids_data = res_data['currency_ids_data']
move_ids_data = res_data['move_ids_data']
for move in moves:
for line in move.report_move_line_ids:
self.write_line(line)
for line in move['report_move_lines']:
currency_data = currency_ids_data.get(
line['currency_id'], False)
currency_name = currency_data and currency_data['name'] or ''
account_data = account_ids_data.get(line['account_id'], False)
account_name = account_data and account_data['name'] or ''
account_code = account_data and account_data['code'] or ''
move_data = move_ids_data.get(line['move_id'], False)
move_entry = move_data and move_data['entry'] or ''
line['account_code'] = account_code
line['account_name'] = account_name
line['currency_name'] = currency_name
line['entry'] = move_entry
line['taxes_description'] = \
report._get_ml_tax_description(
line, res_data['tax_line_data'].get(
line['tax_line_id']),
res_data['move_line_ids_taxes_data'].get(
line['move_line_id'], False))
self.write_line_from_dict(line)
self.row_pos += 1
def _generate_taxes_summary(self, workbook, report, sheet_name, tax_lines):
def _generate_taxes_summary(self, workbook, sheet_name, tax_lines_dict):
self.workbook = workbook
self.sheet = workbook.add_worksheet(sheet_name)

6
account_financial_report/report/open_items_xlsx.py

@ -9,9 +9,9 @@ class OpenItemsXslx(models.AbstractModel):
_name = 'report.a_f_r.report_open_items_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
report_name = _('Open Items')
return self._get_report_complete_name(report, report_name)
return self._get_report_complete_name(report, report_name, data=data)
def _get_report_columns(self, report):
res = {
@ -77,7 +77,7 @@ class OpenItemsXslx(models.AbstractModel):
def _get_col_pos_final_balance_label(self):
return 5
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
# For each account
for account in report.account_ids:
# Write account title

99
account_financial_report/report/templates/journal_ledger.xml

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="report_journal_ledger_qweb">
<template id="journal_ledger">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="account_financial_report.internal_layout">
@ -12,23 +15,23 @@
</template>
<template id="report_journal_ledger_base">
<t t-set="display_currency" t-value="o.foreign_currency"/>
<t t-set="display_account_name" t-value="o.with_account_name"/>
<t t-set="title">Journal Ledger - <t t-raw="o.company_id.name"/> - <t t-raw="o.company_id.currency_id.name"/></t>
<t t-set="company_name" t-value="o.company_id.name"/>
<t t-set="display_currency" t-value="foreign_currency"/>
<t t-set="display_account_name" t-value="with_account_name"/>
<t t-set="title">Journal Ledger - <t t-raw="company_name"/> - <t t-raw="currency_name"/></t>
<t t-set="company_name" t-value="Company_Name"/>
<div class="page">
<div class="row">
<h4 class="mt0" t-esc="title or 'Odoo Report'" style="text-align: center;"/>
</div>
<t t-if="o.group_option == 'none'">
<t t-if="group_option == 'none'">
<div class="page_break">
<t t-call="account_financial_report.report_journal_all"/>
<br/>
<t t-call="account_financial_report.report_journal_all_taxes"/>
</div>
</t>
<t t-if="o.group_option == 'journal'">
<t t-foreach="o.report_journal_ledger_ids" t-as="journal">
<t t-if="group_option == 'journal'">
<t t-foreach="Journal_Ledgers" t-as="journal">
<div class="page_break">
<t t-call="account_financial_report.report_journal_ledger_journal"/>
<br/>
@ -44,7 +47,7 @@
<div class="act_as_table list_table" style="margin-top: 10px;"/>
<div class="act_as_table data_table" style="width: 100%;">
<t t-call="account_financial_report.report_journal_ledger_journal_table_header"/>
<t t-foreach="o.report_move_ids" t-as="move">
<t t-foreach="Moves" t-as="move">
<t t-call="account_financial_report.report_journal_move"/>
</t>
</div>
@ -53,13 +56,13 @@
<template id="account_financial_report.report_journal_ledger_journal">
<div class="act_as_table list_table" style="margin-top: 10px;"/>
<div class="act_as_caption account_title" style="width: 100%;">
<span t-field="journal.name"/> (<span t-field="journal.currency_id.display_name"/>) - <span t-field="o.date_from"/> to <span t-field="o.date_to"/> - <span t-field="o.move_target"/> Moves
<span t-esc="journal['name']"/> (<span t-esc="journal['currency_name']"/>) - <span t-esc="date_from" t-options="{'widget': 'date'}"/> to <span t-esc="date_to" t-options="{'widget': 'date'}"/> - <span t-esc="move_target"/> Moves
</div>
<div class="act_as_table data_table" style="width: 100%;">
<t t-call="account_financial_report.report_journal_ledger_journal_table_header"/>
<t t-call="account_financial_report.report_journal_ledger_journal_first_line"/>
<t t-foreach="journal.report_move_ids" t-as="move">
<t t-foreach="journal['report_moves']" t-as="move">
<t t-call="account_financial_report.report_journal_move"/>
</t>
</div>
@ -155,11 +158,11 @@
name="taxes"/>
<div class="act_as_cell amount"
name="debit">
<b><span t-field="journal.debit"/></b>
<b><span t-esc="journal['debit']" t-options="{'widget': 'float', 'precision': 2}"/></b>
</div>
<div class="act_as_cell amount"
name="credit">
<b><span t-field="journal.credit"/></b>
<b><span t-esc="journal['credit']" t-options="{'widget': 'float', 'precision': 2}"/></b>
</div>
<t t-if="display_currency">
<div class="act_as_cell"
@ -177,9 +180,9 @@
<t t-set="display_move_info" t-value="True"/>
<t t-set="last_partner" t-eval="None"/>
<t t-set="display_partner" t-eval="True"/>
<t t-foreach="move.report_move_line_ids" t-as="move_line">
<t t-foreach="move['report_move_lines']" t-as="move_line">
<div class="act_as_row lines">
<t t-set="current_partner" t-value="move_line.partner_id"/>
<t t-set="current_partner" t-value="o._get_partner_name(move_line['partner_id'], partner_ids_data)"/>
<t t-set="display_partner" t-value="current_partner != last_partner"/>
<t t-call="account_financial_report.report_journal_move_line"/>
<t t-set="last_partner" t-value="current_partner"/>
@ -191,54 +194,54 @@
<template id="account_financial_report.report_journal_move_line">
<div class="act_as_cell left"
name="entry">
<span t-if="display_move_info" t-field="move_line.entry"/>
<span t-if="display_move_info" t-esc="move_ids_data[move_line['move_id']]['entry']"/>
</div>
<div class="act_as_cell left"
name="date">
<span t-if="display_move_info" t-field="move_line.date"/>
<span t-if="display_move_info" t-esc="move_line['date']" t-options="{'widget': 'date'}"/>
</div>
<div class="act_as_cell left"
name="account">
<span t-field="move_line.account_code"/>
<span t-esc="account_ids_data[move_line['account_id']]['code']"/>
<span t-if="display_account_name">
- <span t-field="move_line.account"/>
- <span t-esc="account_ids_data[move_line['account_id']]['name']"/>
</span>
</div>
<div class="act_as_cell left"
name="partner">
<span t-if="display_partner" t-field="move_line.partner"/>
<span t-if="display_partner" t-esc="o._get_partner_name(move_line['partner_id'], partner_ids_data)"/>
</div>
<div class="act_as_cell left"
name="label">
<span t-field="move_line.label"/>
<span t-esc="move_line['label']"/>
</div>
<div class="act_as_cell left"
name="taxes">
<span t-field="move_line.taxes_description"/>
<span t-esc="o._get_ml_tax_description(move_line, tax_line_data.get(move_line['tax_line_id'], False), move_line_ids_taxes_data.get(move_line['move_line_id'], False))"/>
</div>
<div class="act_as_cell amount"
name="debit">
<t t-if="move_line.debit">
<span t-field="move_line.debit"/>
<t t-if="move_line['debit']">
<span t-esc="move_line['debit']" t-options="{'widget': 'float', 'precision': 2}"/>
</t>
</div>
<div class="act_as_cell amount"
name="credit">
<t t-if="move_line.credit">
<span t-field="move_line.credit"/>
<t t-if="move_line['credit']">
<span t-esc="move_line['credit']" t-options="{'widget': 'float', 'precision': 2}"/>
</t>
</div>
<t t-if="display_currency">
<div class="act_as_cell"
name="currency_name">
<t t-if="move_line.currency_name">
<span t-field="move_line.currency_name"/>
<t t-if="move_line['currency_id']">
<span t-esc="currency_ids_data.get(move_line['currency_id'], '')"/>
</t>
</div>
<div class="act_as_cell amount"
name="amount_currency">
<t t-if="move_line.amount_currency">
<span t-field="move_line.amount_currency"/>
<t t-if="move_line['amount_currency']" t-options="{'widget': 'float', 'precision': 2}">
<span t-esc="move_line['amount_currency']" t-options="{'widget': 'float', 'precision': 2}"/>
</t>
</div>
</t>
@ -314,39 +317,39 @@
</div>
</div>
<t t-foreach="journal.report_tax_line_ids" t-as="tax_line">
<t t-foreach="journal['tax_lines']" t-as="tax_line">
<div class="act_as_row lines">
<div class="act_as_cell left"
name="tax_name">
<span t-field="tax_line.tax_name"/>
<span t-esc="tax_line['tax_name']"/>
</div>
<div class="act_as_cell left"
name="tax_code">
<span t-field="tax_line.tax_code"/>
<span t-esc="tax_line['tax_code']"/>
</div>
<div class="act_as_cell amount"
name="base_debit">
<span t-field="tax_line.base_debit"/>
<span t-esc="tax_line['base_debit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="base_credit">
<span t-field="tax_line.base_credit"/>
<span t-esc="tax_line['base_credit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="base_balance">
<span t-field="tax_line.base_balance"/>
<span t-esc="tax_line['base_balance']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_debit">
<span t-field="tax_line.tax_debit"/>
<span t-esc="tax_line['tax_debit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_credit">
<span t-field="tax_line.tax_credit"/>
<span t-esc="tax_line['tax_credit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_balance">
<span t-field="tax_line.tax_balance"/>
<span t-esc="tax_line['tax_balance']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
</div>
</t>
@ -423,39 +426,39 @@
</div>
</div>
<t t-foreach="o.report_tax_line_ids" t-as="tax_line">
<t t-foreach="ReportTaxLines" t-as="tax_line">
<div class="act_as_row lines">
<div class="act_as_cell left"
name="tax_name">
<span t-field="tax_line.tax_name"/>
<span t-esc="tax_line['tax_name']"/>
</div>
<div class="act_as_cell left"
name="tax_code">
<span t-field="tax_line.tax_code"/>
<span t-esc="tax_line['tax_code']"/>
</div>
<div class="act_as_cell amount"
name="base_debit">
<span t-field="tax_line.base_debit"/>
<span t-esc="tax_line['base_debit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="base_credit">
<span t-field="tax_line.base_credit"/>
<span t-esc="tax_line['base_credit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="base_balance">
<span t-field="tax_line.base_balance"/>
<span t-esc="tax_line['base_balance']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_debit">
<span t-field="tax_line.tax_debit"/>
<span t-esc="tax_line['tax_debit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_credit">
<span t-field="tax_line.tax_credit"/>
<span t-esc="tax_line['tax_credit']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
<div class="act_as_cell amount"
name="tax_balance">
<span t-field="tax_line.tax_balance"/>
<span t-esc="tax_line['tax_balance']" t-options="{'widget': 'float', 'precision': 2}"/>
</div>
</div>
</t>

6
account_financial_report/report/trial_balance_xlsx.py

@ -10,9 +10,9 @@ class TrialBalanceXslx(models.AbstractModel):
_name = 'report.a_f_r.report_trial_balance_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
report_name = _('Trial Balance')
return self._get_report_complete_name(report, report_name)
return self._get_report_complete_name(report, report_name, data=data)
def _get_report_columns(self, report):
if not report.show_partner_details:
@ -121,7 +121,7 @@ class TrialBalanceXslx(models.AbstractModel):
def _get_col_count_filter_value(self):
return 3
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
if not report.show_partner_details:
# Display array header for account lines

6
account_financial_report/report/vat_report_xlsx.py

@ -8,9 +8,9 @@ class VATReportXslx(models.AbstractModel):
_name = 'report.a_f_r.report_vat_report_xlsx'
_inherit = 'report.account_financial_report.abstract_report_xlsx'
def _get_report_name(self, report):
def _get_report_name(self, report, data=False):
report_name = _('VAT Report')
return self._get_report_complete_name(report, report_name)
return self._get_report_complete_name(report, report_name, data=data)
def _get_report_columns(self, report):
return {
@ -39,7 +39,7 @@ class VATReportXslx(models.AbstractModel):
def _get_col_count_filter_value(self):
return 2
def _generate_report_content(self, workbook, report):
def _generate_report_content(self, workbook, report, data):
# For each taxtag
self.write_array_header()
for taxtag in report.taxtags_ids:

26
account_financial_report/reports.xml

@ -22,21 +22,21 @@
/>
<!-- Journal Ledger -->
<report
id="action_report_journal_ledger_qweb"
model="report_journal_ledger"
string="Journal Ledger"
<report id="action_print_journal_ledger_wizard_qweb"
model="journal.ledger.report.wizard"
report_type="qweb-pdf"
name="account_financial_report.report_journal_ledger_qweb"
file="account_financial_report.report_journal_ledger_qweb"
/>
<report
id="action_report_journal_ledger_html"
model="report_journal_ledger"
menu="False"
string="Journal Ledger"
name="account_financial_report.journal_ledger"
file="account_financial_report.journal_ledger"
/>
<report id="action_print_journal_ledger_wizard_html"
model="journal.ledger.report.wizard"
report_type="qweb-html"
name="account_financial_report.report_journal_ledger_qweb"
file="account_financial_report.report_journal_ledger_html"
menu="False"
string="Journal Ledger"
name="account_financial_report.journal_ledger"
file="account_financial_report.journal_ledger"
/>
<!-- Trial Balance -->
@ -164,7 +164,7 @@
<record id="action_report_journal_ledger_xlsx" model="ir.actions.report">
<field name="name">Journal Ledger XLSX</field>
<field name="model">report_journal_ledger</field>
<field name="model">journal.ledger.report.wizard</field>
<field name="type">ir.actions.report</field>
<field name="report_name">a_f_r.report_journal_ledger_xlsx</field>
<field name="report_type">xlsx</field>

171
account_financial_report/tests/test_journal_ledger.py

@ -1,85 +1,13 @@
# Copyright 2017 ACSONE SA/NV
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.fields import Date
from odoo.tests.common import TransactionCase
from . import abstract_test_foreign_currency as a_t_f_c
class TestJournalLedger(a_t_f_c.AbstractTestForeignCurrency):
"""
Technical tests for General Ledger Report.
"""
def _getReportModel(self):
return self.env['report_journal_ledger']
def _getQwebReportName(self):
return 'account_financial_report.report_journal_ledger_qweb'
def _getXlsxReportName(self):
return 'a_f_r.report_journal_ledger_xlsx'
def _getXlsxReportActionName(self):
return 'account_financial_report.' \
'action_report_journal_ledger_xlsx'
def _getReportTitle(self):
return 'Odoo'
def _getBaseFilters(self):
return {
'date_from': time.strftime('%Y-01-01'),
'date_to': time.strftime('%Y-12-31'),
'company_id': self.company.id,
'journal_ids': [(6, 0, self.journal_sale.ids)]
}
def _getAdditionalFiltersToBeTested(self):
return [
{'move_target': "All",
'sort_option': "Date",
'group_option': "Journal",
'with_account_name': True,
'foreign_currency': True},
]
def test_02_generation_report_html(self):
"""Check if report HTML is correctly generated"""
# Check if returned report action is correct
report_type = 'qweb-html'
report_action = self.report.print_report(report_type)
self.assertDictContainsSubset(
{
'type': 'ir.actions.report',
'report_name': self.qweb_report_name,
'report_type': 'qweb-html',
},
report_action
)
# Check if report template is correct
report = self.env['ir.actions.report'].search(
[('report_name', '=', self.qweb_report_name),
('report_type', '=', report_type)], limit=1)
self.assertEqual(report.report_type, 'qweb-html')
rep = report.render(self.report.ids, {})
self.assertTrue(self.report_title.encode('utf8') in rep[0])
self.assertTrue(
self.report.journal_ids[0].name.encode('utf8') in rep[0]
)
def test_04_compute_data(self):
return True
class TestJournalReport(TransactionCase):
@ -88,11 +16,12 @@ class TestJournalReport(TransactionCase):
self.AccountObj = self.env['account.account']
self.InvoiceObj = self.env['account.invoice']
self.JournalObj = self.env['account.journal']
self.JournalReportObj = self.env['journal.ledger.report.wizard']
self.MoveObj = self.env['account.move']
self.ReportJournalLedger = self.env['report_journal_ledger']
self.TaxObj = self.env['account.tax']
self.JournalLedgerReportWizard = self.env[
'journal.ledger.report.wizard']
self.JournalLedgerReport = \
self.env['report.account_financial_report.journal_ledger']
self.company = self.env.ref('base.main_company')
today = datetime.today()
@ -193,50 +122,48 @@ class TestJournalReport(TransactionCase):
return self.MoveObj.create(move_vals)
def check_report_journal_debit_credit(
self, report, expected_debit, expected_credit):
self, res_data, expected_debit, expected_credit):
self.assertEqual(
expected_debit,
sum([journal.debit for journal in
report.report_journal_ledger_ids])
sum([rec['debit'] for rec in res_data['Journal_Ledgers']])
)
self.assertEqual(
expected_credit,
sum([journal.credit for journal in
report.report_journal_ledger_ids])
sum([rec['credit'] for rec in res_data['Journal_Ledgers']])
)
def check_report_journal_debit_credit_taxes(
self, report,
self, res_data,
expected_base_debit, expected_base_credit,
expected_tax_debit, expected_tax_credit):
for rec in res_data['Journal_Ledgers']:
self.assertEqual(
expected_base_debit,
sum([
journal.base_debit
for journal in report.report_journal_ledger_tax_line_ids
tax_line['base_debit']
for tax_line in rec['tax_lines']
])
)
self.assertEqual(
expected_base_credit,
sum([
journal.base_credit
for journal in report.report_journal_ledger_tax_line_ids
tax_line['base_credit']
for tax_line in rec['tax_lines']
])
)
self.assertEqual(
expected_tax_debit,
sum([
journal.tax_debit
for journal in report.report_journal_ledger_tax_line_ids
tax_line['tax_debit']
for tax_line in rec['tax_lines']
])
)
self.assertEqual(
expected_tax_credit,
sum([
journal.tax_credit
for journal in report.report_journal_ledger_tax_line_ids
tax_line['tax_credit']
for tax_line in rec['tax_lines']
])
)
@ -251,43 +178,41 @@ class TestJournalReport(TransactionCase):
move2 = self._add_move(
last_year_date, self.journal_sale,
0, 100, 100, 0)
report = self.ReportJournalLedger.create({
wiz = self.JournalLedgerReportWizard.create({
'date_from': self.fy_date_start,
'date_to': self.fy_date_end,
'company_id': self.company.id,
'journal_ids': [(6, 0, self.journal_sale.ids)]
})
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 100, 100)
data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 100, 100)
move3 = self._add_move(
today_date, self.journal_sale,
0, 100, 100, 0)
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 200, 200)
report.move_target = 'posted'
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 0, 0)
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 200, 200)
wiz.move_target = 'posted'
data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 0, 0)
move1.post()
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 100, 100)
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 100, 100)
move2.post()
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 100, 100)
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 100, 100)
move3.post()
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 200, 200)
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 200, 200)
report.date_from = self.previous_fy_date_start
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 300, 300)
wiz.date_from = self.previous_fy_date_start
data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 300, 300)
def test_02_test_taxes_out_invoice(self):
invoice_values = {
@ -315,17 +240,16 @@ class TestJournalReport(TransactionCase):
}
invoice = self.InvoiceObj.create(invoice_values)
invoice.action_invoice_open()
report = self.ReportJournalLedger.create({
wiz = self.JournalLedgerReportWizard.create({
'date_from': self.fy_date_start,
'date_to': self.fy_date_end,
'company_id': self.company.id,
'journal_ids': [(6, 0, self.journal_sale.ids)]
})
report.compute_data_for_report()
self.check_report_journal_debit_credit(report, 250, 250)
self.check_report_journal_debit_credit_taxes(report, 0, 300, 0, 50)
data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(res_data, 250, 250)
self.check_report_journal_debit_credit_taxes(res_data, 0, 300, 0, 50)
def test_03_test_taxes_in_invoice(self):
invoice_values = {
@ -354,13 +278,14 @@ class TestJournalReport(TransactionCase):
invoice = self.InvoiceObj.create(invoice_values)
invoice.action_invoice_open()
report = self.ReportJournalLedger.create({
wiz = self.JournalLedgerReportWizard.create({
'date_from': self.fy_date_start,
'date_to': self.fy_date_end,
'company_id': self.company.id,
'journal_ids': [(6, 0, self.journal_sale.ids)]
})
report.compute_data_for_report()
data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport.get_report_values(wiz, data)
self.check_report_journal_debit_credit(report, 250, 250)
self.check_report_journal_debit_credit_taxes(report, 300, 0, 50, 0)
self.check_report_journal_debit_credit(res_data, 250, 250)
self.check_report_journal_debit_credit_taxes(res_data, 300, 0, 50, 0)

60
account_financial_report/wizard/journal_ledger_wizard.py

@ -1,9 +1,8 @@
# Copyright 2017 ACSONE SA/NV
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo.tools.safe_eval import safe_eval
from odoo.tools import pycompat
class JournalLedgerReportWizard(models.TransientModel):
@ -102,22 +101,24 @@ class JournalLedgerReportWizard(models.TransientModel):
('company_id', '=', self.company_id.id)]
return res
@api.multi
def _print_report(self, report_type):
self.ensure_one()
data = self._prepare_report_journal_ledger()
if report_type == 'xlsx':
report_name = 'a_f_r.report_journal_ledger_xlsx'
else:
report_name = 'account_financial_report.journal_ledger'
return self.env['ir.actions.report'].search(
[('report_name', '=', report_name),
('report_type', '=', report_type)], limit=1).report_action(
self, data=data)
@api.multi
def button_export_html(self):
self.ensure_one()
action = self.env.ref(
'account_financial_report.action_report_journal_ledger')
vals = action.read()[0]
context1 = vals.get('context', {})
if isinstance(context1, pycompat.string_types):
context1 = safe_eval(context1)
model = self.env['report_journal_ledger']
report = model.create(self._prepare_report_journal_ledger())
report.compute_data_for_report()
context1['active_id'] = report.id
context1['active_ids'] = report.ids
vals['context'] = context1
return vals
report_type = 'qweb-html'
return self._export(report_type)
@api.multi
def button_export_pdf(self):
@ -140,12 +141,13 @@ class JournalLedgerReportWizard(models.TransientModel):
journals = self.env['account.journal'].search(
[('company_id', '=', self.company_id.id)])
return {
'wizard_id': self.id,
'date_from': self.date_from,
'date_to': self.date_to,
'move_target': self.move_target,
'foreign_currency': self.foreign_currency,
'company_id': self.company_id.id,
'journal_ids': [(6, 0, journals.ids)],
'journal_ids': journals.ids,
'sort_option': self.sort_option,
'group_option': self.group_option,
'with_account_name': self.with_account_name,
@ -154,7 +156,25 @@ class JournalLedgerReportWizard(models.TransientModel):
def _export(self, report_type):
"""Default export is PDF."""
self.ensure_one()
model = self.env['report_journal_ledger']
report = model.create(self._prepare_report_journal_ledger())
report.compute_data_for_report()
return report.print_report(report_type)
return self._print_report(report_type)
def _get_ml_tax_description(
self, move_line_data, tax_line_data, move_line_taxes_data):
taxes_description = ''
if move_line_data['tax_line_id']:
taxes_description = tax_line_data['description'] or \
tax_line_data['name']
elif move_line_taxes_data:
tax_names = []
for tax_key in move_line_taxes_data:
tax = move_line_taxes_data[tax_key]
tax_names.append(
tax['description'] or tax['name'])
taxes_description = ','.join(tax_names)
return taxes_description
def _get_partner_name(self, partner_id, partner_data):
if partner_id in partner_data.keys():
return partner_data[partner_id]['name']
else:
return ''
Loading…
Cancel
Save