Refactor commerce models and add configuration app
Major refactor of commerce models: restructured Carrier, Payment, and DiscountCode models, improved order total calculation, and integrated Zasilkovna and Stripe logic. Added new configuration Django app for shop settings, updated Zasilkovna and Stripe models, and fixed Zasilkovna client WSDL URL. Removed unused serializers and views in commerce, and registered new apps in settings.
This commit is contained in:
4
backend/thirdparty/stripe/models.py
vendored
4
backend/thirdparty/stripe/models.py
vendored
@@ -1,8 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
#TODO: logika a interakce bude na stripu (třeba aktualizovaní objednávky na zaplacenou apod.)
|
||||
|
||||
class Order(models.Model):
|
||||
class StripePayment(models.Model):
|
||||
STATUS_CHOICES = [
|
||||
("pending", "Pending"),
|
||||
("paid", "Paid"),
|
||||
|
||||
2
backend/thirdparty/zasilkovna/apps.py
vendored
2
backend/thirdparty/zasilkovna/apps.py
vendored
@@ -4,3 +4,5 @@ from django.apps import AppConfig
|
||||
class ZasilkovnaConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'zasilkovna'
|
||||
name = 'thirdparty.zasilkovna'
|
||||
label = "zasilkovna"
|
||||
|
||||
2
backend/thirdparty/zasilkovna/client.py
vendored
2
backend/thirdparty/zasilkovna/client.py
vendored
@@ -7,7 +7,7 @@ import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
WSDL_URL = os.getenv("PACKETA_WSDL_URL", "https://soap.api.packeta.com/api/soap-bugfix.wsdl")
|
||||
WSDL_URL = os.getenv("PACKETA_WSDL_URL", "https://www.zasilkovna.cz/api/soap.wsdl")
|
||||
PACKETA_API_PASSWORD = os.getenv("PACKETA_API_PASSWORD")
|
||||
|
||||
zeepZasClient = Client(wsdl=WSDL_URL)
|
||||
|
||||
23
backend/thirdparty/zasilkovna/models.py
vendored
23
backend/thirdparty/zasilkovna/models.py
vendored
@@ -23,6 +23,8 @@ from django.core.validators import RegexValidator
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
from .client import PacketaAPI
|
||||
from commerce.models import Order, Carrier
|
||||
from configuration.models import Configuration
|
||||
|
||||
packeta_client = PacketaAPI() # single reusable instance
|
||||
|
||||
@@ -71,8 +73,27 @@ class ZasilkovnaPacket(models.Model):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# On first save, create the packet remotely if packet_id is not set
|
||||
carrier = Carrier.objects.get(zasilkovna=self)
|
||||
order = Order.objects.get(carrier=carrier)
|
||||
|
||||
if not self.packet_id:
|
||||
response = packeta_client.create_packet(**kwargs)
|
||||
response = packeta_client.create_packet(
|
||||
address_id=self.addressId,
|
||||
weight=self.weight,
|
||||
number=order.id,
|
||||
name=order.first_name,
|
||||
surname=order.last_name,
|
||||
company=order.company,
|
||||
email=order.email,
|
||||
addressId=Configuration.get_solo().zasilkovna_address_id,
|
||||
|
||||
#FIXME: udělat logiku pro počítaní dobírky a hodnoty zboží
|
||||
cod=100.00,
|
||||
value=100.00,
|
||||
|
||||
currency=Configuration.get_solo().currency,
|
||||
eshop= Configuration.get_solo().name,
|
||||
)
|
||||
self.packet_id = response['packet_id']
|
||||
self.barcode = response['barcode']
|
||||
|
||||
|
||||
8
backend/thirdparty/zasilkovna/views.py
vendored
8
backend/thirdparty/zasilkovna/views.py
vendored
@@ -0,0 +1,8 @@
|
||||
#views.py
|
||||
|
||||
"""
|
||||
TODO: OBJEDNAVANÍ SE VYVOLÁVA V CARRIER V COMMERCE.MODELS.PY
|
||||
získaní labelu,
|
||||
info o kurýrovi, vracení balíku,
|
||||
vytvoření hromadné expedice
|
||||
"""
|
||||
Reference in New Issue
Block a user