Skip to content

Commit 5a137a1

Browse files
authored
Merge pull request #235 from em230418/13.0-database-expiration
commit is created by 👷‍♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
2 parents 4f5f0c4 + 109cd6c commit 5a137a1

File tree

12 files changed

+226
-0
lines changed

12 files changed

+226
-0
lines changed

database_expiration/README.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
2+
:target: https://opensource.org/licenses/MIT
3+
:alt: License: MIT
4+
5+
=====================
6+
Database expiration
7+
=====================
8+
9+
With this module you can make database to expire.
10+
11+
After reaching expiration date "Your database is expired" will be shown.
12+
Expiration date is defined in "System Parameters" as `database_expiration_date`.
13+
14+
Credits
15+
=======
16+
17+
Contributors
18+
------------
19+
* `Eugene Molotov <https://it-projects.info/team/em230418>`__:
20+
21+
Sponsors
22+
--------
23+
* `IT-Projects LLC <https://it-projects.info>`__
24+
25+
Maintainers
26+
-----------
27+
* `IT-Projects LLC <https://it-projects.info>`__
28+
29+
To get a guaranteed support
30+
you are kindly requested to purchase the module
31+
at `odoo apps store <https://apps.odoo.com/apps/modules/13.0/database_expiration/>`__.
32+
33+
Thank you for understanding!
34+
35+
`IT-Projects Team <https://www.it-projects.info/team>`__
36+
37+
Further information
38+
===================
39+
40+
Demo: http://runbot.it-projects.info/demo/access-addons/13.0
41+
42+
HTML Description: https://apps.odoo.com/apps/modules/13.0/database_expiration/
43+
44+
Usage instructions: `<doc/index.rst>`_
45+
46+
Changelog: `<doc/changelog.rst>`_
47+
48+
Notifications on updates: `via Atom <https://github.com/it-projects-llc/access-addons/commits/13.0/database_expiration.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/it-projects-llc/access-addons/commits/13.0/database_expiration.atom>`_
49+
50+
Tested on Odoo 12.0 6a57ad66b8374966ba7011e34cec20f6344f4f6d

database_expiration/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
2+
# License MIT (https://opensource.org/licenses/MIT).
3+
4+
{
5+
"name": """Database expiration""",
6+
"summary": """With this module you can make database to expire""",
7+
"category": "Hidden",
8+
# "live_test_url": "http://apps.it-projects.info/shop/product/DEMO-URL?version=13.0",
9+
"images": [],
10+
"version": "13.0.1.0.0",
11+
"application": False,
12+
"author": "IT-Projects LLC, Eugene Molotov",
13+
"support": "apps@it-projects.info",
14+
"website": "https://apps.odoo.com/apps/modules/13.0/database_expiration/",
15+
"license": "Other OSI approved licence", # MIT
16+
# "price": 9.00,
17+
# "currency": "EUR",
18+
"depends": ["web"],
19+
"external_dependencies": {"python": [], "bin": []},
20+
"data": ["views/assets.xml"],
21+
"demo": [],
22+
"qweb": ["static/src/xml/apps.xml"],
23+
"post_load": None,
24+
"pre_init_hook": None,
25+
"post_init_hook": None,
26+
"uninstall_hook": None,
27+
"auto_install": False,
28+
"installable": True,
29+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`1.0.0`
2+
-------
3+
4+
- **Init version**

database_expiration/doc/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=====================
2+
Database expiration
3+
=====================
4+
5+
Installation
6+
============
7+
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way
8+
9+
Configuration
10+
=============
11+
12+
* `Log in as admin
13+
* `Activate Developer Mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__
14+
* Open menu ``[[ Settings ]] >> Technical >> System Parameter``
15+
* Edit existing record by key `database_expiration_date` or create new one
16+
* Set date with format YYYY-MM-DD HH:MM:SS, click "Save" and reload web page
17+
* If you set past date, "Your database is expired" will appear and will disable navigating
18+
* If you set future date in range of 7 days and you have installed `web_responsive` module installed, you will see warning message in main menu page
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License MIT (https://opensource.org/licenses/MIT).
2+
3+
from . import ir_http
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
2+
# License MIT (https://opensource.org/licenses/MIT).
3+
4+
from datetime import datetime
5+
6+
from odoo import models
7+
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
8+
9+
10+
class IrHttp(models.AbstractModel):
11+
12+
_inherit = "ir.http"
13+
14+
def session_info(self):
15+
res = super(IrHttp, self).session_info()
16+
17+
res["is_database_expired"] = False
18+
now = datetime.now()
19+
database_expiration_date = (
20+
self.env["ir.config_parameter"]
21+
.sudo()
22+
.get_param("database_expiration_date", None)
23+
)
24+
# Note:
25+
# DO NOT USE database.expiration_date (with dot)
26+
# it will be overwritten here: https://github.com/odoo/odoo/blob/f9a559f5455a4b964de9a99ff05756302071e959/addons/mail/models/update.py#L114
27+
28+
if database_expiration_date:
29+
database_expiration_date = datetime.strptime(
30+
database_expiration_date, DEFAULT_SERVER_DATETIME_FORMAT
31+
)
32+
delta = database_expiration_date - now
33+
if now > database_expiration_date:
34+
res["is_database_expired"] = True
35+
res["database_expiration_message"] = "Your database is expired"
36+
elif delta.days > 7:
37+
pass
38+
elif delta.days > 1:
39+
res[
40+
"database_expiration_message"
41+
] = "Your database will expire in {} days".format(delta.days,)
42+
elif delta.days == 1:
43+
res[
44+
"database_expiration_message"
45+
] = "Your database will expire tomorrow"
46+
elif delta.days == 0:
47+
res["database_expiration_message"] = "Your database will expire today"
48+
49+
# database_expiration_message is shown, only if web_responsive installted
50+
if res.get("database_expiration_message") and not self.env[
51+
"ir.module.module"
52+
].search(
53+
[("name", "=", "web_responsive"), ("state", "=", "installed")], limit=1
54+
):
55+
del res["database_expiration_message"]
56+
57+
return res
4.84 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.expiration_message {
2+
width: 100%;
3+
text-align: center;
4+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
2+
License MIT (https://opensource.org/licenses/MIT). */
3+
odoo.define("database_expiration.main", function(require) {
4+
"use strict";
5+
6+
var AppsMenu = require("web.AppsMenu");
7+
8+
AppsMenu.include({
9+
start: function() {
10+
this._super.apply(this, arguments);
11+
12+
if (odoo.session_info.database_expiration_message) {
13+
this.$el
14+
.find(".expiration_message")
15+
.show()
16+
.html(odoo.session_info.database_expiration_message);
17+
}
18+
19+
if (odoo.session_info.is_database_expired) {
20+
$(".o_action_manager").block({
21+
message: $(".block_ui_expiration_message"),
22+
});
23+
$("header").css("z-index", $.blockUI.defaults.baseZ + 20);
24+
}
25+
},
26+
});
27+
});

0 commit comments

Comments
 (0)