|
|
@ -77,27 +77,6 @@ class OrderItem(models.Model):
|
|
|
|
total = self.item.amount
|
|
|
|
total = self.item.amount
|
|
|
|
total = round(total, 2)
|
|
|
|
total = round(total, 2)
|
|
|
|
return total
|
|
|
|
return total
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
|
|
|
if self.purchased_at:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
customer_email = self.order.customer.user.email
|
|
|
|
|
|
|
|
plan_name = self.item.title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
|
|
|
|
'email': customer_email,
|
|
|
|
|
|
|
|
'plan': plan_name
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
response = requests.post('https://osimenu.com/api/create-subscription/', data=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if response.status_code == 201:
|
|
|
|
|
|
|
|
print('Subscription created successfully')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print('Failed to create subscription')
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print(f'Error creating subscription: {e}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
super(OrderItem, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Invoice(models.Model):
|
|
|
|
class Invoice(models.Model):
|
|
|
@ -110,12 +89,12 @@ class Invoice(models.Model):
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.invoice_number:
|
|
|
|
if not self.invoice_number:
|
|
|
|
current_year = str(timezone.now().year)[-2:]
|
|
|
|
current_year = str(timezone.now().year)[-2:]
|
|
|
|
last_invoice = Invoice.objects.filter(invoice_number__startswith=current_year).order_by('-invoice_number').first()
|
|
|
|
last_invoice = Invoice.objects.all().last()
|
|
|
|
if last_invoice:
|
|
|
|
if last_invoice:
|
|
|
|
last_invoice_number = int(last_invoice.invoice_number.split('-')[1].split('+')[0])
|
|
|
|
last_invoice_number = int(last_invoice.invoice_number.split('-')[1].split('+')[0])
|
|
|
|
new_invoice_number = f"${current_year}-{last_invoice_number + 1}"
|
|
|
|
new_invoice_number = f"$0{current_year}-{last_invoice_number + 1}"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
new_invoice_number = f"${current_year}-1425"
|
|
|
|
new_invoice_number = f"$0{current_year}-1425"
|
|
|
|
self.invoice_number = new_invoice_number
|
|
|
|
self.invoice_number = new_invoice_number
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|