Exemple #1
0
 def is_cancellable(self):
     tz = current_app.config['tz']
     now = localize_timezone(utcnow(), tz)
     return self.is_confirmed and (
         now < localize_timezone(self.item.cancellable_until, tz)
         if self.item.cancellable_until
         else True
     )
Exemple #2
0
 def is_transferable(self):
     tz = current_app.config['tz']
     now = localize_timezone(utcnow(), tz)
     if self.current_assignee is None:
         return True  # first time assignment has no deadline for now
     else:
         return (
             now < localize_timezone(self.item.transferable_until, tz)
             if self.item.transferable_until is not None
             else now.date() <= self.item.event_date
             if self.item.event_date is not None
             else True
         )
Exemple #3
0
def session_data(session, with_modal_url=False, with_delete_url=False):
    data = {
        'id':
        session.url_id,
        'title':
        session.title,
        'start_at':
        (localize_timezone(session.start_at, tz=session.project.timezone)
         if session.scheduled else None),
        'end_at':
        (localize_timezone(session.end_at, tz=session.project.timezone)
         if session.scheduled else None),
        'timezone':
        session.project.timezone.zone,
        'speaker':
        session.speaker if session.speaker else None,
        'room_scoped_name':
        (session.venue_room.scoped_name if session.venue_room else None),
        'is_break':
        session.is_break,
        'url_name_uuid_b58':
        session.url_name_uuid_b58,
        'url_name':
        session.url_name,
        'proposal_id':
        session.proposal_id,
        'description':
        session.description,
        'speaker_bio':
        session.speaker_bio,
        'url':
        session.url_for(_external=True),
        'json_url': (session.proposal.url_for('json', _external=True)
                     if session.proposal else None),
        'proposal_url': (session.proposal.url_for(
            _external=True) if session.proposal else None),
        'proposal':
        session.proposal.uuid_b58 if session.proposal else None,
        'feedback_url': (session.url_for('feedback', _external=True)
                         if session.proposal else None),
        'room':
        (session.venue_room.scoped_name if session.venue_room else None),
    }
    if with_modal_url:
        data.update({'modal_url': session.url_for(with_modal_url)})
    if with_delete_url:
        data.update({'delete_url': session.url_for('delete')})
    return data
Exemple #4
0
 def row_handler(row):
     dict_row = dict(zip(headers, row))
     if dict_row.get('status') in INVOICE_STATUS.keys():
         dict_row['status'] = INVOICE_STATUS.get(dict_row['status'])
     if isinstance(dict_row.get('invoiced_at'), datetime):
         dict_row['invoiced_at'] = format_datetime(localize_timezone(dict_row['invoiced_at']), format='long', locale=get_locale() or 'en')
     return dict_row
Exemple #5
0
 def row_handler(row):
     # localize datetime
     row_list = [v if not isinstance(v, datetime) else format_datetime(localize_timezone(v), format='long', locale=get_locale()) for v in row]
     # add assignee url
     access_token = row_list[assignee_url_index]
     if access_token:
         row_list[assignee_url_index] = url_for('line_items', access_token=access_token, _external=True)
     return row_list
Exemple #6
0
 def row_handler(row):
     # localize datetime
     row_list = [
         v if not isinstance(v, datetime) else format_datetime(
             localize_timezone(v), format='long', locale=get_locale())
         for v in row
     ]
     return row_list
Exemple #7
0
 def row_handler(row):
     dict_row = dict(zip(headers, row))
     if dict_row.get('status') in INVOICE_STATUS.keys():
         dict_row['status'] = INVOICE_STATUS.get(dict_row['status'])
     if isinstance(dict_row.get('invoiced_at'), datetime):
         dict_row['invoiced_at'] = format_datetime(
             localize_timezone(dict_row['invoiced_at']),
             format='long',
             locale=get_locale() or 'en')
     return dict_row
def admin_item_collection(item_collection):
    item_ids = [str(item.id) for item in item_collection.items]
    date_item_counts = {}
    date_sales = {}
    for sales_date, sales_count in counts_per_date_per_item(item_collection, g.user.timezone).items():
        date_sales[sales_date.isoformat()] = sales_by_date(sales_date, item_ids, g.user.timezone)
        date_item_counts[sales_date.isoformat()] = sales_count
    today_sales = date_sales.get(localize_timezone(utcnow(), g.user.timezone).date().isoformat(), Decimal(0))
    return dict(title=item_collection.title, item_collection=item_collection, date_item_counts=date_item_counts,
        date_sales=date_sales, today_sales=today_sales,
        sales_delta=sales_delta(g.user.timezone, item_ids))
