PW-570 inquiry price calculations
This commit is contained in:
+1
-1
@@ -6,4 +6,4 @@ ESALES_URL = ''
|
||||
TESTING = True
|
||||
DEBUG = True
|
||||
SQLALCHEMY_ECHO = False
|
||||
API_KEYS = None # api keys are disabled in test
|
||||
API_KEYS = None # api keys are disabled in test
|
||||
|
||||
@@ -4,6 +4,8 @@ import unittest2
|
||||
from api.lib.prices import *
|
||||
from tests.factories import DesignerFactory, ContractCustomerFactory, InquiryFactory
|
||||
from api.models import market
|
||||
from api.models import Inquiry
|
||||
from api.models import Product
|
||||
from api.models.product import Material, MaterialPrice
|
||||
|
||||
|
||||
@@ -19,6 +21,10 @@ us = market.from_territory('US')
|
||||
us.price_adjustments = 1.05
|
||||
us.exchange_rate = 0.119800
|
||||
|
||||
nl = market.from_territory('NL')
|
||||
nl.price_adjustments = 1.15
|
||||
nl.exchange_rate = 0.100000
|
||||
|
||||
russia = market.from_territory('RU')
|
||||
russia.price_adjustments = 1
|
||||
russia.exchange_rate = 0.100000 # russia uses EUR
|
||||
@@ -58,6 +64,9 @@ class TestPrice(unittest2.TestCase):
|
||||
material=standard_canvas, market=russia, designer=designer_moomin, rounded=False, inc_vat=False), places=4)
|
||||
self.assertAlmostEqual(110.88899937662403, m2_price(material=standard_canvas, market=russia,
|
||||
designer=designer_moomin, reseller=piterra, rounded=False, inc_vat=False), places=4)
|
||||
inquiry = Inquiry(pricepremium=36.029411)
|
||||
self.assertEqual(44, m2_price(material=standard_wallpaper,
|
||||
market=russia, reseller=piterra, inquiry=inquiry, inc_vat=False))
|
||||
|
||||
def test_wallpaper_price(self):
|
||||
self.assertEqual(295, wallpaper_price(
|
||||
@@ -156,7 +165,79 @@ class TestPrice(unittest2.TestCase):
|
||||
width=50, height=50, material=standard_canvas, market=sweden, framed=True))
|
||||
self.assertEqual(2972, old_canvas_price(
|
||||
width=150, height=140, material=standard_canvas, market=sweden, framed=True))
|
||||
|
||||
self.assertEqual(168, old_canvas_price(width=100, height=100, material=standard_canvas, market=russia, framed=True,
|
||||
designer=designer_moomin, reseller=piterra))
|
||||
|
||||
self.assertEqual(287, old_canvas_price(
|
||||
width=50, height=50, material=standard_canvas, market=sweden, framed=False, reseller=reseller))
|
||||
self.assertEqual(111, old_canvas_price(width=100, height=100, material=standard_canvas, market=russia, framed=False,
|
||||
designer=designer_moomin, reseller=piterra))
|
||||
|
||||
def test_wallpaper_custom_inquiry_price(self):
|
||||
inquiry = Inquiry(product_group="photo-wallpaper", territory="NL", pricepremium=0,
|
||||
width=350, height=270, price_effect=0, price_retouch=160.00, material=standard_wallpaper)
|
||||
|
||||
self.assertEqual(333, inquiry_price(inquiry))
|
||||
self.assertEqual(310, inquiry_price(inquiry, inc_price_retouch=False))
|
||||
self.assertEqual(160, inquiry.price_retouch)
|
||||
self.assertEqual(18.4, inquiry.local_price_retouch(rounded=False))
|
||||
self.assertEqual(22, inquiry.local_price_retouch(
|
||||
rounded=True, inc_vat=True))
|
||||
|
||||
# test with different material
|
||||
self.assertEqual(342, inquiry_price(
|
||||
inquiry, inc_price_retouch=False, material=premium_wallpaper))
|
||||
self.assertEqual(364, inquiry_price(
|
||||
inquiry, material=premium_wallpaper))
|
||||
|
||||
def test_wallpaper_product_inquiry_price(self):
|
||||
designer = DesignerFactory()
|
||||
designer.pricepremium = 4
|
||||
product = Product(designer=designer)
|
||||
inquiry = Inquiry(product_group="photo-wallpaper", territory="SE", pricepremium=0,
|
||||
width=350, height=280, price_retouch=0, material=standard_wallpaper, product=product)
|
||||
|
||||
self.assertEqual(3007, inquiry_price(inquiry))
|
||||
self.assertEqual(3007, inquiry_price(inquiry, inc_price_retouch=False))
|
||||
self.assertEqual(3312, inquiry_price(
|
||||
inquiry, material=premium_wallpaper))
|
||||
|
||||
def test_wallpaper_product2_inquiry_price(self):
|
||||
designer = DesignerFactory()
|
||||
designer.pricepremium = 4
|
||||
product = Product(designer=designer)
|
||||
inquiry = Inquiry(product_group="photo-wallpaper", territory="SE", pricepremium=25,
|
||||
width=250, height=400, price_retouch=200, material=standard_wallpaper, product=product)
|
||||
|
||||
self.assertEqual(3835, inquiry_price(inquiry, inc_price_retouch=False))
|
||||
self.assertEqual(200, inquiry.price_retouch)
|
||||
self.assertEqual(250, inquiry.local_price_retouch(
|
||||
rounded=True, inc_vat=True))
|
||||
|
||||
def test_wallpaper_piterra_inquiry_price(self):
|
||||
product = Product(designer=None)
|
||||
inquiry = Inquiry(product_group="photo-wallpaper", territory="RU", width=150, height=211, dealer_store=piterra, pricepremium=36.029411,
|
||||
material=standard_wallpaper, product=product)
|
||||
|
||||
self.assertEqual(138, inquiry_price(inquiry, inc_price_retouch=False))
|
||||
self.assertEqual(152, inquiry_price(
|
||||
inquiry, inc_price_retouch=False, material=premium_wallpaper))
|
||||
|
||||
def test_canvas_custom_inquiry_price(self):
|
||||
inquiry = Inquiry(product_group='canvas', territory='SE', width=100, height=100,
|
||||
framed=True, price_retouch=200, pricepremium=0, material=standard_canvas)
|
||||
|
||||
self.assertEqual(1520, inquiry_price(inquiry, inc_price_retouch=False))
|
||||
self.assertEqual(1770, inquiry_price(inquiry, inc_price_retouch=True))
|
||||
self.assertEqual(999, inquiry_price(
|
||||
inquiry, inc_price_retouch=False, framed=False))
|
||||
|
||||
def test_canvas_piterra_inquiry_price(self):
|
||||
inquiry = Inquiry(product_group='canvas', territory='RU', width=100, height=100,
|
||||
framed=True, dealer_store=piterra, pricepremium=0, material=standard_canvas)
|
||||
|
||||
# note: site currently calculates this as €150 which is wrong because
|
||||
# it does not add dealer_store.pricepremium to the frame price
|
||||
self.assertEqual(165, inquiry_price(inquiry))
|
||||
self.assertEqual(109, inquiry_price(inquiry, framed=False))
|
||||
|
||||
@@ -2,6 +2,7 @@ import json
|
||||
import flask_testing
|
||||
from api import create_app, db
|
||||
from api.models.product import Material, MaterialPrice
|
||||
from api.models.inquiry import Inquiry
|
||||
|
||||
|
||||
class TestEndpoints(flask_testing.TestCase):
|
||||
@@ -23,6 +24,13 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
db.session.commit()
|
||||
return material
|
||||
|
||||
def _add_inquiry(self, territory, product_group, price_retouch=100):
|
||||
inquiry = Inquiry(
|
||||
territory=territory, product_group=product_group, price_retouch=price_retouch)
|
||||
db.session.add(inquiry)
|
||||
db.session.commit()
|
||||
return inquiry
|
||||
|
||||
def test_wallpaper(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
@@ -33,7 +41,7 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assertEqual(2, len(products))
|
||||
|
||||
def test_canvas(self):
|
||||
self._add_material('standard-canvas', 2, 799.9)
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
response = self.client.get(
|
||||
'/prices/canvas?width=200&height=10&territory=SE')
|
||||
self.assert200(response)
|
||||
@@ -57,3 +65,18 @@ class TestEndpoints(flask_testing.TestCase):
|
||||
self.assertEqual(150, product['width'], "it adjusts measurements")
|
||||
self.assertEqual(50, product['height'])
|
||||
self.assertAlmostEqual(923.857, product['price'], places=2)
|
||||
|
||||
def test_inquiry_wallpaper(self):
|
||||
self._add_material('standard-wallpaper', 1, 236)
|
||||
self._add_material('premium-wallpaper', 1, 260)
|
||||
self._add_inquiry(territory='SE', product_group='photo-wallpaper')
|
||||
response = self.client.get('/prices/inquiry/1?width=100&height=100')
|
||||
self.assert200(response)
|
||||
self.assertEqual('wallpaper', response.json['group'])
|
||||
|
||||
def test_inquiry_canvas(self):
|
||||
self._add_material('standard-canvas', 2, 799.2)
|
||||
self._add_inquiry(territory='SE', product_group='canvas')
|
||||
response = self.client.get('/prices/inquiry/1?width=100&height=100')
|
||||
self.assert200(response)
|
||||
self.assertEqual('canvas', response.json['group'])
|
||||
|
||||
Reference in New Issue
Block a user