Skip to content

Commit

Permalink
Forced the discount value in the meta
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Nov 27, 2019
1 parent 7de3545 commit b559c2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/budy/models/measurement.py
Expand Up @@ -168,6 +168,10 @@ def from_omni(
)
if not _product: return None

# in case the discount at a merchandise level is not defined
# then tries to use the one coming from the (parent) product
if discount == None: discount = _product.meta.get("discount", None)

# creates the stocks list in case there are valid inventory lines being
# passed on the current measurement update/creation
stocks = None if inventory_lines == None else []
Expand Down Expand Up @@ -228,11 +232,14 @@ def from_omni(
measurement.currency = currency
measurement.product = _product

meta = dict(object_id = object_id, modify_date = modify_date)
meta = dict(
object_id = object_id,
modify_date = modify_date,
discount = discount
)
if hasattr(measurement, "meta") and measurement.meta: measurement.meta.update(meta)
else: measurement.meta = meta
if not stocks == None: measurement.meta["stocks"] = stocks
if not discount == None: measurement.meta["discount"] = discount

if "stock_on_hand" in merchandise or force:
measurement.quantity_hand = merchandise.get("stock_on_hand", 0.0)
Expand Down
7 changes: 5 additions & 2 deletions src/budy/models/product.py
Expand Up @@ -448,11 +448,14 @@ def from_omni(
product.brand = _brand
product.season = _season

meta = dict(object_id = object_id, modify_date = modify_date)
meta = dict(
object_id = object_id,
modify_date = modify_date,
discount = discount
)
if hasattr(product, "meta") and product.meta: product.meta.update(meta)
else: product.meta = meta
if not stocks == None: product.meta["stocks"] = stocks
if not discount == None: product.meta["discount"] = discount

if "stock_on_hand" in merchandise or force:
product.quantity_hand = merchandise.get("stock_on_hand", 0.0)
Expand Down

0 comments on commit b559c2b

Please sign in to comment.