Ejemplo n.º 1
0
    def get_item_price(self, item):

        soldout = getattr(item, 'soldout', False)

        if soldout:
            if getattr(self.context, 'language', "") == "nl":
                return "Uitverkocht"
            else:
                return "Sold out"

        _item_data = get_item_data_provider(item)
        item_vat = Decimal(_item_data.vat)
        net = Decimal(_item_data.net)

        price = net + net / Decimal(100) * item_vat

        decimal_separator = ','
        if getattr(self.context, 'language', "") != "nl":
            decimal_separator = '.'

        price = "%s%s-" % (self.format_number_localized(
            price, "1"), decimal_separator) if round(
                price, 2) % 1 == 0 else self.format_number_localized(
                    price, "1.00")

        if price:
            return "€ %s" % (price)
        else:
            return getattr(item, 'price', '')
Ejemplo n.º 2
0
    def validate_count(self, uid, count):
        """Validate setting cart item count for uid.

        uid - Is the cart item UID.
        count - If count is 0, it means that a cart item is going to be
        deleted, which is always allowed. If count is > 0, it's the aggregated
        item count in cart.
        """
        cart_item = utils.get_object_by_uid(self.context, uid)
        item_data = cartitem.get_item_data_provider(cart_item)
        cart_count_limit = item_data.cart_count_limit
        if cart_count_limit and float(count) > cart_count_limit:
            message = translate(
                _("article_limit_reached", default="Article limit reached"),
                context=self.request,
            )
            return {"success": False, "error": message, "update": False}
        item_state = cartitem.get_item_state(cart_item, self.request)
        if item_state.validate_count(count):
            return {"success": True, "error": ""}
        message = translate(
            _(
                "trying_to_add_more_items_than_available",
                default="Not enough items available, abort.",
            ),
            context=self.request,
        )
        return {"success": False, "error": message, "update": False}
Ejemplo n.º 3
0
 def cart_items(self, items):
     ret = list()
     sm = getSecurityManager()
     for uid, count, comment in items:
         try:
             obj = api.content.get(UID=uid)
         except ValueError:
             remove_item_from_cart(self.request, uid)
             continue
         if obj is None:
             remove_item_from_cart(self.request, uid)
             continue
         if not sm.checkPermission(permissions.ModifyCart, obj):
             remove_item_from_cart(self.request, uid)
             continue
         buyable_period = queryAdapter(obj, IBuyablePeriod)
         if buyable_period:
             now = datetime.now()
             effective = buyable_period.effective
             if effective and now < effective:
                 remove_item_from_cart(self.request, uid)
                 continue
             expires = buyable_period.expires
             if expires and now > expires:
                 remove_item_from_cart(self.request, uid)
                 continue
         data = get_item_data_provider(obj)
         discount_net = data.discount_net(count)
         price = (Decimal(str(data.net)) - discount_net) * count
         discount = discount_net * count
         if data.display_gross:
             price = price + price / Decimal(100) * Decimal(str(data.vat))
             discount = discount + discount / Decimal(100) * Decimal(
                 str(data.vat))
         url = obj.absolute_url()
         quantity_unit = translate(data.quantity_unit, context=self.request)
         item_state = get_item_state(obj, self.request)
         ret.append(
             self.item(
                 uid=uid,
                 title=data.title,
                 count=count,
                 price=price,
                 url=url,
                 comment=comment,
                 description=obj.description,
                 comment_enabled=data.comment_enabled,
                 comment_required=data.comment_required,
                 quantity_unit_float=data.quantity_unit_float,
                 quantity_unit=quantity_unit,
                 preview_image_url=get_item_preview(obj).url,
                 no_longer_available=not item_state.validate_count(count),
                 alert=item_state.alert(count),
                 discount=discount *
                 Decimal(-1) if discount else Decimal(0),
             ))
     return ret
Ejemplo n.º 4
0
 def critical_available_message(self):
     available = self.available
     if not get_item_data_provider(self.context).quantity_unit_float:
         available = int(available)
     message = _(
         u"critical_available_message",
         default=u"Just ${available} items(s) left.",
         mapping={"available": available},
     )
     return message
