def calculate(self, basket):
        if self.currency == basket.currency:
            return super().calculate(basket)

        # If basket currency differs from shipping method's currency,
        # we convert shipping costs to user-selected currency.
        charge_excl_tax = convert_currency(self.currency, basket.currency,
                                           self.charge_excl_tax)
        charge_incl_tax = convert_currency(self.currency, basket.currency,
                                           self.charge_incl_tax)
        return prices.Price(currency=self.currency,
                            excl_tax=charge_excl_tax,
                            incl_tax=charge_incl_tax)
Exemple #2
0
def _record_user_order(user, order):
    try:
        # Since all orders are stored in user-selected currency, for
        # consistency we need to record user analytics in default currency.
        # User might select different currency for different orders,
        # also in order to aggregate analytics we'll need to have data in
        # the same currency.
        record = UserRecord.objects.filter(user=user)
        if order.currency == settings.OSCAR_DEFAULT_CURRENCY:
            total_spent = order.total_incl_tax
        else:
            total_spent = convert_currency(order.currency,
                                           settings.OSCAR_DEFAULT_CURRENCY,
                                           order.total_incl_tax)

        affected = record.update(
            num_orders=F('num_orders') + 1,
            num_order_lines=F('num_order_lines') + order.num_lines,
            num_order_items=F('num_order_items') + order.num_items,
            total_spent=F('total_spent') + total_spent,
            date_last_order=order.date_placed)
        if not affected:
            UserRecord.objects.create(user=user,
                                      num_orders=1,
                                      num_order_lines=order.num_lines,
                                      num_order_items=order.num_items,
                                      total_spent=total_spent,
                                      date_last_order=order.date_placed)
    except IntegrityError:  # pragma: no cover
        logger.error(
            "IntegrityError in analytics when recording a user order.")
 def create_discount_model(self, order, discount):
     offer = discount['offer']
     benefit = offer.benefit
     if benefit.currency != settings.OSCAR_DEFAULT_CURRENCY:
         amount = discount['discount']
         discount['discount'] = convert_currency(
             benefit.currency, settings.OSCAR_DEFAULT_CURRENCY, amount)
     super().create_discount_model(order, discount)
Exemple #4
0
 def get_benefit_value(self, basket):
     if self.currency != basket.currency:
         return convert_currency(self.currency, basket.currency, self.value)
     return self.value
Exemple #5
0
 def apply(self, basket, condition, offer, **kwargs):
     if basket.currency != self.currency:
         discount_amount = kwargs.get('discount_amount', self.value)
         kwargs['discount_amount'] = convert_currency(
             self.currency, basket.currency, discount_amount)
     return super().apply(basket, condition, offer, **kwargs)
Exemple #6
0
 def convert_currency(self, stockrecord, prices):
     currency = self.get_currency()
     price_excl_tax = convert_currency(stockrecord.price_currency, currency, prices.excl_tax)
     return FixedPrice(excl_tax=price_excl_tax, currency=currency, tax=D(0))
Exemple #7
0
 def convert_to_default_currency(self, property_name):
     value = getattr(self, property_name, '')
     if not self.is_in_default_currency and value:
         return convert_currency(self.currency,
                                 settings.OSCAR_DEFAULT_CURRENCY, value)
     return value