예제 #1
0
 def fill_discount(discount):
     if (discount is not None
             and discount.starting_date < timezone.now().date()
             and discount.ending_date > timezone.now().date()):
         if discount.discount_type == FIXED:
             discount_price = money_quantize(
                 Decimal(discount.discount_value))
         else:
             discount_price = money_quantize(
                 -current_price * Decimal(discount.discount_value / 100.))
         new_price = money_quantize(current_price + discount_price)
         price.discount = discount_price
     else:
         price.discount = None
         new_price = current_price
     return new_price
예제 #2
0
 def fill_country_reduction(address):
     db_countriespayment = CountryPayment.objects.all()
     max_pib = db_countriespayment.aggregate(
         Max('pib_per_inhabitant'))['pib_per_inhabitant__max']
     min_pib = db_countriespayment.aggregate(
         Min('pib_per_inhabitant'))['pib_per_inhabitant__min']
     try:
         country = address.country
         own_country_payment = CountryPayment.objects.get(country=country)
     except (AttributeError, ObjectDoesNotExist):
         price.country_reduction = None
         return current_price
     factor = COUNTRY_PPP_TO_PERCENT(min_pib, max_pib,
                                     own_country_payment.pib_per_inhabitant)
     new_price = money_quantize(current_price * Decimal(factor))
     diff_price = money_quantize(new_price - current_price)
     price.country_reduction = diff_price
     return new_price
예제 #3
0
 def fill_scientific_score(user, order_type):
     if order_type == SCIENTIST_ACCOUNT:
         price.scientist_score = None
         price.scientist_score_reduction = None
         return current_price
     skeptic_score = SKEPTIC_SCORE_NORMALIZE(user.skeptic_score)
     mean_publication_score = MEAN_PUBLICATION_SCORE_NORMALIZE(
         user.mean_publication_score)
     mean_impact_factor = MEAN_IMPACT_FACTOR_NORMALIZE(
         user.mean_impact_factor)
     estimator_score = ESTIMATOR_SCORE_NORMALIZE(user.estimator_score)
     reviewer_score = REVIEWER_SCORE_NORMALIZE(user.reviewer_score)
     mean_score = (skeptic_score + mean_publication_score +
                   mean_impact_factor + estimator_score +
                   reviewer_score) / 5.
     payment_percent = -0.08 + (1 +
                                0.08) / (1 +
                                         (mean_score / 0.1214766)**1.137504)
     new_price = money_quantize(current_price * Decimal(payment_percent))
     diff_price = money_quantize(new_price - current_price)
     price.scientist_score = round(mean_score, 2)
     price.scientist_score_reduction = diff_price
     return new_price
예제 #4
0
 def test_high_premice(self):
     self.assertEqual(float(money_quantize(Decimal(12344444444.4))),
                      12344444444.40)
예제 #5
0
 def test_high_decimal(self):
     self.assertEqual(float(money_quantize(Decimal(12.3444444444))), 12.35)
예제 #6
0
 def test_low_limit_decimal(self):
     self.assertEqual(float(money_quantize(Decimal(12.000001))), 12.01)
예제 #7
0
 def test_high_limit_decimal(self):
     self.assertEqual(float(money_quantize(Decimal(12.9999))), 13.)
예제 #8
0
 def test_no_decimal(self):
     self.assertEqual(float(money_quantize(Decimal(12344444444))),
                      12344444444.)
예제 #9
0
 def fill_taxes(percent):
     taxes_amount = money_quantize(current_price * Decimal(percent / 100))
     new_price = money_quantize(current_price + taxes_amount)
     price.tax_percent = percent
     price.tax = taxes_amount
     return new_price