Ejemplo n.º 1
0
def ShippingMethodsVocabulary(context):
    try:
        items = Shippings(context).vocab
    except KeyError:
        # happens GS profile application if registry entries not present yet
        return AvailableShippingMethodsVocabulary(context)
    return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items])
Ejemplo n.º 2
0
 def shipping(self, items):
     shippings = Shippings(self.context)
     shipping = shippings.get(self.shipping_method)
     try:
         return {
             'label': shipping.label,
             'description': shipping.description,
             'net': shipping.net(items),
             'vat': shipping.vat(items),
         }
     # B/C for bda.plone.shipping < 0.4
     except NotImplementedError:
         return {
             'label': shipping.label,
             'description': shipping.description,
             'net': shipping.calculate(items),
             'vat': Decimal(0),
         }
Ejemplo n.º 3
0
 def shipping(self, items):
     shippings = Shippings(self.context)
     shipping = shippings.get(self.shipping_method)
     try:
         return {
             'label': shipping.label,
             'description': shipping.description,
             'net': shipping.net(items),
             'vat': shipping.vat(items),
         }
     # B/C for bda.plone.shipping < 0.4
     except NotImplementedError:
         return {
             'label': shipping.label,
             'description': shipping.description,
             'net': shipping.calculate(items),
             'vat': Decimal(0),
         }
Ejemplo n.º 4
0
 def save(self, providers, widget, data):
     super(OrderCheckoutAdapter, self).save(providers, widget, data)
     creator = None
     member = plone.api.user.get_current()
     if member:
         creator = member.getId()
     created = datetime.datetime.now()
     order = self.order
     # XXX: payment name
     #      payment type
     #      payment total
     #      shipping name
     #      shipping vat
     sid = data.fetch('checkout.shipping_selection.shipping').extracted
     shipping = Shippings(self.context).get(sid)
     order.attrs['shipping'] = shipping.calculate(self.items)
     uid = order.attrs['uid'] = uuid.uuid4()
     order.attrs['creator'] = creator
     order.attrs['created'] = created
     bookings = self.create_bookings(order)
     booking_uids = list()
     vendor_uids = set()
     for booking in bookings:
         booking_uids.append(booking.attrs['uid'])
         vendor_uids.add(booking.attrs['vendor_uid'])
     order.attrs['booking_uids'] = booking_uids
     order.attrs['vendor_uids'] = list(vendor_uids)
     cart_data = get_data_provider(self.context)
     cart_discount = cart_data.discount(self.items)
     order.attrs['cart_discount_net'] = cart_discount['net']
     order.attrs['cart_discount_vat'] = cart_discount['vat']
     orders_soup = get_orders_soup(self.context)
     ordernumber = create_ordernumber()
     while self.ordernumber_exists(orders_soup, ordernumber):
         ordernumber = create_ordernumber()
     order.attrs['ordernumber'] = ordernumber
     orders_soup.add(order)
     bookings_soup = get_bookings_soup(self.context)
     for booking in bookings:
         bookings_soup.add(booking)
     return uid
