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
|
|
|
|
|
2020-08-20 15:22:40 +02:00
|
|
|
from odoo import tools
|
2017-03-31 19:00:59 +02:00
|
|
|
from odoo.modules import get_module_resource
|
|
|
|
from odoo.tests import common
|
|
|
|
|
|
|
|
from ..exceptions import JournalLockDateError
|
|
|
|
|
|
|
|
|
|
|
|
class TestJournalLockDate(common.TransactionCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestJournalLockDate, self).setUp()
|
2020-10-08 00:28:42 +02:00
|
|
|
tools.convert_file(
|
|
|
|
self.cr,
|
|
|
|
"account",
|
|
|
|
get_module_resource("account", "test", "account_minimal_test.xml"),
|
|
|
|
{},
|
|
|
|
"init",
|
|
|
|
False,
|
|
|
|
"test",
|
|
|
|
)
|
2017-03-31 19:00:59 +02:00
|
|
|
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")
|
|
|
|
self.account = self.browse_ref("account.a_recv")
|
|
|
|
self.account2 = self.browse_ref("account.a_expense")
|
|
|
|
self.journal = self.browse_ref("account.bank_journal")
|
|
|
|
|
|
|
|
def test_journal_lock_date(self):
|
2020-10-08 01:58:13 +02:00
|
|
|
self.env.user.write({"groups_id": [(3, self.ref("base.group_system"))]})
|
2020-10-08 00:28:42 +02:00
|
|
|
self.env.user.write(
|
2020-10-08 01:58:13 +02:00
|
|
|
{"groups_id": [(3, self.ref("account.group_account_manager"))]}
|
2020-10-08 00:28:42 +02:00
|
|
|
)
|
|
|
|
self.assertFalse(self.env.user.has_group("account.group_account_manager"))
|
2017-05-04 13:59:42 +02:00
|
|
|
|
2017-03-31 19:00:59 +02:00
|
|
|
# create a move and post it
|
2020-10-08 00:28:42 +02:00
|
|
|
move = self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2017-03-31 19:00:59 +02:00
|
|
|
move.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)
|
2017-03-31 19:00:59 +02:00
|
|
|
# Test that the move cannot be created, written, or cancelled
|
|
|
|
with self.assertRaises(JournalLockDateError):
|
2020-10-08 00:28:42 +02:00
|
|
|
self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2017-03-31 19:00:59 +02:00
|
|
|
|
|
|
|
with self.assertRaises(JournalLockDateError):
|
2020-10-08 00:28:42 +02:00
|
|
|
move.write({"name": "TEST"})
|
2017-03-31 19:00:59 +02:00
|
|
|
|
2019-05-24 17:09:51 +02:00
|
|
|
# allow cancel posted move
|
|
|
|
self.journal.update_posted = True
|
2017-03-31 19:00:59 +02:00
|
|
|
with self.assertRaises(JournalLockDateError):
|
|
|
|
move.button_cancel()
|
|
|
|
|
2020-08-20 15:22:40 +02:00
|
|
|
# create a move after the 'Lock Date for Non-Advisers' and post it
|
2020-10-08 00:28:42 +02:00
|
|
|
move3 = self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2017-03-31 19:00:59 +02:00
|
|
|
move3.post()
|
2017-05-04 13:59:42 +02:00
|
|
|
|
|
|
|
def test_journal_lock_date_adviser(self):
|
|
|
|
""" The journal lock date is ignored for Advisers """
|
2020-10-08 00:28:42 +02:00
|
|
|
self.env.user.write(
|
2020-10-08 01:58:13 +02:00
|
|
|
{"groups_id": [(4, self.ref("account.group_account_manager"))]}
|
2020-10-08 00:28:42 +02:00
|
|
|
)
|
|
|
|
self.assertTrue(self.env.user.has_group("account.group_account_manager"))
|
2020-08-20 15:22:40 +02:00
|
|
|
# create a move and post it
|
2020-10-08 00:28:42 +02:00
|
|
|
move = self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-08-20 15:22:40 +02:00
|
|
|
move.post()
|
|
|
|
# lock journal. Set 'Lock Date'
|
|
|
|
self.journal.fiscalyear_lock_date = date.today() + timedelta(days=2)
|
|
|
|
# lock journal. Set 'Lock Date for Non-Advisers'
|
|
|
|
self.journal.period_lock_date = date.today() + timedelta(days=4)
|
|
|
|
# Advisers cannot create, write, or cancel moves before 'Lock Date'
|
|
|
|
with self.assertRaises(JournalLockDateError):
|
2020-10-08 00:28:42 +02:00
|
|
|
self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-08-20 15:22:40 +02:00
|
|
|
with self.assertRaises(JournalLockDateError):
|
2020-10-08 00:28:42 +02:00
|
|
|
move.write({"name": "TEST"})
|
2020-08-20 15:22:40 +02:00
|
|
|
# allow cancel posted move
|
|
|
|
self.journal.update_posted = True
|
|
|
|
with self.assertRaises(JournalLockDateError):
|
|
|
|
move.button_cancel()
|
|
|
|
# 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)
|
2020-10-08 00:28:42 +02:00
|
|
|
move3 = self.account_move_obj.create(
|
|
|
|
{
|
|
|
|
"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",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-08-20 15:22:40 +02:00
|
|
|
move3.post()
|