34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright NextZen
|
|
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
|
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def post_init_hook(env):
|
|
"""Trial-register on install; deactivate legacy agent cron if present."""
|
|
# Deactivate duplicate cron left by deprecated nextzen_subscription_agent
|
|
old_cron = env.ref(
|
|
"nextzen_subscription_agent.ir_cron_nextzen_subscription_heartbeat",
|
|
raise_if_not_found=False,
|
|
)
|
|
if old_cron and old_cron.active:
|
|
old_cron.active = False
|
|
_logger.info("Deactivated legacy nextzen_subscription_agent heartbeat cron.")
|
|
|
|
try:
|
|
Contract = env["nextzen.subscription.contract"].sudo()
|
|
Contract._ensure_defaults()
|
|
ok = Contract.register_notification()
|
|
if ok:
|
|
_logger.info("NextZen subscription: trial register succeeded.")
|
|
else:
|
|
_logger.info(
|
|
"NextZen subscription: trial register deferred "
|
|
"(Server unreachable / already registered)."
|
|
)
|
|
except Exception as exc:
|
|
_logger.warning("NextZen subscription: trial register on install failed: %s", exc)
|