Ejemplo n.º 5
0
 def save(self, providers, widget, data):
     super(OrderCheckoutAdapter, self).save(providers, widget, data)
     order = self.order
     # order UUID
     uid = order.attrs['uid'] = uuid.uuid4()
     # order creator
     creator = None
     member = plone.api.user.get_current()
     if member:
         creator = member.getId()
     order.attrs['creator'] = creator
     # order creation date
     created = datetime.datetime.now()
     order.attrs['created'] = created
     cart_data = get_data_provider(self.context, self.request)
     # payment related information
     if cart_data.total > Decimal(0):
         payment_param = 'checkout.payment_selection.payment'
         pid = data.fetch(payment_param).extracted
         payment = Payments(self.context).get(pid)
         order.attrs['payment_method'] = pid
         if payment:
             order.attrs['payment_label'] = payment.label
         else:
             order.attrs['payment_label'] = _('unknown', default=u'Unknown')
     # no payment
     else:
         order.attrs['payment_method'] = 'no_payment'
         order.attrs['payment_label'] = _('no_payment',
                                          default=u'No Payment')
     # shipping related information
     if cart_data.include_shipping_costs:
         shipping_param = 'checkout.shipping_selection.shipping'
         sid = data.fetch(shipping_param).extracted
         shipping = Shippings(self.context).get(sid)
         order.attrs['shipping_method'] = sid
         order.attrs['shipping_label'] = shipping.label
         order.attrs['shipping_description'] = shipping.description
         try:
             shipping_net = shipping.net(self.items)
             shipping_vat = shipping.vat(self.items)
             order.attrs['shipping_net'] = shipping_net
             order.attrs['shipping_vat'] = shipping_vat
             order.attrs['shipping'] = shipping_net + shipping_vat
         # B/C for bda.plone.shipping < 0.4
         except NotImplementedError:
             shipping_net = shipping.calculate(self.items)
             order.attrs['shipping_net'] = shipping_net
             order.attrs['shipping_vat'] = Decimal(0)
             order.attrs['shipping'] = shipping_net
     # no shipping
     else:
         order.attrs['shipping_method'] = 'no_shipping'
         order.attrs['shipping_label'] = _('no_shipping',
                                           default=u'No Shipping')
         order.attrs['shipping_description'] = ''
         order.attrs['shipping_net'] = Decimal(0)
         order.attrs['shipping_vat'] = Decimal(0)
         order.attrs['shipping'] = Decimal(0)
     # create order bookings
     bookings = self.create_bookings(order)
     # set order state, needed for sorting in orders table
     order.attrs['state'] = calculate_order_state(bookings)
     # set order salaried, needed for sorting in orders table
     order.attrs['salaried'] = ifaces.SALARIED_NO
     # lookup booking uids, buyable uids and vendor uids
     booking_uids = list()
     buyable_uids = list()
     vendor_uids = set()
     for booking in bookings:
         booking_uids.append(booking.attrs['uid'])
         buyable_uids.append(booking.attrs['buyable_uid'])
         vendor_uids.add(booking.attrs['vendor_uid'])
     order.attrs['booking_uids'] = booking_uids
     order.attrs['buyable_uids'] = buyable_uids
     order.attrs['vendor_uids'] = list(vendor_uids)
     # cart discount related information
     # XXX: in order to be able to reliably modify orders, cart discount
     #      rules for this order must be stored instead of the actual
     #      calculated discount.
     cart_discount = cart_data.discount(self.items)
     order.attrs['cart_discount_net'] = cart_discount['net']
     order.attrs['cart_discount_vat'] = cart_discount['vat']
     # create ordernumber
     orders_soup = get_orders_soup(self.context)
     ordernumber = create_ordernumber()
     while self.ordernumber_exists(orders_soup, ordernumber):
         ordernumber = create_ordernumber()
     order.attrs['ordernumber'] = ordernumber
     # add order
     orders_soup.add(order)
     # add bookings
     bookings_soup = get_bookings_soup(self.context)
     # list containing items where stock threshold has been reached
     stock_threshold_reached_items = list()
     for booking in bookings:
         bookings_soup.add(booking)
         buyable = get_object_by_uid(
             self.context,
             booking.attrs['buyable_uid']
         )
         item_stock = get_item_stock(buyable)
         # no stock applied
         if item_stock is None:
             stock_warning_threshold = None
         else:
             stock_warning_threshold = item_stock.stock_warning_threshold
         if stock_warning_threshold:
             remaining = booking.attrs['remaining_stock_available']
             # stock threshold has been reached
             if remaining <= stock_warning_threshold:
                 stock_threshold_reached_items.append(booking.attrs)
     if stock_threshold_reached_items:
         event = events.StockThresholdReached(
             self.context,
             self.request,
             order.attrs['uid'],
             stock_threshold_reached_items,
         )
         notify(event)
     # return uid of added order
     return uid
Ejemplo n.º 6
0
 def shipping(self, items):
     shippings = Shippings(self.context)
     shipping = shippings.get(self.shipping_method)
     return shipping.calculate(items)
Ejemplo n.º 7
0
def AvailableShippingMethodsVocabulary(context):
    shippings = Shippings(context).shippings
    items = [(shipping.sid, shipping.label) for shipping in shippings]
    return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items])
