2
0

[MIG] account_journal_lock_date: Migration to 14.0

This commit is contained in:
Zar21 2021-03-09 16:53:35 +01:00 committed by Rodrigo
parent c0deb41903
commit d1787c7758
8 changed files with 81 additions and 88 deletions

View File

@ -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",
],

View File

@ -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

View File

@ -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

View File

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 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

View File

@ -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()

View File

@ -3,7 +3,7 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record model="ir.ui.view" id="account_journal_form_view">
<record model="ir.ui.view" id="view_account_journal_form">
<field
name="name"
>account.journal.form (in account_journal_lock_date)</field>
@ -16,7 +16,7 @@
</field>
</field>
</record>
<record model="ir.ui.view" id="account_journal_tree_view">
<record model="ir.ui.view" id="view_account_journal_tree">
<field
name="name"
>account.journal.tree (in account_journal_lock_date)</field>

View File

@ -21,7 +21,9 @@ 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(
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,

View File

@ -2,6 +2,15 @@
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="update_journal_lock_dates_wizard_action" model="ir.actions.act_window">
<field name="name">Update journals lock dates</field>
<field name="res_model">update.journal.lock.dates.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="binding_model_id" ref="account.model_account_journal" />
</record>
<record id="update_journal_lock_dates_wizard_view_form" model="ir.ui.view">
<field name="name">update.journal.lock.dates.wizard.form</field>
<field name="model">update.journal.lock.dates.wizard</field>
@ -27,13 +36,4 @@
</form>
</field>
</record>
<act_window
id="update_journal_lock_dates_wizard_action"
name="Update journals lock dates"
binding_model="account.journal"
res_model="update.journal.lock.dates.wizard"
view_mode="form"
binding_views="form"
target="new"
/>
</odoo>