|
| 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 |
0 commit comments