P5-4906 optimize framed print listprice

This commit is contained in:
Martin Carlsson
2020-03-11 14:14:07 +01:00
committed by GitHub
parent 71cf7f5281
commit 576877d61b
+23 -13
View File
@@ -597,26 +597,36 @@ def list_prices_posters(territory):
@mod.route("/list-prices/<string:territory>/framed-print")
def list_prices_framed_prints(territory):
framed_prints = PrintProduct.query.framed_prints().all()
from api.extensions import db
from types import SimpleNamespace
query = (
"SELECT prints.printid, designers.pricepremium_framed_print, "
'width.value AS width, height.value AS height FROM "product-printproducts" prints '
'JOIN "product-products" products ON prints.productid = products.productid '
'LEFT JOIN "product-products_fields" width ON width.fieldid = 5 and width.productid = products.productid '
'LEFT JOIN "product-products_fields" height ON height.fieldid = 3 and height.productid = products.productid '
"LEFT JOIN designers ON designers.designerid = products.designerid "
"WHERE prints.groupid = :group"
)
rows = db.session.execute(query, {"group": 8})
market = market_model.from_territory(territory)
result = {}
for framed_print in framed_prints:
product_fields = framed_print.product.fields
width = None
height = None
for product_field in product_fields:
if product_field.field.field == "width":
width = product_field.value
if product_field.field.field == "height":
height = product_field.value
for row in rows:
printid, pricepremium_framed_print, width, height = row
if not pricepremium_framed_print:
pricepremium_framed_print = 0
designer = SimpleNamespace(pricepremium_framed_print=pricepremium_framed_print)
if width == height:
sku = pwinty.GLOBAL_CFP_12x12
else:
sku = pwinty.GLOBAL_CFP_11x14
result[framed_print.id] = framed_print_price(
sku=sku, market=market, designer=framed_print.product.designer
)
result[printid] = framed_print_price(sku=sku, market=market, designer=designer)
return jsonify(result)