Skip to content

Commit

Permalink
new quantity support
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jun 16, 2016
1 parent 280528a commit b1f9be7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/budy/models/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Bundle(base.BudyBase):
index = True
)

quantity = appier.field(
type = commons.Decimal,
index = True,
initial = commons.Decimal(0.0),
safe = True
)

sub_total = appier.field(
type = commons.Decimal,
index = True,
Expand Down Expand Up @@ -122,6 +129,9 @@ def validate(cls):
return super(Bundle, cls).validate() + [
appier.not_duplicate("key", cls._name()),

appier.not_null("quantity"),
appier.gte("quantity", 0.0),

appier.not_null("sub_total"),
appier.gte("sub_total", 0.0),

Expand Down Expand Up @@ -288,6 +298,7 @@ def empty_referrals_s(self):

def calculate(self):
lines = self.lines if hasattr(self, "lines") else []
self.quantity = sum(line.quantity for line in lines)
self.sub_total = sum(line.total for line in lines)
self.discount = self.calculate_discount()
self.taxes = self.calculate_taxes()
Expand Down Expand Up @@ -359,10 +370,6 @@ def fix_sub_total_s(self):
self.sub_total = self.total
self.save()

@property
def quantity(self):
return sum(line.quantity for line in self.lines)

@property
def discountable(self):
return self.sub_total
Expand Down

0 comments on commit b1f9be7

Please sign in to comment.