Exemplo n.º 1
0
def create_mail_listing(context, attrs):
    """Create item listing for notification mail.
    """
    soup = get_bookings_soup(context)
    bookings = soup.query((Any('uid', attrs['booking_uids'])))
    lines = []
    for booking in bookings:
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        buyable = brain.getObject()
        title = booking.attrs['title']
        comment = booking.attrs['buyable_comment']
        if comment:
            title = '%s (%s)' % (title, comment)
        line = '{count: 4f} {title}'.format(
            count=booking.attrs['buyable_count'],
            title=title
        )
        lines.append(line)
        if comment:
            lines.append(_indent('({0})'.format(comment)))
        notificationtext = IItemNotificationText(buyable)
        if booking.attrs['state'] == ifaces.STATE_RESERVED\
                and notificationtext.overbook_text:
            lines.append(_indent(notificationtext.overbook_text))
        elif booking.attrs['state'] == ifaces.STATE_NEW\
                and notificationtext.order_text:
            lines.append(_indent(notificationtext.order_text))
    return '\n'.join(lines)
Exemplo n.º 2
0
 def create_booking(self, order, cart_data, uid, count, comment):
     brain = get_catalog_brain(self.context, uid)
     # brain could be None if uid for item in cookie which no longer exists.
     if not brain:
         return
     buyable = brain.getObject()
     item_state = get_item_state(buyable, self.request)
     if not item_state.validate_count(count):
         msg = u'Item no longer available {0}'.format(buyable.id)
         logger.warning(msg)
         raise CheckoutError(msg)
     item_stock = get_item_stock(buyable)
     # stock not applied, state new
     if item_stock is None:
         available = None
         state = ifaces.STATE_NEW
     # calculate state from stock
     else:
         if item_stock.available is not None:
             item_stock.available -= float(count)
         available = item_stock.available
         state = ifaces.STATE_NEW if available is None or available >= 0.0\
             else ifaces.STATE_RESERVED
     item_data = get_item_data_provider(buyable)
     vendor = acquire_vendor_or_shop_root(buyable)
     booking = OOBTNode()
     booking.attrs['email'] = order.attrs['personal_data.email']
     booking.attrs['uid'] = uuid.uuid4()
     booking.attrs['buyable_uid'] = uid
     booking.attrs['buyable_count'] = count
     booking.attrs['buyable_comment'] = comment
     booking.attrs['order_uid'] = order.attrs['uid']
     booking.attrs['vendor_uid'] = uuid.UUID(IUUID(vendor))
     booking.attrs['creator'] = order.attrs['creator']
     booking.attrs['created'] = order.attrs['created']
     booking.attrs['exported'] = False
     booking.attrs['title'] = brain and brain.Title or 'unknown'
     booking.attrs['net'] = item_data.net
     booking.attrs['vat'] = item_data.vat
     booking.attrs['discount_net'] = item_data.discount_net(count)
     booking.attrs['currency'] = cart_data.currency
     booking.attrs['quantity_unit'] = item_data.quantity_unit
     booking.attrs['remaining_stock_available'] = available
     booking.attrs['state'] = state
     booking.attrs['salaried'] = ifaces.SALARIED_NO
     booking.attrs['tid'] = 'none'
     shipping_info = queryAdapter(buyable, IShippingItem)
     if shipping_info:
         booking.attrs['shippable'] = shipping_info.shippable
     else:
         booking.attrs['shippable'] = False
     trading_info = queryAdapter(buyable, ifaces.ITrading)
     if trading_info:
         booking.attrs['item_number'] = trading_info.item_number
         booking.attrs['gtin'] = trading_info.gtin
     else:
         booking.attrs['item_number'] = None
         booking.attrs['gtin'] = None
     return booking
