From 2eb344f23b3a9daa8e7c7ddaead145a8b05b39bf Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Thu, 31 May 2018 10:06:19 +0200 Subject: [ADD] account_lock: new module making the lock date irreversible Was task: https://www.odoo.com/web#id=38178&view_type=form&model=project.task&action=333&active_id=967&menu_id=4720 Was PR #22094 --- addons/account_lock/__init__.py | 3 ++ addons/account_lock/__openerp__.py | 16 +++++++ addons/account_lock/i18n/account_lock.pot | 46 ++++++++++++++++++ addons/account_lock/models/__init__.py | 3 ++ addons/account_lock/models/res_company.py | 77 +++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 addons/account_lock/__init__.py create mode 100644 addons/account_lock/__openerp__.py create mode 100644 addons/account_lock/i18n/account_lock.pot create mode 100644 addons/account_lock/models/__init__.py create mode 100644 addons/account_lock/models/res_company.py (limited to 'addons/account_lock') diff --git a/addons/account_lock/__init__.py b/addons/account_lock/__init__.py new file mode 100644 index 00000000000..cde864bae21 --- /dev/null +++ b/addons/account_lock/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/addons/account_lock/__openerp__.py b/addons/account_lock/__openerp__.py new file mode 100644 index 00000000000..67e76b49098 --- /dev/null +++ b/addons/account_lock/__openerp__.py @@ -0,0 +1,16 @@ +# -*- 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': [], +} diff --git a/addons/account_lock/i18n/account_lock.pot b/addons/account_lock/i18n/account_lock.pot new file mode 100644 index 00000000000..8015c500a2f --- /dev/null +++ b/addons/account_lock/i18n/account_lock.pot @@ -0,0 +1,46 @@ +ยต# 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 "" + diff --git a/addons/account_lock/models/__init__.py b/addons/account_lock/models/__init__.py new file mode 100644 index 00000000000..fbbf76a47b5 --- /dev/null +++ b/addons/account_lock/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import res_company diff --git a/addons/account_lock/models/res_company.py b/addons/account_lock/models/res_company.py new file mode 100644 index 00000000000..c6834f298ee --- /dev/null +++ b/addons/account_lock/models/res_company.py @@ -0,0 +1,77 @@ +# -*- 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.')) -- cgit v1.2.3 From 579b233d383c95ca259b5333b6202b42a1dd80b0 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Thu, 31 May 2018 14:36:34 +0200 Subject: [FIX] l10n_fr_certification: can't change module dependancies on stable version Commit https://github.com/odoo/odoo/commit/2eb344f23b3a9daa8e7c7ddaead145a8b05b39bf changed the dependancies of l10n_fr_certification which is not acceptable on stable. Instead, the method to check is now moved in account module (to avoid duplicated) and it is called by l10n_fr_certification and account_lock module. --- addons/account_lock/i18n/account_lock.pot | 24 ------------ addons/account_lock/models/res_company.py | 65 +------------------------------ 2 files changed, 1 insertion(+), 88 deletions(-) (limited to 'addons/account_lock') diff --git a/addons/account_lock/i18n/account_lock.pot b/addons/account_lock/i18n/account_lock.pot index 8015c500a2f..2cf269729a6 100644 --- a/addons/account_lock/i18n/account_lock.pot +++ b/addons/account_lock/i18n/account_lock.pot @@ -20,27 +20,3 @@ msgstr "" 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 "" - diff --git a/addons/account_lock/models/res_company.py b/addons/account_lock/models/res_company.py index c6834f298ee..7d718b76664 100644 --- a/addons/account_lock/models/res_company.py +++ b/addons/account_lock/models/res_company.py @@ -1,14 +1,6 @@ # -*- 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 +from openerp import models, api class ResCompany(models.Model): @@ -20,58 +12,3 @@ class ResCompany(models.Model): 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.')) -- cgit v1.2.3