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", "name": "Account Journal Lock Date",
"summary": """ "summary": "Lock each journal independently",
Lock each journal independently""", "version": "14.0.1.0.0",
"version": "13.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)", "author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools", "website": "https://github.com/OCA/account-financial-tools",
"depends": ["account"], "depends": ["account"],
"data": [ "data": [
"security/ir.model.access.csv",
"views/account_journal.xml", "views/account_journal.xml",
"wizards/update_journal_lock_dates_views.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 datetime import date
from odoo import _, models from odoo import _, models
from odoo.exceptions import UserError
from odoo.tools.misc import format_date from odoo.tools.misc import format_date
from ..exceptions import JournalLockDateError
class AccountMove(models.Model): class AccountMove(models.Model):
@ -44,5 +43,5 @@ class AccountMove(models.Model):
"Check the Journal settings or ask someone " "Check the Journal settings or ask someone "
"with the 'Adviser' role" "with the 'Adviser' role"
) % (move.journal_id.display_name, lock_date) ) % (move.journal_id.display_name, lock_date)
raise JournalLockDateError(message) raise UserError(message)
return res 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 datetime import date, timedelta
from odoo import tools from odoo.exceptions import UserError
from odoo.modules import get_module_resource
from odoo.tests import common
from ..exceptions import JournalLockDateError from odoo.addons.account.tests import common
class TestJournalLockDate(common.TransactionCase): class TestJournalLockDate(common.AccountTestInvoicingCommon):
def setUp(self): def setUp(self):
super(TestJournalLockDate, self).setUp() 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_obj = self.env["account.move"]
self.account_move_line_obj = self.env["account.move.line"] self.account_move_line_obj = self.env["account.move.line"]
self.company_id = self.ref("base.main_company") self.company_id = self.ref("base.main_company")
self.partner = self.browse_ref("base.res_partner_12") 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.account = self.company_data["default_account_revenue"]
self.env.user.write({"groups_id": [(3, self.ref("base.group_system"))]}) self.account2 = self.company_data["default_account_expense"]
self.env.user.write( self.journal = self.company_data["default_journal_bank"]
{"groups_id": [(3, self.ref("account.group_account_manager"))]}
)
self.assertFalse(self.env.user.has_group("account.group_account_manager"))
# create a move and post it # create a move and post it
move = self.account_move_obj.create( self.move = self.account_move_obj.create(
{ {
"date": date.today(), "date": date.today(),
"journal_id": self.journal.id, "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' # lock journal, set 'Lock Date for Non-Advisers'
self.journal.period_lock_date = date.today() + timedelta(days=2) 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 # Test that the move cannot be created, written, or cancelled
with self.assertRaises(JournalLockDateError): with self.assertRaises(UserError):
self.account_move_obj.create( self.account_move_obj.create(
{ {
"date": date.today(), "date": date.today(),
@ -96,16 +87,14 @@ class TestJournalLockDate(common.TransactionCase):
} }
) )
with self.assertRaises(JournalLockDateError): with self.assertRaises(UserError):
move.write({"name": "TEST"}) self.move.write({"name": "TEST"})
# allow cancel posted move with self.assertRaises(UserError):
self.journal.update_posted = True self.move.button_cancel()
with self.assertRaises(JournalLockDateError):
move.button_cancel()
# create a move after the 'Lock Date for Non-Advisers' and post it # 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), "date": self.journal.period_lock_date + timedelta(days=3),
"journal_id": self.journal.id, "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): # force create move in a lock date
""" The journal lock date is ignored for Advisers """ move3 = self.account_move_obj.with_context(
self.env.user.write( bypass_journal_lock_date=True
{"groups_id": [(4, self.ref("account.group_account_manager"))]} ).create(
)
self.assertTrue(self.env.user.has_group("account.group_account_manager"))
# create a move and post it
move = self.account_move_obj.create(
{ {
"date": date.today(), "date": self.journal.period_lock_date,
"journal_id": self.journal.id, "journal_id": self.journal.id,
"line_ids": [ "line_ids": [
( (
@ -166,13 +151,27 @@ class TestJournalLockDate(common.TransactionCase):
], ],
} }
) )
move.post() move3.action_post()
# lock journal. Set 'Lock Date'
self.journal.fiscalyear_lock_date = date.today() + timedelta(days=2) def test_journal_lock_date_adviser(self):
# lock journal. Set 'Lock Date for Non-Advisers' """ The journal lock date is ignored for Advisers """
self.journal.period_lock_date = date.today() + timedelta(days=4) 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' # Advisers cannot create, write, or cancel moves before 'Lock Date'
with self.assertRaises(JournalLockDateError): with self.assertRaises(UserError):
self.account_move_obj.create( self.account_move_obj.create(
{ {
"date": date.today(), "date": date.today(),
@ -199,16 +198,15 @@ class TestJournalLockDate(common.TransactionCase):
], ],
} }
) )
with self.assertRaises(JournalLockDateError): with self.assertRaises(UserError):
move.write({"name": "TEST"}) self.move.write({"name": "TEST"})
# allow cancel posted move
self.journal.update_posted = True with self.assertRaises(UserError):
with self.assertRaises(JournalLockDateError): self.move.button_cancel()
move.button_cancel()
# Advisers can create movements on a date after the 'Lock Date' # Advisers can create movements on a date after the 'Lock Date'
# even if that date is before and inclusive of # even if that date is before and inclusive of
# the 'Lock Date for Non-Advisers' (self.journal.period_lock_date) # 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, "date": self.journal.period_lock_date,
"journal_id": self.journal.id, "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). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<data> <data>
<record model="ir.ui.view" id="account_journal_form_view"> <record model="ir.ui.view" id="view_account_journal_form">
<field <field
name="name" name="name"
>account.journal.form (in account_journal_lock_date)</field> >account.journal.form (in account_journal_lock_date)</field>
@ -16,7 +16,7 @@
</field> </field>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="account_journal_tree_view"> <record model="ir.ui.view" id="view_account_journal_tree">
<field <field
name="name" name="name"
>account.journal.tree (in account_journal_lock_date)</field> >account.journal.tree (in account_journal_lock_date)</field>

View File

@ -21,9 +21,11 @@ class UpdateJournalLockDatesWizard(models.TransientModel):
def action_update_lock_dates(self): def action_update_lock_dates(self):
self.ensure_one() self.ensure_one()
self._check_execute_allowed() 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:
"period_lock_date": self.period_lock_date, self.env["account.journal"].browse(active_ids).write(
"fiscalyear_lock_date": self.fiscalyear_lock_date, {
} "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 <!-- Copyright 2020 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo> <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"> <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="name">update.journal.lock.dates.wizard.form</field>
<field name="model">update.journal.lock.dates.wizard</field> <field name="model">update.journal.lock.dates.wizard</field>
@ -27,13 +36,4 @@
</form> </form>
</field> </field>
</record> </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> </odoo>