Ejemplo n.º 8
0
 def save(self, providers, widget, data):
     super(OrderCheckoutAdapter, self).save(providers, widget, data)
     order = self.order
     # order UUID
     uid = order.attrs['uid'] = uuid.uuid4()
     # order creator
     creator = None
     member = plone.api.user.get_current()
     if member:
         creator = member.getId()
     order.attrs['creator'] = creator
     # order creation date
     created = datetime.datetime.now()
     order.attrs['created'] = created
     cart_data = get_data_provider(self.context, self.request)
     # payment related information
     if cart_data.total > Decimal(0):
         payment_param = 'checkout.payment_selection.payment'
         pid = data.fetch(payment_param).extracted
         payment = Payments(self.context).get(pid)
         order.attrs['payment_method'] = pid
         if payment:
             order.attrs['payment_label'] = payment.label
         else:
             order.attrs['payment_label'] = _('unknown', default=u'Unknown')
     # no payment
     else:
         order.attrs['payment_method'] = 'no_payment'
         order.attrs['payment_label'] = _('no_payment',
                                          default=u'No Payment')
     # shipping related information
     if cart_data.include_shipping_costs:
         shipping_param = 'checkout.shipping_selection.shipping'
         sid = data.fetch(shipping_param).extracted
         shipping = Shippings(self.context).get(sid)
         order.attrs['shipping_method'] = sid
         order.attrs['shipping_label'] = shipping.label
         order.attrs['shipping_description'] = shipping.description
         try:
             shipping_net = shipping.net(self.items)
             shipping_vat = shipping.vat(self.items)
             order.attrs['shipping_net'] = shipping_net
             order.attrs['shipping_vat'] = shipping_vat
             order.attrs['shipping'] = shipping_net + shipping_vat
         # B/C for bda.plone.shipping < 0.4
         except NotImplementedError:
             shipping_net = shipping.calculate(self.items)
             order.attrs['shipping_net'] = shipping_net
             order.attrs['shipping_vat'] = Decimal(0)
             order.attrs['shipping'] = shipping_net
     # no shipping
     else:
         order.attrs['shipping_method'] = 'no_shipping'
         order.attrs['shipping_label'] = _('no_shipping',
                                           default=u'No Shipping')
         order.attrs['shipping_description'] = ''
         order.attrs['shipping_net'] = Decimal(0)
         order.attrs['shipping_vat'] = Decimal(0)
         order.attrs['shipping'] = Decimal(0)
     # create order bookings
     bookings = self.create_bookings(order)
     # set order state, needed for sorting in orders table
     order.attrs['state'] = calculate_order_state(bookings)
     # set order salaried, needed for sorting in orders table
     order.attrs['salaried'] = ifaces.SALARIED_NO
     # lookup booking uids, buyable uids and vendor uids
     booking_uids = list()
     buyable_uids = list()
     vendor_uids = set()
     for booking in bookings:
         booking_uids.append(booking.attrs['uid'])
         buyable_uids.append(booking.attrs['buyable_uid'])
         vendor_uids.add(booking.attrs['vendor_uid'])
     order.attrs['booking_uids'] = booking_uids
     order.attrs['buyable_uids'] = buyable_uids
     order.attrs['vendor_uids'] = list(vendor_uids)
     # cart discount related information
     cart_discount = cart_data.discount(self.items)
     order.attrs['cart_discount_net'] = cart_discount['net']
     order.attrs['cart_discount_vat'] = cart_discount['vat']
     # create ordernumber
     orders_soup = get_orders_soup(self.context)
     ordernumber = create_ordernumber()
     while self.ordernumber_exists(orders_soup, ordernumber):
         ordernumber = create_ordernumber()
     order.attrs['ordernumber'] = ordernumber
     # add order
     orders_soup.add(order)
     # add bookings
     bookings_soup = get_bookings_soup(self.context)
     # list containing items where stock threshold has been reached
     stock_threshold_reached_items = list()
     for booking in bookings:
         bookings_soup.add(booking)
         buyable = get_object_by_uid(self.context,
                                     booking.attrs['buyable_uid'])
         item_stock = get_item_stock(buyable)
         # no stock applied
         if item_stock is None:
             stock_warning_threshold = None
         else:
             stock_warning_threshold = item_stock.stock_warning_threshold
         if stock_warning_threshold:
             remaining = booking.attrs['remaining_stock_available']
             # stock threshold has been reached
             if remaining <= stock_warning_threshold:
                 stock_threshold_reached_items.append(booking.attrs)
     if stock_threshold_reached_items:
         event = events.StockThresholdReached(
             self.context,
             self.request,
             order.attrs['uid'],
             stock_threshold_reached_items,
         )
         notify(event)
     # return uid of added order
     return uid
