本文整理汇总了Python中shop.models.ordermodel.OrderItem.save方法的典型用法代码示例。如果您正苦于以下问题:Python OrderItem.save方法的具体用法?Python OrderItem.save怎么用?Python OrderItem.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shop.models.ordermodel.OrderItem
的用法示例。
在下文中一共展示了OrderItem.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_from_cart
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
def create_from_cart(self, cart):
"""
This creates a new Order object (and all the rest) from a passed Cart
object.
Specifically, it creates an Order with corresponding OrderItems and
eventually corresponding ExtraPriceFields
This will only actually commit the transaction once the function exits
to minimize useless database access.
Emits the ``processing`` signal.
"""
# must be imported here!
from shop.models.ordermodel import ExtraOrderItemPriceField, ExtraOrderPriceField, OrderItem
from shop.models.cartmodel import CartItem
# Let's create the Order itself:
order = self.model()
order.user = cart.user
order.status = self.model.PROCESSING # Processing
order.order_subtotal = cart.subtotal_price
order.order_total = cart.total_price
order.save()
# Let's serialize all the extra price arguments in DB
for label, value in cart.extra_price_fields:
eoi = ExtraOrderPriceField()
eoi.order = order
eoi.label = str(label)
eoi.value = value
eoi.save()
# There, now move on to the order items.
cart_items = CartItem.objects.filter(cart=cart)
for item in cart_items:
item.update(cart)
order_item = OrderItem()
order_item.order = order
order_item.product_reference = item.product.id
order_item.product_name = item.product.get_name()
order_item.product = item.product
order_item.unit_price = item.product.get_price()
order_item.quantity = item.quantity
order_item.line_total = item.line_total
order_item.line_subtotal = item.line_subtotal
order_item.save()
# For each order item, we save the extra_price_fields to DB
for label, value in item.extra_price_fields:
eoi = ExtraOrderItemPriceField()
eoi.order_item = order_item
# Force unicode, in case it has àö...
eoi.label = unicode(label)
eoi.value = value
eoi.save()
processing.send(self.model, order=order, cart=cart)
return order
示例2: ProductStatisticsTestCase
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
class ProductStatisticsTestCase(TestCase):
def setUp(self):
self.product = Product()
self.product.name = 'test'
self.product.unit_price = Decimal('1.0')
self.product.save()
self.product2 = Product()
self.product2.name = 'test2'
self.product2.unit_price = Decimal('1.0')
self.product2.save()
self.product3 = Product()
self.product3.name = 'test3'
self.product3.unit_price = Decimal('1.0')
self.product3.save()
self.order = Order()
self.order.order_subtotal = Decimal('10')
self.order.order_total = Decimal('10')
self.order.shipping_cost = Decimal('0')
self.order.shipping_name = 'toto'
self.order.shipping_address = 'address'
self.order.shipping_address2 = 'address2'
self.order.shipping_city = 'city'
self.order.shipping_zip_code = 'zip'
self.order.shipping_state = 'state'
self.order.shipping_country = 'country'
self.order.billing_name = 'toto'
self.order.billing_address = 'address'
self.order.billing_address2 = 'address2'
self.order.billing_city = 'city'
self.order.billing_zip_code = 'zip'
self.order.billing_state = 'state'
self.order.billing_country = 'country'
self.order.save()
self.orderitem1 = OrderItem()
self.orderitem1.order = self.order
self.orderitem1.product = self.product
self.orderitem1.quantity = 5 # this will be the most bought
self.orderitem1.save()
self.orderitem2 = OrderItem()
self.orderitem2.order = self.order
self.orderitem2.product = self.product2
self.orderitem2.quantity = 1 # this will be the second most
self.orderitem2.save()
def test_top_selling_works(self):
res = Product.statistics.top_selling_products(10)
self.assertNotEqual(res, None)
self.assertEqual(len(res), 2)
self.assertTrue(self.product3 not in res)
示例3: create_from_cart
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
def create_from_cart(self, cart, request):
"""
This creates a new Order object (and all the rest) from a passed Cart
object.
Specifically, it creates an Order with corresponding OrderItems and
eventually corresponding ExtraPriceFields
This will only actually commit the transaction once the function exits
to minimize useless database access.
The `state` parameter is further passed to process_cart_item,
process_cart, and post_process_cart, so it can be used as a way to
store per-request arbitrary information.
Emits the ``processing`` signal.
"""
# must be imported here!
from shop.models.ordermodel import (
ExtraOrderItemPriceField,
ExtraOrderPriceField,
OrderItem,
)
from shop.models.cartmodel import CartItem
# First, let's remove old orders
self.remove_old_orders(cart)
# Create an empty order object
order = self.create_order_object(cart, request)
order.save()
# Let's serialize all the extra price arguments in DB
for field in cart.extra_price_fields:
eoi = ExtraOrderPriceField()
eoi.order = order
eoi.label = unicode(field[0])
eoi.value = field[1]
if len(field) == 3:
eoi.data = field[2]
eoi.save()
# There, now move on to the order items.
cart_items = CartItem.objects.filter(cart=cart)
for item in cart_items:
item.update(request)
order_item = OrderItem()
order_item.order = order
order_item.product_reference = item.product.get_product_reference()
order_item.product_name = item.product.get_name()
order_item.product = item.product
order_item.unit_price = item.product.get_price()
order_item.quantity = item.quantity
order_item.line_total = item.line_total
order_item.line_subtotal = item.line_subtotal
order_item.save()
# For each order item, we save the extra_price_fields to DB
for field in item.extra_price_fields:
eoi = ExtraOrderItemPriceField()
eoi.order_item = order_item
# Force unicode, in case it has àö...
eoi.label = unicode(field[0])
eoi.value = field[1]
if len(field) == 3:
eoi.data = field[2]
eoi.save()
processing.send(self.model, order=order, cart=cart)
return order
示例4: PayOnDeliveryTestCase
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
class PayOnDeliveryTestCase(TestCase):
def create_fixtures(self):
self.user = User.objects.create(username="test",
email="[email protected]",
first_name="Test",
last_name = "Toto")
self.user.save()
self.client = Client()
self.client.user = self.user
self.client.save()
self.country = Country.objects.create(name='CH')
self.address = Address()
self.address.client = self.client
self.address.address = 'address'
self.address.address2 = 'address2'
self.address.zip_code = '1234'
self.address.state = 'ZH'
self.address.country = self.country
self.address.is_billing = False
self.address.is_shipping = True
self.address.save()
self.address2 = Address()
self.address2.client = self.client
self.address2.address = '2address'
self.address2.address2 = '2address2'
self.address2.zip_code = '21234'
self.address2.state = '2ZH'
self.address2.country = self.country
self.address2.is_billing = True
self.address2.is_shipping = False
self.address2.save()
# The order fixture
self.order = Order()
self.order.user = self.user
self.order.order_subtotal = Decimal('100') # One item worth 100
self.order.order_total = Decimal('120') # plus a test field worth 10
self.order.status = Order.PROCESSING
ship_address = self.address
bill_address = self.address2
self.order.shipping_name = "%s %s" %(self.address.client.user.first_name,
self.address.client.user.last_name)
self.order.shipping_address = ship_address.address
self.order.shipping_address2 = ship_address.address2
self.order.shipping_zip_code = ship_address.zip_code
self.order.shipping_state = ship_address.state
self.order.shipping_country = ship_address.country.name
self.order.shipping_name = "%s %s" %(self.address.client.user.first_name,
self.address.client.user.last_name)
self.order.billing_address = bill_address.address
self.order.billing_address2 = bill_address.address2
self.order.billing_zip_code = bill_address.zip_code
self.order.billing_state = bill_address.state
self.order.billing_country = bill_address.country.name
self.order.save()
# Orderitems
self.orderitem = OrderItem()
self.orderitem.order = self.order
self.orderitem.product_reference = 'fakeref'
self.orderitem.product_name = 'Test item'
self.orderitem.unit_price = Decimal("100")
self.orderitem.quantity = 1
self.orderitem.line_subtotal = Decimal('100')
self.orderitem.line_total = Decimal('110')
self.orderitem.save()
eoif = ExtraOrderItemPriceField()
eoif.order_item = self.orderitem
eoif.label = 'Fake extra field'
eoif.value = Decimal("10")
eoif.save()
eof = ExtraOrderPriceField()
eof.order = self.order
eof.label = "Fake Taxes"
eof.value = Decimal("10")
eof.save()
def test_01_backend_returns_urls(self):
self.create_fixtures()
be = PayOnDeliveryBackend(shop=PaymentAPI())
urls = be.get_urls()
self.assertNotEqual(urls,None)
self.assertEqual(len(urls), 1)
示例5: PayOnDeliveryTestCase
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
class PayOnDeliveryTestCase(TestCase):
def setUp(self):
self.user = User.objects.create(username="test",
email="[email protected]",
first_name="Test",
last_name="Toto")
self.user.save()
self.country = Country.objects.create(name='CH')
self.address = Address()
self.address.client = self.client
self.address.address = 'address'
self.address.address2 = 'address2'
self.address.zip_code = '1234'
self.address.state = 'ZH'
self.address.country = self.country
self.address.is_billing = False
self.address.is_shipping = True
self.address.save()
self.address2 = Address()
self.address2.client = self.client
self.address2.address = '2address'
self.address2.address2 = '2address2'
self.address2.zip_code = '21234'
self.address2.state = '2ZH'
self.address2.country = self.country
self.address2.is_billing = True
self.address2.is_shipping = False
self.address2.save()
# The order fixture
self.order = Order()
self.order.user = self.user
self.order.order_subtotal = Decimal('100') # One item worth 100
self.order.order_total = Decimal('120') # plus a test field worth 10
self.order.status = Order.PROCESSING
ship_address = self.address
bill_address = self.address2
self.order.set_shipping_address(ship_address)
self.order.set_billing_address(bill_address)
self.order.save()
# Orderitems
self.orderitem = OrderItem()
self.orderitem.order = self.order
self.orderitem.product_name = 'Test item'
self.orderitem.unit_price = Decimal("100")
self.orderitem.quantity = 1
self.orderitem.line_subtotal = Decimal('100')
self.orderitem.line_total = Decimal('110')
self.orderitem.save()
eoif = ExtraOrderItemPriceField()
eoif.order_item = self.orderitem
eoif.label = 'Fake extra field'
eoif.value = Decimal("10")
eoif.save()
eof = ExtraOrderPriceField()
eof.order = self.order
eof.label = "Fake Taxes"
eof.value = Decimal("10")
eof.save()
def test01_backend_returns_urls(self):
be = PayOnDeliveryBackend(shop=PaymentAPI())
urls = be.get_urls()
self.assertNotEqual(urls, None)
self.assertEqual(len(urls), 1)
def test02_must_be_logged_in_if_setting_is_true(self):
with SettingsOverride(SHOP_FORCE_LOGIN=True):
resp = self.client.get(reverse('shop:pay-on-delivery'))
self.assertEqual(resp.status_code, 302)
self.assertTrue('accounts/login/' in resp._headers['location'][1])
def test_order_required_before_payment(self):
""" See issue #84 """
# Session only (no order)
response = self.client.get(reverse('shop:pay-on-delivery'))
self.assertEqual(302, response.status_code)
self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1])
# User logged in (no order)
username = 'user'
pw = 'pass'
User.objects.create_user(username=username, password=pw, email='[email protected]')
logged_in = self.client.login(username=username, password=pw)
self.assertTrue(logged_in)
response = self.client.get(reverse('shop:pay-on-delivery'))
self.assertEqual(302, response.status_code)
self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1])
self.client.logout()
# User logged in and has order
#.........这里部分代码省略.........
示例6: BaseBackendTestCase
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
class BaseBackendTestCase(TestCase):
def setUp(self):
self.user = User.objects.create(
username="test",
email="[email protected]",
first_name="Test",
last_name="User")
self.shop = PaymentAPI()
self.backend = GenericPayerBackend(shop=self.shop)
class Mock(object):
pass
self.request = Mock()
setattr(self.request, 'user', self.user)
self.user.save()
self.country = Country.objects.create(name='CH')
self.address = AddressModel()
self.address.client = self.client
self.address.address = 'address'
self.address.address2 = 'address2'
self.address.zip_code = '1234'
self.address.state = 'ZH'
self.address.country = self.country
self.address.is_billing = False
self.address.is_shipping = True
self.address.save()
self.address2 = AddressModel()
self.address2.client = self.client
self.address2.address = '2address'
self.address2.address2 = '2address2'
self.address2.zip_code = '21234'
self.address2.state = '2ZH'
self.address2.country = self.country
self.address2.is_billing = True
self.address2.is_shipping = False
self.address2.save()
# The order fixture
self.order = Order()
self.order.user = self.user
self.order.order_subtotal = Decimal('100') # One item worth 100
self.order.order_total = Decimal('120') # plus a test field worth 10
self.order.status = Order.PROCESSING
ship_address = self.address
bill_address = self.address2
self.order.set_shipping_address(ship_address)
self.order.set_billing_address(bill_address)
self.order.save()
# Orderitems
self.orderitem = OrderItem()
self.orderitem.order = self.order
self.orderitem.product_name = 'Test item'
self.orderitem.unit_price = Decimal("100")
self.orderitem.quantity = 1
self.orderitem.line_subtotal = Decimal('100')
self.orderitem.line_total = Decimal('110')
self.orderitem.save()
oi = OrderExtraInfo()
oi.order = self.order
oi.text = "buffalo " * 64
oi.save()
eoif = ExtraOrderItemPriceField()
eoif.order_item = self.orderitem
eoif.label = 'Fake extra field'
eoif.value = Decimal("10")
eoif.save()
eof = ExtraOrderPriceField()
eof.order = self.order
eof.label = "Fake Taxes"
eof.value = Decimal("10")
eof.save()
示例7: PayOnDeliveryTestCase
# 需要导入模块: from shop.models.ordermodel import OrderItem [as 别名]
# 或者: from shop.models.ordermodel.OrderItem import save [as 别名]
class PayOnDeliveryTestCase(TestCase):
def setUp(self):
self.user = User.objects.create(username="test",
email="[email protected]",
first_name="Test",
last_name="Toto")
self.user.save()
self.country = Country.objects.create(name='CH')
self.address = Address()
self.address.client = self.client
self.address.address = 'address'
self.address.address2 = 'address2'
self.address.zip_code = '1234'
self.address.state = 'ZH'
self.address.country = self.country
self.address.is_billing = False
self.address.is_shipping = True
self.address.save()
self.address2 = Address()
self.address2.client = self.client
self.address2.address = '2address'
self.address2.address2 = '2address2'
self.address2.zip_code = '21234'
self.address2.state = '2ZH'
self.address2.country = self.country
self.address2.is_billing = True
self.address2.is_shipping = False
self.address2.save()
# The order fixture
self.order = Order()
self.order.user = self.user
self.order.order_subtotal = Decimal('100') # One item worth 100
self.order.order_total = Decimal('120') # plus a test field worth 10
self.order.status = Order.PROCESSING
ship_address = self.address
bill_address = self.address2
self.order.set_shipping_address(ship_address)
self.order.set_billing_address(bill_address)
self.order.save()
# Orderitems
self.orderitem = OrderItem()
self.orderitem.order = self.order
self.orderitem.product_name = 'Test item'
self.orderitem.unit_price = Decimal("100")
self.orderitem.quantity = 1
self.orderitem.line_subtotal = Decimal('100')
self.orderitem.line_total = Decimal('110')
self.orderitem.save()
eoif = ExtraOrderItemPriceField()
eoif.order_item = self.orderitem
eoif.label = 'Fake extra field'
eoif.value = Decimal("10")
eoif.save()
eof = ExtraOrderPriceField()
eof.order = self.order
eof.label = "Fake Taxes"
eof.value = Decimal("10")
eof.save()
def test01_backend_returns_urls(self):
be = PayOnDeliveryBackend(shop=PaymentAPI())
urls = be.get_urls()
self.assertNotEqual(urls, None)
self.assertEqual(len(urls), 1)
def test02_must_be_logged_in_if_setting_is_true(self):
with SettingsOverride(SHOP_FORCE_LOGIN=True):
resp = self.client.get(reverse('pay-on-delivery'))
self.assertEqual(resp.status_code, 302)
self.assertTrue('accounts/login/' in resp._headers['location'][1])