2017-03-31 19:00:59 +02:00
|
|
|
# Copyright 2017 ACSONE SA/NV
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from datetime import date, timedelta
|
|
|
|
|
2021-03-09 16:53:35 +01:00
|
|
|
from odoo.exceptions import UserError
|
2022-04-18 15:00:16 +02:00
|
|
|
from odoo.tests import tagged
|
2017-03-31 19:00:59 +02:00
|
|
|
|
2021-03-09 16:53:35 +01:00
|
|
|
from odoo.addons.account.tests import common
|
2017-03-31 19:00:59 +02:00
|
|
|
|
|
|
|
|
2022-04-18 15:00:16 +02:00
|
|
|
@tagged("post_install", "-at_install")
|
2021-03-09 16:53:35 +01:00
|
|
|
class TestJournalLockDate(common.AccountTestInvoicingCommon):
|
2017-03-31 19:00:59 +02:00
|
|
|
def setUp(self):
|
|
|
|
super(TestJournalLockDate, self).setUp()
|
|
|
|
self.account_move_obj = self.env["account.move"]
|
2020-10-08 00:28:42 +02:00
|
|
|
self.account_move_line_obj = self.env["account.move.line"]
|
|
|
|
self.company_id = self.ref("base.main_company")
|
2017-03-31 19:00:59 +02:00
|
|
|
self.partner = self.browse_ref("base.res_partner_12")
|
|
|
|
|
2021-03-09 16:53:35 +01:00
|
|
|
self.account = self.company_data["default_account_revenue"]
|
|
|
|
self.account2 = self.company_data["default_account_expense"]
|
|
|
|
self.journal = self.company_data["default_journal_bank"]
|
2017-05-04 13:59:42 +02:00
|
|
|
|
2017-03-31 19:00:59 +02:00
|
|
|
# create a move and post it
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move = self.account_move_obj.create(
|
2020-10-08 00:28:42 +02:00
|
|
|
{
|
|
|
|
"date": date.today(),
|
|
|
|
"journal_id": self.journal.id,
|
|
|
|
"line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account.id,
|
|
|
|
"credit": 1000.0,
|
|
|
|
"name": "Credit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account2.id,
|
|
|
|
"debit": 1000.0,
|
|
|
|
"name": "Debit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move.action_post()
|
2020-08-20 15:22:40 +02:00
|
|
|
# lock journal, set 'Lock Date for Non-Advisers'
|
2020-10-08 00:28:42 +02:00
|
|
|
self.journal.period_lock_date = date.today() + timedelta(days=2)
|
2021-03-09 16:53:35 +01:00
|
|
|
|
|
|
|
def test_journal_lock_date(self):
|
|
|
|
self.env.user.write({"groups_id": [(3, self.ref("base.group_system"))]})
|
|
|
|
self.env.user.write(
|
|
|
|
{"groups_id": [(3, self.ref("account.group_account_manager"))]}
|
|
|
|
)
|
|
|
|
self.assertFalse(self.env.user.has_group("account.group_account_manager"))
|
|
|
|
|
2023-01-09 12:57:48 +01:00
|
|
|
# Test that the move cannot be written, or cancelled
|
|
|
|
with self.assertRaisesRegex(
|
|
|
|
UserError, ".*prior to and inclusive of the lock date.*"
|
|
|
|
):
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move.write({"name": "TEST"})
|
2017-03-31 19:00:59 +02:00
|
|
|
|
2023-01-09 12:57:48 +01:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
UserError, ".*prior to and inclusive of the lock date.*"
|
|
|
|
):
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move.button_cancel()
|
2017-03-31 19:00:59 +02:00
|
|
|
|
2020-08-20 15:22:40 +02:00
|
|
|
# create a move after the 'Lock Date for Non-Advisers' and post it
|
2021-03-09 16:53:35 +01:00
|
|
|
move2 = self.account_move_obj.create(
|
2020-10-08 00:28:42 +02:00
|
|
|
{
|
|
|
|
"date": self.journal.period_lock_date + timedelta(days=3),
|
|
|
|
"journal_id": self.journal.id,
|
|
|
|
"line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account.id,
|
|
|
|
"credit": 1000.0,
|
|
|
|
"name": "Credit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account2.id,
|
|
|
|
"debit": 1000.0,
|
|
|
|
"name": "Debit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2021-03-09 16:53:35 +01:00
|
|
|
move2.action_post()
|
2017-05-04 13:59:42 +02:00
|
|
|
|
2021-03-09 16:53:35 +01:00
|
|
|
# force create move in a lock date
|
|
|
|
move3 = self.account_move_obj.with_context(
|
|
|
|
bypass_journal_lock_date=True
|
|
|
|
).create(
|
2020-10-08 00:28:42 +02:00
|
|
|
{
|
2021-03-09 16:53:35 +01:00
|
|
|
"date": self.journal.period_lock_date,
|
2020-10-08 00:28:42 +02:00
|
|
|
"journal_id": self.journal.id,
|
|
|
|
"line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account.id,
|
|
|
|
"credit": 1000.0,
|
|
|
|
"name": "Credit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account2.id,
|
|
|
|
"debit": 1000.0,
|
|
|
|
"name": "Debit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2021-03-09 16:53:35 +01:00
|
|
|
move3.action_post()
|
|
|
|
|
|
|
|
def test_journal_lock_date_adviser(self):
|
2022-03-30 21:38:04 +02:00
|
|
|
"""The journal lock date is ignored for Advisers"""
|
2021-03-09 16:53:35 +01:00
|
|
|
self.env.user.write(
|
|
|
|
{"groups_id": [(4, self.env.ref("account.group_account_manager").id)]}
|
|
|
|
)
|
|
|
|
self.assertTrue(self.env.user.has_group("account.group_account_manager"))
|
|
|
|
wizard = (
|
|
|
|
self.env["update.journal.lock.dates.wizard"]
|
|
|
|
.with_context(active_model="account.journal", active_ids=self.journal.id)
|
|
|
|
.create(
|
|
|
|
{
|
|
|
|
"fiscalyear_lock_date": date.today() + timedelta(days=2),
|
|
|
|
"period_lock_date": date.today() + timedelta(days=4),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
wizard.action_update_lock_dates()
|
2023-01-09 12:57:48 +01:00
|
|
|
# Advisers cannot write, or cancel moves before 'Lock Date'
|
|
|
|
with self.assertRaisesRegex(
|
|
|
|
UserError, ".*prior to and inclusive of the lock date.*"
|
|
|
|
):
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move.write({"name": "TEST"})
|
|
|
|
|
2023-01-09 12:57:48 +01:00
|
|
|
with self.assertRaisesRegex(
|
|
|
|
UserError, ".*prior to and inclusive of the lock date.*"
|
|
|
|
):
|
2021-03-09 16:53:35 +01:00
|
|
|
self.move.button_cancel()
|
2020-08-20 15:22:40 +02:00
|
|
|
# Advisers can create movements on a date after the 'Lock Date'
|
|
|
|
# even if that date is before and inclusive of
|
|
|
|
# the 'Lock Date for Non-Advisers' (self.journal.period_lock_date)
|
2021-03-09 16:53:35 +01:00
|
|
|
move2 = self.account_move_obj.create(
|
2020-10-08 00:28:42 +02:00
|
|
|
{
|
|
|
|
"date": self.journal.period_lock_date,
|
|
|
|
"journal_id": self.journal.id,
|
|
|
|
"line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account.id,
|
|
|
|
"credit": 1000.0,
|
|
|
|
"name": "Credit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": self.account2.id,
|
|
|
|
"debit": 1000.0,
|
|
|
|
"name": "Debit line",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2021-03-09 16:53:35 +01:00
|
|
|
move2.action_post()
|