diff --git a/core/models.py b/core/models.py index dd0054e3..9d5419de 100644 --- a/core/models.py +++ b/core/models.py @@ -1831,7 +1831,7 @@ class CustomerRelationshipManagementProvider(ExportModelOperationsMixin("crm_pro verbose_name_plural = _("CRMs") -class OrderCrmLink(ExportModelOperationsMixin("order_crm_link"), NiceModel): +class OrderCrmLink(ExportModelOperationsMixin("order_crm_link"), NiceModel): # type: ignore order = ForeignKey(to=Order, on_delete=PROTECT, related_name="crm_links") crm = ForeignKey(to=CustomerRelationshipManagementProvider, on_delete=PROTECT, related_name="order_links") crm_lead_id = CharField(max_length=30, unique=True, db_index=True) diff --git a/core/serializers/utility.py b/core/serializers/utility.py index e7be7054..ec855c61 100644 --- a/core/serializers/utility.py +++ b/core/serializers/utility.py @@ -177,6 +177,7 @@ class BuyUnregisteredOrderSerializer(Serializer): class BuyAsBusinessOrderSerializer(Serializer): products = AddOrderProductSerializer(many=True, required=True) business_identificator = CharField(required=True) + promocode_uuid = UUIDField(required=False) business_email = CharField(required=True) business_phone_number = CharField(required=True) billing_business_address_uuid = CharField(required=False) diff --git a/core/views.py b/core/views.py index 278c53da..3b6bec4c 100644 --- a/core/views.py +++ b/core/views.py @@ -455,7 +455,7 @@ class BuyAsBusinessView(APIView): order.save() return Response( status=status.HTTP_400_BAD_REQUEST, - data={"error": str(e)}, + data={"detail": str(e)}, ) diff --git a/core/viewsets.py b/core/viewsets.py index 4165d148..9b99fe07 100644 --- a/core/viewsets.py +++ b/core/viewsets.py @@ -846,17 +846,20 @@ class OrderViewSet(EvibesViewSet): serializer.is_valid(raise_exception=True) order = Order.objects.create(status="MOMENTAL") products = [p["product_uuid"] for p in serializer.validated_data["products"]] - transaction = order.buy_without_registration( - products=products, - promocode_uuid=serializer.validated_data.get("promocode_uuid"), - customer_name=serializer.validated_data.get("customer_name"), - customer_email=serializer.validated_data.get("customer_email"), - customer_phone_number=serializer.validated_data.get("customer_phone_number"), - billing_customer_address=serializer.validated_data.get("billing_customer_address_uuid"), - shipping_customer_address=serializer.validated_data.get("shipping_customer_address_uuid"), - payment_method=serializer.validated_data.get("payment_method"), - ) - return Response(status=status.HTTP_202_ACCEPTED, data=TransactionProcessSerializer(transaction).data) + try: + transaction = order.buy_without_registration( + products=products, + promocode_uuid=serializer.validated_data.get("promocode_uuid"), + customer_name=serializer.validated_data.get("customer_name"), + customer_email=serializer.validated_data.get("customer_email"), + customer_phone_number=serializer.validated_data.get("customer_phone_number"), + billing_customer_address=serializer.validated_data.get("billing_customer_address_uuid"), + shipping_customer_address=serializer.validated_data.get("shipping_customer_address_uuid"), + payment_method=serializer.validated_data.get("payment_method"), + ) + return Response(status=status.HTTP_201_CREATED, data=TransactionProcessSerializer(transaction).data) + except Exception as e: + return Response(status=status.HTTP_400_BAD_REQUEST, data={"detail": str(e)}) @action(detail=True, methods=["post"], url_path="add_order_product") def add_order_product(self, request, **kwargs):