Skip to content

Commit

Permalink
#533 Set lower bound for gm.yml offers (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 authored Aug 25, 2018
1 parent 64939d2 commit cebb049
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions shopelectro/management/commands/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ def filter_categories(utm):

return result_categories

# @todo #533:30m Move `price.prepare_products` logic to `ProductQuerySet`
def prepare_products(categories_, utm):
"""Filter product list and patch it for rendering."""
products_except_others = (
products_result_qs = (
Product.actives
.select_related('page')
.prefetch_related('category')
Expand All @@ -110,15 +111,21 @@ def prepare_products(categories_, utm):
Yandex Market feed requires items in some categories to have pictures
To simplify filtering we are excluding all products without pictures
"""
products_except_others = (
products_except_others
products_result_qs = (
products_result_qs
.filter(page__images__isnull=False)
.distinct()
)

if utm == 'GM':
products_result_qs = (
products_result_qs
.filter(price__gt=settings.PRICE_GM_LOWER_BOUND)
)

result_products = [
put_crumbs(put_utm(product))
for product in products_except_others
for product in products_result_qs
]

return result_products
Expand Down
3 changes: 3 additions & 0 deletions shopelectro/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,6 @@ def get_robots_content():
SLUG_HASH_SIZE = 5

BRAND_TAG_GROUP_NAME = 'Производитель'

# products with price lower this value should not be presented at gm.yml price
PRICE_GM_LOWER_BOUND = 200.0
9 changes: 9 additions & 0 deletions shopelectro/tests/tests_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ def test_products_in_price(self):
products_in_price = self.get_price_offers_node('priceru.xml')
self.assertEqual(len(products_in_price), Product.objects.count())

def test_products_in_gm_price_bounds(self):
"""GM.yml should contain only offers with price > CONST."""
offers = self.get_price_offers_node('gm.yml').findall('offer')
prices_are_in_bounds = all(
float(offer.find('price').text) > settings.PRICE_GM_LOWER_BOUND
for offer in offers
)
self.assertTrue(prices_are_in_bounds)

def test_products_in_yandex_price(self):
products_in_yandex_price = self.get_price_offers_node('yandex.yml')
self.assertEqual(
Expand Down

1 comment on commit cebb049

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on cebb049 Aug 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 533-219400c4 discovered in shopelectro/management/commands/price.py and submitted as #547. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.