Add external product prices (#47)
Co-authored-by: Niklas Fondberg <niklas.fondberg@photowall.se>
This commit is contained in:
co-authored by
Niklas Fondberg
parent
f0b18c6757
commit
b1177a1e1c
+98
-1
@@ -1,3 +1,4 @@
|
||||
from api.models.external_print_product import get_cheapest_canvas_product, get_cheapest_poster_product
|
||||
from flask import Blueprint, request, jsonify, abort
|
||||
from api.helpers import check_api_key
|
||||
from api.validators import validate_number, validate_any_of, validate_exists
|
||||
@@ -20,6 +21,7 @@ from api.lib.prices import (
|
||||
wallpaper_m2_price,
|
||||
inquiry_price,
|
||||
wallpaper_kit_price,
|
||||
external_product_price,
|
||||
)
|
||||
from api.lib.limits import calculate_canvas_limits
|
||||
|
||||
@@ -524,6 +526,32 @@ def inquiry_poster(inquiry):
|
||||
return data
|
||||
|
||||
|
||||
def inquiry_external_product(inquiry):
|
||||
external_id = request.args.get("external_product_id", type=str)
|
||||
data = {
|
||||
"id": inquiry.id,
|
||||
"retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True),
|
||||
"prices": [
|
||||
{
|
||||
"inquiry_price": inquiry_price(
|
||||
inquiry, external_id=external_id, rounded=False, inc_vat=True
|
||||
),
|
||||
"inquiry_price_excl_vat": inquiry_price(
|
||||
inquiry, external_id=external_id, rounded=False, inc_vat=False
|
||||
),
|
||||
"inquiry_price_excl_retouch": inquiry_price(
|
||||
inquiry, external_id=external_id, rounded=False, inc_vat=True, inc_price_retouch=False,
|
||||
),
|
||||
"inquiry_price_excl_retouch_excl_vat": inquiry_price(
|
||||
inquiry, external_id=external_id, rounded=False, inc_vat=False, inc_price_retouch=False,
|
||||
),
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def inquiry_framed_print(inquiry):
|
||||
sku = request.args.get("sku", type=str)
|
||||
data = {
|
||||
@@ -563,8 +591,11 @@ def inquiry_framed_print(inquiry):
|
||||
@mod.route("/inquiry/<int:inquiry_id>", methods=["GET"])
|
||||
def inquiry(inquiry_id):
|
||||
inquiry = Inquiry.query.get_or_404(inquiry_id)
|
||||
external_id = request.args.get("external_product_id")
|
||||
sku = request.args.get("sku", type=str)
|
||||
if inquiry.product_group == "photo-wallpaper":
|
||||
if external_id:
|
||||
data = inquiry_external_product(inquiry)
|
||||
elif inquiry.product_group == "photo-wallpaper":
|
||||
data = inquiry_wallpaper(inquiry)
|
||||
elif inquiry.product_group == "canvas":
|
||||
data = inquiry_canvas(inquiry)
|
||||
@@ -592,6 +623,40 @@ def list_prices_wallpaper(market_id):
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<int:market_id>/canvas_external")
|
||||
def list_prices_canvas_external(market_id):
|
||||
canvases = PrintProduct.query.canvases().all()
|
||||
market = Market.query.get_or_404(market_id)
|
||||
external_product_id = get_cheapest_canvas_product()
|
||||
|
||||
result = {}
|
||||
for canvas in canvases:
|
||||
result[canvas.id] = external_product_price(
|
||||
id = external_product_id,
|
||||
market=market,
|
||||
designer=canvas.product.designer
|
||||
)
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<int:market_id>/poster_external")
|
||||
def list_prices_poster_external(market_id):
|
||||
posters = PrintProduct.query.posters().all()
|
||||
market = Market.query.get_or_404(market_id)
|
||||
external_product_id = get_cheapest_poster_product()
|
||||
|
||||
result = {}
|
||||
for poster in posters:
|
||||
result[poster.id] = external_product_price(
|
||||
id = external_product_id,
|
||||
market=market,
|
||||
designer=poster.product.designer
|
||||
)
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<int:market_id>/canvas")
|
||||
def list_prices_canvas(market_id):
|
||||
canvases = PrintProduct.query.canvases().all()
|
||||
@@ -661,3 +726,35 @@ def list_prices_framed_prints(market_id):
|
||||
result[printid] = framed_print_price(sku=sku, market=market, designer=designer)
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/external-product", methods=["GET"])
|
||||
@validate_exists("market")
|
||||
@validate_exists("id")
|
||||
def external_product():
|
||||
market_id = request.args.get("market", type=int)
|
||||
market = Market.query.get_or_404(market_id)
|
||||
designer = get_designer()
|
||||
id = request.args.get("id", type=str)
|
||||
|
||||
data = [
|
||||
{
|
||||
"id": id,
|
||||
"price": external_product_price(
|
||||
id,
|
||||
market,
|
||||
designer=designer,
|
||||
rounded=False,
|
||||
inc_vat=True,
|
||||
),
|
||||
"price_excl_vat": external_product_price(
|
||||
id,
|
||||
market,
|
||||
designer=designer,
|
||||
rounded=False,
|
||||
inc_vat=False,
|
||||
),
|
||||
}
|
||||
]
|
||||
|
||||
return jsonify(data=data)
|
||||
|
||||
Reference in New Issue
Block a user