From 37bd924fb39b77ae67f80eae73d98e91216908f6 Mon Sep 17 00:00:00 2001 From: Guidomadormo <68272608+Guidomadormo@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:56:40 +0100 Subject: [PATCH 1/2] [FIX] account_cutoff_start_end_dates: Only expense cutoffs retrieve expense lines --- account_cutoff_start_end_dates/README.rst | 3 + .../__manifest__.py | 2 +- .../models/account_cutoff.py | 10 +++ .../readme/CONTRIBUTORS.rst | 3 + .../static/description/index.html | 5 ++ .../tests/test_account_cutoff_prepaid.py | 75 ++++++++++++++++++- 6 files changed, 94 insertions(+), 4 deletions(-) diff --git a/account_cutoff_start_end_dates/README.rst b/account_cutoff_start_end_dates/README.rst index 63abb379bbf..07fd3a9b4ce 100644 --- a/account_cutoff_start_end_dates/README.rst +++ b/account_cutoff_start_end_dates/README.rst @@ -99,6 +99,9 @@ Contributors * Jim Hoefnagels * `Trobz `_: * Dzung Tran +* `Aion Tech `_: + * Federico Medici + * Simone Rubino Other credits ~~~~~~~~~~~~~ diff --git a/account_cutoff_start_end_dates/__manifest__.py b/account_cutoff_start_end_dates/__manifest__.py index ed7835b6528..e888b276ae5 100644 --- a/account_cutoff_start_end_dates/__manifest__.py +++ b/account_cutoff_start_end_dates/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Cut-off Start End Dates", - "version": "16.0.1.1.0", + "version": "16.0.1.1.1", "category": "Accounting & Finance", "license": "AGPL-3", "summary": "Cutoffs based on start/end dates", diff --git a/account_cutoff_start_end_dates/models/account_cutoff.py b/account_cutoff_start_end_dates/models/account_cutoff.py index 7e706f56427..fa5b425f0f8 100644 --- a/account_cutoff_start_end_dates/models/account_cutoff.py +++ b/account_cutoff_start_end_dates/models/account_cutoff.py @@ -1,5 +1,6 @@ # Copyright 2016-2022 Akretion France # @author: Alexis de Lattre +# 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 @@ -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: diff --git a/account_cutoff_start_end_dates/readme/CONTRIBUTORS.rst b/account_cutoff_start_end_dates/readme/CONTRIBUTORS.rst index 6f95cf77696..0be532304a8 100644 --- a/account_cutoff_start_end_dates/readme/CONTRIBUTORS.rst +++ b/account_cutoff_start_end_dates/readme/CONTRIBUTORS.rst @@ -3,3 +3,6 @@ * Jim Hoefnagels * `Trobz `_: * Dzung Tran +* `Aion Tech `_: + * Federico Medici + * Simone Rubino diff --git a/account_cutoff_start_end_dates/static/description/index.html b/account_cutoff_start_end_dates/static/description/index.html index 40604a2741d..4c3d796bcc0 100644 --- a/account_cutoff_start_end_dates/static/description/index.html +++ b/account_cutoff_start_end_dates/static/description/index.html @@ -446,6 +446,11 @@

Contributors

+
  • Aion Tech: +
  • diff --git a/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py b/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py index a941d1a204f..f5ae3f62316 100644 --- a/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py +++ b/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py @@ -1,13 +1,15 @@ # Copyright 2014-2022 ACSONE SA/NV (http://acsone.eu) # @author Stéphane Bidoul # Copyright 2016-2022 Akretion (Alexis de Lattre ) +# 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 +from odoo.tests.common import TransactionCase, Form class TestCutoffPrepaid(TransactionCase): @@ -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])], @@ -145,3 +147,70 @@ 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( + [ + ("internal_type", "=", "liquidity"), + ("company_id", "=", company.id), + ], + 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) From 0cceebc6d4935635e3a3d0ba9852f70f4f64d87e Mon Sep 17 00:00:00 2001 From: Guidomadormo <68272608+Guidomadormo@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:47:21 +0100 Subject: [PATCH 2/2] [FIX]test_general_entry_prepaid_expense_cutoff_account --- .../__manifest__.py | 2 +- .../tests/test_account_cutoff_prepaid.py | 100 +++++++++++++----- 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/account_cutoff_start_end_dates/__manifest__.py b/account_cutoff_start_end_dates/__manifest__.py index e888b276ae5..1371dca7070 100644 --- a/account_cutoff_start_end_dates/__manifest__.py +++ b/account_cutoff_start_end_dates/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Cut-off Start End Dates", - "version": "16.0.1.1.1", + "version": "16.0.1.1.2", "category": "Accounting & Finance", "license": "AGPL-3", "summary": "Cutoffs based on start/end dates", diff --git a/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py b/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py index f5ae3f62316..21a454a31f1 100644 --- a/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py +++ b/account_cutoff_start_end_dates/tests/test_account_cutoff_prepaid.py @@ -9,7 +9,7 @@ from datetime import date from odoo import fields -from odoo.tests.common import TransactionCase, Form +from odoo.tests.common import TransactionCase class TestCutoffPrepaid(TransactionCase): @@ -105,7 +105,7 @@ def _create_cutoff(self, date, cutoff_type="prepaid_expense"): { "company_id": self.env.ref("base.main_company").id, "cutoff_date": self._date(date), - "cutoff_type": "cutoff_type", + "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])], @@ -156,41 +156,89 @@ def test_general_entry_prepaid_expense_cutoff_account(self): company = self.env.ref("base.main_company") bank_account = self.env["account.account"].search( [ - ("internal_type", "=", "liquidity"), + ("account_type", "=", "asset_cash"), ("company_id", "=", company.id), ], 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() + 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() - prepaid_expense_cutoff = self._create_cutoff( - month_day_move_date, - cutoff_type="prepaid_expense", + # 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, ) - prepaid_expense_cutoff.source_journal_ids = misc_journal - prepaid_revenue_cutoff = self._create_cutoff( - month_day_move_date, - cutoff_type="prepaid_revenue", + 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, ) - prepaid_revenue_cutoff.source_journal_ids = misc_journal + + 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(