def report_on_site_payments():
    one_month_ago = datetime.datetime.today() - relativedelta(months=1)
    min_date = int(time.mktime(one_month_ago.timetuple()))

    invoices = Invoice.all().filter('payment_type',
                                    Invoice.PAYMENT_ON_SITE).filter(
                                        'date >=', min_date)
    charges = Charge.get((i.charge_key for i in invoices))
    customers = Customer.get((i.order_key.parent() for i in invoices))

    l = [
        '[%(date_str)s][%(customer)s][%(manager)s][%(amount).02f][%(charge_number)s]'
        % dict(customer=c.name,
               manager=i.operator,
               amount=i.amount / 100.0,
               date=i.date,
               date_str=time.ctime(i.date),
               charge_number=charge.charge_number)
        for (i, charge, c) in sorted(zip(invoices, charges, customers),
                                     key=lambda t: t[0].date)
    ]
    body = "\n".join(l) or u"There were no on site payments for the last month"
    logging.info(body)

    server_settings = get_server_settings()
    solution_server_settings = get_solution_server_settings()
    subject = u'On site payments for the last month'
    send_mail(server_settings.dashboardEmail,
              solution_server_settings.shop_payment_admin_emails, subject,
              body)
Esempio n. 2
0
def _fix_charge(charge_key):
    charge = Charge.get(charge_key)
    charge.team_id = Customer.get(charge.customer_key).team_id
    if not charge.team_id:
        logging.error(
            'Cannot fix charge {}: No team set on customer {}'.format(
                charge.id, charge.customer_id))
    charge.put()
Esempio n. 3
0
def _gather_events_for_customer(customer_key, cap_key, organization_type):
    customer = Customer.get(customer_key)
    if not customer.service_email:
        logging.debug('This customer has no service yet: %s',
                      db.to_dict(customer))
        return
    if cap_key.parent().name() == customer.service_email:
        # do not gather own events
        return
    sln_settings = get_solution_settings(customer.service_user)
    if SolutionModule.AGENDA not in sln_settings.modules:
        return
    if sln_settings.default_calendar is None:
        logging.error(
            'This customer has no default calendar!\n\nSolutionSettings: %s\n\nCustomer: %s',
            db.to_dict(sln_settings),
            db.to_dict(customer),
            _suppress=False)
        return
    sc = SolutionCalendar.get_by_id(
        sln_settings.default_calendar,
        parent_key(customer.service_user, sln_settings.solution))
    if not sc:
        return

    event_items = []
    for event in sc.events:
        event_item = EventItemTO.fromEventItemObject(event)
        event_item.calendar_id = organization_type
        event_items.append(event_item)

    if event_items:
        new_events = serialize_complex_value(event_items, EventItemTO, True)
        gather_events_key = u"%s" % organization_type

        def trans():
            cap = CityAppProfile.get(cap_key)
            stream = cap.gather_events.get(gather_events_key)
            if stream:
                json_list = json.load(stream)
            else:
                json_list = list()
            json_list.extend(new_events)
            with closing(StringIO()) as stream:
                json.dump(json_list, stream)
                cap.gather_events[gather_events_key] = stream
            cap.put()

        db.run_in_transaction(trans)
        sln_settings.put_identity_pending = True
        sln_settings.put()
 def trans():
     to_put = list()
     customer = Customer.get(customer_key)
     if App.APP_ID_ROGERTHAT not in customer.app_ids and customer.service_email:
         customer.app_ids.append(App.APP_ID_ROGERTHAT)
         to_put.append(customer)
         service_identity = get_default_service_identity(
             customer.service_user)
         if App.APP_ID_ROGERTHAT not in service_identity.appIds:
             service_identity.appIds.append(App.APP_ID_ROGERTHAT)
             deferred.defer(re_index,
                            service_identity.service_identity_user,
                            _queue=MIGRATION_QUEUE,
                            _transactional=True)
             to_put.append(service_identity)
         deferred.defer(re_index_customer,
                        customer.key(),
                        _queue=MIGRATION_QUEUE,
                        _transactional=True)
         put_and_invalidate_cache(*to_put)
Esempio n. 5
0
    def trans():
        customer = Customer.get(customer_key)

        if customer.stripe_id:
            if customer.stripe_credit_card_id:
                old_cc = CreditCard.get_by_key_name(
                    customer.stripe_credit_card_id, parent=customer)
                old_cc.deleted = True
                old_cc.put()
        else:
            customer.stripe_id = stripe_customer_id

        cc = CreditCard(key_name=stripe_card_id, parent=customer)
        cc.creation_time = stripe_token_created
        cc.contact_id = contact_id
        cc.put()

        customer.stripe_id_created = stripe_token_created
        customer.stripe_credit_card_id = stripe_card_id
        customer.put()