def admin_item_collection(item_collection):
    item_ids = [str(item.id) for item in item_collection.items]
    date_item_counts = {}
    date_sales = {}
    for sales_date, sales_count in counts_per_date_per_item(item_collection, g.user.timezone).items():
        date_sales[sales_date.isoformat()] = sales_by_date(sales_date, item_ids, g.user.timezone)
        date_item_counts[sales_date.isoformat()] = sales_count
    today_sales = date_sales.get(localize_timezone(datetime.datetime.utcnow(), g.user.timezone).date().isoformat(), Decimal(0))
    return dict(title=item_collection.title, item_collection=item_collection, date_item_counts=date_item_counts,
        date_sales=date_sales, today_sales=today_sales,
        sales_delta=sales_delta(g.user.timezone, item_ids))
def format_refund_transaction(settlement_id, payment_id, transaction, payment_status):
    transaction_date = transaction.created_at
    return {
        'settlement_id': settlement_id,
        'order_id': transaction.order.id,
        'item_collection': transaction.order.item_collection.title,
        'payment_id': payment_id,
        'item_title': transaction.refund_description,
        'final_amount': transaction.amount,
        'payment_status': payment_status,
        'transaction_date': localize_timezone(transaction_date, 'Asia/Kolkata')
    }
Exemple #11
0
def format_refund_transaction(settlement_id, payment_id, transaction,
                              payment_status):
    transaction_date = transaction.created_at
    return {
        'settlement_id': settlement_id,
        'order_id': transaction.order.id,
        'item_collection': transaction.order.item_collection.title,
        'payment_id': payment_id,
        'item_title': transaction.refund_description,
        'final_amount': transaction.amount,
        'payment_status': payment_status,
        'transaction_date': localize_timezone(transaction_date, 'Asia/Kolkata')
    }
Exemple #12
0
 def edit_schedule(self):
     schedule_transition_form = ProjectScheduleTransitionForm(obj=self.obj)
     proposals = {
         'unscheduled': [{
             'title': proposal.title,
             'modal_url': proposal.url_for('schedule')
         } for proposal in self.obj.proposals_all.filter(
             Proposal.state.CONFIRMED).order_by(Proposal.title)
                         if not proposal.state.SCHEDULED],
         'scheduled':
         session_list_data(self.obj.scheduled_sessions,
                           with_modal_url='edit',
                           with_delete_url=True),
     }
     return {
         'project':
         self.obj,
         'proposals':
         proposals,
         'from_date': (localize_timezone(self.obj.schedule_start_at,
                                         tz=self.obj.timezone).isoformat()
                       if self.obj.schedule_start_at else None),
         'to_date': (localize_timezone(self.obj.schedule_end_at,
                                       tz=self.obj.timezone).isoformat()
                     if self.obj.schedule_start_at else None),
         'timezone':
         self.obj.timezone.zone,
         'venues': [venue.current_access() for venue in self.obj.venues],
         'rooms': {
             room.scoped_name: {
                 'title': room.title,
                 'vtitle': room.venue.title + " - " + room.title,
                 'bgcolor': room.bgcolor,
             }
             for room in self.obj.rooms
         },
         'schedule_transition_form':
         schedule_transition_form,
     }
Exemple #13
0
 def view(self):
     scheduled_sessions_list = session_list_data(
         self.obj.project.scheduled_sessions, with_modal_url='view_popup')
     return {
         'project':
         self.obj.project,
         'from_date':
         (localize_timezone(self.obj.project.schedule_start_at,
                            tz=self.obj.project.timezone).isoformat()
          if self.obj.project.schedule_start_at else None),
         'to_date':
         (localize_timezone(self.obj.project.schedule_end_at,
                            tz=self.obj.project.timezone).isoformat()
          if self.obj.project.schedule_end_at else None),
         'active_session':
         session_data(self.obj, with_modal_url='view_popup'),
         'sessions':
         scheduled_sessions_list,
         'timezone':
         self.obj.project.timezone.zone,
         'venues': [
             venue.current_access(datasets=('without_parent', 'related'))
             for venue in self.obj.project.venues
         ],
         'rooms': {
             room.scoped_name: {
                 'title': room.title,
                 'bgcolor': room.bgcolor
             }
             for room in self.obj.project.rooms
         },
         'schedule':
         schedule_data(self.obj,
                       with_slots=False,
                       scheduled_sessions=scheduled_sessions_list),
         'csrf_form':
         forms.Form(),
     }