Exemplo n.º 3
0
 def create_booking(self, order, cart_data, uid, count, comment):
     brain = get_catalog_brain(self.context, uid)
     # brain could be None if uid for item in cookie which no longer exists.
     if not brain:
         return
     buyable = brain.getObject()
     item_state = get_item_state(buyable, self.request)
     if not item_state.validate_count(count):
         msg = u'Item no longer available {0}'.format(buyable.id)
         logger.warning(msg)
         raise CheckoutError(msg)
     item_stock = get_item_stock(buyable)
     # stock not applied, state new
     if item_stock is None:
         available = None
         state = ifaces.STATE_NEW
     # calculate state from stock
     else:
         if item_stock.available is not None:
             item_stock.available -= float(count)
         available = item_stock.available
         state = ifaces.STATE_NEW if available is None or available >= 0.0\
             else ifaces.STATE_RESERVED
     item_data = get_item_data_provider(buyable)
     vendor = acquire_vendor_or_shop_root(buyable)
     booking = OOBTNode()
     booking.attrs['email'] = order.attrs['personal_data.email']
     booking.attrs['uid'] = uuid.uuid4()
     booking.attrs['buyable_uid'] = uid
     booking.attrs['buyable_count'] = count
     booking.attrs['buyable_comment'] = comment
     booking.attrs['order_uid'] = order.attrs['uid']
     booking.attrs['vendor_uid'] = uuid.UUID(IUUID(vendor))
     booking.attrs['creator'] = order.attrs['creator']
     booking.attrs['created'] = order.attrs['created']
     booking.attrs['exported'] = False
     booking.attrs['title'] = brain and brain.Title or 'unknown'
     booking.attrs['net'] = item_data.net
     booking.attrs['vat'] = item_data.vat
     booking.attrs['discount_net'] = item_data.discount_net(count)
     booking.attrs['currency'] = cart_data.currency
     booking.attrs['quantity_unit'] = item_data.quantity_unit
     booking.attrs['remaining_stock_available'] = available
     booking.attrs['state'] = state
     booking.attrs['salaried'] = ifaces.SALARIED_NO
     booking.attrs['tid'] = 'none'
     shipping_info = queryAdapter(buyable, IShippingItem)
     if shipping_info:
         booking.attrs['shippable'] = shipping_info.shippable
     else:
         booking.attrs['shippable'] = False
     trading_info = queryAdapter(buyable, ifaces.ITrading)
     if trading_info:
         booking.attrs['item_number'] = trading_info.item_number
         booking.attrs['gtin'] = trading_info.gtin
     else:
         booking.attrs['item_number'] = None
         booking.attrs['gtin'] = None
     return booking
Exemplo n.º 4
0
def create_mail_listing(context,
                        order_data,
                        include_booking_states=(ifaces.STATE_FINISHED,
                                                ifaces.STATE_NEW,
                                                ifaces.STATE_PROCESSING)):
    """Create item listing for notification mail.
    """
    lines = []
    for booking in order_data.bookings:
        state = safe_unicode(booking.attrs.get('state'))
        if state not in include_booking_states:
            continue
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        # fetch buyable
        buyable = brain.getObject()
        # fetch buyable title
        title = safe_unicode(booking.attrs['title'])
        # fetch item_number
        item_number = u''
        if booking.attrs['item_number']:
            item_number = u' ({0})'.format(
                safe_unicode(booking.attrs['item_number']))
        # fetch buyable comment
        comment = safe_unicode(booking.attrs['buyable_comment'])
        if comment:
            title = u'{0} ({1})'.format(title, comment)
        # fetch currency
        currency = safe_unicode(booking.attrs['currency'])
        # fetch net
        net = booking.attrs['net']
        # build price
        price = u'{currency} {net: 0.2f}'.format(currency=currency, net=net)
        # XXX: discount
        state_text = u''
        if state == ifaces.STATE_RESERVED:
            state_text = u' ({0})'.format(vocabs.state_vocab()[state])
        line = u'{count: 4f} {title}{item_number} {state} {price}'.format(
            count=booking.attrs['buyable_count'],
            title=title,
            item_number=item_number,
            state=state_text,
            price=price,
        )
        lines.append(line)
        if comment:
            lines.append(_indent(u'({0})'.format(comment)))
        notificationtext = IItemNotificationText(buyable)
        if state == ifaces.STATE_RESERVED:
            text = notificationtext.overbook_text
        elif state == ifaces.STATE_NEW:
            text = notificationtext.order_text
        else:
            text = None
        if text:
            lines.append(_indent(text))
    return u'\n'.join(lines)
Exemplo n.º 5
0
def create_mail_listing(context, order_data):
    """Create item listing for notification mail.
    """
    lines = []
    for booking in order_data.bookings:
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        # fetch buyable
        buyable = brain.getObject()
        # fetch buyable title
        title = safe_encode(booking.attrs['title'])
        # fetch buyable comment
        comment = booking.attrs['buyable_comment']
        if comment:
            title = '%s (%s)' % (title, comment)
        # fetch currency
        currency = booking.attrs['currency']
        # fetch net
        net = booking.attrs['net']
        # build price
        price = '%s %0.2f' % (currency, net)
        # XXX: discount
        state = booking.attrs.get('state')
        state_text = ''
        if state == ifaces.STATE_RESERVED:
            state_text = ' ({})'.format(vocabs.state_vocab()[state])
        line = '{count: 4f} {title}{state} {price}'.format(
            count=booking.attrs['buyable_count'],
            title=title,
            state=state_text,
            price=price,
        )
        lines.append(line)
        if comment:
            lines.append(_indent('({0})'.format(comment)))
        notificationtext = IItemNotificationText(buyable)
        if state == ifaces.STATE_RESERVED:
            text = notificationtext.overbook_text
        elif state == ifaces.STATE_NEW:
            text = notificationtext.order_text
        else:
            text = None
        if text:
            lines.append(_indent(text))
    return '\n'.join([safe_encode(l) for l in lines])
