Skip to content

Commit

Permalink
Merge PR #3200 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by eLBati
  • Loading branch information
OCA-git-bot committed Mar 31, 2023
2 parents 73aa198 + 6e7b901 commit 7d982a1
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ReportAccountBalanceReport(models.TransientModel):
[('profit_loss', "Profit & Loss"),
('balance_sheet', "Balance Sheet")],
)
hide_accounts_codes = fields.Boolean()
left_col_name = fields.Char()
right_col_name = fields.Char()
section_credit_ids = fields.One2many(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<div class="act_as_row lines">
<!-- Account code -->
<div class="act_as_cell left">
<t t-if="line.account_id">
<t t-if="line.account_id and not o.hide_accounts_codes">
<t t-set="res_model" t-value="'account.account'"/>
<span>
<a t-att-data-active-id="line.account_id.id"
Expand Down
3 changes: 3 additions & 0 deletions l10n_it_account_balance_report/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_balance_report
113 changes: 113 additions & 0 deletions l10n_it_account_balance_report/tests/test_balance_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2023 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import timedelta

from odoo import tests
from odoo.tests import Form


class TestBalanceReport (tests.SavepointCase):

@classmethod
def _create_invoice(cls, partner, products=None, post=False):
"""Get an invoice for `partner`, containing `products`.
If `post`, the invoice is opened.
"""
if products is None:
products = cls.env['product.product'].browse()

invoice_form = Form(cls.env['account.invoice'])
invoice_form.partner_id = partner
for product in products:
with invoice_form.invoice_line_ids.new() as line:
line.product_id = product
invoice = invoice_form.save()

if post:
invoice.action_invoice_open()
return invoice

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.customer = cls.env['res.partner'].create({
'name': "Test Customer",
'customer': True,
})

cls.product = cls.env['product.product'].create({
'name': "Test Product",
})

cls.posted_invoice = cls._create_invoice(
cls.customer,
products=cls.product,
post=True,
)

def _get_report_content(self, wizard_values):
"""Get the PDF content from the wizard created with `wizard_values`."""
# Get the Report Action from the Wizard
wiz = self.env['trial.balance.report.wizard'].create(wizard_values)
report_action = wiz.button_export_pdf()

# Get the Report from the Report Action
report_name = report_action['report_name']
context = report_action['context']
report_ids = context['active_ids']
report = self.env['ir.actions.report']._get_report_from_name(report_name)

# Render the Report
report_content, report_type = report \
.with_context(context) \
.render_qweb_pdf(report_ids)
report_content = report_content.decode()
return report_content

def test_hide_accounts_codes(self):
"""The Account Code is hidden
when `hide_accounts_codes` is enabled.
"""
# Arrange
invoice = self.posted_invoice
account = invoice.invoice_line_ids.account_id
# pre-condition: An Invoice is posted
self.assertEqual(invoice.state, 'open')

# Act: Print the Report containing the Invoice,
# enabling `hide_accounts_codes`
one_day = timedelta(days=1)
report_content = self._get_report_content({
'account_balance_report_type': 'profit_loss',
'hide_accounts_codes': True,
'date_from': invoice.date_invoice - one_day,
'date_to': invoice.date_invoice + one_day,
})

# Assert: The Account Code is hidden
self.assertNotIn(account.code, report_content)
self.assertIn(account.name, report_content)

def test_show_accounts_codes(self):
"""The Account Code is shown
when `hide_accounts_codes` is disabled (default value).
"""
# Arrange
invoice = self.posted_invoice
account = invoice.invoice_line_ids.account_id
# pre-condition: An Invoice is posted
self.assertEqual(invoice.state, 'open')

# Act: Print the Report containing the Invoice
one_day = timedelta(days=1)
report_content = self._get_report_content({
'account_balance_report_type': 'profit_loss',
'date_from': invoice.date_invoice - one_day,
'date_to': invoice.date_invoice + one_day,
})

# Assert: The Account Code is shown
self.assertIn(account.code, report_content)
self.assertIn(account.name, report_content)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ReportAccountBalanceWizard(models.TransientModel):
('balance_sheet', "Balance Sheet")],
string="Report Type"
)
hide_accounts_codes = fields.Boolean()

@api.onchange('show_partner_details')
def onchange_show_partner_details(self):
Expand Down Expand Up @@ -63,6 +64,7 @@ def prepare_report_vals(self):
return {
'account_balance_report_type': self.account_balance_report_type,
'trial_balance_id': trial_balance.id,
'hide_accounts_codes': self.hide_accounts_codes,
}

def prepare_trial_balance_vals(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<field name="target_move"
widget="radio"/>
<field name="hide_account_at_0"/>
<field name="hide_accounts_codes"/>
<field name="show_partner_details"/>
<field name="hierarchy_on" invisible="1"/>
<field name="limit_hierarchy_level"
Expand Down

0 comments on commit 7d982a1

Please sign in to comment.