Refactor commerce models and enhance payment logic
Refactored commerce models to remove language prefixes from status choices, improved order and payment validation, and enforced business rules for payment and shipping combinations. Updated order item and cart calculations to use VAT-inclusive prices, added unique constraints and indexes to reviews, and improved stock management logic. Added new Stripe client methods for session and refund management, and updated Zasilkovna and Deutsche Post models for consistency. Minor fixes and improvements across related tasks, URLs, and configuration models.
This commit is contained in:
19
backend/thirdparty/stripe/models.py
vendored
19
backend/thirdparty/stripe/models.py
vendored
@@ -1,5 +1,6 @@
|
||||
from django.db import models
|
||||
from django.apps import apps
|
||||
from django.utils import timezone
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@@ -29,23 +30,25 @@ class StripeModel(models.Model):
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
#if new
|
||||
if self.pk:
|
||||
# If new (no primary key yet)
|
||||
if self.pk is None:
|
||||
super().save(*args, **kwargs) # Save first to get pk
|
||||
|
||||
Order = apps.get_model('commerce', 'Order')
|
||||
Payment = apps.get_model('commerce', 'Payment')
|
||||
|
||||
order = Order.objects.get(payment=Payment.objects.get(stripe=self))
|
||||
|
||||
session = StripeClient.create_checkout_session(order)# <-- předáme self.StripePayment
|
||||
session = StripeClient.create_checkout_session(order)
|
||||
|
||||
self.stripe_session_id = session.id
|
||||
self.stripe_payment_intent = session.payment_intent
|
||||
self.stripe_session_url = session.url
|
||||
|
||||
|
||||
# Save again with Stripe data
|
||||
super().save(update_fields=['stripe_session_id', 'stripe_payment_intent', 'stripe_session_url', 'updated_at'])
|
||||
else:
|
||||
self.updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
self.updated_at = timezone.now()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def paid(self):
|
||||
self.status = self.STATUS_CHOICES.PAID
|
||||
|
||||
Reference in New Issue
Block a user