Skip to content
Snippets Groups Projects
Commit 54a7e441 authored by aronabencherif.diatta@xcg.africa's avatar aronabencherif.diatta@xcg.africa
Browse files

Add 'period_id' in form view, add tests about it and update translations

parent 49169557
No related branches found
Tags 16.0.1.1.0
1 merge request!16Add 'period_id' in form view, add tests about it and update translations
Pipeline #83978 passed
......@@ -2,6 +2,13 @@
ChangeLog
=========
16.0.1.1.0
==========
- Add 'period_id' field in form view
- Add tests about it and
- Update translations
16.0.1.0.2
==========
......
......@@ -19,7 +19,7 @@
##############################################################################
{
"name": "Alternate Ledger",
"version": "16.0.1.0.3",
"version": "16.0.1.1.0",
"author": "XCG Consulting",
"category": "Accounting",
"summary": """Allow the creation of new accounting ledgers that store
......
This diff is collapsed.
##############################################################################
#
# Alternate Ledger, for Odoo
# Copyright © 2020 XCG Consulting <https://xcg-consulting.fr>
# Copyright © 2020, 2024 XCG Consulting <https://xcg-consulting.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -18,7 +18,9 @@
#
##############################################################################
from odoo import Command
from freezegun import freeze_time
from odoo import Command, fields, tools
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
......@@ -35,6 +37,8 @@
self.ledger_type = self.env.ref("alternate_ledger.ledger_type_b")
self.journal = self.company_data["default_journal_misc"]
self.partner = self.partner_a
self.today = fields.Date.context_today(self.env.user)
self.Period = self.env["account.period"]
# Create a draft ledger entry.
self.move = self.env["alternate_ledger.move"].create(
......@@ -69,5 +73,63 @@
self.assertTrue(self.move.unlink())
self.assertEqual(self._count_moves(), 0)
def test_period(self):
# Dates & period around today.
year = fields.Date.from_string(self.today).year
period_today = self.Period.find(date=self.today)
# Check move values
self.assertTrue(period_today)
self.assertEqual(self.move.state, "draft")
self.assertFalse(self.move.period_id)
self._post_move_and_check_states(self.move)
# Check: Default dates & period around today.
self.assertEqual(self.move.date, self.today)
self.assertEqual(self.move.period_id.id, period_today.id)
# Force a date on the alternate ledger move; ensure period selection follows it.
date_2022 = self.today.replace(year=2022)
period_2022 = self.Period.find(date=date_2022)
move_2022 = self._make_alter_ledger_move(
date=date_2022, alterne_ledger_move_ref="TEST force date"
)
self._post_move_and_check_states(move_2022)
self.assertFalse(
move_2022.is_sale_document(include_receipts=True), "Move type is 'entry'"
)
highest_name = move_2022.highest_name or move_2022._get_last_sequence(
relaxed=True, lock=False
)
self.assertTrue(highest_name, "The highest name of the movement is defined")
number_reset = move_2022._deduce_sequence_number_reset(highest_name)
self.assertEqual(
number_reset, "month", "The highest name of the movement include the month"
)
move_date = tools.date_utils.get_month(date_2022)[1]
self.assertEqual(
move_2022.date, move_date, "Move date is set to the last day of this month"
)
self.assertEqual(move_2022.period_id.id, period_2022.id)
# Ensure period selection around midnight follows timezone.
# In this test we simulate an invoice at 31/01 23:50 UTC, which becomes
# 01/02 00:50 (or 01:50) in the Paris timezone.
self.env.user.tz = "Europe/Paris"
with freeze_time(f"{year}-01-31 23:50:00"):
test_move = self._make_alter_ledger_move(
alterne_ledger_move_ref="TEST around midnight date", amount=250.0
)
self._post_move_and_check_states(test_move)
self.assertEqual(test_move.date.isoformat(), f"{year}-02-01")
self.assertEqual(
test_move.period_id.date_start.isoformat(), f"{year}-02-01"
)
def _count_moves(self):
return self.env["alternate_ledger.move"].search_count([])
......@@ -72,2 +134,37 @@
def _count_moves(self):
return self.env["alternate_ledger.move"].search_count([])
def _make_alter_ledger_move(
self, date=None, alterne_ledger_move_ref="TEST Ref", amount=55.0
):
if date is None:
date = fields.Date.context_today(self.env.user)
return self.env["alternate_ledger.move"].create(
{
"journal_id": self.journal.id,
"ledger_type_id": self.ledger_type.id,
"ref": alterne_ledger_move_ref,
"invoice_date": date,
"line_ids": [
Command.create(
{
"account_id": self.account.id,
"partner_id": self.partner.id,
"debit": amount,
}
),
Command.create(
{
"account_id": self.account.id,
"partner_id": self.partner.id,
"credit": amount,
}
),
],
}
)
def _post_move_and_check_states(self, account_move):
account_move.action_post()
self.assertEqual(account_move.state, "posted")
self.assertTrue(account_move.period_id)
......@@ -385,6 +385,7 @@
'readonly': [('state', '!=', 'draft')],
}"
/>
<field name="period_id" />
<field
name="payment_reference"
attrs="{'invisible': [('move_type', 'not in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment