Include segment in price requests (#70)

This commit is contained in:
Fredrik Ringqvist
2023-05-12 09:22:33 +02:00
committed by GitHub
parent 4556155a84
commit ad36f31122
3 changed files with 40 additions and 9 deletions
+17 -2
View File
@@ -16,10 +16,14 @@ def wallpaper_m2_price_new(
if own_image:
price_m2_incl_vat = get_own_image_wallpaper_m2_price(material_id, market.id)
segment = "OWN-IMAGE"
else:
price_m2_incl_vat = get_wallpaper_m2_price(product_id, material_id, market.id)
prices = get_wallpaper_m2_price(product_id, material_id, market.id)
price_m2_incl_vat = prices["price"]
segment = prices["segment"]
price_m2_excl_vat = price_m2_incl_vat / market.vat
segment_price = price_m2_incl_vat
if inquiry:
inquiry_premium = (float(inquiry.pricepremium) / 100) + 1
@@ -29,6 +33,8 @@ def wallpaper_m2_price_new(
return {
"incl_vat": price_m2_incl_vat,
"excl_vat": price_m2_excl_vat,
"segment": segment,
"segment_price": segment_price,
}
@@ -93,6 +99,8 @@ def wallpaper_price_new(
"excl_vat": price_excl_vat,
"m2_price_incl_vat": m2_prices["incl_vat"],
"m2_price_excl_vat": m2_prices["excl_vat"],
"segment": m2_prices["segment"],
"segment_price": m2_prices["incl_vat"],
}
@@ -149,17 +157,22 @@ def external_product_own_image_price(external_product_id, market):
return {
'incl_vat': price_incl_vat,
'excl_vat': price_excl_vat,
'segment': 'OWN-IMAGE',
'segment_price': price_incl_vat,
}
def external_product_price_new(product_id, external_product_id, market):
price_incl_vat = get_external_product_price(product_id, external_product_id, market.id)
prices = get_external_product_price(product_id, external_product_id, market.id)
price_incl_vat = prices['price']
price_excl_vat = price_incl_vat / market.vat
return {
'incl_vat': price_incl_vat,
'excl_vat': price_excl_vat,
'segment': prices['segment'],
'segment_price': price_incl_vat,
}
@@ -234,6 +247,8 @@ def inquiry_price_new(
"excl_retouch_excl_vat": price_excl_retouch_excl_vat,
"m2_price_incl_vat": prices["m2_price_incl_vat"],
"m2_price_excl_vat": prices["m2_price_excl_vat"],
"segment": prices["segment"],
"segment_price": prices["segment_price"],
}
+14 -6
View File
@@ -6,10 +6,11 @@ from api.extensions import db
def get_wallpaper_m2_price(product_id, material_id, market_id):
sql = """
select
price
price, ps.name
from
v_price_product_segments v
join prices_wallpaper_m2 p on v.segment_id = p.segment_id
join price_segments ps on v.segment_id = ps.id
where
productid = :product_id and market_id = :market_id and material_id = :material_id
order by priority desc
@@ -24,8 +25,11 @@ def get_wallpaper_m2_price(product_id, material_id, market_id):
rows = result.fetchall()
for row in rows:
price = row[0]
return float(price)
[price, segment] = row
return {
"price": float(price),
"segment": segment,
}
raise Exception("Failed reading wallpaper m2 price")
@@ -33,10 +37,11 @@ def get_wallpaper_m2_price(product_id, material_id, market_id):
def get_external_product_price(product_id, external_product_id, market_id):
sql = """
select
price
price, price_segments.name
from
v_price_product_segments v
join prices_external_products p on v.segment_id = p.segment_id
join price_segments on v.segment_id = price_segments.id
where
productid = :product_id and market_id = :market_id and external_product_id = :external_id
order by priority desc
@@ -51,8 +56,11 @@ def get_external_product_price(product_id, external_product_id, market_id):
rows = result.fetchall()
for row in rows:
price = row[0]
return float(price)
[price, segment] = row
return {
"price": float(price),
"segment": segment,
}
raise Exception("Failed reading external product price")
+9 -1
View File
@@ -70,6 +70,8 @@ def wallpaper():
"m2_price_excl_vat": prices["m2_price_excl_vat"],
"price": prices["incl_vat"],
"price_excl_vat": prices["excl_vat"],
"segment": prices["segment"],
"segment_price": prices["segment_price"],
}
)
continue
@@ -183,6 +185,8 @@ def inquiry_wallpaper(inquiry, new_version=False):
"inquiry_price_excl_vat": price["excl_vat"],
"inquiry_price_excl_retouch": price["excl_retouch_incl_vat"],
"inquiry_price_excl_retouch_excl_vat": price["excl_retouch_excl_vat"],
"segment": price["segment"],
"segment_price": price["segment_price"],
}
)
continue
@@ -263,6 +267,8 @@ def inquiry_external_product(inquiry, external_id, new_version):
"inquiry_price_excl_vat": result["excl_vat"],
"inquiry_price_excl_retouch": result["incl_vat"],
"inquiry_price_excl_retouch_excl_vat": result["excl_vat"],
"segment": result["segment"],
"segment_price": result["segment_price"],
}
],
}
@@ -333,7 +339,9 @@ def external_product():
{
"id": id,
"price": prices["incl_vat"],
"price_excl_vat": prices['excl_vat']
"price_excl_vat": prices["excl_vat"],
"segment": prices["segment"],
"segment_price": prices["segment_price"],
}
]
return jsonify(data=data)