Skip to content

Commit

Permalink
new base shipping cost support for product
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jun 16, 2016
1 parent a18f7fe commit bd8144e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/budy/models/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def order_name(self):
def line_cls(cls):
return bundle_line.BundleLine

@classmethod
def eval_shipping(cls, *args, **kwargs):
shipping = appier.conf("BUDY_SHIPPING", None)
if not shipping: return 0.0
shipping = eval(shipping)
return shipping(*args, **kwargs)

def pre_validate(self):
base.BudyBase.pre_validate(self)
self.calculate()
Expand Down Expand Up @@ -305,10 +312,8 @@ def build_taxes(self):
return 0.0

def build_shipping(self):
shipping = appier.conf("BUDY_SHIPPING", None)
if not shipping: return 0.0
shipping = eval(shipping)
return shipping(self.sub_total, self.taxes, self.quantity)
cls = self.__class__
return cls.eval_shipping(self.sub_total, self.taxes, self.quantity)

def collect_empty(self):
empty = []
Expand Down
8 changes: 8 additions & 0 deletions src/budy/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import appier

from . import base
from . import bundle

class Product(base.BudyBase):

Expand Down Expand Up @@ -408,6 +409,13 @@ def simple_csv_url(cls, absolute = False):
absolute = absolute
)

@classmethod
def _build(cls, model, map):
price = model.get("price", None)
if price == None: shipping_cost = None
else: shipping_cost = bundle.Bundle.eval_shipping(price, 0.0, 0.0)
model["shipping_cost"] = shipping_cost

def pre_save(self):
base.BudyBase.pre_save(self)
if not self.measurements: return
Expand Down

0 comments on commit bd8144e

Please sign in to comment.