Exemple #14
0
 def row_handler(row):
     # localize datetime
     row_list = [
         v if not isinstance(v, datetime) else format_datetime(
             localize_timezone(v), format='long', locale=get_locale())
         for v in row
     ]
     # add assignee url
     access_token = row_list[assignee_url_index]
     if access_token:
         row_list[assignee_url_index] = url_for('line_items',
                                                access_token=access_token,
                                                _external=True)
     return row_list
Exemple #15
0
def format_line_item(settlement_id, payment_id, line_item, payment_status):
    transaction_date = line_item.ordered_at if line_item.is_confirmed else line_item.cancelled_at
    return {
        'settlement_id': settlement_id,
        'order_id': line_item.order.id,
        'item_collection': line_item.item.item_collection.title,
        'payment_id': payment_id,
        'line_item_id': line_item.id,
        'item_title': line_item.item.title,
        'base_amount': line_item.base_amount,
        'discounted_amount': line_item.discounted_amount,
        'final_amount': line_item.final_amount,
        'payment_status': payment_status,
        'transaction_date': localize_timezone(transaction_date, 'Asia/Kolkata')
    }
Exemple #16
0
 def row_handler(row):
     # Convert row to a dict
     dict_row = {}
     for idx, item in enumerate(row):
         # 'assignee_details' is a dict already, so copy and include prefixes
         if idx == attendee_details_index and isinstance(item, dict):
             for key in item.keys():
                 dict_row['attendee_details_'+key] = item[key]
         # Item is a datetime object, so format and add to dict
         elif isinstance(item, datetime):
             dict_row[headers[idx]] = format_datetime(localize_timezone(item), format='long', locale=get_locale())
         # Item is a string, add it to the dict with the corresponding key
         else:
             dict_row[headers[idx]] = item
     return dict_row
def format_line_item(settlement_id, payment_id, line_item, payment_status):
    transaction_date = line_item.ordered_at if line_item.is_confirmed else line_item.cancelled_at
    return {
        'settlement_id': settlement_id,
        'order_id': line_item.order.id,
        'item_collection': line_item.item.item_collection.title,
        'payment_id': payment_id,
        'line_item_id': line_item.id,
        'item_title': line_item.item.title,
        'base_amount': line_item.base_amount,
        'discounted_amount': line_item.discounted_amount,
        'final_amount': line_item.final_amount,
        'payment_status': payment_status,
        'transaction_date': localize_timezone(transaction_date, 'Asia/Kolkata')
    }
Exemple #18
0
 def row_handler(row):
     # Convert row to a dict
     dict_row = {}
     for idx, item in enumerate(row):
         # 'assignee_details' is a dict already, so copy and include prefixs
         if idx == attendee_details_index and isinstance(item, dict):
             for key in item.keys():
                 dict_row['attendee_details_'+key] = item[key]
         # Item is a datetime object, so format and add to dict
         elif isinstance(item, datetime):
             dict_row[headers[idx]] = format_datetime(localize_timezone(item), format='long', locale=get_locale() or 'en') # FIXME: How to handle locale where the accept langauges header isn't specified? Relevant issue in baseframe https://github.com/hasgeek/baseframe/issues/154
         # Value is a string, add it to the dict with the corresponding key
         else:
             dict_row[headers[idx]] = item
     return dict_row
Exemple #19
0
 def row_handler(row):
     # Convert row to a dict
     dict_row = {}
     for idx, item in enumerate(row):
         # 'assignee_details' is a dict already, so copy and include prefixes
         if idx == attendee_details_index and isinstance(item, dict):
             for key in item.keys():
                 dict_row['attendee_details_' + key] = item[key]
         # Item is a datetime object, so format and add to dict
         elif isinstance(item, datetime):
             dict_row[headers[idx]] = format_datetime(
                 localize_timezone(item),
                 format='long',
                 locale=get_locale())
         # Item is a string, add it to the dict with the corresponding key
         else:
             dict_row[headers[idx]] = item
     return dict_row
