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 f8b4ac5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
3 changes: 3 additions & 0 deletions account_cutoff_base/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Contributors
* Pedro M. Baeza <[email protected]>
* Jeroen Evens <[email protected]>
* Jim Hoefnagels <[email protected]>
* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions account_cutoff_base/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
* Pedro M. Baeza <[email protected]>
* Jeroen Evens <[email protected]>
* Jim Hoefnagels <[email protected]>
* `Aion Tech <https://aiontech.company/>`_:

* Simone Rubino <[email protected]>
16 changes: 11 additions & 5 deletions account_cutoff_base/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -432,12 +432,18 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;gmail.com">pedro.baeza&#64;gmail.com</a>&gt;</li>
<li>Jeroen Evens &lt;<a class="reference external" href="mailto:jeroen.evenss&#64;dynapps.be">jeroen.evenss&#64;dynapps.be</a>&gt;</li>
<li>Jim Hoefnagels &lt;<a class="reference external" href="mailto:jim.hoefnagels&#64;dynapps.be">jim.hoefnagels&#64;dynapps.be</a>&gt;</li>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<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>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
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 f8b4ac5

Please sign in to comment.