Exemplo n.º 6
0
def create_mail_listing(context, order_data):
    """Create item listing for notification mail.
    """
    lines = []
    for booking in order_data.bookings:
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        # fetch buyable
        buyable = brain.getObject()
        # fetch buyable title
        title = safe_encode(booking.attrs['title'])
        # fetch buyable comment
        comment = booking.attrs['buyable_comment']
        if comment:
            title = '%s (%s)' % (title, comment)
        # fetch currency
        currency = booking.attrs['currency']
        # fetch net
        net = booking.attrs['net']
        # build price
        price = '%s %0.2f' % (currency, net)
        # XXX: discount
        state = booking.attrs.get('state')
        state_text = ''
        if state == ifaces.STATE_RESERVED:
            state_text = ' ({})'.format(vocabs.state_vocab()[state])
        line = '{count: 4f} {title}{state} {price}'.format(
            count=booking.attrs['buyable_count'],
            title=title,
            state=state_text,
            price=price,
        )
        lines.append(line)
        if comment:
            lines.append(_indent('({0})'.format(comment)))
        notificationtext = IItemNotificationText(buyable)
        if state == ifaces.STATE_RESERVED:
            text = notificationtext.overbook_text
        elif state == ifaces.STATE_NEW:
            text = notificationtext.order_text
        else:
            text = None
        if text:
            lines.append(_indent(text))
    return '\n'.join([safe_encode(l) for l in lines])
Exemplo n.º 7
0
    def create_booking(self, order, cart_data, uid, count, comment):
        booking = super(TicketOrderCheckoutAdapter, self).create_booking(
            order, cart_data, uid, count, comment
        )

        brain = get_catalog_brain(self.context, uid)
        if not brain:
            return
        buyable = brain.getObject()
        titledict = ticket_title_generator(buyable)

        booking.attrs['title'] = titledict['title']
        if titledict['eventtitle']:
            booking.attrs['eventtitle'] = titledict['eventtitle']
        if titledict['eventstart']:
            booking.attrs['eventstart'] = titledict['eventstart']
        if titledict['eventend']:
            booking.attrs['eventend'] = titledict['eventend']
        return booking
Exemplo n.º 8
0
    def create_booking(self, order, cart_data, uid, count, comment):
        booking = super(TicketOrderCheckoutAdapter,
                        self).create_booking(order, cart_data, uid, count,
                                             comment)

        brain = get_catalog_brain(self.context, uid)
        if not brain:
            return
        buyable = brain.getObject()
        titledict = ticket_title_generator(buyable)

        booking.attrs['title'] = titledict['title']
        if titledict['eventtitle']:
            booking.attrs['eventtitle'] = titledict['eventtitle']
        if titledict['eventstart']:
            booking.attrs['eventstart'] = titledict['eventstart']
        if titledict['eventend']:
            booking.attrs['eventend'] = titledict['eventend']
        return booking
Exemplo n.º 9
0
def create_global_text(context, order_data):
    order_state = order_data.state
    notifications = set()
    for booking in order_data.bookings:
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        buyable = brain.getObject()
        notificationtext = IGlobalNotificationText(buyable)
        if order_state in (ifaces.STATE_RESERVED, ifaces.STATE_MIXED):
            # XXX: might need custom text for MIXED state
            text = notificationtext.global_overbook_text
            if text:
                notifications.add(text)
        elif order_state == ifaces.STATE_NEW:
            text = notificationtext.global_order_text
            if text:
                notifications.add(text)
    global_text = '\n\n'.join([safe_encode(line) for line in notifications])
    if global_text.strip():
        return '\n\n' + global_text.strip() + '\n'
    return ''
Exemplo n.º 10
0
def create_global_text(context, order_data):
    order_state = order_data.state
    notifications = set()
    for booking in order_data.bookings:
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        buyable = brain.getObject()
        notificationtext = IGlobalNotificationText(buyable)
        if order_state in (ifaces.STATE_RESERVED, ifaces.STATE_MIXED):
            # XXX: might need custom text for MIXED state
            text = notificationtext.global_overbook_text
            if text:
                notifications.add(text)
        elif order_state == ifaces.STATE_NEW:
            text = notificationtext.global_order_text
            if text:
                notifications.add(text)
    global_text = u'\n\n'.join(notifications)
    if global_text.strip():
        return u'\n\n{global_text}\n'.format(global_text=global_text.strip())
    return u''
