Files

113 lines
3.0 KiB
Python

# coding=UTF-8
from api.extensions import db
def get_wallpaper_m2_price(product_id, material_id, market_id):
sql = """
select
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
limit 1;
"""
result = db.session.execute(sql, {
"product_id": product_id,
"market_id": market_id,
"material_id": material_id,
})
rows = result.fetchall()
for row in rows:
[price, segment] = row
return {
"price": float(price),
"segment": segment,
}
raise Exception("Failed reading wallpaper m2 price")
def get_external_product_price(product_id, external_product_id, market_id):
sql = """
select
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
limit 1;
"""
result = db.session.execute(sql, {
"product_id": product_id,
"market_id": market_id,
"external_id": external_product_id,
})
rows = result.fetchall()
for row in rows:
[price, segment] = row
return {
"price": float(price),
"segment": segment,
}
raise Exception("Failed reading external product price")
def get_own_image_wallpaper_m2_price(material_id, market_id):
sql = """
select
price
from
prices_wallpaper_m2
where
market_id = :market_id and material_id = :material_id
and segment_id = (select id from price_segments where name = 'OWN-IMAGE')
"""
result = db.session.execute(sql, {
"market_id": market_id,
"material_id": material_id,
})
rows = result.fetchall()
for row in rows:
price = row[0]
return float(price)
raise Exception("Failed reading own image wallpaper m2 price")
def get_external_product_own_image_price(external_product_id, market_id):
sql = """
select
price
from
prices_external_products
where
market_id = :market_id and external_product_id = :external_id
and segment_id = (select id from price_segments where name = 'OWN-IMAGE')
"""
result = db.session.execute(sql, {
"market_id": market_id,
"external_id": external_product_id,
})
rows = result.fetchall()
for row in rows:
price = row[0]
return float(price)
raise Exception("Failed reading external product own image price")