2017-08-17 13:10:25 +02:00
|
|
|
# Copyright 2017 ACSONE SA/NV
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2019-04-25 07:27:57 +02:00
|
|
|
from odoo import fields
|
2021-05-18 16:24:41 +02:00
|
|
|
from odoo.exceptions import AccessError
|
2020-01-17 11:41:26 +01:00
|
|
|
from odoo.tests.common import TransactionCase
|
2017-08-17 13:10:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestAccountLockDateUpdate(TransactionCase):
|
2023-02-16 10:55:56 +01:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super().setUpClass()
|
2023-10-13 12:30:27 +02:00
|
|
|
cls.env = cls.env(
|
|
|
|
context=dict(
|
|
|
|
cls.env.context,
|
|
|
|
mail_create_nolog=True,
|
|
|
|
mail_create_nosubscribe=True,
|
|
|
|
mail_notrack=True,
|
|
|
|
no_reset_password=True,
|
|
|
|
tracking_disable=True,
|
|
|
|
)
|
|
|
|
)
|
2023-02-16 10:55:56 +01:00
|
|
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
|
|
|
cls.company = cls.env.ref("base.main_company")
|
|
|
|
cls.demo_user = cls.env.ref("base.user_demo")
|
|
|
|
cls.adviser_group = cls.env.ref("account.group_account_manager")
|
2017-08-17 13:10:25 +02:00
|
|
|
|
|
|
|
def test_01_update_without_access(self):
|
2020-01-17 11:41:26 +01:00
|
|
|
self.demo_user.write({"groups_id": [(3, self.adviser_group.id)]})
|
2021-05-18 16:24:41 +02:00
|
|
|
with self.assertRaises(AccessError):
|
|
|
|
self.env["account.update.lock_date"].with_user(self.demo_user.id).create(
|
|
|
|
{"company_id": self.company.id}
|
|
|
|
)
|
2017-08-17 13:10:25 +02:00
|
|
|
|
|
|
|
def test_02_update_with_access(self):
|
2021-05-18 16:24:41 +02:00
|
|
|
self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]})
|
|
|
|
wizard = (
|
|
|
|
self.env["account.update.lock_date"]
|
|
|
|
.with_user(self.demo_user.id)
|
|
|
|
.create({"company_id": self.company.id})
|
|
|
|
)
|
2020-01-17 11:41:26 +01:00
|
|
|
wizard.write(
|
2021-11-18 19:14:45 +01:00
|
|
|
{
|
|
|
|
"period_lock_date": "2000-02-01",
|
|
|
|
"fiscalyear_lock_date": "2000-01-01",
|
|
|
|
"tax_lock_date": "2000-01-01",
|
|
|
|
}
|
2020-01-17 11:41:26 +01:00
|
|
|
)
|
2020-01-17 11:39:54 +01:00
|
|
|
wizard.with_user(self.demo_user.id).execute()
|
2019-04-25 07:27:57 +02:00
|
|
|
self.assertEqual(
|
2020-01-17 11:41:26 +01:00
|
|
|
fields.Date.to_string(self.company.period_lock_date), "2000-02-01"
|
|
|
|
)
|
2019-04-25 07:27:57 +02:00
|
|
|
self.assertEqual(
|
2020-01-17 11:41:26 +01:00
|
|
|
fields.Date.to_string(self.company.fiscalyear_lock_date), "2000-01-01"
|
|
|
|
)
|
2021-11-18 19:14:45 +01:00
|
|
|
self.assertEqual(
|
|
|
|
fields.Date.to_string(self.company.tax_lock_date), "2000-01-01"
|
|
|
|
)
|