Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_cutoff_start_end_dates: Only expense cutoffs retrieve e… #314

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions account_cutoff_start_end_dates/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Contributors
* Jim Hoefnagels <jim.hoefnagels@dynapps.be>
* `Trobz <https://trobz.com>`_:
* Dzung Tran <dungtd@trobz.com>
* `Aion Tech <https://aiontech.company/>`_:
* Federico Medici <federico.medici@aion-tech.it>
* Simone Rubino <simone.rubino@aion-tech.it>

Other credits
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion account_cutoff_start_end_dates/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
"name": "Account Cut-off Start End Dates",
"version": "16.0.1.1.0",
"version": "16.0.1.1.2",
"category": "Accounting & Finance",
"license": "AGPL-3",
"summary": "Cutoffs based on start/end dates",
Expand Down
10 changes: 10 additions & 0 deletions account_cutoff_start_end_dates/models/account_cutoff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2016-2022 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2025 Federico Medici, Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
Expand Down Expand Up @@ -186,6 +187,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.state == "forecast":
if not self.start_date or not self.end_date:
Expand Down
3 changes: 3 additions & 0 deletions account_cutoff_start_end_dates/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
* Jim Hoefnagels <jim.hoefnagels@dynapps.be>
* `Trobz <https://trobz.com>`_:
* Dzung Tran <dungtd@trobz.com>
* `Aion Tech <https://aiontech.company/>`_:
* Federico Medici <federico.medici@aion-tech.it>
* Simone Rubino <simone.rubino@aion-tech.it>
5 changes: 5 additions & 0 deletions account_cutoff_start_end_dates/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<dd><ul class="first last">
<li>Dzung Tran &lt;<a class="reference external" href="mailto:dungtd&#64;trobz.com">dungtd&#64;trobz.com</a>&gt;</li>
</ul>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<li>Federico Medici &lt;<a class="reference external" href="mailto:federico.medici&#64;aion-tech.it">federico.medici&#64;aion-tech.it</a>&gt;</li>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
</ul>
</li>
</dd>
</dl>
</li>
Expand Down
121 changes: 119 additions & 2 deletions account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2014-2022 ACSONE SA/NV (http://acsone.eu)
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
# Copyright 2016-2022 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2025 Federico Medici, Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


import time
from datetime import date

from odoo import fields
from odoo.tests.common import TransactionCase
Expand Down Expand Up @@ -98,12 +100,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 @@ -145,3 +147,118 @@ 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
company = self.env.ref("base.main_company")
bank_account = self.env["account.account"].search(
[
("account_type", "=", "asset_cash"),
("company_id", "=", company.id),
],
limit=1,
)
expense_account = self.account_expense
misc_journal = self.cutoff_journal
month_day_move_date = "2025-10-31"
move_date = fields.Date.from_string(month_day_move_date)

# Create the move directly
move = self.env["account.move"].create(
{
"date": move_date,
"journal_id": misc_journal.id,
"company_id": company.id,
"move_type": "entry",
}
)

# Add lines to the move
move.write(
{
"line_ids": [
(
0,
0,
{
"account_id": expense_account.id,
"debit": 1000,
"start_date": date(move_date.year + 1, 1, 1),
"end_date": date(move_date.year + 1, 12, 31),
},
),
(
0,
0,
{
"account_id": bank_account.id,
"credit": 1000,
},
),
]
}
)

# Post the move
move.action_post()

# Create the cutoff entries, checking if they already exist
prepaid_expense_cutoff = self.env["account.cutoff"].search(
[
("cutoff_date", "=", move_date),
("company_id", "=", company.id),
("cutoff_type", "=", "prepaid_expense"),
],
limit=1,
)

cutoff_date = month_day_move_date.split("2025-")[-1]

if not prepaid_expense_cutoff:
prepaid_expense_cutoff = self._create_cutoff(
cutoff_date,
cutoff_type="prepaid_expense",
)
prepaid_expense_cutoff.source_journal_ids = misc_journal

prepaid_revenue_cutoff = self.env["account.cutoff"].search(
[
("cutoff_date", "=", month_day_move_date.split("202cutoff_date5-")[-1]),
("company_id", "=", company.id),
("cutoff_type", "=", "prepaid_revenue"),
],
limit=1,
)

if not prepaid_revenue_cutoff:
prepaid_revenue_cutoff = self._create_cutoff(
cutoff_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)
Loading