예제 #1
0
    def add_extra_cart_row(self, cart, request):
        if not self.is_active(cart) and len(
                cart_modifiers_pool.get_shipping_modifiers()) > 1:
            return

        weight = max(cart.weight, Decimal('0.001')).quantize(Decimal('0.000'))
        cheapest_destination = ShippingDestination.objects.filter(
            shipping_method__carrier=self.carrier,
            country=cart.shipping_address.country
            if cart.shipping_address else None,
            shipping_method__min_weight__lte=weight,
            shipping_method__max_weight__gte=weight,
        ).order_by('price').first()
        if cheapest_destination:
            parcel = self.get_sendcloud_parcel(cart)
            parcel.update(
                shipment={'id': cheapest_destination.shipping_method_id},
                weight=str(weight),
            )
            cart.extra['sendcloud_data'] = {'parcel': parcel}
            amount = EUR(cheapest_destination.price)
            instance = {'label': _("Shipping costs"), 'amount': amount}
            cart.extra_rows[self.identifier] = ExtraCartRow(instance)
            cart.total += amount
        else:
            instance = {'label': _("Unable to ship"), 'amount': EUR()}
            cart.extra_rows[self.identifier] = ExtraCartRow(instance)
예제 #2
0
    def add_extra_cart_row(self, cart, request):
        """
        Add a field on cart.extra_price_fields:
        """
        subtotal10 = (cart.items.filter(product__tax_switch=False).values(
            'quantity',
            'product__unit_price').aggregate(total=ExpressionWrapper(
                Sum(F('quantity') * F('product__unit_price')), DecimalField()))
                      )['total']  # 10 percent tax
        subtotal20 = (cart.items.filter(product__tax_switch=True).values(
            'quantity',
            'product__unit_price').aggregate(total=ExpressionWrapper(
                Sum(F('quantity') * F('product__unit_price')), DecimalField()))
                      )['total']  # 20 percent tax

        amount10 = (subtotal10 or 0) * self.taxes10
        amount20 = (subtotal20 or 0) * self.taxes20

        instance10 = {
            'label':
            _("{}% VAT incl.").format(settings.SHOP_VALUE_ADDED_TAX10),
            'amount': Money(amount10),
        }
        instance20 = {
            'label': _("{}% VAT incl.").format(settings.SHOP_VALUE_ADDED_TAX),
            'amount': Money(amount20),
        }
        cart.extra_rows[self.identifier + '10'] = ExtraCartRow(instance10)
        cart.extra_rows[self.identifier + '20'] = ExtraCartRow(instance20)
예제 #3
0
 def add_extra_cart_item_row(self, cart_item, request):
     amount = cart_item.line_total * self.taxes
     instance = {
         'label': _("{}% VAT incl.").format(app_settings.VALUE_ADDED_TAX),
         'amount': amount,
     }
     cart_item.extra_rows[self.identifier] = ExtraCartRow(instance)
예제 #4
0
파일: modifiers.py 프로젝트: bwrm/alby
 def add_extra_cart_row(self, cart, request):
     if not self.is_active(cart.extra.get('payment_modifier')) and len(cart_modifiers_pool.get_payment_modifiers()) > 1:
         return False
     amount = Money('30')
     instance = {'label': _("Extra charge by post"), 'amount': amount}
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
     cart.total += amount
 def add_extra_cart_row(self, cart, request):
     if not self.is_active(cart) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1:
         return
     # add a shipping flat fee
     amount = Money('5')
     instance = {'label': _("Shipping costs"), 'amount': amount}
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
     cart.total += amount
예제 #6
0
 def add_extra_cart_row(self, cart, request):
     if not self.is_active(cart.extra.get('shipping_modifier')) and len(
             cart_modifiers_pool.get_shipping_modifiers()) > 1:
         return
     amount = Money(settings.WELTLADEN_BIKING_PRICE)
     instance = {'label': _("Shipping costs"), 'amount': amount}
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
     cart.total += amount
예제 #7
0
 def add_extra_cart_row(self, cart, request):
     """
     Add a field on cart.extra_price_fields:
     """
     amount = cart.subtotal * self.taxes
     instance = {
         'label': _("{}% VAT incl.").format(app_settings.VALUE_ADDED_TAX),
         'amount': amount,
     }
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
예제 #8
0
 def add_extra_cart_row(self, cart, request):
     if not self.is_active(cart) or not self.commision_percentage:
         return
     amount = cart.total * Decimal(self.commision_percentage / 100.0)
     instance = {
         'label': _("+ %d%% handling fee") % self.commision_percentage,
         'amount': amount
     }
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
     cart.total += amount
