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:
2025-11-14 02:21:20 +01:00
parent 052f7ab533
commit f14c09bf7a
16 changed files with 249 additions and 275 deletions

View File

@@ -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']