[IMP] account_journal_lock_date: black, isort, prettier
This commit is contained in:
parent
aec4ed94fe
commit
72086957e1
@ -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": [],
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
@ -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."
|
||||
"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."
|
||||
"for this journal, for example.",
|
||||
)
|
||||
|
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -1,35 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2017 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<data>
|
||||
<record model="ir.ui.view" id="account_journal_form_view">
|
||||
<field name="name">account.journal.form (in account_journal_lock_date)</field>
|
||||
<field
|
||||
name="name"
|
||||
>account.journal.form (in account_journal_lock_date)</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_form"/>
|
||||
<field name="inherit_id" ref="account.view_account_journal_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="account_control_ids" position="after">
|
||||
<field name="fiscalyear_lock_date"/>
|
||||
<field name="period_lock_date"/>
|
||||
<field name="fiscalyear_lock_date" />
|
||||
<field name="period_lock_date" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="account_journal_tree_view">
|
||||
<field name="name">account.journal.tree (in account_journal_lock_date)</field>
|
||||
<field
|
||||
name="name"
|
||||
>account.journal.tree (in account_journal_lock_date)</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_tree"/>
|
||||
<field name="inherit_id" ref="account.view_account_journal_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="type" position="after">
|
||||
<field name="fiscalyear_lock_date"/>
|
||||
<field name="period_lock_date"/>
|
||||
<field name="fiscalyear_lock_date" />
|
||||
<field name="period_lock_date" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</data>
|
||||
</odoo>
|
||||
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
@ -9,25 +9,26 @@
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<field name="fiscalyear_lock_date"/>
|
||||
<field name="fiscalyear_lock_date" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="period_lock_date"/>
|
||||
<field name="period_lock_date" />
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_update_lock_dates"
|
||||
<button
|
||||
name="action_update_lock_dates"
|
||||
string="Update"
|
||||
type="object"
|
||||
class="btn-primary"/>
|
||||
<button string="Cancel"
|
||||
class="btn-secondary"
|
||||
special="cancel" />
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<act_window id="update_journal_lock_dates_wizard_action"
|
||||
<act_window
|
||||
id="update_journal_lock_dates_wizard_action"
|
||||
name="Update journals lock dates"
|
||||
src_model="account.journal"
|
||||
res_model="update.journal.lock.dates.wizard"
|
||||
@ -35,5 +36,6 @@
|
||||
view_mode="form"
|
||||
key2="client_action_multi"
|
||||
target="new"
|
||||
multi="True"/>
|
||||
multi="True"
|
||||
/>
|
||||
</odoo>
|
||||
|
Loading…
x
Reference in New Issue
Block a user