Ejemplo n.º 1
0
 def _sendmail(self, notifier, uid, tpl, subject):
     order_data = OrderData(self.context, uid=uid)
     order = order_data.order
     data = {}
     for key in TEMPLATE.defaults:
         # XXX: refactor and use configurable callbacks
         # special case gender
         if key == 'personal_data.gender':
             data[key] = translate(mail_gender_vocab()[order.attrs[key]],
                                   context=self.request)
             continue
         # special case salaried
         if key == 'salaried':
             data[key] = translate(salaried_vocab()[order_data.salaried],
                                   context=self.request)
             continue
         # special case state
         if key == 'state':
             data[key] = translate(state_vocab()[order_data.state],
                                   context=self.request)
             continue
         # read attrs from order
         if key in order.attrs:
             data[key] = order.attrs[key]
     body = TEMPLATE(tpl, data).encode('utf-8')
     notifier.send(subject, body, order.attrs['personal_data.email'])
 def _sendmail(self, notifier, uid, tpl, subject):
     order_data = OrderData(self.context, uid=uid)
     order = order_data.order
     data = {}
     for key in TEMPLATE.defaults:
         # XXX: refactor and use configurable callbacks
         # special case gender
         if key == 'personal_data.gender':
             data[key] = translate(mail_gender_vocab()[order.attrs[key]],
                                   context=self.request)
             continue
         # special case salaried
         if key == 'salaried':
             data[key] = translate(salaried_vocab()[order_data.salaried],
                                   context=self.request)
             continue
         # special case state
         if key == 'state':
             data[key] = translate(state_vocab()[order_data.state],
                                   context=self.request)
             continue
         # read attrs from order
         if key in order.attrs:
             data[key] = order.attrs[key]
     body = TEMPLATE(tpl, data).encode('utf-8')
     notifier.send(subject, body, order.attrs['personal_data.email'])
Ejemplo n.º 3
0
 def listing(self):
     # XXX: discount
     ret = list()
     for booking in self.order_data.bookings:
         obj = get_object_by_uid(self.context, booking.attrs['buyable_uid'])
         state = vocabs.state_vocab()[booking.attrs.get('state')]
         salaried = vocabs.salaried_vocab()[booking.attrs.get('salaried')]
         ret.append({
             'uid':
             booking.attrs['uid'],
             'title':
             booking.attrs['title'],
             'url':
             obj.absolute_url(),
             'count':
             booking.attrs['buyable_count'],
             'net':
             ascur(booking.attrs.get('net', 0.0)),
             'discount_net':
             ascur(float(booking.attrs['discount_net'])),
             'vat':
             booking.attrs.get('vat', 0.0),
             'comment':
             booking.attrs['buyable_comment'],
             'quantity_unit':
             booking.attrs.get('quantity_unit'),
             'currency':
             booking.attrs.get('currency'),
             'state':
             state,
             'salaried':
             salaried,
         })
     return ret
Ejemplo n.º 4
0
 def listing(self):
     # XXX: discount
     can_cancel_booking = self.can_cancel_booking
     ret = list()
     for booking in self.order_data.bookings:
         obj = get_object_by_uid(self.context, booking.attrs['buyable_uid'])
         state = vocabs.state_vocab()[booking.attrs.get('state')]
         salaried = vocabs.salaried_vocab()[booking.attrs.get('salaried')]
         cancel_target = None
         if can_cancel_booking and state != ifaces.STATE_CANCELLED:
             cancel_target = addTokenToUrl('{}?uid={}'.format(
                 self.context.absolute_url(),
                 booking.attrs['uid'])
             )
         ret.append({
             'uid': booking.attrs['uid'],
             'title': booking.attrs['title'],
             'url': obj.absolute_url() if obj else None,
             'cancel_target': cancel_target,
             'count': booking.attrs['buyable_count'],
             'net': ascur(booking.attrs.get('net', 0.0)),
             'discount_net': ascur(float(booking.attrs['discount_net'])),
             'vat': booking.attrs.get('vat', 0.0),
             'comment': booking.attrs['buyable_comment'],
             'quantity_unit': booking.attrs.get('quantity_unit'),
             'currency': booking.attrs.get('currency'),
             'state': state,
             'salaried': salaried,
         })
     return ret
