|
|
@ -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,52 +122,50 @@ 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): |
|
|
|
|
|
|
|
self.assertEqual( |
|
|
|
expected_base_debit, |
|
|
|
sum([ |
|
|
|
journal.base_debit |
|
|
|
for journal in report.report_journal_ledger_tax_line_ids |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_base_credit, |
|
|
|
sum([ |
|
|
|
journal.base_credit |
|
|
|
for journal in report.report_journal_ledger_tax_line_ids |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_tax_debit, |
|
|
|
sum([ |
|
|
|
journal.tax_debit |
|
|
|
for journal in report.report_journal_ledger_tax_line_ids |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_tax_credit, |
|
|
|
sum([ |
|
|
|
journal.tax_credit |
|
|
|
for journal in report.report_journal_ledger_tax_line_ids |
|
|
|
]) |
|
|
|
) |
|
|
|
for rec in res_data['Journal_Ledgers']: |
|
|
|
self.assertEqual( |
|
|
|
expected_base_debit, |
|
|
|
sum([ |
|
|
|
tax_line['base_debit'] |
|
|
|
for tax_line in rec['tax_lines'] |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_base_credit, |
|
|
|
sum([ |
|
|
|
tax_line['base_credit'] |
|
|
|
for tax_line in rec['tax_lines'] |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_tax_debit, |
|
|
|
sum([ |
|
|
|
tax_line['tax_debit'] |
|
|
|
for tax_line in rec['tax_lines'] |
|
|
|
]) |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
expected_tax_credit, |
|
|
|
sum([ |
|
|
|
tax_line['tax_credit'] |
|
|
|
for tax_line in rec['tax_lines'] |
|
|
|
]) |
|
|
|
) |
|
|
|
|
|
|
|
def test_01_test_total(self): |
|
|
|
today_date = Date.today() |
|
|
@ -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) |