Skip to content

Commit

Permalink
[FIX] account_cutoff_dates: Only expense cutoffs retrieve expense lines
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Nov 11, 2024
1 parent 46f79d0 commit 3fd154d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
9 changes: 9 additions & 0 deletions account_cutoff_start_end_dates/models/account_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ def get_lines(self):
else:
domain.append(("parent_state", "in", ("draft", "posted")))

if self.cutoff_type in ["prepaid_expense", "accrued_expense"]:
domain += [
("account_internal_group", "=", "expense"),
]
elif self.cutoff_type in ["prepaid_revenue", "accrued_revenue"]:
domain += [
("account_internal_group", "=", "income"),
]

if self.cutoff_type in ["prepaid_expense", "prepaid_revenue"]:
if self.forecast:
domain += [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@


import time
from datetime import date

from odoo import fields
from odoo.tests.common import SavepointCase
from odoo.tests.common import Form, SavepointCase


class TestCutoffPrepaid(SavepointCase):
Expand Down Expand Up @@ -104,12 +105,12 @@ def _create_invoice(self, date, amount, start_date, end_date):
self.assertEqual(amount, invoice.amount_untaxed)
return invoice

def _create_cutoff(self, date):
def _create_cutoff(self, date, cutoff_type="prepaid_expense"):
cutoff = self.cutoff_model.create(
{
"company_id": self.env.ref("base.main_company").id,
"cutoff_date": self._date(date),
"cutoff_type": "prepaid_revenue",
"cutoff_type": cutoff_type,
"cutoff_journal_id": self.cutoff_journal.id,
"cutoff_account_id": self.account_cutoff.id,
"source_journal_ids": [(6, 0, [self.purchase_journal.id])],
Expand Down Expand Up @@ -151,3 +152,65 @@ def tests_1(self):
# two invoices, but two lines (because the two cutoff lines
# have been grouped into one line plus one counterpart)
self.assertEqual(len(cutoff.move_id.line_ids), 2)

def test_general_entry_prepaid_expense_cutoff_account(self):
"""
Create an account move on a general journal for an expense account,
only the expense cutoff should retrieve its line."""
# Arrange
bank_account = self.env["account.account"].search(
[("internal_type", "=", "liquidity")], limit=1
)
expense_account = self.account_expense
misc_journal = self.cutoff_journal
month_day_move_date = "10-31"
move_date = fields.Date.from_string(self._date(month_day_move_date))

move_form = Form(self.env["account.move"])
move_form.date = move_date
move_form.journal_id = misc_journal
with move_form.line_ids.new() as line:
line.account_id = expense_account
line.debit = 1000
line.start_date = date(move_date.year + 1, 1, 1)
line.end_date = date(move_date.year + 1, 12, 31)
with move_form.line_ids.new() as line:
line.account_id = bank_account
line.credit = 1000
move = move_form.save()
move.action_post()

prepaid_expense_cutoff = self._create_cutoff(
month_day_move_date,
cutoff_type="prepaid_expense",
)
prepaid_expense_cutoff.source_journal_ids = misc_journal

prepaid_revenue_cutoff = self._create_cutoff(
month_day_move_date,
cutoff_type="prepaid_revenue",
)
prepaid_revenue_cutoff.source_journal_ids = misc_journal

# pre-condition
expense_move_line = move.line_ids.filtered(
lambda line: line.account_id.internal_group == "expense"
)
self.assertTrue(expense_move_line)
self.assertEqual(move.journal_id.type, "general")

self.assertEqual(prepaid_expense_cutoff.cutoff_type, "prepaid_expense")
self.assertEqual(prepaid_expense_cutoff.source_journal_ids.type, "general")

self.assertEqual(prepaid_revenue_cutoff.cutoff_type, "prepaid_revenue")
self.assertEqual(prepaid_revenue_cutoff.source_journal_ids.type, "general")

# Act
prepaid_expense_cutoff.get_lines()
prepaid_revenue_cutoff.get_lines()

# Assert
self.assertEqual(
prepaid_expense_cutoff.line_ids.origin_move_line_id, expense_move_line
)
self.assertFalse(prepaid_revenue_cutoff.line_ids)

0 comments on commit 3fd154d

Please sign in to comment.