[MIG] account_financial_report: Migration to 13.0

This commit is contained in:
Ernesto Tejeda
2020-03-23 11:15:55 -04:00
committed by chaule97
parent 40c874a112
commit 712d4a898a
39 changed files with 789 additions and 1677 deletions

View File

@@ -18,6 +18,7 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.previous_fy_date_end = fields.Date.from_string("2015-12-31")
self.fy_date_start = fields.Date.from_string("2016-01-01")
self.fy_date_end = fields.Date.from_string("2016-12-31")
self.receivable_account = self.env["account.account"].search(
[("user_type_id.name", "=", "Receivable")], limit=1
)
@@ -46,19 +47,16 @@ class TestGeneralLedgerReport(common.TransactionCase):
unaffected_debit=0,
unaffected_credit=0,
):
move_name = "expense accrual"
journal = self.env["account.journal"].search([], limit=1)
partner = self.env.ref("base.res_partner_12")
move_vals = {
"journal_id": journal.id,
"name": move_name,
"date": date,
"line_ids": [
(
0,
0,
{
"name": move_name,
"debit": receivable_debit,
"credit": receivable_credit,
"account_id": self.receivable_account.id,
@@ -69,7 +67,6 @@ class TestGeneralLedgerReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": income_debit,
"credit": income_credit,
"account_id": self.income_account.id,
@@ -80,7 +77,6 @@ class TestGeneralLedgerReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": unaffected_debit,
"credit": unaffected_credit,
"account_id": self.unaffected_account.id,
@@ -678,9 +674,7 @@ class TestGeneralLedgerReport(common.TransactionCase):
def test_validate_date(self):
company_id = self.env.ref("base.main_company")
company_id.write(
{"fiscalyear_last_day": 31, "fiscalyear_last_month": 12,}
)
company_id.write({"fiscalyear_last_day": 31, "fiscalyear_last_month": "12"})
user = self.env.ref("base.user_root").with_context(company_id=company_id.id)
wizard = self.env["general.ledger.report.wizard"].with_context(user=user.id)
self.assertEqual(wizard._init_date_from(), time.strftime("%Y") + "-01-01")

View File

@@ -7,14 +7,14 @@ from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo.fields import Date
from odoo.tests.common import TransactionCase
from odoo.tests.common import Form, TransactionCase
class TestJournalReport(TransactionCase):
def setUp(self):
super(TestJournalReport, self).setUp()
self.AccountObj = self.env["account.account"]
self.InvoiceObj = self.env["account.invoice"]
self.InvoiceObj = self.env["account.move"]
self.JournalObj = self.env["account.journal"]
self.MoveObj = self.env["account.move"]
self.TaxObj = self.env["account.tax"]
@@ -24,6 +24,8 @@ class TestJournalReport(TransactionCase):
"report.account_financial_report.journal_ledger"
]
self.company = self.env.ref("base.main_company")
self.company.account_sale_tax_id = False
self.company.account_purchase_tax_id = False
today = datetime.today()
last_year = today - relativedelta(years=1)
@@ -39,6 +41,9 @@ class TestJournalReport(TransactionCase):
self.income_account = self.AccountObj.search(
[("user_type_id.name", "=", "Income")], limit=1
)
self.expense_account = self.AccountObj.search(
[("user_type_id.name", "=", "Expenses")], limit=1
)
self.payable_account = self.AccountObj.search(
[("user_type_id.name", "=", "Payable")], limit=1
)
@@ -55,7 +60,7 @@ class TestJournalReport(TransactionCase):
{
"name": "Test journal purchase",
"code": "TST-JRNL-P",
"type": "sale",
"type": "purchase",
"company_id": self.company.id,
}
)
@@ -194,6 +199,7 @@ class TestJournalReport(TransactionCase):
"date_to": self.fy_date_end,
"company_id": self.company.id,
"journal_ids": [(6, 0, self.journal_sale.ids)],
"move_target": "all",
}
)
data = wiz._prepare_report_journal_ledger()
@@ -227,39 +233,26 @@ class TestJournalReport(TransactionCase):
self.check_report_journal_debit_credit(res_data, 300, 300)
def test_02_test_taxes_out_invoice(self):
invoice_values = {
"journal_id": self.journal_sale.id,
"partner_id": self.partner_2.id,
"type": "out_invoice",
"invoice_line_ids": [
(
0,
0,
{
"quantity": 1.0,
"price_unit": 100,
"account_id": self.receivable_account.id,
"name": "Test",
"invoice_line_tax_ids": [(6, 0, [self.tax_15_s.id])],
},
),
(
0,
0,
{
"quantity": 1.0,
"price_unit": 100,
"account_id": self.receivable_account.id,
"name": "Test",
"invoice_line_tax_ids": [
(6, 0, [self.tax_15_s.id, self.tax_20_s.id])
],
},
),
],
}
invoice = self.InvoiceObj.create(invoice_values)
invoice.action_invoice_open()
move_form = Form(
self.env["account.move"].with_context(default_type="out_invoice")
)
move_form.partner_id = self.partner_2
move_form.journal_id = self.journal_sale
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test"
line_form.quantity = 1.0
line_form.price_unit = 100
line_form.account_id = self.income_account
line_form.tax_ids.add(self.tax_15_s)
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test"
line_form.quantity = 1.0
line_form.price_unit = 100
line_form.account_id = self.income_account
line_form.tax_ids.add(self.tax_15_s)
line_form.tax_ids.add(self.tax_20_s)
invoice = move_form.save()
invoice.post()
wiz = self.JournalLedgerReportWizard.create(
{
@@ -267,6 +260,7 @@ class TestJournalReport(TransactionCase):
"date_to": self.fy_date_end,
"company_id": self.company.id,
"journal_ids": [(6, 0, self.journal_sale.ids)],
"move_target": "all",
}
)
data = wiz._prepare_report_journal_ledger()
@@ -275,46 +269,68 @@ class TestJournalReport(TransactionCase):
self.check_report_journal_debit_credit_taxes(res_data, 0, 300, 0, 50)
def test_03_test_taxes_in_invoice(self):
invoice_values = {
"journal_id": self.journal_sale.id,
"partner_id": self.partner_2.id,
"type": "in_invoice",
"invoice_line_ids": [
(
0,
0,
{
"quantity": 1.0,
"price_unit": 100,
"account_id": self.payable_account.id,
"name": "Test",
"invoice_line_tax_ids": [(6, 0, [self.tax_15_p.id])],
},
),
(
0,
0,
{
"quantity": 1.0,
"price_unit": 100,
"account_id": self.payable_account.id,
"name": "Test",
"invoice_line_tax_ids": [
(6, 0, [self.tax_15_p.id, self.tax_20_p.id])
],
},
),
],
}
invoice = self.InvoiceObj.create(invoice_values)
invoice.action_invoice_open()
# invoice_values = {
# "journal_id": self.journal_purchase.id,
# "partner_id": self.partner_2.id,
# "type": "in_invoice",
# "invoice_line_ids": [
# (
# 0,
# 0,
# {
# "quantity": 1.0,
# "price_unit": 100,
# "account_id": self.payable_account.id,
# "name": "Test",
# "tax_ids": [(6, 0, [self.tax_15_p.id])],
# },
# ),
# (
# 0,
# 0,
# {
# "quantity": 1.0,
# "price_unit": 100,
# "account_id": self.payable_account.id,
# "name": "Test",
# "tax_ids": [
# (6, 0, [self.tax_15_p.id, self.tax_20_p.id])
# ],
# },
# ),
# ],
# }
# invoice = self.InvoiceObj.create(invoice_values)
# invoice.post()
move_form = Form(
self.env["account.move"].with_context(default_type="in_invoice")
)
move_form.partner_id = self.partner_2
move_form.journal_id = self.journal_purchase
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test"
line_form.quantity = 1.0
line_form.price_unit = 100
line_form.account_id = self.expense_account
line_form.tax_ids.add(self.tax_15_p)
with move_form.invoice_line_ids.new() as line_form:
line_form.name = "test"
line_form.quantity = 1.0
line_form.price_unit = 100
line_form.account_id = self.expense_account
line_form.tax_ids.add(self.tax_15_p)
line_form.tax_ids.add(self.tax_20_p)
invoice = move_form.save()
invoice.post()
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)],
"journal_ids": [(6, 0, self.journal_purchase.ids)],
"move_target": "all",
}
)
data = wiz._prepare_report_journal_ledger()

