P5-4777 add listprice resources
This commit is contained in:
+80
-1
@@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify, abort
|
||||
from api.helpers import check_api_key
|
||||
from api.validators import validate_territory, validate_number, validate_any_of
|
||||
from api.models.inquiry import Inquiry
|
||||
from api.models.product import Material, Product
|
||||
from api.models.product import Material, Product, PrintProduct
|
||||
from api.models.contract_customer import ContractCustomer
|
||||
from api.models import market as market_model
|
||||
from api.lib import pwinty
|
||||
@@ -508,3 +508,82 @@ def inquiry(inquiry_id):
|
||||
raise ValueError("Invalid group {}".format(inquiry.product_group))
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/wallpaper")
|
||||
def list_prices_wallpaper(territory):
|
||||
wallpapers = PrintProduct.query.wallpapers().with_relations().all()
|
||||
result = {}
|
||||
material = Material.query.filter(Material.name == "standard-wallpaper").one()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
for wallpaper in wallpapers:
|
||||
result[wallpaper.id] = wallpaper_price(
|
||||
width=100,
|
||||
height=100,
|
||||
material=material,
|
||||
market=market,
|
||||
designer=wallpaper.product.designer,
|
||||
)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/canvas")
|
||||
def list_prices_canvas(territory):
|
||||
canvases = PrintProduct.query.canvases().with_relations().all()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
result = {}
|
||||
for canvas in canvases:
|
||||
result[canvas.id] = canvas_price(
|
||||
width=40,
|
||||
height=40,
|
||||
market=market,
|
||||
framed=True,
|
||||
designer=canvas.product.designer,
|
||||
)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/poster")
|
||||
def list_prices_posters(territory):
|
||||
posters = PrintProduct.query.posters().with_relations().all()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
result = {}
|
||||
for poster in posters:
|
||||
result[poster.id] = poster_price(
|
||||
width=30,
|
||||
height=30,
|
||||
market=market,
|
||||
hanger=True,
|
||||
designer=poster.product.designer,
|
||||
)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/framed-print")
|
||||
def list_prices_framed_prints(territory):
|
||||
framed_prints = PrintProduct.query.framed_prints().with_relations().all()
|
||||
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
|
||||
|
||||
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
|
||||
)
|
||||
return jsonify(result)
|
||||
|
||||
Reference in New Issue
Block a user