Exemple #20
0
 def row_handler(row):
     # Convert row to a dict
     dict_row = {}
     for idx, item in enumerate(row):
         # 'assignee_details' is a dict already, so copy and include prefixs
         if idx == attendee_details_index and isinstance(item, dict):
             for key in item.keys():
                 dict_row['attendee_details_' + key] = item[key]
         # Item is a datetime object, so format and add to dict
         elif isinstance(item, datetime):
             dict_row[headers[idx]] = format_datetime(
                 localize_timezone(item),
                 format='long',
                 locale=get_locale() or 'en'
             )  # FIXME: How to handle locale where the accept langauges header isn't specified? Relevant issue in baseframe https://github.com/hasgeek/baseframe/issues/154
         # Value is a string, add it to the dict with the corresponding key
         else:
             dict_row[headers[idx]] = item
     return dict_row
Exemple #21
0
def get_settled_transactions(date_range, tz=None):
    if not tz:
        tz = app.config['TIMEZONE']
    settled_transactions = get_settlements(date_range)
    headers = ['settlement_id', 'transaction_type', 'order_id', 'payment_id', 'refund_id',
        'item_collection', 'description', 'base_amount', 'discounted_amount',
        'final_amount', 'order_paid_amount', 'transaction_date', 'settled_at',
        'razorpay_fees', 'order_amount', 'credit', 'debit',
        'receivable_amount', 'settlement_amount', 'buyer_fullname']
    # Nested list of dictionaries consisting of transaction details
    rows = []
    external_transaction_msg = "Transaction external to Boxoffice. Credited directly to Razorpay?"

    for settled_transaction in settled_transactions:
        if settled_transaction['type'] == 'settlement':
            rows.append({
                'settlement_id': settled_transaction['entity_id'],
                'settlement_amount': settled_transaction['amount'],
                'settled_at': settled_transaction['settled_at'],
                'transaction_type': settled_transaction['type']
                })
        elif settled_transaction['type'] == 'payment':
            payment = OnlinePayment.query.filter_by(pg_paymentid=settled_transaction['entity_id']).one_or_none()
            if payment:
                order = payment.order
                rows.append({
                    'settlement_id': settled_transaction['settlement_id'],
                    'transaction_type': settled_transaction['type'],
                    'order_id': order.id,
                    'payment_id': settled_transaction['entity_id'],
                    'razorpay_fees': settled_transaction['fee'],
                    'transaction_date': localize_timezone(order.paid_at, tz),
                    'credit': settled_transaction['credit'],
                    'buyer_fullname': order.buyer_fullname,
                    'item_collection': order.item_collection.title
                    })
                for line_item in order.initial_line_items:
                    rows.append({
                        'settlement_id': settled_transaction['settlement_id'],
                        'payment_id': settled_transaction['entity_id'],
                        'order_id': order.id,
                        'item_collection': order.item_collection.title,
                        'description': line_item.item.title,
                        'base_amount': line_item.base_amount,
                        'discounted_amount': line_item.discounted_amount,
                        'final_amount': line_item.final_amount
                        })
            else:
                # Transaction outside of Boxoffice
                rows.append({
                    'settlement_id': settled_transaction['settlement_id'],
                    'payment_id': settled_transaction['entity_id'],
                    'credit': settled_transaction['credit'],
                    'description': external_transaction_msg
                    })
        elif settled_transaction['type'] == 'refund':
            payment = OnlinePayment.query.filter_by(pg_paymentid=settled_transaction['payment_id']).one()
            refund = PaymentTransaction.query.filter(PaymentTransaction.online_payment == payment,
                PaymentTransaction.transaction_type == TRANSACTION_TYPE.REFUND,
                PaymentTransaction.pg_refundid == settled_transaction['entity_id']
                ).one()
            order = refund.order
            rows.append({
                'settlement_id': settled_transaction['settlement_id'],
                'refund_id': settled_transaction['entity_id'],
                'payment_id': settled_transaction['payment_id'],
                'transaction_type': settled_transaction['type'],
                'order_id': order.id,
                'razorpay_fees': settled_transaction['fee'],
                'debit': settled_transaction['debit'],
                'buyer_fullname': order.buyer_fullname,
                'description': refund.refund_description,
                'amount': refund.amount,
                'item_collection': order.item_collection.title
                })
    return (headers, rows)
Exemple #22
0
def longdate(date):
    return localize_timezone(date).strftime('%e %B %Y')
Exemple #23
0
def json_date_format(dt):
    return localize_timezone(dt).isoformat()
Exemple #24
0
 def schedule_end_at_localized(self):
     return (localize_timezone(self.schedule_end_at, tz=self.timezone)
             if self.schedule_end_at else None)
Exemple #25
0
 def end_at_localized(self):
     return (localize_timezone(self.end_at, tz=self.project.timezone)
             if self.end_at else None)
