def get_products(): service_user = users.get_current_user() sln_settings = get_solution_settings(service_user) keys = [ Product.create_key('BEAC'), Product.create_key('POSM'), Product.create_key(Product.PRODUCT_CARDS) ] if SolutionModule.CITY_APP not in sln_settings.modules: # city apps cannot order more city apps keys.append(Product.create_key(Product.PRODUCT_EXTRA_CITY)) else: keys.append(Product.create_key(Product.PRODUCT_ROLLUP_BANNER)) return [ ProductTO.create(p, sln_settings.main_language) for p in Product.get(keys) ]
def trans(): charge = None expired_subscription, customer = db.get([ExpiredSubscription.create_key(customer_id), Customer.create_key(customer_id)]) expired_subscription.status = status expired_subscription.status_updated_timestamp = now() if status == ExpiredSubscription.STATUS_WILL_LINK_CREDIT_CARD: # Create a task for regiomanager to check if the customer has linked his credit card after two weeks. # the ExpiredSubscription object from this customer will be cleaned up in recurrentbilling the day after he has linked it. to_put.append(expired_subscription) team, prospect = db.get([RegioManagerTeam.create_key(customer.team_id), Prospect.create_key(customer.prospect_id)]) execution_time = now() + DAY * 14 date_string = datetime.datetime.utcfromtimestamp(execution_time).strftime(u'%A %d %b %Y') comment = u'Check if the customer has linked his creditcard (for automatic subscription renewal).' \ u' If he hasn\'t linked it before %s, contact him again.' % date_string task = create_task(current_user.email(), prospect, team.support_manager, execution_time, ShopTask.TYPE_CHECK_CREDIT_CARD, prospect.app_id, comment=comment) to_put.append(task) elif status == ExpiredSubscription.STATUS_EXTEND_SUBSCRIPTION: # Creates a new charge using the customer his subscription order. subscription_order, team = db.get([Order.create_key(customer.id, customer.subscription_order_number), RegioManagerTeam.create_key(customer.team_id)]) extension_order_item_keys = list() order_items = list(OrderItem.list_by_order(subscription_order.key())) products_to_get = list() for item in order_items: products_to_get.append(Product.create_key(item.product_code)) products = {p.code: p for p in Product.get(products_to_get)} # extend per year months = 12 total_amount = 0 for item in order_items: product = products[item.product_code] if product.is_subscription and item.price > 0: total_amount += months * item.price elif not product.is_subscription and (product.is_subscription_discount or product.extra_subscription_months > 0): total_amount += months * item.price elif product.is_subscription_extension: total_amount += months * item.price extension_order_item_keys.append(item.key()) if total_amount <= 0: raise BusinessException('The created charge has a negative amount (%d)' % total_amount) next_charge_datetime = datetime.datetime.utcfromtimestamp(now()) + relativedelta(months=months) subscription_order.next_charge_date = get_epoch_from_datetime(next_charge_datetime) to_put.append(subscription_order) # reconnect all previously connected friends if the service was disabled in the past if customer.service_disabled_at != 0: deferred.defer(set_service_enabled, customer.id, _transactional=True) vat_pct = get_vat_pct(customer, team) charge = Charge(parent=subscription_order) charge.date = now() charge.type = Charge.TYPE_SUBSCRIPTION_EXTENSION charge.subscription_extension_length = months charge.subscription_extension_order_item_keys = extension_order_item_keys charge.amount = total_amount charge.vat_pct = vat_pct charge.vat = int(total_amount * vat_pct / 100) charge.total_amount = charge.amount + charge.vat charge.currency_code = team.legal_entity.currency_code to_put.append(charge) to_delete.append(expired_subscription) db.put(to_put) if to_delete: db.delete(to_delete) return charge