diff --git a/core/crm/amo/gateway.py b/core/crm/amo/gateway.py index 49979504..b9093e90 100644 --- a/core/crm/amo/gateway.py +++ b/core/crm/amo/gateway.py @@ -4,7 +4,6 @@ from typing import Optional import requests from constance import config -from django.conf import settings from django.core.cache import cache from django.db import transaction @@ -90,7 +89,15 @@ class AmoCRM: if type(order.attributes) is not dict: raise ValueError("order.attributes must be a dict") - if not order.attributes.get("business_identificator"): + business_identificator = ( + order.attributes.get("business_identificator") + or order.attributes.get("businessIdentificator") + or order.user.attributes.get("business_identificator") + or order.user.attributes.get("businessIdentificator") + or "" + ) + + if not business_identificator: return ( order.user.get_full_name() if order.user @@ -101,10 +108,10 @@ class AmoCRM: ) ) try: - business_identificator = order.attributes.get("business_identificator") r = requests.get( f"https://api-fns.ru/api/egr?req={business_identificator}&key={self.fns_api_key}", timeout=15 ) + r.raise_for_status() body = r.json() except requests.exceptions.RequestException as rex: logger.error(f"Unable to get company info with FNS: {rex}")