Exemple #26
0
def invoice_date_filter(date, format):
    return localize_timezone(date, app.config['TIMEZONE']).strftime(format)
Exemple #27
0
def date_format(datetime):
    return localize_timezone(datetime).strftime('%d %b %Y')
Exemple #28
0
 def cfp_end_at_localized(self):
     return (localize_timezone(self.cfp_end_at, tz=self.timezone)
             if self.cfp_end_at else None)
Exemple #29
0
 def row_handler(row):
     row_list = list(row)
     # localize datetime
     row_list[-1] = format_datetime(localize_timezone(row_list[-1]), format='long', locale=get_locale())
     return row_list
Exemple #30
0
def date_time_format(datetime):
    return localize_timezone(datetime).strftime("%d %b %Y %H:%M:%S")
Exemple #31
0
def json_date_format(dt):
    return localize_timezone(dt).isoformat()
Exemple #32
0
def longdate(date):
    return localize_timezone(date).strftime('%e %B %Y')
Exemple #33
0
def get_settled_transactions(date_range, tz=None):
    if not tz:
        tz = app.config['TIMEZONE']
    settled_transactions = get_settlements(date_range)
    headers = ['settlement_id', 'transaction_type', 'order_id', 'payment_id', 'refund_id',
        'item_collection', 'description', 'base_amount', 'discounted_amount',
        'final_amount', 'order_paid_amount', 'transaction_date', 'settled_at',
        'razorpay_fees', 'order_amount', 'credit', 'debit',
        'receivable_amount', 'settlement_amount', 'buyer_fullname']
    # Nested list of dictionaries consisting of transaction details
    rows = []
    external_transaction_msg = u"Transaction external to Boxoffice. Credited directly to Razorpay?"

    for settled_transaction in settled_transactions:
        if settled_transaction['type'] == 'settlement':
          rows.append({
            'settlement_id': settled_transaction['entity_id'],
            'settlement_amount': settled_transaction['amount'],
            'settled_at': settled_transaction['settled_at'],
            'transaction_type': settled_transaction['type']
          })
        elif settled_transaction['type'] == 'payment':
            payment = OnlinePayment.query.filter_by(pg_paymentid=settled_transaction['entity_id']).one_or_none()
            if payment:
                order = payment.order
                rows.append({
                    'settlement_id': settled_transaction['settlement_id'],
                    'transaction_type': settled_transaction['type'],
                    'order_id': order.id,
                    'payment_id': settled_transaction['entity_id'],
                    'razorpay_fees': settled_transaction['fee'],
                    'transaction_date': localize_timezone(order.paid_at, tz),
                    'credit': settled_transaction['credit'],
                    'buyer_fullname': order.buyer_fullname,
                    'item_collection': order.item_collection.title
                })
                for line_item in order.initial_line_items:
                    rows.append({
                        'settlement_id': settled_transaction['settlement_id'],
                        'payment_id': settled_transaction['entity_id'],
                        'order_id': order.id,
                        'item_collection': order.item_collection.title,
                        'description': line_item.item.title,
                        'base_amount': line_item.base_amount,
                        'discounted_amount': line_item.discounted_amount,
                        'final_amount': line_item.final_amount
                    })
            else:
                # Transaction outside of Boxoffice
                rows.append({
                    'settlement_id': settled_transaction['settlement_id'],
                    'payment_id': settled_transaction['entity_id'],
                    'credit': settled_transaction['credit'],
                    'description': external_transaction_msg
                })
        elif settled_transaction['type'] == 'refund':
            payment = OnlinePayment.query.filter_by(pg_paymentid=settled_transaction['payment_id']).one()
            refund = PaymentTransaction.query.filter(PaymentTransaction.online_payment == payment,
                PaymentTransaction.transaction_type == TRANSACTION_TYPE.REFUND,
                PaymentTransaction.pg_refundid == settled_transaction['entity_id']
                ).one()
            order = refund.order
            rows.append({
                'settlement_id': settled_transaction['settlement_id'],
                'refund_id': settled_transaction['entity_id'],
                'payment_id': settled_transaction['payment_id'],
                'transaction_type': settled_transaction['type'],
                'order_id': order.id,
                'razorpay_fees': settled_transaction['fee'],
                'debit': settled_transaction['debit'],
                'buyer_fullname': order.buyer_fullname,
                'description': refund.refund_description,
                'amount': refund.amount,
                'item_collection': order.item_collection.title
            })
    return (headers, rows)