Ejemplo n.º 9
0
    def save(self, providers, widget, data):
        super(OrderCheckoutAdapter, self).save(providers, widget, data)
        order = self.order
        # order UUID
        uid = order.attrs['uid'] = uuid.uuid4()
        # order creator
        creator = None
        member = plone.api.user.get_current()
        if member:
            creator = member.getId()
        order.attrs['creator'] = creator
        # order creation date
        created = datetime.datetime.now()
        order.attrs['created'] = created
        cart_data = get_data_provider(self.context, self.request)
        # payment related information
        if cart_data.total > Decimal(0):
            payment_param = 'checkout.payment_selection.payment'
            pid = data.fetch(payment_param).extracted
            payment = Payments(self.context).get(pid)
            order.attrs['payment_method'] = pid
            if payment:
                order.attrs['payment_label'] = payment.label
            else:
                order.attrs['payment_label'] = _('unknown', default=u'Unknown')
        # no payment
        else:
            order.attrs['payment_method'] = 'no_payment'
            order.attrs['payment_label'] = _('no_payment',
                                             default=u'No Payment')
        # shipping related information
        if cart_data.include_shipping_costs:
            shipping_param = 'checkout.shipping_selection.shipping'
            sid = data.fetch(shipping_param).extracted
            shipping = Shippings(self.context).get(sid)
            order.attrs['shipping_method'] = sid
            order.attrs['shipping_label'] = shipping.label
            order.attrs['shipping_description'] = shipping.description
            try:
                shipping_net = shipping.net(self.items)
                shipping_vat = shipping.vat(self.items)
                order.attrs['shipping_net'] = shipping_net
                order.attrs['shipping_vat'] = shipping_vat
                order.attrs['shipping'] = shipping_net + shipping_vat
            # B/C for bda.plone.shipping < 0.4
            except NotImplementedError:
                shipping_net = shipping.calculate(self.items)
                order.attrs['shipping_net'] = shipping_net
                order.attrs['shipping_vat'] = Decimal(0)
                order.attrs['shipping'] = shipping_net
        # no shipping
        else:
            order.attrs['shipping_method'] = 'no_shipping'
            order.attrs['shipping_label'] = _('no_shipping',
                                              default=u'No Shipping')
            order.attrs['shipping_description'] = ''
            order.attrs['shipping_net'] = Decimal(0)
            order.attrs['shipping_vat'] = Decimal(0)
            order.attrs['shipping'] = Decimal(0)
        # create order bookings
        bookings = self.create_bookings(order)
        # lookup booking uids, buyable uids and vendor uids
        booking_uids = list()
        buyable_uids = list()
        vendor_uids = set()
        for booking in bookings:
            booking_uids.append(booking.attrs['uid'])
            buyable_uids.append(booking.attrs['buyable_uid'])
            vendor_uids.add(booking.attrs['vendor_uid'])
        order.attrs['booking_uids'] = booking_uids
        order.attrs['buyable_uids'] = buyable_uids
        order.attrs['vendor_uids'] = list(vendor_uids)
        # cart discount related information
        cart_discount = cart_data.discount(self.items)
        order.attrs['cart_discount_net'] = cart_discount['net']
        order.attrs['cart_discount_vat'] = cart_discount['vat']
        # create ordernumber
        orders_soup = get_orders_soup(self.context)
        ordernumber = create_ordernumber()
        while self.ordernumber_exists(orders_soup, ordernumber):
            ordernumber = create_ordernumber()
        order.attrs['ordernumber'] = ordernumber

        order.attrs['state'] = ifaces.STATE_NEW
        order.attrs['salaried'] = ifaces.SALARIED_NO

        # add order
        orders_soup.add(order)
        # add bookings
        bookings_soup = get_bookings_soup(self.context)
        for booking in bookings:
            bookings_soup.add(booking)
        # return uid of added order
        return uid