Features: 1) Add handling for multiple AMO CRM providers in gateway initialization; 2) Suppress CRMException in CRM-related signal processing;
Fixes: 1) Correct provider name from "amo" to "AmoCRM"; Extra: 1) Remove unused `time` import and redundant token caching logic; 2) Add missing CRMException import to signals; 3) Minor code cleanup and readability improvements;
This commit is contained in:
parent
2c67af969e
commit
4d9e276f2b
2 changed files with 8 additions and 7 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import logging
|
||||
import time
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
|
|
@ -18,10 +17,13 @@ class AmoCRM:
|
|||
|
||||
def __init__(self):
|
||||
try:
|
||||
self.instance = CustomerRelationshipManagementProvider.objects.get(name="amo")
|
||||
self.instance = CustomerRelationshipManagementProvider.objects.get(name="AmoCRM")
|
||||
except CustomerRelationshipManagementProvider.DoesNotExist as dne:
|
||||
logger.warning("AMO CRM provider not found")
|
||||
raise CRMException("AMO CRM provider not found") from dne
|
||||
except CustomerRelationshipManagementProvider.MultipleObjectsReturned as mre:
|
||||
logger.warning("Multiple AMO CRM providers found")
|
||||
raise CRMException("Multiple AMO CRM providers found") from mre
|
||||
|
||||
self.base = f"https://{self.instance.integration_url}"
|
||||
|
||||
|
|
@ -46,10 +48,6 @@ class AmoCRM:
|
|||
raise CRMException("AMO CRM provider not configured")
|
||||
|
||||
def _token(self) -> str:
|
||||
cached = getattr(self, "_cached_token", None)
|
||||
expiry = getattr(self, "_cached_expiry", 0)
|
||||
if cached and time.time() < expiry - 15:
|
||||
return cached
|
||||
payload = {
|
||||
"client_id": self.client_id,
|
||||
"client_secret": self.client_secret,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from contextlib import suppress
|
||||
from datetime import timedelta
|
||||
|
||||
from django.db import IntegrityError
|
||||
|
|
@ -11,6 +12,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from sentry_sdk import capture_exception
|
||||
|
||||
from core.crm import any_crm_integrations
|
||||
from core.crm.exceptions import CRMException
|
||||
from core.models import Category, Order, Product, PromoCode, Wishlist, DigitalAssetDownload
|
||||
from core.utils import (
|
||||
generate_human_readable_id,
|
||||
|
|
@ -69,7 +71,8 @@ def process_order_changes(instance, created, **_kwargs):
|
|||
instance.attributes = {}
|
||||
|
||||
if any_crm_integrations():
|
||||
instance.trigger_crm()
|
||||
with suppress(CRMException):
|
||||
instance.trigger_crm()
|
||||
|
||||
if not created:
|
||||
if instance.status != "PENDING" and instance.user:
|
||||
|
|
|
|||
Loading…
Reference in a new issue