Skip to content

Commit

Permalink
minor changes from hoosnick/payme-pkg-3.0b
Browse files Browse the repository at this point in the history
payme/models.py
  • Loading branch information
hoosnick authored Aug 26, 2023
2 parents bb05d2b + fc32c0a commit 03b86d3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/payme/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ShippingDetail(models.Model):
price = models.BigIntegerField(default=0)

def __str__(self) -> str:
return f"[{self.pk}] {self.title} {self.price}"
return f"[{self.pk}] {self.title} - {self.price:,}"


class Item(models.Model):
Expand All @@ -50,7 +50,7 @@ class Item(models.Model):
vat_percent = models.IntegerField(default=0, null=True, blank=True)

def __str__(self) -> str:
return f"[{self.id}] {self.title} ({self.count} pc.) x {self.price}"
return f"[{self.id}] {self.title} ({self.count} pc.) x {self.price:,}"


class OrderDetail(models.Model):
Expand All @@ -69,12 +69,13 @@ class OrderDetail(models.Model):
@property
def get_items_display(self):
# pylint: disable=missing-function-docstring
return ', '.join([items.title for items in self.items.all()[:2]])
return ', '.join([items.title for items in self.items.all()])

@property
def get_total_items_price(self) -> int:
# pylint: disable=missing-function-docstring
return self.items.all().aggregate(
shipping_price = self.shipping.price if self.shipping else 0
return shipping_price + self.items.all().aggregate(
total_price=models.Sum(
models.F('price') * models.F('count')
)
Expand Down Expand Up @@ -117,6 +118,9 @@ def amount(self):
# pylint: disable=missing-function-docstring
return self.detail.get_total_items_price

def __str__(self):
return f"ORDER ID: {self.id} - AMOUNT: {self.amount:,}"

class Meta:
# pylint: disable=missing-class-docstring
abstract = True

0 comments on commit 03b86d3

Please sign in to comment.