Skip to content

Commit

Permalink
beter support for modification timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jun 23, 2016
1 parent 03952be commit bb9a3f4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/budy/bots/omni_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ def sync_products_store(self):
is_sub_product = _class in ("SubProduct",)
is_valid = is_product or is_sub_product
if not is_valid: continue
if is_product: self.sync_product_safe(merchandise)
else: self.sync_sub_product_safe(merchandise)
inventory_lines = api.list_inventory_lines(
store_id = self.store,
**{
"filter_string" : "",
"filters[]" : [
"functional_unit:equals:%d" % self.store,
"merchandise:equals:%d" % merchandise["object_id"]
]
}
)
inventory_line = inventory_lines[0]
if is_product: self.sync_product_safe(merchandise, inventory_line = inventory_line)
else: self.sync_sub_product_safe(merchandise, inventory_line = inventory_line)

def sync_products_db(self):
api = self.get_api()
Expand Down Expand Up @@ -168,7 +179,7 @@ def sync_product_safe(self, merchandise, *args, **kwargs):
"Problem syncing product %d - %s ..." % (object_id, exception)
)

def sync_product(self, merchandise, force = False):
def sync_product(self, merchandise, inventory_line = None, force = False):
# retrieves the reference to the api object that is
# going to be used for api based operations
api = self.get_api()
Expand All @@ -180,7 +191,11 @@ def sync_product(self, merchandise, force = False):

# builds a new product instance from the merchandise
# information that has just been retrieved
product = budy.Product.from_omni(merchandise, force = force)
product = budy.Product.from_omni(
merchandise,
inventory_line = inventory_line,
force = force
)
product.save()
product.images = []

Expand Down Expand Up @@ -243,7 +258,7 @@ def sync_sub_product_safe(self, merchandise, *args, **kwargs):
"Problem syncing sub product %d - %s ..." % (object_id, exception)
)

def sync_sub_product(self, merchandise, force = False):
def sync_sub_product(self, merchandise, inventory_line = None, force = False):
api = self.get_api()

object_id = merchandise["object_id"]
Expand All @@ -258,6 +273,7 @@ def sync_sub_product(self, merchandise, force = False):
measurement = budy.Measurement.from_omni(
merchandise,
sub_product = sub_product,
inventory_line = inventory_line,
force = force
)
if not measurement:
Expand All @@ -266,6 +282,7 @@ def sync_sub_product(self, merchandise, force = False):
measurement = budy.Measurement.from_omni(
merchandise,
sub_product = sub_product,
inventory_line = inventory_line,
force = force
)

Expand Down
8 changes: 8 additions & 0 deletions src/budy/models/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def from_omni(
cls,
merchandise,
sub_product = None,
inventory_line = None,
name = "size",
currency = "EUR",
force = False
Expand All @@ -126,6 +127,13 @@ def from_omni(
modify_date = merchandise["modify_date"]
company_product_code = merchandise["company_product_code"]

# verifies if an inventory line has been provided, if that's the case
# it's possible to determine a proper modification date for the sub product
# taking into account also the modification date of its inventory line
if inventory_line:
modify_date_line = inventory_line["modify_date"]
if modify_date_line > modify_date: modify_date = modify_date_line

_product = product.Product.get(
product_id = parent["company_product_code"],
raise_e = False
Expand Down
9 changes: 9 additions & 0 deletions src/budy/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def token_names(cls):
def from_omni(
cls,
merchandise,
inventory_line = None,
gender = "Both",
currency = "EUR",
force = False
Expand All @@ -298,6 +299,14 @@ def from_omni(
_collection = metadata.get("collection") or []
_brand = metadata.get("brand")
order = metadata.get("order")

# verifies if an inventory line has been provided, if that's the case
# it's possible to determine a proper modification date for the product
# taking into account also the modification date of its inventory line
if inventory_line:
modify_date_line = inventory_line["modify_date"]
if modify_date_line > modify_date: modify_date = modify_date_line

colors = _color if isinstance(_color, list) else [_color]
categories = _category if isinstance(_category, list) else [_category]
collections = _collection if isinstance(_collection, list) else [_collection]
Expand Down

0 comments on commit bb9a3f4

Please sign in to comment.