Beispiel #1
0
    def trans():
        new_order = Order.get(new_order_key)
        with closing(StringIO()) as pdf:
            generate_order_or_invoice_pdf(pdf, customer, new_order)
            new_order.pdf = pdf.getvalue()

        new_order.put()
        deferred.defer(send_order_email,
                       new_order_key,
                       service_user,
                       _transactional=True)
Beispiel #2
0
def _update_next_charge_date(order_key, default_next_charge_date,
                             all_products):
    """Set next charge date to next month."""
    order = Order.get(order_key)

    def is_free_subscription(order_item):
        product = all_products[order_item.product_code]
        return product.is_subscription and product.price == 0

    order_items = order.list_items()
    if any((is_free_subscription(item) for item in order_items)):
        order.next_charge_date = default_next_charge_date
        put_and_invalidate_cache(order)
Beispiel #3
0
def get_order_items():
    # get the order items for this customer from the latest order that isn't signed yet
    service_user = users.get_current_user()
    customer = get_customer(service_user)
    if not customer:
        return []
    order_key = Order.create_key(customer.id,
                                 Order.CUSTOMER_STORE_ORDER_NUMBER)
    order = Order.get(order_key)
    if order:
        sln_settings = get_solution_settings(service_user)
        lang = sln_settings.main_language
        remaining_length, sub_order = get_subscription_order_remaining_length(
            customer.id, customer.subscription_order_number)
        subscription_order_charge_date = format_date(
            datetime.datetime.utcfromtimestamp(sub_order.next_charge_date),
            locale=lang)
        order_items = list(OrderItem.list_by_order(order_key))
        order_items_updated = list()
        to_put = list()
        to_get = list(
            set([Product.create_key(o.product_code) for o in order_items] +
                [Product.create_key(Product.PRODUCT_EXTRA_CITY)]))
        products = {p.code: p for p in db.get(to_get)}
        # update the order items if necessary.
        for order_item in order_items:
            if products[
                    order_item.
                    product_code].is_subscription_extension and order_item.count != remaining_length:
                order_item.count = remaining_length
                to_put.append(order_item)
            order_items_updated.append(order_item)
        if to_put:
            db.put(to_put)
        extra_city_price = format_price(
            products[Product.PRODUCT_EXTRA_CITY].price, sln_settings.currency)
        service_visible_in_translation = translate(
            lang,
            SOLUTION_COMMON,
            'service_visible_in_app',
            subscription_expiration_date=subscription_order_charge_date,
            amount_of_months=remaining_length,
            extra_city_price=extra_city_price,
            app_name='%(app_name)s')
        return [
            OrderItemTO.create(i, service_visible_in_translation)
            for i in order_items_updated
        ]
    else:
        return []
Beispiel #4
0
 def fromCustomerModel(customer, can_edit, is_admin):
     c = CustomerTO()
     c.name = customer.name
     c.address1 = customer.address1
     c.address2 = customer.address2
     c.zip_code = customer.zip_code
     c.city = customer.city
     c.country = customer.country
     c.vat = customer.vat
     c.organization_type = customer.organization_type
     c.id = customer.id
     c.service_email = customer.service_email
     c.user_email = customer.user_email
     c.auto_login_url = customer.auto_login_url if customer.service_email else None
     c.stripe_valid = customer.stripe_valid
     c.migration_job = customer.migration_job
     c.manager = customer.manager.email().decode(
         'utf-8') if customer.manager else None
     c.app_ids = customer.sorted_app_ids
     c.extra_apps_count = customer.extra_apps_count
     c.prospect_id = customer.prospect_id
     c.language = customer.language
     c.subscription_type = customer.SUBSCRIPTION_TYPES[
         customer.subscription_type]
     c.has_loyalty = customer.has_loyalty
     c.creation_time = customer.creation_time
     c.team_id = customer.team_id
     c.can_edit = can_edit
     c.is_admin = is_admin
     c.service_disabled_at = customer.service_disabled_at
     if customer.subscription_cancel_pending_date != 0 and customer.subscription_order_number:
         c.cancelling_on_date = Order.get(
             Order.create_key(
                 customer.id,
                 customer.subscription_order_number)).next_charge_date
     else:
         c.cancelling_on_date = 0
     c.service_disabled_reason = customer.disabled_reason or customer.disabled_reason_str
     c.service_disabled_reason_int = customer.disabled_reason_int
     c.subscription_cancel_pending_date = customer.subscription_cancel_pending_date
     c.website = customer.website
     c.facebook_page = customer.facebook_page
     return c
Beispiel #5
0
def get_subscription_order_remaining_length(customer_id,
                                            subscription_order_number):
    subscription_order = Order.get(
        Order.create_key(customer_id, subscription_order_number))
    if subscription_order.next_charge_date:
        next_charge_date = subscription_order.next_charge_date + DAY * 14
        try:
            next_charge_datetime = datetime.datetime.utcfromtimestamp(
                next_charge_date)
        except ValueError:  # Eg. year out of range
            months_till_charge = 1
        else:
            timedelta = dateutil.relativedelta.relativedelta(
                next_charge_datetime, datetime.datetime.now())
            months_till_charge = timedelta.years * 12 + timedelta.months
            if months_till_charge < 1:
                months_till_charge = 1
    else:
        months_till_charge = 1
    return months_till_charge, subscription_order
Beispiel #6
0
def _add_properties():
    customers = Customer.all()
    to_put = list()
    for customer in customers:
        if customer.subscription_order_number:
            order_key = Order.create_key(customer.id,
                                         customer.subscription_order_number)
            order = Order.get(order_key)
            customer.creation_time = order.date
            customer.subscription_type = 0 if OrderItem.all(
                keys_only=True).ancestor(order_key).filter(
                    'product_code', 'MSSU').get() else 1
        else:
            customer.creation_time = 0  # at this point it's not known when the customer was created
        if customer.service_email:
            service_user = users.User(email=customer.service_email)
            sln_settings = get_solution_settings(service_user)
            customer.has_loyalty = True if u'loyalty' in sln_settings.modules else False
        else:
            customer.has_loyalty = False
        to_put.append(customer)
    db.put(to_put)