order list view and serilaizer

This commit is contained in:
Parsa Nazer
2025-02-25 00:54:50 +03:30
parent 1246a3a8bb
commit 880ab60fac
4 changed files with 33 additions and 19 deletions
+11 -9
View File
@@ -59,21 +59,23 @@ class OrderModel(models.Model):
print('didnt send')
super().save(*args, **kwargs)
def total_with_discount(self):
total_with_item_discount = sum(item.total_with_discount() for item in self.items.all())
if self.discount_code:
if not self.discount_code.is_valid():
raise DiscountNotAvailableError('این کد تخفیف دیگر معتبر نیست')
discount_percent = self.discount_code.percent
return total_with_item_discount * ((100 - discount_percent) / 100)
return total_with_item_discount
def discount(self):
pass
# total_with_item_discount = sum(item.total_with_discount() for item in self.items.all())
# if self.discount_code:
# if not self.discount_code.is_valid():
# raise DiscountNotAvailableError('این کد تخفیف دیگر معتبر نیست')
# discount_percent = self.discount_code.percent
# return total_with_item_discount * ((100 - discount_percent) / 100)
# return total_with_item_discount
def tax(self):
return self.total_without_tax() * 0.2
def total(self):
return self.total_with_discount() + self.tax()
pass
# return self.total_with_discount() + self.tax()
def remove_order_item(self, item_pk, quantity):
pass