Major refactor of commerce and Stripe integration
Refactored commerce models to support refunds, invoices, and improved carrier/payment logic. Added new serializers and viewsets for products, categories, images, discount codes, and refunds. Introduced Stripe client integration and removed legacy Stripe admin/model code. Updated Dockerfile for PDF generation dependencies. Removed obsolete migration files and updated configuration app initialization. Added invoice template and tasks for order cleanup.
This commit is contained in:
38
backend/thirdparty/zasilkovna/models.py
vendored
38
backend/thirdparty/zasilkovna/models.py
vendored
@@ -21,10 +21,11 @@ from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.core.validators import RegexValidator
|
||||
from django.core.files.base import ContentFile
|
||||
from django.apps import apps
|
||||
|
||||
from .client import PacketaAPI
|
||||
from commerce.models import Order, Carrier
|
||||
from configuration.models import Configuration
|
||||
|
||||
from configuration.models import ShopConfiguration
|
||||
|
||||
packeta_client = PacketaAPI() # single reusable instance
|
||||
|
||||
@@ -55,6 +56,13 @@ class ZasilkovnaPacket(models.Model):
|
||||
help_text="Hmotnost zásilky v gramech"
|
||||
)
|
||||
|
||||
# 🚚 návratové směrovací kódy (pro vrácení zásilky)
|
||||
return_routing = models.JSONField(
|
||||
default=list,
|
||||
blank=True,
|
||||
help_text="Seznam 2 routing stringů pro vrácení zásilky"
|
||||
)
|
||||
|
||||
class PDF_SIZE(models.TextChoices):
|
||||
A6_ON_A6 = ("A6 on A6", "105x148 mm (A6) label on a page of the same size")
|
||||
A7_ON_A7 = ("A7 on A7", "105x74 mm (A7) label on a page of the same size")
|
||||
@@ -63,19 +71,16 @@ class ZasilkovnaPacket(models.Model):
|
||||
A8_ON_A8 = ("A8 on A8", "50x74 mm (A8) label on a page of the same size")
|
||||
size_of_pdf = models.CharField(max_length=20, choices=PDF_SIZE.choices, default=PDF_SIZE.A6_ON_A6)
|
||||
|
||||
|
||||
# 🚚 návratové směrovací kódy (pro vrácení zásilky)
|
||||
return_routing = models.JSONField(
|
||||
default=list,
|
||||
blank=True,
|
||||
help_text="Seznam 2 routing stringů pro vrácení zásilky"
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# On first save, create the packet remotely if packet_id is not set
|
||||
# workaroud to avoid circular import
|
||||
Carrier = apps.get_model('commerce', 'Carrier')
|
||||
Order = apps.get_model('commerce', 'Order')
|
||||
|
||||
carrier = Carrier.objects.get(zasilkovna=self)
|
||||
order = Order.objects.get(carrier=carrier)
|
||||
|
||||
cash_on_delivery = order.payment.payment_method == order.payment.PAYMENT.CASH_ON_DELIVERY
|
||||
|
||||
if not self.packet_id:
|
||||
response = packeta_client.create_packet(
|
||||
address_id=self.addressId,
|
||||
@@ -85,14 +90,13 @@ class ZasilkovnaPacket(models.Model):
|
||||
surname=order.last_name,
|
||||
company=order.company,
|
||||
email=order.email,
|
||||
addressId=Configuration.get_solo().zasilkovna_address_id,
|
||||
addressId=ShopConfiguration.get_solo().zasilkovna_address_id,
|
||||
|
||||
#FIXME: udělat logiku pro počítaní dobírky a hodnoty zboží
|
||||
cod=100.00,
|
||||
value=100.00,
|
||||
cod=order.total_price if cash_on_delivery else 0, # dobírka
|
||||
value=order.total_price,
|
||||
|
||||
currency=Configuration.get_solo().currency,
|
||||
eshop= Configuration.get_solo().name,
|
||||
currency=ShopConfiguration.get_solo().currency,
|
||||
eshop= ShopConfiguration.get_solo().name,
|
||||
)
|
||||
self.packet_id = response['packet_id']
|
||||
self.barcode = response['barcode']
|
||||
|
||||
Reference in New Issue
Block a user