Skip to content
Snippets Groups Projects
Commit 2eb344f2 authored by Laurent Smet's avatar Laurent Smet Committed by qdp-odoo
Browse files

[ADD] account_lock: new module making the lock date irreversible

parent 1ad3d184
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
from . import models
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Irreversible Lock Date',
'version' : '1.0',
'category': 'Accounting',
'description': """
Make the lock date irreversible:
* You cannot define stricter conditions on advisors than on users. Then, the lock date on advisor must be set before the lock date for users.
* You cannot lock a period that is not finished yet. Then, the lock date for advisors must be set before the last day of the previous month.
* The new lock date for advisors must be set after the previous lock date.
""",
'depends' : ['account'],
'data': [],
}
µ# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_lock
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-14 08:33+0000\n"
"PO-Revision-Date: 2018-03-14 08:33+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_lock
#: model:ir.model,name:account_lock.model_res_company
msgid "Companies"
msgstr ""
#. module: account_lock
#: code:addons/account_lock/models/res_company.py:51
#, python-format
msgid "The lock date for advisors is irreversible and can't be removed."
msgstr ""
#. module: account_lock
#: code:addons/account_lock/models/res_company.py:55
#, python-format
msgid "The new lock date for advisors must be set after the previous lock date."
msgstr ""
#. module: account_lock
#: code:addons/account_lock/models/res_company.py:77
#, python-format
msgid "You cannot define stricter conditions on advisors than on users. Please make sure that the lock date on advisor is set before the lock date for users."
msgstr ""
#. module: account_lock
#: code:addons/account_lock/models/res_company.py:66
#, python-format
msgid "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."
msgstr ""
# -*- coding: utf-8 -*-
import res_company
# -*- coding: utf-8 -*-
import time
import calendar
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp import fields, models, api, _
from openerp.exceptions import ValidationError
from openerp.tools.misc import DEFAULT_SERVER_DATE_FORMAT
class ResCompany(models.Model):
_inherit = 'res.company'
@api.multi
def write(self, vals):
# fiscalyear_lock_date can't be set to a prior date
if 'fiscalyear_lock_date' in vals or 'period_lock_date' in vals:
self._check_lock_dates(vals)
return super(ResCompany, self).write(vals)
@api.multi
def _check_lock_dates(self, vals):
'''Check the lock dates for the current companies. This can't be done in a api.constrains because we need
to perform some comparison between new/old values. This method forces the lock dates to be irreversible.
* You cannot define stricter conditions on advisors than on users. Then, the lock date on advisor must be set
after the lock date for users.
* You cannot lock a period that is not finished yet. Then, the lock date for advisors must be set after the
last day of the previous month.
* The new lock date for advisors must be set after the previous lock date.
:param vals: The values passed to the write method.
'''
period_lock_date = vals.get('period_lock_date') and\
time.strptime(vals['period_lock_date'], DEFAULT_SERVER_DATE_FORMAT)
fiscalyear_lock_date = vals.get('fiscalyear_lock_date') and\
time.strptime(vals['fiscalyear_lock_date'], DEFAULT_SERVER_DATE_FORMAT)
previous_month = datetime.strptime(fields.Date.today(), DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=-1)
days_previous_month = calendar.monthrange(previous_month.year, previous_month.month)
previous_month = previous_month.replace(day=days_previous_month[1]).timetuple()
for company in self:
old_fiscalyear_lock_date = company.fiscalyear_lock_date and\
time.strptime(company.fiscalyear_lock_date, DEFAULT_SERVER_DATE_FORMAT)
# The user attempts to remove the lock date for advisors
if old_fiscalyear_lock_date and not fiscalyear_lock_date and 'fiscalyear_lock_date' in vals:
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_date and fiscalyear_lock_date and fiscalyear_lock_date < old_fiscalyear_lock_date:
raise ValidationError(_('The new lock date for advisors must be set after the previous lock date.'))
# In case of no new fiscal year in vals, fallback to the oldest
if not fiscalyear_lock_date:
if old_fiscalyear_lock_date:
fiscalyear_lock_date = old_fiscalyear_lock_date
else:
continue
# The user attempts to set a lock date for advisors prior to the last day of previous month
if fiscalyear_lock_date > previous_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 date in vals, fallback to the one defined in the company
if not period_lock_date:
if company.period_lock_date:
period_lock_date = time.strptime(company.period_lock_date, DEFAULT_SERVER_DATE_FORMAT)
else:
continue
# The user attempts to set a lock date for advisors prior to the lock date for users
if period_lock_date < fiscalyear_lock_date:
raise ValidationError(_('You cannot define stricter conditions on advisors than on users. Please make sure that the lock date on advisor is set before the lock date for users.'))
......@@ -19,7 +19,7 @@ The module adds following features:
Access to download the mandatory Certificate of Conformity delivered by Odoo SA (only for Odoo Enterprise users)
""",
'depends': ['l10n_fr'],
'depends': ['l10n_fr', 'account_lock'],
'installable': True,
'auto_install': False,
'application': False,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment