diff --git a/account_journal_lock_date/__manifest__.py b/account_journal_lock_date/__manifest__.py
index da853481..1a8c659d 100644
--- a/account_journal_lock_date/__manifest__.py
+++ b/account_journal_lock_date/__manifest__.py
@@ -2,20 +2,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
- 'name': 'Account Journal Lock Date',
- 'summary': """
+ "name": "Account Journal Lock Date",
+ "summary": """
Lock each journal independently""",
- 'version': '12.0.2.0.0',
- 'license': 'AGPL-3',
- 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
- 'website': 'https://github.com/OCA/account-financial-tools',
- 'depends': [
- 'account',
- ],
- 'data': [
- 'views/account_journal.xml',
- 'wizards/update_journal_lock_dates_views.xml',
- ],
- 'demo': [
+ "version": "12.0.2.0.0",
+ "license": "AGPL-3",
+ "author": "ACSONE SA/NV,Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/account-financial-tools",
+ "depends": ["account",],
+ "data": [
+ "views/account_journal.xml",
+ "wizards/update_journal_lock_dates_views.xml",
],
+ "demo": [],
}
diff --git a/account_journal_lock_date/exceptions.py b/account_journal_lock_date/exceptions.py
index 6a17c27a..222caf8a 100644
--- a/account_journal_lock_date/exceptions.py
+++ b/account_journal_lock_date/exceptions.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
diff --git a/account_journal_lock_date/models/account_journal.py b/account_journal_lock_date/models/account_journal.py
index 958ddf68..2e427a25 100644
--- a/account_journal_lock_date/models/account_journal.py
+++ b/account_journal_lock_date/models/account_journal.py
@@ -6,18 +6,18 @@ from odoo import fields, models
class AccountJournal(models.Model):
- _inherit = 'account.journal'
+ _inherit = "account.journal"
fiscalyear_lock_date = fields.Date(
string="Lock Date",
help="No users, including Advisers, can edit accounts prior "
- "to and inclusive of this date for this journal. Use it "
- "for fiscal year locking for this journal, for example."
+ "to and inclusive of this date for this journal. Use it "
+ "for fiscal year locking for this journal, for example.",
)
period_lock_date = fields.Date(
string="Lock Date for Non-Advisers",
help="Only users with the 'Adviser' role can edit accounts "
- "prior to and inclusive of this date for this journal. "
- "Use it for period locking inside an open fiscal year "
- "for this journal, for example."
+ "prior to and inclusive of this date for this journal. "
+ "Use it for period locking inside an open fiscal year "
+ "for this journal, for example.",
)
diff --git a/account_journal_lock_date/models/account_move.py b/account_journal_lock_date/models/account_move.py
index ec5c780a..4bd457f5 100644
--- a/account_journal_lock_date/models/account_move.py
+++ b/account_journal_lock_date/models/account_move.py
@@ -2,14 +2,15 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import date
-from odoo import api, models, _
+
+from odoo import _, api, models
from ..exceptions import JournalLockDateError
class AccountMove(models.Model):
- _inherit = 'account.move'
+ _inherit = "account.move"
@api.model
def create(self, values):
@@ -29,7 +30,7 @@ class AccountMove(models.Model):
if self.env.context.get("bypass_journal_lock_date"):
return res
for move in self:
- if self.user_has_groups('account.group_account_manager'):
+ if self.user_has_groups("account.group_account_manager"):
lock_date = move.journal_id.fiscalyear_lock_date or date.min
else:
lock_date = max(
@@ -37,7 +38,7 @@ class AccountMove(models.Model):
move.journal_id.fiscalyear_lock_date or date.min,
)
if move.date <= lock_date:
- if self.user_has_groups('account.group_account_manager'):
+ if self.user_has_groups("account.group_account_manager"):
message = _(
"You cannot add/modify entries for the journal '%s' "
"prior to and inclusive of the lock date %s"
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 469b5930..800ca059 100644
--- a/account_journal_lock_date/tests/test_journal_lock_date.py
+++ b/account_journal_lock_date/tests/test_journal_lock_date.py
@@ -11,67 +11,95 @@ from ..exceptions import JournalLockDateError
class TestJournalLockDate(common.TransactionCase):
-
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')
+ 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.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.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"))
# create a move and post it
- move = self.account_move_obj.create({
- 'date': date.today(),
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ move = self.account_move_obj.create(
+ {
+ "date": date.today(),
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
move.post()
# 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)
# Test that the move cannot be created, written, or cancelled
with self.assertRaises(JournalLockDateError):
- self.account_move_obj.create({
- 'date': date.today(),
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ self.account_move_obj.create(
+ {
+ "date": date.today(),
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
with self.assertRaises(JournalLockDateError):
- move.write({'name': 'TEST'})
+ move.write({"name": "TEST"})
# allow cancel posted move
self.journal.update_posted = True
@@ -79,42 +107,67 @@ class TestJournalLockDate(common.TransactionCase):
move.button_cancel()
# create a move after the 'Lock Date for Non-Advisers' and post it
- move3 = self.account_move_obj.create({
- 'date': self.journal.period_lock_date + timedelta(days=3),
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ move3 = self.account_move_obj.create(
+ {
+ "date": self.journal.period_lock_date + timedelta(days=3),
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
move3.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'))
+ 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({
- 'date': date.today(),
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ move = self.account_move_obj.create(
+ {
+ "date": date.today(),
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
move.post()
# lock journal. Set 'Lock Date'
self.journal.fiscalyear_lock_date = date.today() + timedelta(days=2)
@@ -122,21 +175,34 @@ class TestJournalLockDate(common.TransactionCase):
self.journal.period_lock_date = date.today() + timedelta(days=4)
# Advisers cannot create, write, or cancel moves before 'Lock Date'
with self.assertRaises(JournalLockDateError):
- self.account_move_obj.create({
- 'date': date.today(),
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ self.account_move_obj.create(
+ {
+ "date": date.today(),
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
with self.assertRaises(JournalLockDateError):
- move.write({'name': 'TEST'})
+ move.write({"name": "TEST"})
# allow cancel posted move
self.journal.update_posted = True
with self.assertRaises(JournalLockDateError):
@@ -144,17 +210,30 @@ class TestJournalLockDate(common.TransactionCase):
# 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({
- 'date': self.journal.period_lock_date,
- 'journal_id': self.journal.id,
- 'line_ids': [(0, 0, {
- 'account_id': self.account.id,
- 'credit': 1000.0,
- 'name': 'Credit line',
- }), (0, 0, {
- 'account_id': self.account2.id,
- 'debit': 1000.0,
- 'name': 'Debit line',
- })]
- })
+ move3 = self.account_move_obj.create(
+ {
+ "date": self.journal.period_lock_date,
+ "journal_id": self.journal.id,
+ "line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account.id,
+ "credit": 1000.0,
+ "name": "Credit line",
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "account_id": self.account2.id,
+ "debit": 1000.0,
+ "name": "Debit line",
+ },
+ ),
+ ],
+ }
+ )
move3.post()
diff --git a/account_journal_lock_date/views/account_journal.xml b/account_journal_lock_date/views/account_journal.xml
index bbfae57c..172a8262 100644
--- a/account_journal_lock_date/views/account_journal.xml
+++ b/account_journal_lock_date/views/account_journal.xml
@@ -1,35 +1,33 @@
-
+
-
-
-
-
- account.journal.form (in account_journal_lock_date)
- account.journal
-
-
-
-
-
+
+
+ account.journal.form (in account_journal_lock_date)
+ account.journal
+
+
+
+
+
+
-
-
-
-
-
- account.journal.tree (in account_journal_lock_date)
- account.journal
-
-
-
-
-
+
+
+ account.journal.tree (in account_journal_lock_date)
+ account.journal
+
+
+
+
+
+
-
-
-
-
-
+
+
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 cf89fe94..8dbcf571 100644
--- a/account_journal_lock_date/wizards/update_journal_lock_dates.py
+++ b/account_journal_lock_date/wizards/update_journal_lock_dates.py
@@ -1,30 +1,29 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-from odoo import _, fields, models, SUPERUSER_ID
+from odoo import SUPERUSER_ID, _, fields, models
from odoo.exceptions import UserError
class UpdateJournalLockDatesWizard(models.TransientModel):
- _name = 'update.journal.lock.dates.wizard'
- _description = 'Mass Update Journal Lock Dates Wizard'
+ _name = "update.journal.lock.dates.wizard"
+ _description = "Mass Update Journal Lock Dates Wizard"
period_lock_date = fields.Date(string="Lock Date for Non-Advisers")
fiscalyear_lock_date = fields.Date(string="Lock Date")
def _check_execute_allowed(self):
self.ensure_one()
- has_adviser_group = self.env.user.has_group(
- 'account.group_account_manager')
+ has_adviser_group = self.env.user.has_group("account.group_account_manager")
if not (has_adviser_group or self.env.uid == SUPERUSER_ID):
raise UserError(_("You are not allowed to execute this action."))
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,
- })
+ 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,
+ }
+ )
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 da829041..f426f4c9 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
@@ -1,4 +1,4 @@
-
+
@@ -9,31 +9,33 @@
-
+