Enhance discount logic and shop configuration models
Refactored discount application logic in OrderItem to support multiple coupons with configurable multiplication and addition rules from ShopConfiguration. Updated DiscountCode model to use PositiveIntegerField for percent and improved validation. Extended ShopConfiguration with new fields for contact, social media, and coupon settings. Ensured ShopConfiguration singleton creation at app startup.
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
from .models import ShopConfiguration
|
||||
|
||||
class ConfigurationConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'configuration'
|
||||
|
||||
def ready(self):
|
||||
"""Ensure the ShopConfiguration singleton exists at startup.
|
||||
|
||||
Wrapped in broad DB error handling so that commands like
|
||||
makemigrations/migrate don't fail when the table does not yet exist.
|
||||
"""
|
||||
try:
|
||||
ShopConfiguration.get_solo()
|
||||
|
||||
except (OperationalError, ProgrammingError):
|
||||
ShopConfiguration.objects.create()
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,30 @@ from django.db import models
|
||||
class ShopConfiguration(models.Model):
|
||||
name = models.CharField(max_length=100, default="Shop name", unique=True)
|
||||
|
||||
logo = models.ImageField(upload_to='shop_logos/', blank=True, null=True)
|
||||
favicon = models.ImageField(upload_to='shop_favicons/', blank=True, null=True)
|
||||
|
||||
contact_email = models.EmailField(max_length=254, blank=True, null=True)
|
||||
contact_phone = models.CharField(max_length=20, blank=True, null=True)
|
||||
contact_address = models.TextField(blank=True, null=True)
|
||||
opening_hours = models.JSONField(blank=True, null=True) #FIXME: vytvoř tvar pro otvírací dobu
|
||||
|
||||
#Social
|
||||
facebook_url = models.URLField(max_length=200, blank=True, null=True)
|
||||
instagram_url = models.URLField(max_length=200, blank=True, null=True)
|
||||
youtube_url = models.URLField(max_length=200, blank=True, null=True)
|
||||
tiktok_url = models.URLField(max_length=200, blank=True, null=True)
|
||||
whatsapp_number = models.CharField(max_length=20, blank=True, null=True)
|
||||
|
||||
#zasilkovna settings
|
||||
zasilkovna_shipping_price = models.DecimalField(max_digits=10, decimal_places=2, default=50)
|
||||
zasilkovna_address_id = models.CharField(max_length=100, blank=True, null=True, help_text="ID výdejního místa Zásilkovny pro odesílání zásilek")
|
||||
free_shipping_over = models.DecimalField(max_digits=10, decimal_places=2, default=2000)
|
||||
|
||||
|
||||
#coupon settings
|
||||
multiplying_coupons = models.BooleanField(default=True, help_text="Násobení kupónů v objednávce (ano/ne), pokud ne tak se použije pouze nejvyšší slevový kupón")
|
||||
addition_of_coupons_amount = models.BooleanField(default=False, help_text="Sčítání slevových kupónů v objednávce (ano/ne), pokud ne tak se použije pouze nejvyšší slevový kupón")
|
||||
|
||||
class CURRENCY(models.TextChoices):
|
||||
CZK = "CZK", "Czech Koruna"
|
||||
EUR = "EUR", "Euro"
|
||||
|
||||
Reference in New Issue
Block a user