当前位置: 首页>>代码示例>>Python>>正文


Python Order.subscription_period_in_months方法代码示例

本文整理汇总了Python中models.Order.subscription_period_in_months方法的典型用法代码示例。如果您正苦于以下问题:Python Order.subscription_period_in_months方法的具体用法?Python Order.subscription_period_in_months怎么用?Python Order.subscription_period_in_months使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Order的用法示例。


在下文中一共展示了Order.subscription_period_in_months方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import subscription_period_in_months [as 别名]
    def post(self):
        # Get customer and create an invoice.
        customer = Customer.get_by_key_name(self.get_current_username())
        invoice = Invoice(customer=customer)
        invoice.put()

        # Now start processing subscription data.
        subscription_data = self.session['subscription-data']
        products = db.get([db.Key(key) for key in subscription_data.get('products')])
        period = subscription_data.get('period')
        subscription_period = SubscriptionPeriod.get_by_period(period)

        units = [product for product in products if 'product_keys' not in product.properties()]
        baskets = [product for product in products if 'product_keys' in product.properties()]

        activation_credentials_list = []
        orders = []
        for unit in units:
            subscription = Subscription.get_by_product_and_period(unit, period)

            order = Order(customer=customer, invoice=invoice, subscription=subscription)
            order.subscription_price = subscription.price
            order.subscription_general_sales_tax = subscription.general_sales_tax
            order.subscription_period_in_months = subscription.period_in_months
            order.subscription_free_period_in_months = subscription_period.free_period_in_months
            order.price = subscription.price + subscription.general_sales_tax
            order.subscription_currency = subscription.currency
            orders.append(order)
            order.put()

            unit_id = unit.key().id()
            activation_credentials = ActivationCredentials()
            activation_credentials.serial_number = self.get_argument('u_%d_serial_number' % unit_id)
            activation_credentials.machine_id = self.get_argument('u_%d_machine_id' % unit_id)
            activation_credentials.order = order
            activation_credentials.product = unit
            activation_credentials.customer = customer
            logging.info(activation_credentials)
            activation_credentials_list.append(activation_credentials)

        for basket in baskets:
            subscription = Subscription.get_by_product_and_period(basket, period)

            order = Order(customer=customer, invoice=invoice, subscription=subscription)
            order.subscription_price = subscription.price
            order.subscription_general_sales_tax = subscription.general_sales_tax
            order.subscription_period_in_months = subscription.period_in_months
            order.subscription_free_period_in_months = subscription_period.free_period_in_months
            order.price = subscription.price + subscription.general_sales_tax
            order.subscription_currency = subscription.currency
            orders.append(order)
            order.put()

            for unit in basket.products:
                basket_id = basket.key().id()
                unit_id = unit.key().id()

                activation_credentials = ActivationCredentials()
                activation_credentials.serial_number = self.get_argument('b_%d_u_%d_serial_number' % (basket_id, unit_id,))
                activation_credentials.machine_id = self.get_argument('b_%d_u_%d_machine_id' % (basket_id, unit_id,))
                activation_credentials.order = order
                activation_credentials.product = unit
                activation_credentials.customer = customer
                logging.info(activation_credentials)
                activation_credentials_list.append(activation_credentials)

        db.put(activation_credentials_list)
        
        invoice.total_price = sum([order.price for order in orders])
        invoice.currency = orders[0].subscription_currency
        invoice.put()
        
        self.session['activation-invoice-key'] = str(invoice.key())
        self.redirect('/activate/overview')
开发者ID:yesudeep,项目名称:maths-school-activation,代码行数:76,代码来源:handlers.py


注:本文中的models.Order.subscription_period_in_months方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。