View File

@@ -92,19 +92,16 @@ class TestTrialBalanceReport(common.TransactionCase):
unaffected_debit=0,
unaffected_credit=0,
):
move_name = "expense accrual"
journal = self.env["account.journal"].search([], limit=1)
partner = self.env.ref("base.res_partner_12")
move_vals = {
"journal_id": journal.id,
"name": move_name,
"date": date,
"line_ids": [
(
0,
0,
{
"name": move_name,
"debit": receivable_debit,
"credit": receivable_credit,
"partner_id": partner.id,
@@ -115,7 +112,6 @@ class TestTrialBalanceReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": income_debit,
"credit": income_credit,
"partner_id": partner.id,
@@ -126,7 +122,6 @@ class TestTrialBalanceReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": unaffected_debit,
"credit": unaffected_credit,
"partner_id": partner.id,
@@ -137,7 +132,6 @@ class TestTrialBalanceReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": receivable_debit,
"credit": receivable_credit,
"partner_id": partner.id,
@@ -148,7 +142,6 @@ class TestTrialBalanceReport(common.TransactionCase):
0,
0,
{
"name": move_name,
"debit": receivable_credit,
"credit": receivable_debit,
"partner_id": partner.id,
@@ -240,8 +233,8 @@ class TestTrialBalanceReport(common.TransactionCase):
return total
def test_00_account_group(self):
self.assertGreaterEqual(len(self.group1.compute_account_ids), 19)
self.assertGreaterEqual(len(self.group2.compute_account_ids), 9)
self.assertTrue(self.account100 in self.group1.compute_account_ids)
self.assertTrue(self.account200 in self.group2.compute_account_ids)
def test_01_account_balance_computed(self):
# Make sure there's no account of type "Current Year Earnings" in the
@@ -660,32 +653,20 @@ class TestTrialBalanceReport(common.TransactionCase):
def test_04_undistributed_pl(self):
# Add a P&L Move in the previous FY
move_name = "current year pl move"
journal = self.env["account.journal"].search([], limit=1)
move_vals = {
"journal_id": journal.id,
"name": move_name,
"date": self.previous_fy_date_end,
"line_ids": [
(
0,
0,
{
"name": move_name,
"debit": 0.0,
"credit": 1000.0,
"account_id": self.account300.id,
},
{"debit": 0.0, "credit": 1000.0, "account_id": self.account300.id},
),
(
0,
0,
{
"name": move_name,
"debit": 1000.0,
"credit": 0.0,
"account_id": self.account100.id,
},
{"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
),
],
}
@@ -724,32 +705,20 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(unaffected_lines["credit"], 0)
self.assertEqual(unaffected_lines["final_balance"], -1000)
# Add a P&L Move to the current FY
move_name = "current year pl move"
journal = self.env["account.journal"].search([], limit=1)
move_vals = {
"journal_id": journal.id,
"name": move_name,
"date": self.date_start,
"line_ids": [
(
0,
0,
{
"name": move_name,
"debit": 0.0,
"credit": 1000.0,
"account_id": self.account300.id,
},
{"debit": 0.0, "credit": 1000.0, "account_id": self.account300.id},
),
(
0,
0,
{
"name": move_name,
"debit": 1000.0,
"credit": 0.0,
"account_id": self.account100.id,
},
{"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
),
],
}
@@ -788,32 +757,20 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(unaffected_lines["credit"], 0)
self.assertEqual(unaffected_lines["final_balance"], -1000)
# Add a Move including Unaffected Earnings to the current FY
move_name = "current year unaffected earnings move"
journal = self.env["account.journal"].search([], limit=1)
move_vals = {
"journal_id": journal.id,
"name": move_name,
"date": self.date_start,
"line_ids": [
(
0,
0,
{
"name": move_name,
"debit": 0.0,
"credit": 1000.0,
"account_id": self.account110.id,
},
{"debit": 0.0, "credit": 1000.0, "account_id": self.account110.id},
),
(
0,
0,
{
"name": move_name,
"debit": 1000.0,
"credit": 0.0,
"account_id": self.account100.id,
},
{"debit": 1000.0, "credit": 0.0, "account_id": self.account100.id},
),
],
}

View File

@@ -45,13 +45,25 @@ class TestVATReport(common.TransactionCase):
[("type", "=", "bank"), ("company_id", "=", self.company.id)], limit=1
)
self.tax_tag_01 = self.env["account.account.tag"].create(
{"name": "Tag 01", "applicability": "taxes"}
{
"name": "Tag 01",
"applicability": "taxes",
"country_id": self.company.country_id.id,
}
)
self.tax_tag_02 = self.env["account.account.tag"].create(
{"name": "Tag 02", "applicability": "taxes"}
{
"name": "Tag 02",
"applicability": "taxes",
"country_id": self.company.country_id.id,
}
)
self.tax_tag_03 = self.env["account.account.tag"].create(
{"name": "Tag 03", "applicability": "taxes"}
{
"name": "Tag 03",
"applicability": "taxes",
"country_id": self.company.country_id.id,
}
)
self.tax_group_10 = self.env["account.tax.group"].create(
{"name": "Tax 10%", "sequence": 1}
@@ -65,11 +77,35 @@ class TestVATReport(common.TransactionCase):
"amount": 10.0,
"amount_type": "percent",
"type_tax_use": "sale",
"account_id": self.tax_account.id,
"company_id": self.company.id,
"refund_account_id": self.tax_account.id,
"tax_group_id": self.tax_group_10.id,
"tag_ids": [(6, 0, [self.tax_tag_01.id, self.tax_tag_02.id])],
"invoice_repartition_line_ids": [
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
(
0,
0,
{
"factor_percent": 100,
"repartition_type": "tax",
"account_id": self.tax_account.id,
"tag_ids": [
(6, 0, [self.tax_tag_01.id, self.tax_tag_02.id])
],
},
),
],
"refund_repartition_line_ids": [
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
(
0,
0,
{
"factor_percent": 100,
"repartition_type": "tax",
"account_id": self.tax_account.id,
},
),
],
}
)
self.tax_20 = self.env["account.tax"].create(
@@ -79,67 +115,65 @@ class TestVATReport(common.TransactionCase):
"amount": 20.0,
"amount_type": "percent",
"type_tax_use": "sale",
"tax_exigibility": "on_payment",
"account_id": self.tax_account.id,
"company_id": self.company.id,
"refund_account_id": self.tax_account.id,
"cash_basis_account_id": self.tax_account.id,
"cash_basis_transition_account_id": self.tax_account.id,
"tax_group_id": self.tax_group_20.id,
"tag_ids": [(6, 0, [self.tax_tag_02.id, self.tax_tag_03.id])],
"invoice_repartition_line_ids": [
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
(
0,
0,
{
"factor_percent": 100,
"repartition_type": "tax",
"account_id": self.tax_account.id,
"tag_ids": [
(6, 0, [self.tax_tag_02.id, self.tax_tag_03.id])
],
},
),
],
"refund_repartition_line_ids": [
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
(
0,
0,
{
"factor_percent": 100,
"repartition_type": "tax",
"account_id": self.tax_account.id,
},
),
],
}
)
invoice = self.env["account.invoice"].create(
{
"partner_id": self.env.ref("base.res_partner_2").id,
"account_id": self.receivable_account.id,
"company_id": self.company.id,
"date_invoice": time.strftime("%Y-%m-03"),
"type": "out_invoice",
}
move_form = common.Form(
self.env["account.move"].with_context(default_type="out_invoice")
)
move_form.partner_id = self.env.ref("base.res_partner_2")
move_form.invoice_date = time.strftime("%Y-%m-03")
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.env.ref("product.product_product_4")
line_form.quantity = 1.0
line_form.price_unit = 100.0
line_form.account_id = self.income_account
line_form.tax_ids.add(self.tax_10)
invoice = move_form.save()
invoice.post()
self.env["account.invoice.line"].create(
{
"product_id": self.env.ref("product.product_product_4").id,
"quantity": 1.0,
"price_unit": 100.0,
"invoice_id": invoice.id,
"name": "product",
"account_id": self.income_account.id,
"invoice_line_tax_ids": [(6, 0, [self.tax_10.id])],
}
)
invoice.compute_taxes()
invoice.action_invoice_open()
self.cbinvoice = self.env["account.invoice"].create(
{
"partner_id": self.env.ref("base.res_partner_2").id,
"account_id": self.receivable_account.id,
"company_id": self.company.id,
"date_invoice": time.strftime("%Y-%m-05"),
"type": "out_invoice",
}
)
self.env["account.invoice.line"].create(
{
"product_id": self.env.ref("product.product_product_4").id,
"quantity": 1.0,
"price_unit": 500.0,
"invoice_id": self.cbinvoice.id,
"name": "product",
"account_id": self.income_account.id,
"invoice_line_tax_ids": [(6, 0, [self.tax_20.id])],
}
)
self.cbinvoice.compute_taxes()
self.cbinvoice.action_invoice_open()
self.cbinvoice.pay_and_reconcile(
self.bank_journal.id, 300, date(date.today().year, date.today().month, 10)
move_form = common.Form(
self.env["account.move"].with_context(default_type="out_invoice")
)
move_form.partner_id = self.env.ref("base.res_partner_2")
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.env.ref("product.product_product_4")
line_form.quantity = 1.0
line_form.price_unit = 250.0
line_form.account_id = self.income_account
line_form.tax_ids.add(self.tax_20)
self.cbinvoice = move_form.save()
self.cbinvoice.post()
def _get_report_lines(self, taxgroups=False):
based_on = "taxtags"