Browse Source

[FIX] account_financial_report: Fix tests

On multi-company settings, we need to make sure we are searching and creating objects with the correct company associated.
Also take into account previously created account groups

 TT28423
pull/758/head
João Marques 4 years ago
parent
commit
919dd45c28
  1. 20
      account_financial_report/tests/test_general_ledger.py
  2. 25
      account_financial_report/tests/test_journal_ledger.py
  3. 1
      account_financial_report/tests/test_open_items.py
  4. 34
      account_financial_report/tests/test_trial_balance.py
  5. 1
      account_financial_report/tests/test_vat_report.py

20
account_financial_report/tests/test_general_ledger.py

@ -13,6 +13,7 @@ from odoo.tests import common
class TestGeneralLedgerReport(common.TransactionCase): class TestGeneralLedgerReport(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestGeneralLedgerReport, self).setUp() super(TestGeneralLedgerReport, self).setUp()
self.env.user.company_id = self.env.ref("base.main_company").id
self.before_previous_fy_year = fields.Date.from_string("2014-05-05") self.before_previous_fy_year = fields.Date.from_string("2014-05-05")
self.previous_fy_date_start = fields.Date.from_string("2015-01-01") self.previous_fy_date_start = fields.Date.from_string("2015-01-01")
self.previous_fy_date_end = fields.Date.from_string("2015-12-31") self.previous_fy_date_end = fields.Date.from_string("2015-12-31")
@ -20,10 +21,18 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.fy_date_end = fields.Date.from_string("2016-12-31") self.fy_date_end = fields.Date.from_string("2016-12-31")
self.receivable_account = self.env["account.account"].search( self.receivable_account = self.env["account.account"].search(
[("user_type_id.name", "=", "Receivable")], limit=1
[
("user_type_id.name", "=", "Receivable"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.income_account = self.env["account.account"].search( self.income_account = self.env["account.account"].search(
[("user_type_id.name", "=", "Income")], limit=1
[
("user_type_id.name", "=", "Income"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.unaffected_account = self.env["account.account"].search( self.unaffected_account = self.env["account.account"].search(
[ [
@ -31,7 +40,8 @@ class TestGeneralLedgerReport(common.TransactionCase):
"user_type_id", "user_type_id",
"=", "=",
self.env.ref("account.data_unaffected_earnings").id, self.env.ref("account.data_unaffected_earnings").id,
)
),
("company_id", "=", self.env.user.company_id.id),
], ],
limit=1, limit=1,
) )
@ -47,7 +57,9 @@ class TestGeneralLedgerReport(common.TransactionCase):
unaffected_debit=0, unaffected_debit=0,
unaffected_credit=0, unaffected_credit=0,
): ):
journal = self.env["account.journal"].search([], limit=1)
journal = self.env["account.journal"].search(
[("company_id", "=", self.env.user.company_id.id)], limit=1
)
partner = self.env.ref("base.res_partner_12") partner = self.env.ref("base.res_partner_12")
move_vals = { move_vals = {
"journal_id": journal.id, "journal_id": journal.id,

25
account_financial_report/tests/test_journal_ledger.py

@ -13,6 +13,7 @@ from odoo.tests.common import Form, TransactionCase
class TestJournalReport(TransactionCase): class TestJournalReport(TransactionCase):
def setUp(self): def setUp(self):
super(TestJournalReport, self).setUp() super(TestJournalReport, self).setUp()
self.env.user.company_id = self.env.ref("base.main_company").id
self.AccountObj = self.env["account.account"] self.AccountObj = self.env["account.account"]
self.InvoiceObj = self.env["account.move"] self.InvoiceObj = self.env["account.move"]
self.JournalObj = self.env["account.journal"] self.JournalObj = self.env["account.journal"]
@ -36,16 +37,32 @@ class TestJournalReport(TransactionCase):
self.fy_date_end = Date.to_string(today.replace(month=12, day=31)) self.fy_date_end = Date.to_string(today.replace(month=12, day=31))
self.receivable_account = self.AccountObj.search( self.receivable_account = self.AccountObj.search(
[("user_type_id.name", "=", "Receivable")], limit=1
[
("user_type_id.name", "=", "Receivable"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.income_account = self.AccountObj.search( self.income_account = self.AccountObj.search(
[("user_type_id.name", "=", "Income")], limit=1
[
("user_type_id.name", "=", "Income"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.expense_account = self.AccountObj.search( self.expense_account = self.AccountObj.search(
[("user_type_id.name", "=", "Expenses")], limit=1
[
("user_type_id.name", "=", "Expenses"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.payable_account = self.AccountObj.search( self.payable_account = self.AccountObj.search(
[("user_type_id.name", "=", "Payable")], limit=1
[
("user_type_id.name", "=", "Payable"),
("company_id", "=", self.env.user.company_id.id),
],
limit=1,
) )
self.journal_sale = self.JournalObj.create( self.journal_sale = self.JournalObj.create(

1
account_financial_report/tests/test_open_items.py

@ -7,6 +7,7 @@ from odoo.tests.common import TransactionCase
class TestOpenItems(TransactionCase): class TestOpenItems(TransactionCase):
def test_partner_filter(self): def test_partner_filter(self):
self.env.user.company_id = self.env.ref("base.main_company").id
partner_1 = self.env.ref("base.res_partner_1") partner_1 = self.env.ref("base.res_partner_1")
partner_2 = self.env.ref("base.res_partner_2") partner_2 = self.env.ref("base.res_partner_2")
partner_3 = self.env.ref("base.res_partner_3") partner_3 = self.env.ref("base.res_partner_3")

34
account_financial_report/tests/test_trial_balance.py

@ -9,7 +9,10 @@ from odoo.tests import common
class TestTrialBalanceReport(common.TransactionCase): class TestTrialBalanceReport(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestTrialBalanceReport, self).setUp() super(TestTrialBalanceReport, self).setUp()
self.env.user.company_id = self.env.ref("base.main_company").id
group_obj = self.env["account.group"] group_obj = self.env["account.group"]
# Remove previous account groups and related invoices to avoid conflicts
group_obj.search([("code_prefix_start", "in", ["1", "2", "11"])]).unlink()
self.group1 = group_obj.create({"code_prefix_start": "1", "name": "Group 1"}) self.group1 = group_obj.create({"code_prefix_start": "1", "name": "Group 1"})
self.group11 = group_obj.create( self.group11 = group_obj.create(
{"code_prefix_start": "11", "name": "Group 11", "parent_id": self.group1.id} {"code_prefix_start": "11", "name": "Group 11", "parent_id": self.group1.id}
@ -30,7 +33,8 @@ class TestTrialBalanceReport(common.TransactionCase):
"user_type_id", "user_type_id",
"=", "=",
self.env.ref("account.data_unaffected_earnings").id, self.env.ref("account.data_unaffected_earnings").id,
)
),
("company_id", "=", self.env.user.company_id.id),
], ],
limit=1, limit=1,
) )
@ -76,7 +80,8 @@ class TestTrialBalanceReport(common.TransactionCase):
"user_type_id", "user_type_id",
"=", "=",
self.env.ref("account.data_unaffected_earnings").id, self.env.ref("account.data_unaffected_earnings").id,
)
),
("company_id", "=", self.env.user.company_id.id),
], ],
limit=1, limit=1,
) )
@ -97,7 +102,9 @@ class TestTrialBalanceReport(common.TransactionCase):
unaffected_debit=0, unaffected_debit=0,
unaffected_credit=0, unaffected_credit=0,
): ):
journal = self.env["account.journal"].search([], limit=1)
journal = self.env["account.journal"].search(
[("company_id", "=", self.env.user.company_id.id)], limit=1
)
partner = self.env.ref("base.res_partner_12") partner = self.env.ref("base.res_partner_12")
move_vals = { move_vals = {
"journal_id": journal.id, "journal_id": journal.id,
@ -245,7 +252,14 @@ class TestTrialBalanceReport(common.TransactionCase):
# Make sure there's no account of type "Current Year Earnings" in the # Make sure there's no account of type "Current Year Earnings" in the
# groups - We change the code # groups - We change the code
earning_accs = self.env["account.account"].search( earning_accs = self.env["account.account"].search(
[("user_type_id", "=", self.env.ref("account.data_unaffected_earnings").id)]
[
(
"user_type_id",
"=",
self.env.ref("account.data_unaffected_earnings").id,
),
("company_id", "=", self.env.user.company_id.id),
]
) )
for acc in earning_accs: for acc in earning_accs:
if acc.code.startswith("1") or acc.code.startswith("2"): if acc.code.startswith("1") or acc.code.startswith("2"):
@ -658,7 +672,9 @@ class TestTrialBalanceReport(common.TransactionCase):
def test_04_undistributed_pl(self): def test_04_undistributed_pl(self):
# Add a P&L Move in the previous FY # Add a P&L Move in the previous FY
journal = self.env["account.journal"].search([], limit=1)
journal = self.env["account.journal"].search(
[("company_id", "=", self.env.user.company_id.id)], limit=1
)
move_vals = { move_vals = {
"journal_id": journal.id, "journal_id": journal.id,
"date": self.previous_fy_date_end, "date": self.previous_fy_date_end,
@ -710,7 +726,9 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(unaffected_lines["credit"], 0) self.assertEqual(unaffected_lines["credit"], 0)
self.assertEqual(unaffected_lines["final_balance"], -1000) self.assertEqual(unaffected_lines["final_balance"], -1000)
# Add a P&L Move to the current FY # Add a P&L Move to the current FY
journal = self.env["account.journal"].search([], limit=1)
journal = self.env["account.journal"].search(
[("company_id", "=", self.env.user.company_id.id)], limit=1
)
move_vals = { move_vals = {
"journal_id": journal.id, "journal_id": journal.id,
"date": self.date_start, "date": self.date_start,
@ -762,7 +780,9 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(unaffected_lines["credit"], 0) self.assertEqual(unaffected_lines["credit"], 0)
self.assertEqual(unaffected_lines["final_balance"], -1000) self.assertEqual(unaffected_lines["final_balance"], -1000)
# Add a Move including Unaffected Earnings to the current FY # Add a Move including Unaffected Earnings to the current FY
journal = self.env["account.journal"].search([], limit=1)
journal = self.env["account.journal"].search(
[("company_id", "=", self.env.user.company_id.id)], limit=1
)
move_vals = { move_vals = {
"journal_id": journal.id, "journal_id": journal.id,
"date": self.date_start, "date": self.date_start,

1
account_financial_report/tests/test_vat_report.py

@ -11,6 +11,7 @@ from odoo.tests import common
class TestVATReport(common.TransactionCase): class TestVATReport(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestVATReport, self).setUp() super(TestVATReport, self).setUp()
self.env.user.company_id = self.env.ref("base.main_company").id
self.date_from = time.strftime("%Y-%m-01") self.date_from = time.strftime("%Y-%m-01")
self.date_to = time.strftime("%Y-%m-28") self.date_to = time.strftime("%Y-%m-28")
self.company = self.env.ref("base.main_company") self.company = self.env.ref("base.main_company")

Loading…
Cancel
Save