forked from OCA/account-financial-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OCA#815 from Eficent/11.0-account_lock_future_date
[11.0]]add] account_lock_to_date
- Loading branch information
Showing
16 changed files
with
902 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
==================== | ||
Account Lock To Date | ||
==================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-financial-tools/tree/11.0/account_lock_to_date | ||
:alt: OCA/account-financial-tools | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-financial-tools-11-0/account-financial-tools-11-0-account_lock_to_date | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/92/11.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to set a Period and Fiscal year Locking end dates. This | ||
will prevent users from posting journal entries on a date after the defined | ||
period or fiscal year end date. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To set a new lock to dates, go to *Invoicing / Adviser / Actions / Update accounting lock to dates*. | ||
|
||
A user without an Adviser group will not be able to post or update posted | ||
journal entries on the date "Lock To Date for Non-Advisers" or after. | ||
|
||
A user that has an Adviser group will not be able to post or update posted | ||
journal entries on the date "Lock To Date" or after. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_lock_to_date%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Eficent | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Eficent <https://www.eficent.com> | ||
** Jordi Ballester Alomar <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/11.0/account_lock_to_date>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2019 Eficent Business and IT Consulting Services, S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Account Lock To Date', | ||
'summary': """ | ||
Allows to set an account lock date in the future.""", | ||
'version': '11.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'author': 'Eficent, Odoo Community Association (OCA)', | ||
'website': 'https://github.com/OCA/account-financial-tools', | ||
'installable': True, | ||
'depends': [ | ||
'account', | ||
], | ||
'data': [ | ||
'wizards/account_update_lock_to_date.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import res_company | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2019 Eficent Business and IT Consulting Services, S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import api, models, _ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = 'account.move' | ||
|
||
@api.multi | ||
def _check_lock_date(self): | ||
res = super()._check_lock_date() | ||
for move in self: | ||
lock_to_date = min( | ||
move.company_id.period_lock_to_date or '0000-00-00', | ||
move.company_id.fiscalyear_lock_to_date or '0000-00-00') | ||
if self.user_has_groups('account.group_account_manager'): | ||
lock_to_date = move.company_id.fiscalyear_lock_to_date | ||
if lock_to_date and move.date >= (lock_to_date or '0000-00-00'): | ||
if self.user_has_groups('account.group_account_manager'): | ||
message = _("You cannot add/modify entries after and " | ||
"inclusive of the lock to date %s") % ( | ||
lock_to_date) | ||
else: | ||
message = _("You cannot add/modify entries after and " | ||
"inclusive of the lock to date %s. " | ||
"Check the company settings or ask someone " | ||
"with the 'Adviser' role") % ( | ||
lock_to_date) | ||
raise UserError(message) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Copyright 2019 Eficent Business and IT Consulting Services, S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from datetime import datetime | ||
from dateutil.relativedelta import relativedelta | ||
import calendar | ||
import time | ||
from odoo import api, fields, models, SUPERUSER_ID, _ | ||
from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = 'res.company' | ||
|
||
period_lock_to_date = fields.Date( | ||
string="Lock To Date for Non-Advisers", | ||
help="Only users with the 'Adviser' role can edit " | ||
"accounts after this date. " | ||
"Use it for period locking inside an open fiscal year, " | ||
"for example.") | ||
fiscalyear_lock_to_date = fields.Date( | ||
string="Lock To Date", | ||
help="No users, including Advisers, can edit accounts after " | ||
"this date. Use it for fiscal year locking for example.") | ||
|
||
@api.multi | ||
def write(self, vals): | ||
# fiscalyear_lock_date can't be set to a prior date | ||
if 'fiscalyear_lock_to_date' in vals or 'period_lock_to_date' in vals: | ||
self._check_lock_to_dates(vals) | ||
return super(ResCompany, self).write(vals) | ||
|
||
@api.multi | ||
def _check_lock_to_dates(self, vals): | ||
'''Check the lock to dates for the current companies. | ||
:param vals: The values passed to the write method. | ||
''' | ||
period_lock_to_date = vals.get('period_lock_to_date') and\ | ||
time.strptime(vals['period_lock_to_date'], | ||
DEFAULT_SERVER_DATE_FORMAT) | ||
fiscalyear_lock_to_date = vals.get('fiscalyear_lock_to_date') and\ | ||
time.strptime(vals['fiscalyear_lock_to_date'], | ||
DEFAULT_SERVER_DATE_FORMAT) | ||
|
||
next_month = datetime.strptime( | ||
fields.Date.today(), | ||
DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=+1) | ||
days_next_month = calendar.monthrange(next_month.year, | ||
next_month.month) | ||
next_month = next_month.replace( | ||
day=days_next_month[1]).timetuple() | ||
for company in self: | ||
old_fiscalyear_lock_to_date = company.fiscalyear_lock_to_date and\ | ||
time.strptime(company.fiscalyear_lock_to_date, | ||
DEFAULT_SERVER_DATE_FORMAT) | ||
|
||
# The user attempts to remove the lock date for advisors | ||
if old_fiscalyear_lock_to_date and \ | ||
not fiscalyear_lock_to_date and \ | ||
'fiscalyear_lock_to_date' in vals and \ | ||
not self._uid == SUPERUSER_ID: | ||
raise ValidationError(_('The lock date for advisors is ' | ||
'irreversible and can\'t be removed.')) | ||
|
||
# The user attempts to set a lock date for advisors prior | ||
# to the previous one | ||
if old_fiscalyear_lock_to_date and fiscalyear_lock_to_date and \ | ||
fiscalyear_lock_to_date > old_fiscalyear_lock_to_date: | ||
raise ValidationError( | ||
_('The new lock to date for advisors must be set after ' | ||
'the previous lock to date.')) | ||
|
||
# In case of no new fiscal year in vals, fallback to the oldest | ||
if not fiscalyear_lock_to_date: | ||
if old_fiscalyear_lock_to_date: | ||
fiscalyear_lock_to_date = old_fiscalyear_lock_to_date | ||
else: | ||
continue | ||
|
||
# The user attempts to set a lock date for advisors after | ||
# the first day of next month | ||
if fiscalyear_lock_to_date < next_month: | ||
raise ValidationError( | ||
_('You cannot lock a period that is not finished yet. ' | ||
'Please make sure that the lock date for advisors is ' | ||
'not set after the last day of the previous month.')) | ||
|
||
# In case of no new period lock to date in vals, | ||
# fallback to the one defined in the company | ||
if not period_lock_to_date: | ||
if company.period_lock_date: | ||
period_lock_to_date = time.strptime( | ||
company.period_lock_to_date, | ||
DEFAULT_SERVER_DATE_FORMAT) | ||
else: | ||
continue | ||
|
||
# The user attempts to set a lock to date for advisors | ||
# prior to the lock to date for users | ||
if period_lock_to_date > fiscalyear_lock_to_date: | ||
raise ValidationError( | ||
_('You cannot define stricter conditions on advisors ' | ||
'than on users. Please make sure that the lock date ' | ||
'on advisor is set after the lock date for users.')) | ||
|
||
@api.multi | ||
def _validate_fiscalyear_lock(self, values): | ||
res = super()._validate_fiscalyear_lock(values) | ||
if values.get('fiscalyear_lock_to_date'): | ||
nb_draft_entries = self.env['account.move'].search([ | ||
('company_id', 'in', self.ids), | ||
('state', '=', 'draft'), | ||
('date', '>=', values['fiscalyear_lock_to_date'])], limit=1) | ||
if nb_draft_entries: | ||
raise ValidationError( | ||
_('There are still unposted entries in the period to date' | ||
' you want to lock. ' | ||
'You should either post or delete them.')) | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Eficent <https://www.eficent.com> | ||
** Jordi Ballester Alomar <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows to set a Period and Fiscal year Locking end dates. This | ||
will prevent users from posting journal entries on a date after the defined | ||
period or fiscal year end date. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
To set a new lock to dates, go to *Invoicing / Adviser / Actions / Update accounting lock to dates*. | ||
|
||
A user without an Adviser group will not be able to post or update posted | ||
journal entries on the date "Lock To Date for Non-Advisers" or after. | ||
|
||
A user that has an Adviser group will not be able to post or update posted | ||
journal entries on the date "Lock To Date" or after. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.