fix: docker build
This commit is contained in:
+24
-22
@@ -7,14 +7,13 @@ from decimal import Decimal
|
||||
import pyDes
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpRequest
|
||||
from django.utils import timezone
|
||||
from django.utils.text import gettext_lazy as _
|
||||
|
||||
from shop.exceptions import RedsysPaymentException, RedsysValidationException
|
||||
from shop.models import Cart, CartItem, Order, OrderLine, Payment, Product, ProductBatch, ProductPrice, ShippingMethod
|
||||
from shop.settings import ERROR_CODES
|
||||
from shop.signals import clear_cart
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@@ -69,7 +68,7 @@ def create_order(
|
||||
|
||||
def delete_product_batch(batch: ProductBatch):
|
||||
product = batch.product
|
||||
product.stock = max(product.stock - batch.quantity, 0)
|
||||
product.stock = max(product.stock - batch.quantity, Decimal('0.00'))
|
||||
product.save()
|
||||
batch.delete()
|
||||
|
||||
@@ -77,20 +76,20 @@ def delete_product_batch(batch: ProductBatch):
|
||||
def create_order_from_cart(
|
||||
cart: Cart,
|
||||
shipping_method: ShippingMethod,
|
||||
billing_address_full_name='',
|
||||
billing_address_address='',
|
||||
billing_address_town='',
|
||||
billing_address_state='',
|
||||
billing_address_country='',
|
||||
billing_address_zip='',
|
||||
shipping_address_full_name='',
|
||||
shipping_address_address='',
|
||||
shipping_address_town='',
|
||||
shipping_address_state='',
|
||||
shipping_address_country='',
|
||||
shipping_address_zip='',
|
||||
shipping_address_phone='',
|
||||
email='',
|
||||
billing_address_full_name: str = '',
|
||||
billing_address_address: str = '',
|
||||
billing_address_town: str = '',
|
||||
billing_address_state: str = '',
|
||||
billing_address_country: str = '',
|
||||
billing_address_zip: str = '',
|
||||
shipping_address_full_name: str = '',
|
||||
shipping_address_address: str = '',
|
||||
shipping_address_town: str = '',
|
||||
shipping_address_state: str = '',
|
||||
shipping_address_country: str = '',
|
||||
shipping_address_zip: str = '',
|
||||
shipping_address_phone: str = '',
|
||||
email: str = '',
|
||||
):
|
||||
order = Order.objects.create(
|
||||
billing_address=f'{billing_address_full_name} {billing_address_address}',
|
||||
@@ -155,7 +154,7 @@ def add_shipping_order_line(order, shipping_method):
|
||||
order.calculate_total_from_lines()
|
||||
|
||||
|
||||
def compute_signature(salt, payload, key):
|
||||
def compute_signature(salt: str, payload: str, key: str) -> bytes:
|
||||
"""
|
||||
:param salt: order number (Ds_Order or Ds_Merchant_Order)
|
||||
:param payload: Ds_MerchantParameters
|
||||
@@ -171,7 +170,7 @@ def compute_signature(salt, payload, key):
|
||||
return base64.b64encode(payload_hash)
|
||||
|
||||
|
||||
def validate_payment_for_order(request, order: Order) -> Decimal:
|
||||
def validate_payment_for_order(request: HttpRequest, order: Order) -> Decimal:
|
||||
"""
|
||||
example_response_data = {
|
||||
'Ds_MerchantCode': '999008881',
|
||||
@@ -262,15 +261,18 @@ def update_order_payment_status(order: Order):
|
||||
order.save()
|
||||
|
||||
|
||||
def delete_cart_items_from_order(order):
|
||||
def delete_cart_items_from_order(order: Order):
|
||||
if order.status == Order.Statuses.STATUS_PAID and order.from_cart:
|
||||
CartItem.objects.filter(cart=order.from_cart).delete()
|
||||
|
||||
|
||||
def add_payment_to_order(order: Order, amount):
|
||||
def add_payment_to_order(order: Order, amount: Decimal):
|
||||
with transaction.atomic():
|
||||
payment = Payment.objects.create(
|
||||
amount=amount, order=order, user=order.user, method=Payment.MethodChoices.REDSYS
|
||||
amount=amount,
|
||||
order=order,
|
||||
user=order.user,
|
||||
method=Payment.MethodChoices.REDSYS,
|
||||
)
|
||||
order.amount_paid += payment.amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user