Revert "Add price calculations in inches, new minimum size 30x30cm (#74)" (#75)

This reverts commit 5ca2ae727c.
This commit is contained in:
Fredrik Ringqvist
2024-05-24 14:35:43 +02:00
committed by GitHub
parent 5ca2ae727c
commit 5f9f6c90ed
2 changed files with 12 additions and 31 deletions
+3 -10
View File
@@ -80,19 +80,13 @@ def wallpaper_price_new(
height, height,
material, material,
market, market,
unit,
inquiry=None, inquiry=None,
): ):
m2_prices = wallpaper_m2_price_new(product_id, material.id, market, inquiry) m2_prices = wallpaper_m2_price_new(product_id, material.id, market, inquiry)
if (unit == 'inch'):
width = width * 2.54
height = height * 2.54
sqm = (width / 100) * (height / 100) sqm = (width / 100) * (height / 100)
# 0.09 m2 = 30x30 cm, which means we can accept 1 sq feet (0.0929 m2) min_sqm = 1
min_sqm = 0.09
sqm = max(sqm, min_sqm) sqm = max(sqm, min_sqm)
@@ -213,7 +207,6 @@ def inquiry_price_new(
): ):
width = kwargs.get("width", inquiry.width) width = kwargs.get("width", inquiry.width)
height = kwargs.get("height", inquiry.height) height = kwargs.get("height", inquiry.height)
unit = kwargs.get("unit", None)
material = kwargs.get("material", inquiry.material) material = kwargs.get("material", inquiry.material)
external_id = kwargs.get("external_id") external_id = kwargs.get("external_id")
@@ -227,9 +220,9 @@ def inquiry_price_new(
return prices return prices
elif inquiry.product_group == "photo-wallpaper": elif inquiry.product_group == "photo-wallpaper":
if is_own_image: if is_own_image:
prices = wallpaper_price_new(None, width, height, material, inquiry.market, unit, inquiry) prices = wallpaper_price_new(None, width, height, material, inquiry.market, inquiry)
else: else:
prices = wallpaper_price_new(product_id, width, height, material, inquiry.market, unit, inquiry) prices = wallpaper_price_new(product_id, width, height, material, inquiry.market, inquiry)
else: else:
raise ValueError("Invalid product group: {}".format(inquiry.product_group)) raise ValueError("Invalid product group: {}".format(inquiry.product_group))
+9 -21
View File
@@ -45,24 +45,23 @@ def get_designer():
@validate_number("width", "height") @validate_number("width", "height")
@validate_exists("market") @validate_exists("market")
def wallpaper(): def wallpaper():
width = request.args.get("width", type=float) width = request.args.get("width", type=int)
height = request.args.get("height", type=float) height = request.args.get("height", type=int)
market_id = request.args.get("market", type=int) market_id = request.args.get("market", type=int)
product_id = request.args.get("product", type=int) product_id = request.args.get("product", type=int)
unit = request.args.get("unit", type=str)
new_version = request.args.get("new_version") is not None new_version = request.args.get("new_version") is not None
market = Market.query.get_or_404(market_id) market = Market.query.get_or_404(market_id)
designer = get_designer() designer = get_designer()
reseller = get_reseller() reseller = get_reseller()
if width is None or height is None: if width is None or height is None:
raise ValidationError("width and height must be float") raise ValidationError("width and height must be integers")
materials = Material.query.wallpapers().all() materials = Material.query.wallpapers().all()
data = [] data = []
for material in materials: for material in materials:
if new_version: if new_version:
prices = wallpaper_price_new(product_id, width, height, material, market, unit) prices = wallpaper_price_new(product_id, width, height, material, market)
data.append( data.append(
{ {
"material": material.name, "material": material.name,
@@ -147,18 +146,8 @@ def get_inquiry_measurements(inquiry):
# first try to get it from the query string. If that fails try to get it # first try to get it from the query string. If that fails try to get it
# from the inquiry row in the database # from the inquiry row in the database
unit = request.args.get("unit", type=str, default=None) width = request.args.get("width", type=int, default=inquiry.width)
width = request.args.get("width", type=float, default=None) height = request.args.get("height", type=int, default=inquiry.height)
height = request.args.get("height", type=float, default=None)
if unit and not (width and height):
raise Exception("With unit in query string width and height must also be there.")
if not width:
width = inquiry.width
if not height:
height = inquiry.height
# if we still are missing a width/height just set them to 1 to avoid # if we still are missing a width/height just set them to 1 to avoid
# errors in the price calculations # errors in the price calculations
@@ -168,25 +157,24 @@ def get_inquiry_measurements(inquiry):
if not height: if not height:
height = 1 height = 1
return width, height, unit return width, height
def inquiry_wallpaper(inquiry, new_version=False): def inquiry_wallpaper(inquiry, new_version=False):
width, height, unit = get_inquiry_measurements(inquiry) width, height = get_inquiry_measurements(inquiry)
data = { data = {
"id": inquiry.id, "id": inquiry.id,
"group": "wallpaper", "group": "wallpaper",
"width": width, "width": width,
"height": height, "height": height,
"unit": unit,
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True), "retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
} }
materials = Material.query.wallpapers().all() materials = Material.query.wallpapers().all()
prices = [] prices = []
for material in materials: for material in materials:
if new_version: if new_version:
price = inquiry_price_new(inquiry, material=material, width=width, height=height, unit=unit) price = inquiry_price_new(inquiry, material=material, width=width, height=height)
prices.append( prices.append(
{ {
"material": material.name, "material": material.name,