Exemplo n.º 11
0
 def create_booking(self, order, cart_data, uid, count, comment):
     brain = get_catalog_brain(self.context, uid)
     # brain could be None if uid for item in cookie which no longer exists.
     if not brain:
         return
     buyable = brain.getObject()
     item_state = get_item_state(buyable, self.request)
     if not item_state.validate_count(item_state.aggregated_count):
         raise CheckoutError(u'Item no longer available')
     item_stock = get_item_stock(buyable)
     if item_stock.available is not None:
         item_stock.available -= float(count)
     available = item_stock.available
     state = (available is None or available >= 0) and ifaces.STATE_NEW\
         or ifaces.STATE_RESERVED
     item_data = get_item_data_provider(buyable)
     vendor = acquire_vendor_or_shop_root(buyable)
     booking = OOBTNode()
     booking.attrs['uid'] = uuid.uuid4()
     booking.attrs['buyable_uid'] = uid
     booking.attrs['buyable_count'] = count
     booking.attrs['buyable_comment'] = comment
     booking.attrs['order_uid'] = order.attrs['uid']
     booking.attrs['vendor_uid'] = uuid.UUID(IUUID(vendor))
     booking.attrs['creator'] = order.attrs['creator']
     booking.attrs['created'] = order.attrs['created']
     booking.attrs['exported'] = False
     booking.attrs['title'] = brain and brain.Title or 'unknown'
     booking.attrs['net'] = item_data.net
     booking.attrs['vat'] = item_data.vat
     booking.attrs['discount_net'] = item_data.discount_net(count)
     booking.attrs['currency'] = cart_data.currency
     booking.attrs['quantity_unit'] = item_data.quantity_unit
     booking.attrs['remaining_stock_available'] = available
     booking.attrs['state'] = state
     booking.attrs['salaried'] = ifaces.SALARIED_NO
     booking.attrs['tid'] = 'none'
     return booking
Exemplo n.º 12
0
    def test_get_catalog_brain(self):
        from bda.plone.cart import get_catalog_brain

        self.assertEquals(get_catalog_brain(self.portal, "foo"), None)
        brain = get_catalog_brain(self.portal, IUUID(self.doc))
        self.assertEquals(brain.getObject(), self.doc)
Exemplo n.º 13
0
    def test_get_catalog_brain(self):
        from bda.plone.cart import get_catalog_brain

        self.assertEquals(get_catalog_brain(self.portal, 'foo'), None)
        brain = get_catalog_brain(self.portal, IUUID(self.doc))
        self.assertEquals(brain.getObject(), self.doc)
Exemplo n.º 14
0
def create_mail_listing(
    context,
    order_data,
    include_booking_states=(
        ifaces.STATE_FINISHED,
        ifaces.STATE_NEW,
        ifaces.STATE_PROCESSING
    )
):
    """Create item listing for notification mail.
    """
    lines = []
    for booking in order_data.bookings:
        state = safe_unicode(booking.attrs.get('state'))
        if state not in include_booking_states:
            continue
        brain = get_catalog_brain(context, booking.attrs['buyable_uid'])
        # fetch buyable
        buyable = brain.getObject()
        # fetch buyable title
        title = safe_unicode(booking.attrs['title'])
        # fetch item_number
        item_number = u''
        if booking.attrs['item_number']:
            item_number = u' ({0})'.format(
                safe_unicode(booking.attrs['item_number']))
        # fetch buyable comment
        comment = safe_unicode(booking.attrs['buyable_comment'])
        if comment:
            title = u'{0} ({1})'.format(title, comment)
        # fetch currency
        currency = safe_unicode(booking.attrs['currency'])
        # fetch net
        net = booking.attrs['net']
        # build price
        price = u'{currency} {net: 0.2f}'.format(
            currency=currency,
            net=net
        )
        # XXX: discount
        state_text = u''
        if state == ifaces.STATE_RESERVED:
            state_text = u' ({0})'.format(vocabs.state_vocab()[state])
        line = u'{count: 4f} {title}{item_number} {state} {price}'.format(
            count=booking.attrs['buyable_count'],
            title=title,
            item_number=item_number,
            state=state_text,
            price=price,
        )
        lines.append(line)
        if comment:
            lines.append(_indent(u'({0})'.format(comment)))
        notificationtext = IItemNotificationText(buyable)
        if state == ifaces.STATE_RESERVED:
            text = notificationtext.overbook_text
        elif state == ifaces.STATE_NEW:
            text = notificationtext.order_text
        else:
            text = None
        if text:
            lines.append(_indent(text))
    return u'\n'.join(lines)