Features: 1) Add handling for business user attributes in order logic; 2) Update HTTP response codes for business order creation to 201.
Fixes: 1) Fix typo `business_inn` to `business_identificator`. Extra: 1) Improve exception handling with specific error cases for invalid `force` values; 2) Minor formatting adjustments in `models.py`.
This commit is contained in:
parent
06b88254e0
commit
a44b8fb652
4 changed files with 10 additions and 5 deletions
|
|
@ -91,7 +91,7 @@ BUY_AS_BUSINESS_SCHEMA = {
|
|||
summary=_("purchase an order as a business"),
|
||||
request=BuyAsBusinessOrderSerializer,
|
||||
responses={
|
||||
200: TransactionProcessSerializer,
|
||||
201: TransactionProcessSerializer,
|
||||
400: error,
|
||||
},
|
||||
description=(
|
||||
|
|
|
|||
|
|
@ -1640,6 +1640,11 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
|||
if not order.user:
|
||||
raise ValueError(_("you cannot buy an order without a user"))
|
||||
|
||||
if order.user.attributes.get("is_business", False):
|
||||
if type(order.attributes) is not dict:
|
||||
order.attributes = {}
|
||||
order.attributes.update({"is_business": True})
|
||||
|
||||
if not order.user.payments_balance:
|
||||
raise ValueError(_("a user without a balance cannot buy with balance"))
|
||||
|
||||
|
|
@ -1663,8 +1668,8 @@ class Order(ExportModelOperationsMixin("order"), NiceModel): # type: ignore [mi
|
|||
currency=CURRENCY_CODE,
|
||||
order=order,
|
||||
)
|
||||
|
||||
return order
|
||||
case _:
|
||||
raise ValueError(_("invalid force value"))
|
||||
|
||||
def buy_without_registration(self, products: list, promocode_uuid, **kwargs) -> Transaction | None:
|
||||
if config.DISABLED_COMMERCE:
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ class BuyUnregisteredOrderSerializer(Serializer):
|
|||
|
||||
class BuyAsBusinessOrderSerializer(Serializer):
|
||||
products = ListField(child=AddOrderProductSerializer(), required=True)
|
||||
business_inn = CharField(required=True)
|
||||
business_identificator = CharField(required=True)
|
||||
business_email = CharField(required=True)
|
||||
business_phone_number = CharField(required=True)
|
||||
billing_business_address_uuid = CharField(required=False)
|
||||
|
|
|
|||
|
|
@ -445,7 +445,7 @@ class BuyAsBusinessView(APIView):
|
|||
is_business=True,
|
||||
)
|
||||
return Response(
|
||||
status=status.HTTP_202_ACCEPTED,
|
||||
status=status.HTTP_201_CREATED,
|
||||
data=TransactionProcessSerializer(transaction).data,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue