summaryrefslogtreecommitdiff
path: root/addons/account_lock
diff options
context:
space:
mode:
Diffstat (limited to 'addons/account_lock')
-rw-r--r--addons/account_lock/__init__.py3
-rw-r--r--addons/account_lock/__openerp__.py16
-rw-r--r--addons/account_lock/i18n/account_lock.pot46
-rw-r--r--addons/account_lock/models/__init__.py3
-rw-r--r--addons/account_lock/models/res_company.py77
5 files changed, 145 insertions, 0 deletions
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.'))