<commit_before># Copyright 2017 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class TestAccountLockDateUpdate(TransactionCase):

    def setUp(self):
        super(TestAccountLockDateUpdate, self).setUp()
        self.UpdateLockDateUpdateObj = self.env['account.update.lock_date']

        self.company = self.env.ref('base.main_company')
        self.demo_user = self.env.ref('base.user_demo')
        self.adviser_group = self.env.ref('account.group_account_manager')

    def create_account_lock_date_update(self):
        return self.UpdateLockDateUpdateObj.create({
            'company_id': self.company.id,
        })

    def test_01_update_without_access(self):
        wizard = self.create_account_lock_date_update()
        wizard.write({
            'period_lock_date': '2000-01-01',
            'fiscalyear_lock_date': '2000-01-01',
        })

        self.demo_user.write({
            'groups_id': [(3, self.adviser_group.id)],
        })

        with self.assertRaises(UserError):
            wizard.sudo(self.demo_user.id).execute()

    def test_02_update_with_access(self):
        wizard = self.create_account_lock_date_update()
        wizard.write({
            'period_lock_date': '2000-01-01',
            'fiscalyear_lock_date': '2000-01-01',
        })

        self.demo_user.write({
            'groups_id': [(4, self.adviser_group.id)],
        })

        wizard.sudo(self.demo_user.id).execute()<commit_msg>[FIX] account_lock_date_update: Fix tests<commit_after># Copyright 2017 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError


class TestAccountLockDateUpdate(TransactionCase):

    def setUp(self):
        super(TestAccountLockDateUpdate, self).setUp()
        self.company = self.env.ref('base.main_company')
        self.demo_user = self.env.ref('base.user_demo')
        self.adviser_group = self.env.ref('account.group_account_manager')
        self.UpdateLockDateUpdateObj = self.env[
            'account.update.lock_date'
        ].sudo(self.demo_user)

    def create_account_lock_date_update(self):
        return self.UpdateLockDateUpdateObj.create({
            'company_id': self.company.id,
        })

    def test_01_update_without_access(self):
        wizard = self.create_account_lock_date_update()
        wizard.write({
            'period_lock_date': '2000-01-01',
            'fiscalyear_lock_date': '2000-01-01',
        })
        self.demo_user.write({
            'groups_id': [(3, self.adviser_group.id)],
        })
        with self.assertRaises(UserError):
            wizard.sudo(self.demo_user.id).execute()

    def test_02_update_with_access(self):
        wizard = self.create_account_lock_date_update()
        wizard.write({
            'period_lock_date': '2000-02-01',
            'fiscalyear_lock_date': '2000-01-01',
        })
        self.demo_user.write({
            'groups_id': [(4, self.adviser_group.id)],
        })
        wizard.sudo(self.demo_user.id).execute()
        self.assertEqual(self.company.period_lock_date, '2000-02-01')
        self.assertEqual(self.company.fiscalyear_lock_date, '2000-01-01')
{'fraction_non_alphanumeric': 0.12620481927710844, 'fraction_numerical': 0.03132530120481928, 'mean_word_length': 2.7440811724915446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5759646', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1060, 'n_words': 142}