def test_basicranges(self): macaw_price = ProductPrice.objects.create(product=self.macaw, price=Decimal('10.0')) macaw_price.offsets.create(variant=self.macaw_blue_a, price_offset=Decimal('2.0')) macaw_price.offsets.create(variant=self.macaw_red_d, price_offset=Decimal('3.0')) macaw_price.offsets.create(variant=self.macaw_red_a, price_offset=Decimal('6.0')) cockatoo_price = ProductPrice.objects.create(product=self.cockatoo, price=Decimal('12.0')) cockatoo_price.offsets.create(variant=self.cockatoo_white_d, price_offset=Decimal('-5.0')) cockatoo_price.offsets.create(variant=self.cockatoo_green_d, price_offset=Decimal('-8.0')) cockatoo_price.offsets.create(variant=self.cockatoo_green_a, price_offset=Decimal('4.0')) self.assertEqual(get_product_price_range(self.macaw, currency='BTC'), PriceRange(min_price=Price(Decimal('10.0'), currency='BTC'), max_price=Price(Decimal('16.0'), currency='BTC'))) self.assertEqual(get_product_price_range(self.cockatoo, currency='BTC'), PriceRange(min_price=Price(Decimal('4.0'), currency='BTC'), max_price=Price(Decimal('16.0'), currency='BTC')))
def test_default(self): self.vat23.default = True self.vat23.save() # these have 8% VAT self.assertEqual( handler.get_variant_price(self.macaw_blue_d, currency="PLN"), Price(10, Decimal("10.80"), currency="PLN") ) self.assertEqual( handler.get_variant_price(self.macaw_blue_a, currency="PLN"), Price(12, Decimal("12.96"), currency="PLN") ) # while these have default 23% VAT self.assertEqual( handler.get_variant_price(self.cockatoo_white_a, currency="PLN"), Price(20, Decimal("24.60"), currency="PLN"), ) self.assertEqual( handler.get_variant_price(self.cockatoo_green_a, currency="PLN"), Price(25, Decimal("30.75"), currency="PLN"), ) pr = handler.get_product_price_range(self.cockatoo, currency="PLN") self.assertEqual( pr, PriceRange( min_price=Price(20, Decimal("24.60"), currency="PLN"), max_price=Price(25, Decimal("30.75"), currency="PLN"), ), )
def product_price_range(product, currency=getattr(settings, 'SATCHLESS_DEFAULT_CURRENCY', None)): if not currency: return '' try: from satchless.pricing.handler import get_product_price_range min_price, max_price = get_product_price_range(product, currency) if min_price is not None and min_price.has_value(): return SortedDict((('min', min_price), ('max', max_price))) except ImportError: pass return ''
def test_basicranges(self): macaw_price = ProductPrice.objects.create(product=self.macaw, price=Decimal('10.0')) macaw_price.offsets.create(variant=self.macaw_blue_a, price_offset=Decimal('2.0')) macaw_price.offsets.create(variant=self.macaw_red_d, price_offset=Decimal('3.0')) macaw_price.offsets.create(variant=self.macaw_red_a, price_offset=Decimal('6.0')) cockatoo_price = ProductPrice.objects.create(product=self.cockatoo, price=Decimal('12.0')) cockatoo_price.offsets.create(variant=self.cockatoo_white_d, price_offset=Decimal('-5.0')) cockatoo_price.offsets.create(variant=self.cockatoo_green_d, price_offset=Decimal('-8.0')) cockatoo_price.offsets.create(variant=self.cockatoo_green_a, price_offset=Decimal('4.0')) self.assertEqual(get_product_price_range(self.macaw, currency='BTC'), (Price(Decimal('10.0'), currency='BTC'), Price(Decimal('16.0'), currency='BTC'))) self.assertEqual( get_product_price_range(self.cockatoo, currency='BTC'), (Price(Decimal('4.0'), currency='BTC'), Price(Decimal('16.0'), currency='BTC')))
def test_nodefault(self): # these have 8% VAT self.assertEqual( handler.get_variant_price(self.macaw_blue_d, currency="PLN"), Price(10, Decimal("10.80"), currency="PLN") ) self.assertEqual( handler.get_variant_price(self.macaw_blue_a, currency="PLN"), Price(12, Decimal("12.96"), currency="PLN") ) # while these have no tax group, hence the tax is zero self.assertEqual( handler.get_variant_price(self.cockatoo_white_a, currency="PLN"), Price(20, 20, currency="PLN") ) self.assertEqual( handler.get_variant_price(self.cockatoo_green_a, currency="PLN"), Price(25, 25, currency="PLN") ) pr = handler.get_product_price_range(self.cockatoo, currency="PLN") self.assertEqual( pr, PriceRange(min_price=Price(20, 20, currency="PLN"), max_price=Price(25, 25, currency="PLN")) )
def get_price(self, product, currency, **kwargs): from satchless.pricing.handler import get_product_price_range min_price, max_price = get_product_price_range(product, currency, **kwargs) if min_price is not None and min_price.has_value(): return SortedDict((('min', min_price), ('max', max_price)))
def get_price(self, product, currency, **kwargs): from satchless.pricing.handler import get_product_price_range return get_product_price_range(product, currency, **kwargs)