Skip to content

Commit

Permalink
#801 Drop wholesale from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Apr 2, 2019
1 parent 9053a01 commit 4660bc7
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 414 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ for info about both of them.
It's good to print list.
- [Link to no-images prods in admin panel](https://www.shopelectro.ru/admin/shopelectro/productpage/?has_images=no&is_active__exact=1).
It has filters.

## Оптовые цены
Убрали их с интерфейса в этой задаче.
Есть небольшая вероятность, что вернём.
https://github.com/fidals/shopelectro/issues/801
91 changes: 0 additions & 91 deletions shopelectro/cart.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,5 @@
from collections import OrderedDict
from functools import wraps

from django.db.models import Model
from django.conf import settings

from ecommerce.cart import Cart

from shopelectro.models import Product


def recalculate(func):
@wraps(func)
def wrapper(*args, **kwargs):
recalculate_price(func(*args, **kwargs))
return wrapper


def recalculate_price(cart: Cart):
"""
Define what type of price should be used in Cart.
Actualize price if needed.
"""
wholesale_types = OrderedDict([
('wholesale_large', settings.PRICE_BOUNDS['wholesale_large']),
('wholesale_medium', settings.PRICE_BOUNDS['wholesale_medium']),
('wholesale_small', settings.PRICE_BOUNDS['wholesale_small']),
])

product_ids = [id_ for id_, _ in cart]
products = Product.objects.filter(id__in=product_ids)

def get_product(id_):
return next((product for product in products if product.id == id_), {})

def get_product_data(price_type: str) -> list:
return [{
'id': id_,
'quantity': position['quantity'],
'price': getattr(
get_product(id_), price_type or 'price',
),
} for id_, position in cart]

def get_total_price(price_type: str):
return sum(
product_data['price'] * product_data['quantity']
for product_data in get_product_data(price_type)
)

total_wholesale_prices = {
price_type: get_total_price(price_type)
for price_type in wholesale_types
}

def define_price_type() -> "Wholesale price type" or None:
def is_applicable(price_type):
return (
wholesale_types[price_type] <
total_wholesale_prices[price_type]
)

for price_type in wholesale_types:
if is_applicable(price_type):
return price_type

def set_position_prices(price_type: str):
"""
Set price from Product.price.
If price_type is NoneType, then it is retail price, set price from
Product.price.
"""
cart.update_position_prices(get_product_data(price_type))

set_position_prices(define_price_type())


class SECart(Cart):
"""Override Cart class for Wholesale features."""
Expand All @@ -88,21 +12,6 @@ def get_position_data(self, position):
'purchase_price': position.purchase_price,
}

@recalculate
def add(self, position: Model, quantity=1):
super().add(position, quantity)
return self

@recalculate
def set_position_quantity(self, position: Model, quantity: int):
super().set_position_quantity(position, quantity)
return self

@recalculate
def remove(self, position: Model):
super().remove(position)
return self

def total_revenue(self):
return sum(
(position['price'] - position['purchase_price']) * position['quantity']
Expand Down
3 changes: 1 addition & 2 deletions shopelectro/management/commands/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from images.models import Image, model_directory_path
from pages.models import Page, FlatPage, PageTemplate
from pages.utils import save_custom_pages, init_redirects_app

from shopelectro import models as se_models, tests as se_tests


Expand Down Expand Up @@ -151,7 +150,7 @@ def create_product(parent: se_models.Category, tags_, price_factor):
id=self.product_id,
# vendor_code should be differ from id for tests.
vendor_code=self._product_id + 1,
name='Product #{} of {}'.format(price_factor, parent),
name=f'Product #{price_factor} of {parent}',
in_stock=price_factor % 3,
price=price_factor * 100,
category=parent,
Expand Down
6 changes: 0 additions & 6 deletions shopelectro/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,6 @@ def get_robots_content():
],
}

PRICE_BOUNDS = {
'wholesale_large': 100000,
'wholesale_medium': 50000,
'wholesale_small': 20000,
}

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

# products with price lower this value should not be presented at gm.yml price
Expand Down
Loading

0 comments on commit 4660bc7

Please sign in to comment.