Ejemplo n.º 5
0
 def listing(self):
     # XXX: discount
     ret = list()
     for booking in self.order_data.bookings:
         obj = get_object_by_uid(self.context, booking.attrs['buyable_uid'])
         state = vocabs.state_vocab()[booking.attrs.get('state')]
         salaried = vocabs.salaried_vocab()[booking.attrs.get('salaried')]
         ret.append({
             'uid': booking.attrs['uid'],
             'title': booking.attrs['title'],
             'url': obj.absolute_url(),
             'reserved': reserved(
                 booking.attrs['remaining_stock_available'],
                 booking.attrs['buyable_count']),
             'count': booking.attrs['buyable_count'],
             'net': ascur(booking.attrs.get('net', 0.0)),
             'discount_net': ascur(float(booking.attrs['discount_net'])),
             'vat': booking.attrs.get('vat', 0.0),
             'comment': booking.attrs['buyable_comment'],
             'quantity_unit': booking.attrs.get('quantity_unit'),
             'currency': booking.attrs.get('currency'),
             'state': state,
             'salaried': salaried,
         })
     return ret
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def render_state(self, colname, record):
     if not self.check_modify_order(record):
         state = OrderData(self.context, order=record).state
         return translate(vocabs.state_vocab()[state],
                          context=self.request)
     return OrderStateDropdown(
         self.context,
         self.request,
         record
     ).render()
Ejemplo n.º 8
0
 def render_state(self, colname, record):
     if not self.check_modify_order(record):
         state = BookingData(
             self.context,
             booking=record
         ).state
         return translate(
             vocabs.state_vocab()[state],
             context=self.request
         )
     return StateDropdown(self.context, self.request, record).render()
Ejemplo n.º 9
0
 def render_state(self, colname, record):
     if not self.check_modify_order(record):
         booking_data = BookingData(
             self.context,
             booking=record
         )
         return translate(
             vocabs.state_vocab()[booking_data.state],
             context=self.request
         )
     return BookingStateDropdown(
         self.context,
         self.request,
         record
     ).render()
Ejemplo n.º 10
0
class OrderStateDropdown(OrderDropdown):
    name = 'state'
    css = 'dropdown change_order_state_dropdown'
    action = 'orderstatetransition'
    vocab = vocabs.state_vocab()
    transitions = vocabs.state_transitions_vocab()

    @property
    def value(self):
        return self.order_data.state

    @property
    def items(self):
        transitions = transitions_of_main_state(self.value)
        return self.create_items(transitions)
Ejemplo n.º 11
0
class BookingStateDropdown(BookingsDropdown):
    name = 'state'
    css = 'dropdown change_booking_state_dropdown'
    action = 'bookingstatetransition'
    vocab = vocabs.state_vocab()
    transitions = vocabs.state_transitions_vocab()

    @property
    def value(self):
        return self.booking_data.state

    @property
    def items(self):
        transitions = transitions_of_main_state(self.value)
        return self.create_items(transitions)
Ejemplo n.º 12
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])
Ejemplo n.º 13
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])
Ejemplo n.º 14
0
class RedeemStateDropdown(RedeemDropdown):
    name = 'state'
    css = 'dropdown change_order_state_dropdown'
    action = 'redeemtransition'
    vocab = vocabs.state_vocab()
    transitions = vocabs.state_transitions_vocab()

    @property
    def value(self):
        return self.redeem_state

    @property
    def items(self):
        state = self.redeem_state
        transitions = list()
        if state in [ifaces.STATE_NEW, ifaces.STATE_RESERVED]:
            transitions = [ifaces.STATE_TRANSITION_REDEEM]
        else:
            transitions = [ifaces.STATE_TRANSITION_RENEW]
        return self.create_items(transitions)
Ejemplo n.º 15
0
 def state(self):
     state = self.order_data.state or ifaces.STATE_NEW
     return vocabs.state_vocab()[state]
Ejemplo n.º 16
0
 def render_state(self, colname, record, redeem_state, uid=None):
     state = redeem_state
     return translate(vocabs.state_vocab()[state], context=self.request)
Ejemplo n.º 17
0
 def render_state(self, colname, record):
     state = OrderData(self.context, order=record).state
     if not state:
         return '-/-'
     return translate(vocabs.state_vocab()[state], context=self.request)
Ejemplo n.º 18
0
def states_form_vocab():
    states = vocabs.state_vocab()
    return [('', _('all', default='All'))] + states.items()
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def state(self):
     state = self.order_data.state or ifaces.STATE_NEW
     return vocabs.state_vocab()[state]
Ejemplo n.º 21
0
 def render_state(self, colname, record):
     state = OrderData(self.context, order=record).state
     if not state:
         return '-/-'
     return translate(vocabs.state_vocab()[state], context=self.request)
Ejemplo n.º 22
0
 def render_state(self, colname, record, redeem_state, uid=None):
     state = redeem_state
     return translate(vocabs.state_vocab()[state],
                      context=self.request)
Ejemplo n.º 23
0
def states_form_vocab():
    states = vocabs.state_vocab()
    return [('', _('all', default='All'))] + states.items()