def payment_failed(event): if event.payment.pid == 'pxpay_payment': data = event.data order = OrderData(event.context, uid=event.order_uid) # Processed already if data['tid'] in order.tid: return order.salaried = ifaces.SALARIED_FAILED order.tid = data['tid'] order.receipt = data['receipt']
def get_etickets(self, order_id): tickets = {"tickets": [], "customer": "", "total_tickets": 0} try: data = OrderData(self.context, uid=order_id) bookings = data.bookings total_items = 0 first_name = data.order.attrs['personal_data.firstname'] last_name = data.order.attrs['personal_data.lastname'] created_date = data.order.attrs['created'] customer_name = "%s %s" % (first_name, last_name) tickets['customer'] = customer_name for booking in bookings: print booking.attrs.keys() original_price = (Decimal(str(booking.attrs['net']))) * 1 price_total = original_price + original_price / Decimal( 100) * Decimal(str(booking.attrs['vat'])) total_items += booking.attrs['buyable_count'] tickets['tickets'].append({ "cart_item_title": booking.attrs['title'], "cart_item_price": ascur(price_total), "cart_item_count": len(booking.attrs['to_redeem']), "booking_uid": booking.attrs['uid'], "cart_item_original_price": "", "order_created_date": created_date, "to_redeem": booking.attrs['to_redeem'] }) tickets["total_tickets"] = total_items except: raise return tickets return tickets
def __call__(self): transition = self.request['transition'] booking_uid = self.request['uid'] ticket_uid = self.request['ticket_uid'] order_uid = self.request['order_uid'] # Get booking by uid ticket_booking = None order = OrderData(self.context, uid=order_uid) bookings = order.bookings for booking in bookings: if str(booking.attrs['uid']) == booking_uid: ticket_booking = booking break #print "Ticket UID transition.\nTransition: %s\nBooking UID: %s\nTicket UID: %s\nOrder UID: %s" %(transition, str(booking_uid), str(ticket_uid), str(order_uid)) ticket_state = self.do_ticket_transaction(transition, ticket_uid, ticket_booking) return self.dropdown(self.context, self.request, ticket_booking, ticket_state, ticket_uid).render()
def notify_order_success(event, who=None): """Send notification mail after order succeeded. """ if who not in ['customer', 'shopmanager']: raise ValueError( 'kw "who" mus be one out of ("customer", "shopmanager")') order_data = OrderData(event.context, uid=get_order_uid(event)) templates = dict() state = order_data.state if state in (ifaces.STATE_RESERVED, ifaces.STATE_MIXED): templates.update(get_reservation_templates(event.context)) templates['reserved_item_listing_cb'] = create_reserved_item_listing else: templates.update(get_order_templates(event.context)) templates['item_listing_cb'] = create_mail_listing templates['order_summary_cb'] = create_order_summary templates['global_text_cb'] = create_global_text templates['payment_text_cb'] = create_payment_text if who == "customer": do_notify_customer(event.context, order_data, templates) else: do_notify_shopmanager(event.context, order_data, templates)
def order_data(self): return OrderData(self.context, uid=self.request.get('uid'))
def order_data(self): return OrderData(self.context, uid=self.uid, vendor_uids=self.vendor_uids)
def order_data(self): return OrderData(self.context, uid=self.uid)
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()
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)
def render_salaried(self, colname, record): salaried = OrderData(self.context, order=record).salaried\ or ifaces.SALARIED_NO return translate(vocabs.salaried_vocab()[salaried], context=self.request)
def get_csv(self): context = self.context # prepare csv writer sio = StringIO() ex = csv.writer(sio, dialect='excel-colon', quoting=csv.QUOTE_MINIMAL) # exported column keys as first line ex.writerow(ORDER_EXPORT_ATTRS + COMPUTED_ORDER_EXPORT_ATTRS.keys() + BOOKING_EXPORT_ATTRS + COMPUTED_BOOKING_EXPORT_ATTRS.keys()) bookings_soup = get_bookings_soup(context) # First, filter by allowed vendor areas vendor_uids = get_vendor_uids_for() query_b = Any('vendor_uid', vendor_uids) # Second, query for the buyable query_cat = {} query_cat['object_provides'] = IBuyable.__identifier__ query_cat['path'] = '/'.join(context.getPhysicalPath()) cat = getToolByName(context, 'portal_catalog') res = cat(**query_cat) buyable_uids = [IUUID(it.getObject()) for it in res] query_b = query_b & Any('buyable_uid', buyable_uids) all_orders = {} for booking in bookings_soup.query(query_b): booking_attrs = [] # booking export attrs for attr_name in BOOKING_EXPORT_ATTRS: val = self.export_val(booking, attr_name) booking_attrs.append(val) # computed booking export attrs for attr_name in COMPUTED_BOOKING_EXPORT_ATTRS: cb = COMPUTED_BOOKING_EXPORT_ATTRS[attr_name] val = cb(context, booking) val = cleanup_for_csv(val) booking_attrs.append(val) # create order_attrs, if it doesn't exist order_uid = booking.attrs.get('order_uid') if order_uid not in all_orders: order = get_order(context, order_uid) order_data = OrderData(context, order=order, vendor_uids=vendor_uids) order_attrs = [] # order export attrs for attr_name in ORDER_EXPORT_ATTRS: val = self.export_val(order, attr_name) order_attrs.append(val) # computed order export attrs for attr_name in COMPUTED_ORDER_EXPORT_ATTRS: cb = COMPUTED_ORDER_EXPORT_ATTRS[attr_name] val = cb(self.context, order_data) val = cleanup_for_csv(val) order_attrs.append(val) all_orders[order_uid] = order_attrs ex.writerow(all_orders[order_uid] + booking_attrs) # TODO: also set for contextual exports? i'd say no. # booking.attrs['exported'] = True # bookings_soup.reindex(booking) ret = sio.getvalue() sio.close() return ret
def csv(self, request): # get orders soup orders_soup = get_orders_soup(self.context) # get bookings soup bookings_soup = get_bookings_soup(self.context) # fetch user vendor uids vendor_uids = get_vendor_uids_for() # base query for time range query = Ge('created', self.from_date) & Le('created', self.to_date) # filter by given vendor uid or user vendor uids vendor_uid = self.vendor if vendor_uid: vendor_uid = uuid.UUID(vendor_uid) # raise if given vendor uid not in user vendor uids if vendor_uid not in vendor_uids: raise Unauthorized query = query & Any('vendor_uids', [vendor_uid]) else: query = query & Any('vendor_uids', vendor_uids) # filter by customer if given customer = self.customer if customer: query = query & Eq('creator', customer) # prepare csv writer sio = StringIO() ex = csv.writer(sio, dialect='excel-colon', quoting=csv.QUOTE_MINIMAL) # exported column keys as first line ex.writerow(ORDER_EXPORT_ATTRS + COMPUTED_ORDER_EXPORT_ATTRS.keys() + BOOKING_EXPORT_ATTRS + COMPUTED_BOOKING_EXPORT_ATTRS.keys()) # query orders for order in orders_soup.query(query): # restrict order bookings for current vendor_uids order_data = OrderData(self.context, order=order, vendor_uids=vendor_uids) order_attrs = list() # order export attrs for attr_name in ORDER_EXPORT_ATTRS: val = self.export_val(order, attr_name) order_attrs.append(val) # computed order export attrs for attr_name in COMPUTED_ORDER_EXPORT_ATTRS: cb = COMPUTED_ORDER_EXPORT_ATTRS[attr_name] val = cb(self.context, order_data) val = cleanup_for_csv(val) order_attrs.append(val) for booking in order_data.bookings: booking_attrs = list() # booking export attrs for attr_name in BOOKING_EXPORT_ATTRS: val = self.export_val(booking, attr_name) booking_attrs.append(val) # computed booking export attrs for attr_name in COMPUTED_BOOKING_EXPORT_ATTRS: cb = COMPUTED_BOOKING_EXPORT_ATTRS[attr_name] val = cb(self.context, booking) val = cleanup_for_csv(val) booking_attrs.append(val) ex.writerow(order_attrs + booking_attrs) booking.attrs['exported'] = True bookings_soup.reindex(booking) # create and return response s_start = self.from_date.strftime('%G-%m-%d_%H-%M-%S') s_end = self.to_date.strftime('%G-%m-%d_%H-%M-%S') filename = 'orders-export-%s-%s.csv' % (s_start, s_end) self.request.response.setHeader('Content-Type', 'text/csv') self.request.response.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) ret = sio.getvalue() sio.close() return ret
def render_dt(self, colname, record): order = OrderData(self.context, uid=record.attrs['order_uid']) value = order.order.attrs.get(colname, '') if value: value = value.strftime(DT_FORMAT) return value
def render_order_lastname(self, colname, record): order = OrderData(self.context, uid=record.attrs['order_uid']) name = order.order.attrs.get('personal_data.lastname', '') if name: value = name return value
def verify(self): # # Get Payment details # # Get order order = None tickets = is_context_ticket(self.context) skip_payment = False order_data = { "order_id": "", "total": "", "shipping": "", "currency": "", "tax": "", "ticket": tickets, "download_link": None, "verified": False } data = self.request.form ordernumber = data.get('orderID', '') if ordernumber: order_uid = IPaymentData(self.context).uid_for(ordernumber) if get_status_category(int(data['STATUS'])) != SUCCESS_STATUS: return order_data else: order_uid = data.get('order_uid', '') if order_uid: try: order = OrderData(self.context, uid=order_uid) except: order = None if order: if order.total > 0: return order_data else: skip_payment = True else: return order_data else: return order_data # # SHA passphrase verification # signer = OmnikassaSignature(data, 'sha512', SHA_OUT_PASSWORD) payment = Payments(self.context).get('omnikassa_payment') if not order: try: order = OrderData(self.context, uid=order_uid) except: order = None # Check if order exists if order_uid != None and order != None: order = OrderData(self.context, uid=order_uid) order_nr = order.order.attrs['ordernumber'] # Build order data order_data = { "ordernumber": str(order_nr), "order_id": str(order_uid), "total": str(order.total), "shipping": str(order.shipping), "currency": str(order.currency), "tax": str(order.vat), "ticket": tickets, "download_link": None, "verified": False, "already_sent":False, "bookings":json.dumps([]) } order_bookings = [] for booking in order.bookings: try: booking_uid = booking.attrs['buyable_uid'] item_number = booking.attrs['item_number'] if item_number: sku = str(item_number) else: sku = str(booking_uid) item_category = "Product" # Default category if tickets: item_category = "E-Ticket" order_bookings.append({ 'id':sku, 'price': str(float(booking.attrs['net'])), 'name': str(booking.attrs['title']), 'category': item_category, 'quantity': int(booking.attrs['buyable_count']), }) except: pass try: order_data['bookings'] = json.dumps(order_bookings) except: # Invalid JSON format order_data['bookings'] = json.dumps([]) if tickets: base_url = self.context.portal_url() params = "?order_id=%s" %(str(order_uid)) download_as_pdf_link = "%s/download_as_pdf?page_url=%s/tickets/etickets%s" %(base_url, base_url, params) order_data['download_link'] = download_as_pdf_link else: # Order doesn't exist in the database # return blank ticket order_data = { "order_id": "", "total": "", "shipping": "", "currency": "", "tax": "", "ticket": tickets, "download_link": None, "verified": False } return order_data shasign = data.get('SHASIGN', '') if shasign == signer.signature() or skip_payment: order_data['verified'] = True order = OrderData(self.context, uid=order_uid) order.salaried = ifaces.SALARIED_YES if order.order.attrs['email_sent'] != 'yes': order.order.attrs['email_sent'] = 'yes' orders_soup = get_orders_soup(self.context) order_record = order.order orders_soup.reindex(records=[order_record]) transaction.get().commit() if not skip_payment: payment.succeed(self.context, order_uid) return order_data else: return order_data else: payment.failed(self.context, order_uid) return order_data
def render_salaried(self, colname, record): if not self.check_modify_order(record): salaried = OrderData(self.context, order=record).salaried return translate(vocabs.salaried_vocab()[salaried], context=self.request) return SalariedDropdown(self.context, self.request, record).render()