diff --git a/account_journal_lock_date/__manifest__.py b/account_journal_lock_date/__manifest__.py index a2a41e8e..d05bf5ac 100644 --- a/account_journal_lock_date/__manifest__.py +++ b/account_journal_lock_date/__manifest__.py @@ -3,14 +3,14 @@ { "name": "Account Journal Lock Date", - "summary": """ - Lock each journal independently""", - "version": "13.0.1.0.0", + "summary": "Lock each journal independently", + "version": "14.0.1.0.0", "license": "AGPL-3", "author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "depends": ["account"], "data": [ + "security/ir.model.access.csv", "views/account_journal.xml", "wizards/update_journal_lock_dates_views.xml", ], diff --git a/account_journal_lock_date/exceptions.py b/account_journal_lock_date/exceptions.py deleted file mode 100644 index 222caf8a..00000000 --- a/account_journal_lock_date/exceptions.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright 2017 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo.exceptions import UserError - - -class JournalLockDateError(UserError): - pass diff --git a/account_journal_lock_date/models/account_move.py b/account_journal_lock_date/models/account_move.py index 622a0a35..29cbd0f1 100644 --- a/account_journal_lock_date/models/account_move.py +++ b/account_journal_lock_date/models/account_move.py @@ -4,10 +4,9 @@ from datetime import date from odoo import _, models +from odoo.exceptions import UserError from odoo.tools.misc import format_date -from ..exceptions import JournalLockDateError - class AccountMove(models.Model): @@ -44,5 +43,5 @@ class AccountMove(models.Model): "Check the Journal settings or ask someone " "with the 'Adviser' role" ) % (move.journal_id.display_name, lock_date) - raise JournalLockDateError(message) + raise UserError(message) return res diff --git a/account_journal_lock_date/security/ir.model.access.csv b/account_journal_lock_date/security/ir.model.access.csv new file mode 100644 index 00000000..1c69d96d --- /dev/null +++ b/account_journal_lock_date/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_update_journal_lock_dates_wizard,access_update_journal_lock_dates_wizard,model_update_journal_lock_dates_wizard,account.group_account_manager,1,1,1,1 diff --git a/account_journal_lock_date/tests/test_journal_lock_date.py b/account_journal_lock_date/tests/test_journal_lock_date.py index 61044f91..a59f63e7 100644 --- a/account_journal_lock_date/tests/test_journal_lock_date.py +++ b/account_journal_lock_date/tests/test_journal_lock_date.py @@ -3,42 +3,25 @@ from datetime import date, timedelta -from odoo import tools -from odoo.modules import get_module_resource -from odoo.tests import common +from odoo.exceptions import UserError -from ..exceptions import JournalLockDateError +from odoo.addons.account.tests import common -class TestJournalLockDate(common.TransactionCase): +class TestJournalLockDate(common.AccountTestInvoicingCommon): def setUp(self): super(TestJournalLockDate, self).setUp() - tools.convert_file( - self.cr, - "account", - get_module_resource("account", "test", "account_minimal_test.xml"), - {}, - "init", - False, - "test", - ) self.account_move_obj = self.env["account.move"] self.account_move_line_obj = self.env["account.move.line"] self.company_id = self.ref("base.main_company") 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): - 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")) + self.account = self.company_data["default_account_revenue"] + self.account2 = self.company_data["default_account_expense"] + self.journal = self.company_data["default_journal_bank"] # create a move and post it - move = self.account_move_obj.create( + self.move = self.account_move_obj.create( { "date": date.today(), "journal_id": self.journal.id, @@ -64,11 +47,19 @@ class TestJournalLockDate(common.TransactionCase): ], } ) - move.post() + self.move.action_post() # lock journal, set 'Lock Date for Non-Advisers' self.journal.period_lock_date = date.today() + timedelta(days=2) + + 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")) + # Test that the move cannot be created, written, or cancelled - with self.assertRaises(JournalLockDateError): + with self.assertRaises(UserError): self.account_move_obj.create( { "date": date.today(), @@ -96,16 +87,14 @@ class TestJournalLockDate(common.TransactionCase): } ) - with self.assertRaises(JournalLockDateError): - move.write({"name": "TEST"}) + with self.assertRaises(UserError): + self.move.write({"name": "TEST"}) - # allow cancel posted move - self.journal.update_posted = True - with self.assertRaises(JournalLockDateError): - move.button_cancel() + with self.assertRaises(UserError): + self.move.button_cancel() # create a move after the 'Lock Date for Non-Advisers' and post it - move3 = self.account_move_obj.create( + move2 = self.account_move_obj.create( { "date": self.journal.period_lock_date + timedelta(days=3), "journal_id": self.journal.id, @@ -131,18 +120,14 @@ class TestJournalLockDate(common.TransactionCase): ], } ) - move3.post() + move2.action_post() - def test_journal_lock_date_adviser(self): - """ The journal lock date is ignored for Advisers """ - self.env.user.write( - {"groups_id": [(4, self.ref("account.group_account_manager"))]} - ) - self.assertTrue(self.env.user.has_group("account.group_account_manager")) - # create a move and post it - move = self.account_move_obj.create( + # force create move in a lock date + move3 = self.account_move_obj.with_context( + bypass_journal_lock_date=True + ).create( { - "date": date.today(), + "date": self.journal.period_lock_date, "journal_id": self.journal.id, "line_ids": [ ( @@ -166,13 +151,27 @@ class TestJournalLockDate(common.TransactionCase): ], } ) - 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) + move3.action_post() + + def test_journal_lock_date_adviser(self): + """ The journal lock date is ignored for Advisers """ + 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() # Advisers cannot create, write, or cancel moves before 'Lock Date' - with self.assertRaises(JournalLockDateError): + with self.assertRaises(UserError): self.account_move_obj.create( { "date": date.today(), @@ -199,16 +198,15 @@ class TestJournalLockDate(common.TransactionCase): ], } ) - with self.assertRaises(JournalLockDateError): - move.write({"name": "TEST"}) - # allow cancel posted move - self.journal.update_posted = True - with self.assertRaises(JournalLockDateError): - move.button_cancel() + with self.assertRaises(UserError): + self.move.write({"name": "TEST"}) + + with self.assertRaises(UserError): + self.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) - move3 = self.account_move_obj.create( + move2 = self.account_move_obj.create( { "date": self.journal.period_lock_date, "journal_id": self.journal.id, @@ -234,4 +232,4 @@ class TestJournalLockDate(common.TransactionCase): ], } ) - move3.post() + move2.action_post() diff --git a/account_journal_lock_date/views/account_journal.xml b/account_journal_lock_date/views/account_journal.xml index 172a8262..15d85bb8 100644 --- a/account_journal_lock_date/views/account_journal.xml +++ b/account_journal_lock_date/views/account_journal.xml @@ -3,7 +3,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> - + account.journal.form (in account_journal_lock_date) @@ -16,7 +16,7 @@ - + account.journal.tree (in account_journal_lock_date) diff --git a/account_journal_lock_date/wizards/update_journal_lock_dates.py b/account_journal_lock_date/wizards/update_journal_lock_dates.py index 8dbcf571..2da97db3 100644 --- a/account_journal_lock_date/wizards/update_journal_lock_dates.py +++ b/account_journal_lock_date/wizards/update_journal_lock_dates.py @@ -21,9 +21,11 @@ class UpdateJournalLockDatesWizard(models.TransientModel): def action_update_lock_dates(self): self.ensure_one() self._check_execute_allowed() - self.env["account.journal"].browse(self.env.context.get("active_ids")).write( - { - "period_lock_date": self.period_lock_date, - "fiscalyear_lock_date": self.fiscalyear_lock_date, - } - ) + active_ids = self.env.context.get("active_ids", False) + if active_ids: + self.env["account.journal"].browse(active_ids).write( + { + "period_lock_date": self.period_lock_date, + "fiscalyear_lock_date": self.fiscalyear_lock_date, + } + ) diff --git a/account_journal_lock_date/wizards/update_journal_lock_dates_views.xml b/account_journal_lock_date/wizards/update_journal_lock_dates_views.xml index 14bd20f9..3f08b761 100644 --- a/account_journal_lock_date/wizards/update_journal_lock_dates_views.xml +++ b/account_journal_lock_date/wizards/update_journal_lock_dates_views.xml @@ -2,6 +2,15 @@ + + + Update journals lock dates + update.journal.lock.dates.wizard + form + new + + + update.journal.lock.dates.wizard.form update.journal.lock.dates.wizard @@ -27,13 +36,4 @@ -