예제 #9
0
 def add_extra_cart_row(self, cart, request):
     if "discount" in cart.extra:
         code = cart.extra["discount"]["code"]
         coupon = Coupon.objects.get(code=code)
         discount = coupon.apply_discount(cart.subtotal)
         row = ExtraCartRow({
             "label": "Discount Coupon",
             "amount": discount
         })
         cart.extra_rows[self.identifier] = row
         cart.extra["discount"].update({"amount": str(discount)})
         cart.total = max(cart.total - discount, 0)
     return cart
예제 #10
0
    def add_extra_cart_row(self, cart, request):
        if not self.is_active(cart) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1:
            return

        destinations = ShippingDestination.objects.filter(
            shipping_method__carrier=self.carrier,
            country=cart.shipping_address.country,
            shipping_method__min_weight__lte=cart.weight,
            shipping_method__max_weight__gte=cart.weight,
        ).order_by('price')
        if destinations:
            destination = destinations.first()
            parcel = self.get_sendcloud_parcel(cart)
            parcel['shipment'] = {'id': destination.shipping_method_id}
            cart.extra['sendcloud_data'] = {'parcel': parcel}
            amount = EUR(destination.price)
            instance = {'label': _("Shipping costs"), 'amount': amount}
            cart.extra_rows[self.identifier] = ExtraCartRow(instance)
            cart.total += amount
        else:
            instance = {'label': _("Unable to ship"), 'amount': EUR()}
            cart.extra_rows[self.identifier] = ExtraCartRow(instance)
예제 #11
0
    def add_extra_cart_row(self, cart, request):
        from decimal import Decimal
        from shop.serializers.cart import ExtraCartRow

        if not self.is_active(cart) or not self.commision_percentage:
            return
        amount = cart.total * Decimal(self.commision_percentage / 100.0)
        instance = {
            'label': _("+ {}% handling fee").format(self.commision_percentage),
            'amount': amount
        }
        cart.extra_rows[self.identifier] = ExtraCartRow(instance)
        cart.total += amount
예제 #12
0
    def add_extra_cart_item_row(self, cart_item, request):
        t_format = settings.SHOP_VALUE_ADDED_TAX10
        if cart_item.product.tax_switch:
            taxes = self.taxes20
            t_format = settings.SHOP_VALUE_ADDED_TAX
        else:
            taxes = self.taxes10
            t_format = settings.SHOP_VALUE_ADDED_TAX10

        amount = cart_item.line_total * taxes
        instance = {
            'label': _("{}% VAT").format(t_format),
            'amount': amount,
        }
        cart_item.extra_rows[self.identifier] = ExtraCartRow(instance)
예제 #13
0
 def add_extra_cart_row(self, cart, request):
     if not self.is_active(cart) and len(
             cart_modifiers_pool.get_shipping_modifiers()) > 1:
         return
     # postal tarifs by Siarhei
     if cart.total_weight < 1:
         amount = Money('6')
     elif cart.total_weight >= 1 and cart.total_weight < 3:
         amount = Money('9')
     elif cart.total_weight >= 3 and cart.total_weight < 15:
         amount = Money('12')
     elif cart.total_weight >= 15 and cart.total_weight < 30:
         amount = Money('23')
     elif cart.total_weight > 30:
         amount = Money('500')
     else:
         amount = Money('999')
     # add a shipping flat fee
     instance = {'label': _("Shipping costs to home"), 'amount': amount}
     cart.extra_rows[self.identifier] = ExtraCartRow(instance)
     cart.total += amount
예제 #14
0
파일: modifiers.py 프로젝트: bwrm/alby
    def add_extra_cart_row(self, cart, request):
        if not self.is_active(cart.extra.get('shipping_modifier')) and len(cart_modifiers_pool.get_shipping_modifiers()) > 1:
            return
        # add a shipping flat fee
        amount = Money('5')
        if cart.total_weight<1:
            amount = Money('4')
        elif cart.total_weight >=1 and cart.total_weight < 3:
            amount = Money('7.5')
        elif cart.total_weight >=3 and cart.total_weight < 15:
            amount = Money('10')
        elif cart.total_weight >=15 and cart.total_weight < 30:
            amount = Money('20')
        elif cart.total_weight > 30:
            amount = Money('500')
        else:
            amount = Money('999')

        instance = {'label': _("Shipping costs"), 'amount': amount}
        cart.extra_rows[self.identifier] = ExtraCartRow(instance)
        cart.total += amount