P5-4906 optimize framed print listprice
This commit is contained in:
+23
-13
@@ -597,26 +597,36 @@ def list_prices_posters(territory):
|
|||||||
|
|
||||||
@mod.route("/list-prices/<string:territory>/framed-print")
|
@mod.route("/list-prices/<string:territory>/framed-print")
|
||||||
def list_prices_framed_prints(territory):
|
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)
|
market = market_model.from_territory(territory)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for framed_print in framed_prints:
|
for row in rows:
|
||||||
product_fields = framed_print.product.fields
|
printid, pricepremium_framed_print, width, height = row
|
||||||
width = None
|
|
||||||
height = None
|
if not pricepremium_framed_print:
|
||||||
for product_field in product_fields:
|
pricepremium_framed_print = 0
|
||||||
if product_field.field.field == "width":
|
|
||||||
width = product_field.value
|
designer = SimpleNamespace(pricepremium_framed_print=pricepremium_framed_print)
|
||||||
if product_field.field.field == "height":
|
|
||||||
height = product_field.value
|
|
||||||
|
|
||||||
if width == height:
|
if width == height:
|
||||||
sku = pwinty.GLOBAL_CFP_12x12
|
sku = pwinty.GLOBAL_CFP_12x12
|
||||||
else:
|
else:
|
||||||
sku = pwinty.GLOBAL_CFP_11x14
|
sku = pwinty.GLOBAL_CFP_11x14
|
||||||
|
|
||||||
result[framed_print.id] = framed_print_price(
|
result[printid] = framed_print_price(sku=sku, market=market, designer=designer)
|
||||||
sku=sku, market=market, designer=framed_print.product.designer
|
|
||||||
)
|
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user