Ejemplo n.º 5
0
 def item_vat(self, item):
     """VAT of item.
     """
     uid, count, _ = item
     try:
         obj = api.content.get(UID=uid)
     except ValueError:
         return Decimal(0)
     data = get_item_data_provider(obj)
     discount_net = data.discount_net(count)
     item_net = Decimal(str(data.net)) - discount_net
     return (item_net / Decimal(100)) * Decimal(str(data.vat)) * count
Ejemplo n.º 6
0
 def full_available_message(self):
     available = self.available
     if available is None:
         available = ""
     else:
         if not get_item_data_provider(self.context).quantity_unit_float:
             available = int(available)
     message = _(
         u"full_available_message",
         default=u"${available} items(s) available.",
         mapping={"available": available},
     )
     return message
Ejemplo n.º 7
0
 def _discounted_items(self, items):
     # return list of 2-tuples containing (net, vat percent) of discounted
     # items in cart. count is already considered.
     # XXX: from gross
     result = list()
     cat = api.portal.get_tool(name="portal_catalog")
     for uid, count, comment in items:
         brain = cat(UID=uid)
         if not brain:
             continue
         data = get_item_data_provider(brain[0].getObject())
         discount_net = data.discount_net(count)
         item_net = Decimal(str(data.net)) - discount_net
         result.append((item_net * count, Decimal(str(data.vat))))
     return result
Ejemplo n.º 8
0
 def vat(self, items):
     """Overall VAT of items.
     """
     vat = Decimal(0)
     for uid, count, unused in items:
         try:
             obj = api.content.get(UID=uid)
         except ValueError:
             continue
         if obj is None:
             continue
         data = get_item_data_provider(obj)
         discount_net = data.discount_net(count)
         item_net = Decimal(str(data.net)) - discount_net
         vat += (item_net / Decimal(100)) * Decimal(str(data.vat)) * count
     return vat
Ejemplo n.º 9
0
 def net(self, items):
     """Overall net of items.
     """
     net = Decimal(0)
     for uid, count, unused in items:
         try:
             obj = api.content.get(UID=uid)
         except ValueError:
             continue
         if obj is None:
             continue
         data = get_item_data_provider(obj)
         discount_net = data.discount_net(count)
         item_net = Decimal(str(data.net)) - discount_net
         net += item_net * count
     return net
Ejemplo n.º 10
0
 def overbook_available_message(self):
     state = get_item_state(self.context, self.request)
     overbook = self.stock.overbook
     if overbook is None:
         reservable = ""
     else:
         reservable = overbook - state.reserved
         if not get_item_data_provider(self.context).quantity_unit_float:
             reservable = int(reservable)
     message = _(
         u"overbook_available_message",
         default=u"Item is sold out. You can pre-order "
         u"${reservable} items. As soon as item is "
         u"available again, it gets delivered.",
         mapping={"reservable": reservable},
     )
     return message
Ejemplo n.º 11
0
    def alert(self, count):
        stock = get_item_stock(self.context)
        # stock not applied
        if stock is None:
            return ""
        available = stock.available
        # no limitation
        if available is None:
            return ""
        reserved = self.reserved
        exceed = self.exceed
        # no reservations and no exceed
        if not reserved and not exceed:
            # no message
            return ""
        item_data = get_item_data_provider(self.context)
        quantity_unit = item_data.quantity_unit
        quantity_unit_float = item_data.quantity_unit_float

        def display_format(num):
            if quantity_unit_float:
                return num
            return int(num)

        # exceed
        if exceed:
            remaining_available = self.remaining_available
            # partly exceeded
            if remaining_available > 0:
                return self.partly_exceeded_alert(display_format(exceed),
                                                  quantity_unit)
            # completely exceeded
            return self.completely_exceeded_alert
        # reservations
        if reserved:
            aggregated_count = float(self.aggregated_count)
            count = float(count)
            # some reservations message
            if aggregated_count > count:
                return self.some_reservations_alert
            # number reservations message
            else:
                return self.number_reservations_alert(display_format(reserved),
                                                      quantity_unit)
        return ""
Ejemplo n.º 12
0
 def _item_data(self):
     return get_item_data_provider(self.context)
Ejemplo n.º 13
0
def item_net(obj):
    item_data = get_item_data_provider(obj)
    return Decimal(item_data.net)