Skip to content

Commit

Permalink
Merge 16881c8 into b11b083
Browse files Browse the repository at this point in the history
  • Loading branch information
gcandal committed Sep 30, 2016
2 parents b11b083 + 16881c8 commit c5fc9ab
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/budy/models/bundle_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class BundleLine(base.BudyBase):
type = int
)

closed = appier.field(
type = bool,
initial = False,
index = True
)

attributes = appier.field()

product = appier.field(
Expand All @@ -105,6 +111,7 @@ def pre_save(self):
self.ensure_valid()

def calculate(self, currency = None, country = None, force = False):
if self.closed: return
currency = currency or self.currency
country = country or self.country
self.total_taxes = self.quantity * self.get_taxes(
Expand All @@ -119,13 +126,18 @@ def calculate(self, currency = None, country = None, force = False):
)

def measure(self, currency = None, country = None, force = False):
if self.closed: return
if self.size and self.scale and not force: return
self.size, self.scale = self.get_size(
currency = currency,
country = country,
force = force
)

def close_s(self):
self.closed = True
self.save()

def get_price(self, currency = None, country = None, force = False):
is_dirty = self.is_dirty(currency = currency, country = country)
if not is_dirty and not force: return self.price
Expand Down
16 changes: 16 additions & 0 deletions src/budy/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ def ensure_waiting_s(self):
if not self.status == "created": return
self.mark_waiting_payment_s()

def close_lines_s(self):
for line in self.lines: line.close_s()

def get_paypal(self, return_url = None, cancel_url = None):
items = []
for line in self.lines:
Expand Down Expand Up @@ -501,6 +504,14 @@ def is_payable(self):
if self.date: return False
return True

def is_open(self):
if not self.status == "created": return False
if self.paid: return False
return True

def is_closed(self):
return not self.is_open()

def verify_base(self):
"""
Series of base verifications that define the basic integrity
Expand Down Expand Up @@ -693,6 +704,11 @@ def lines_csv_url(self, absolute = False):
absolute = absolute
)

@appier.operation(name = "Fix Closed Lines")
def fix_closed_s(self):
if not self.is_closed(): return
self.close_lines_s()

@property
def payable(self):
return self.total
Expand Down
37 changes: 37 additions & 0 deletions src/budy/test/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,40 @@ def test_free(self):
self.assertEqual(isinstance(order.total, commons.Decimal), True)
self.assertEqual(isinstance(order.payable, commons.Decimal), True)
self.assertEqual(isinstance(order.discountable, commons.Decimal), True)

def test_is_open(self):
order = budy.Order()
order.save()

product = budy.Product(
short_description = "product",
gender = "Male",
price = 10.0
)
product.save()

order_line = budy.OrderLine(quantity = 2.0)
order_line.product = product
order_line.save()
order.add_line_s(order_line)

address = budy.Address(
first_name = "first name",
last_name = "last name",
address = "address",
city = "city"
)
address.save()

order.shipping_address = address
order.billing_address = address
order.email = "username@email.com"
order.save()

self.assertEqual(order.is_open(), True)
self.assertEqual(order.is_closed(), False)

order.mark_waiting_payment_s()

self.assertEqual(order.is_open(), False)
self.assertEqual(order.is_closed(), True)

0 comments on commit c5fc9ab

Please sign in to comment.