Пример #1
0
def charge(context, tenant_id, subscription_id, quantity, order_size, price):
    line_total = order_size * price / quantity
    values = {
        'subscription_id': subscription_id,
        'quantity': quantity,
        'line_total': line_total,
    }
    db.purchase_create(context, values)
Пример #2
0
def charge(context, tenant_id, subscription_id, quantity, order_size, price):
    line_total = order_size * price / quantity
    values = {
        'subscription_id': subscription_id,
        'quantity': quantity,
        'line_total': line_total,
    }
    db.purchase_create(context, values)
    conn = driver.get_connection('corporate')
    conn.deduct(tenant_id, line_total)
Пример #3
0
def charge(context, tenant_id, subscription_id, quantity, order_size, price):
    if not quantity:
        return
    line_total = price * quantity / order_size 
    values = {
        'subscription_id': subscription_id,
        'quantity': quantity,
        'line_total': line_total,
    }
    db.purchase_create(context, values)
Пример #4
0
def charge(context, tenant_id, subscription_id, quantity, order_size, price):
    if not quantity:
        return
    line_total = price * quantity / order_size
    values = {
        'subscription_id': subscription_id,
        'quantity': quantity,
        'line_total': line_total,
    }
    print "purchase_create, tenant_id=%s, subid=%s" % (tenant_id, subscription_id)
    print values
    context.app.info("purchase_create:tenant_id=%s, subid=%s, line_total=%s" % (tenant_id, subscription_id, str(line_total)))
    db.purchase_create(context, values)
Пример #5
0
def charge(context, tenant_id, subscription_id, quantity, order_size, price):
    if not quantity:
        return
    line_total = price * quantity / order_size
    values = {
        'subscription_id': subscription_id,
        'quantity': quantity,
        'line_total': line_total,
    }
    print "purchase_create, tenant_id=%s, subid=%s" % (tenant_id,
                                                       subscription_id)
    print values
    context.app.info("purchase_create:tenant_id=%s, subid=%s, line_total=%s" %
                     (tenant_id, subscription_id, str(line_total)))
    db.purchase_create(context, values)
Пример #6
0
 def test_purchase_get_by_subscription_recent_not_found(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     self.truncate_table("purchases")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(self.context,
                                               {'name': 'a_payment_type',
                                                'interval_unit': 'days',
                                                'interval_size': 12345,
                                                'is_prepaid': False})
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
         }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
         }
     subscription_ref = db.subscription_create(self.context, values)
     values = {
         'subscription_id': subscription_ref.id,
         'quantity': 1.56,
         'line_total': 1.56 * product_ref.price,
         }
     db.purchase_create(self.context, values)
     self.assertRaises(exception.PurchaseNotFoundBySubscription,
                       db.purchase_get_by_subscription_recent,
                       self.context, 12345)
Пример #7
0
 def test_purchase_get_all_by_subscription_and_timeframe(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     self.truncate_table("purchases")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(
         self.context, {
             'name': 'a_payment_type',
             'interval_unit': 'days',
             'interval_size': 12345,
             'is_prepaid': False
         })
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
     }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
     }
     subscription_ref = db.subscription_create(self.context, values)
     values = {
         'subscription_id': subscription_ref.id,
         'quantity': 1.56,
         'line_total': 1.56 * product_ref.price,
     }
     expect = db.purchase_create(self.context, values)
     purchases = db.purchase_get_all_by_subscription_and_timeframe(
         self.context, expect.subscription_id,
         datetime.datetime.now() - datetime.timedelta(seconds=3),
         datetime.datetime.now() + datetime.timedelta(seconds=3))
     self.compare_records(expect, purchases[0])
Пример #8
0
 def test_purchase_destroy(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     self.truncate_table("purchases")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(
         self.context, {
             'name': 'a_payment_type',
             'interval_unit': 'days',
             'interval_size': 12345,
             'is_prepaid': False
         })
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
     }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
     }
     subscription_ref = db.subscription_create(self.context, values)
     values = {
         'subscription_id': subscription_ref.id,
         'quantity': 1.56,
         'line_total': 1.56 * product_ref.price,
     }
     expect = db.purchase_create(self.context, values)
     db.purchase_destroy(self.context, expect.id)
     self.assertRaises(exception.PurchaseNotFound, db.purchase_get,
                       self.context, expect.id)
Пример #9
0
 def test_purchase_get_all_by_subscription_and_timeframe(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     self.truncate_table("purchases")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(self.context,
                                               {'name': 'a_payment_type',
                                                'interval_unit': 'days',
                                                'interval_size': 12345,
                                                'is_prepaid': False})
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
         }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
         }
     subscription_ref = db.subscription_create(self.context, values)
     values = {
         'subscription_id': subscription_ref.id,
         'quantity': 1.56,
         'line_total': 1.56 * product_ref.price,
         }
     expect = db.purchase_create(self.context, values)
     purchases = db.purchase_get_all_by_subscription_and_timeframe(
             self.context, expect.subscription_id,
             datetime.datetime.now() - datetime.timedelta(seconds=3),
             datetime.datetime.now() + datetime.timedelta(seconds=3))
     self.compare_records(expect, purchases[0])