Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Rename item/line for OrderLine class

akjanikf0797969183c
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 87582cae4a..c8d67e4e4d 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -206,7 +206,7 @@ class ShipGroupForm(forms.ModelForm):
def save(self):
order = self.instance.order
- for line in self.instance.items.all():
+ for line in self.instance.lines.all():
stock = line.stock
if stock is not None:
# remove and deallocate quantity
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index 70e8f772cf..e45dc88bab 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -43,7 +43,7 @@ def create_invoice_pdf(order_pk, absolute_url):
def create_packing_slip_pdf(group_pk, absolute_url):
group = (DeliveryGroup.objects.prefetch_related(
- 'items', 'order', 'order__user', 'order__shipping_address',
+ 'lines', 'order', 'order__user', 'order__shipping_address',
'order__billing_address').get(pk=group_pk))
ctx = {'group': group}
rendered_template = get_template(PACKING_SLIP_TEMPLATE).render(ctx)
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index ee2f19573d..faea144c4c 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -35,7 +35,7 @@ from ...userprofile.i18n import AddressForm
@permission_required('order.view_order')
def order_list(request):
orders = (Order.objects.prefetch_related(
- 'payments', 'groups__items', 'user').order_by('-pk'))
+ 'payments', 'groups__lines', 'user').order_by('-pk'))
order_filter = OrderFilter(request.GET, queryset=orders)
orders = get_paginator_items(
order_filter.qs, settings.DASHBOARD_PAGINATE_BY,
@@ -49,7 +49,7 @@ def order_list(request):
def order_details(request, order_pk):
qs = (Order.objects
.select_related('user', 'shipping_address', 'billing_address')
- .prefetch_related('notes', 'payments', 'history', 'groups__items'))
+ .prefetch_related('notes', 'payments', 'history', 'groups__lines'))
order = get_object_or_404(qs, pk=order_pk)
notes = order.notes.all()
all_payments = order.payments.exclude(status=PaymentStatus.INPUT)
diff --git a/saleor/dashboard/views.py b/saleor/dashboard/views.py
index b25ca1b615..39a38c5533 100644
--- a/saleor/dashboard/views.py
+++ b/saleor/dashboard/views.py
@@ -39,7 +39,7 @@ def index(request):
orders_to_ship = Order.objects.filter(status=OrderStatus.FULLY_PAID)
orders_to_ship = (orders_to_ship
.select_related('user')
- .prefetch_related('groups', 'groups__items', 'payments'))
+ .prefetch_related('groups', 'groups__lines', 'payments'))
payments = Payment.objects.filter(
status=PaymentStatus.PREAUTH).order_by('-created')
payments = payments.select_related('order', 'order__user')
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 81941eb51d..875c74cd68 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -253,7 +253,7 @@ class DeliveryGroup(models.Model, ItemSet):
def __iter__(self):
if self.id:
- return iter(self.items.all())
+ return iter(self.lines.all())
return super(DeliveryGroup, self).__iter__()
@property
@@ -287,11 +287,11 @@ class DeliveryGroup(models.Model, ItemSet):
class OrderLineManager(models.Manager):
def move_to_group(self, line, target_group, quantity):
try:
- target_line = target_group.items.get(
+ target_line = target_group.lines.get(
product=line.product, product_name=line.product_name,
product_sku=line.product_sku, stock=line.stock)
except ObjectDoesNotExist:
- target_group.items.create(
+ target_group.lines.create(
delivery_group=target_group, product=line.product,
product_name=line.product_name, product_sku=line.product_sku,
quantity=quantity, unit_price_net=line.unit_price_net,
@@ -324,7 +324,7 @@ class OrderLineManager(models.Manager):
@python_2_unicode_compatible
class OrderLine(models.Model, ItemLine):
delivery_group = models.ForeignKey(
- DeliveryGroup, related_name='items', editable=False,
+ DeliveryGroup, related_name='lines', editable=False,
verbose_name=pgettext_lazy('Ordered line field', 'delivery group'),
on_delete=models.CASCADE)
product = models.ForeignKey(
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index bb8d76dbb9..d28d73d94b 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -91,7 +91,7 @@ def add_variant_to_delivery_group(
if quantity_left > stock.quantity_available
else quantity_left
)
- group.items.create(
+ group.lines.create(
product=variant.product,
product_name=variant.display_product(),
product_sku=variant.sku,
@@ -117,7 +117,7 @@ def add_variant_to_existing_lines(group, variant, total_quantity):
Returns quantity that could not be fulfilled with existing lines.
"""
# order descending by lines' stock available quantity
- lines = group.items.filter(
+ lines = group.lines.filter(
product=variant.product, product_sku=variant.sku,
stock__isnull=False).order_by(
F('stock__quantity_allocated') - F('stock__quantity'))
@@ -163,7 +163,7 @@ def merge_duplicated_lines(line):
""" Merges duplicated lines in delivery group into one (given) line.
If there are no duplicates, nothing will happen.
"""
- lines = line.delivery_group.items.filter(
+ lines = line.delivery_group.lines.filter(
product=line.product, product_name=line.product_name,
product_sku=line.product_sku, stock=line.stock)
if lines.count() > 1:
diff --git a/saleor/order/views.py b/saleor/order/views.py
index 9813d07da1..c2da2aee5f 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -24,7 +24,7 @@ logger = logging.getLogger(__name__)
def details(request, token):
- orders = Order.objects.prefetch_related('groups__items__product')
+ orders = Order.objects.prefetch_related('groups__lines__product')
orders = orders.select_related('billing_address', 'shipping_address',
'user')
order = get_object_or_404(orders, token=token)
@@ -34,7 +34,7 @@ def details(request, token):
def payment(request, token):
- orders = Order.objects.prefetch_related('groups__items__product')
+ orders = Order.objects.prefetch_related('groups__lines__product')
orders = orders.select_related('billing_address', 'shipping_address',
'user')
order = get_object_or_404(orders, token=token)
diff --git a/saleor/userprofile/views.py b/saleor/userprofile/views.py
index 55dacc901d..10037d49e1 100755
--- a/saleor/userprofile/views.py
+++ b/saleor/userprofile/views.py
@@ -16,7 +16,7 @@ from .forms import (
def details(request):
password_form = get_or_process_password_form(request)
ctx = {'addresses': request.user.addresses.all(),
- 'orders': request.user.orders.prefetch_related('groups__items'),
+ 'orders': request.user.orders.prefetch_related('groups__lines'),
'change_password_form': password_form}
return TemplateResponse(request, 'userprofile/details.html', ctx)
diff --git a/tests/conftest.py b/tests/conftest.py
index 79712001d0..e0c5ae24d1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -351,7 +351,7 @@ def voucher(db): # pylint: disable=W0613
@pytest.fixture()
-def order_with_items(order, product_class):
+def order_with_lines(order, product_class):
group = DeliveryGroup.objects.create(order=order)
product = Product.objects.create(
name='Test product', price=Decimal('10.00'),
@@ -397,7 +397,7 @@ def order_with_items(order, product_class):
@pytest.fixture()
-def order_with_items_and_stock(order, product_class):
+def order_with_lines_and_stock(order, product_class):
group = DeliveryGroup.objects.create(order=order)
product = Product.objects.create(
name='Test product', price=Decimal('10.00'),
@@ -442,7 +442,7 @@ def order_with_items_and_stock(order, product_class):
@pytest.fixture()
-def order_with_variant_from_different_stocks(order_with_items_and_stock):
+def order_with_variant_from_different_stocks(order_with_lines_and_stock):
line = OrderLine.objects.get(product_sku='SKU_A')
variant = ProductVariant.objects.get(sku=line.product_sku)
warehouse_2 = StockLocation.objects.create(name='Warehouse 2')
@@ -464,7 +464,7 @@ def order_with_variant_from_different_stocks(order_with_items_and_stock):
Stock.objects.create(
variant=variant, cost_price=1, quantity=5, quantity_allocated=0,
location=warehouse_2)
- return order_with_items_and_stock
+ return order_with_lines_and_stock
@pytest.fixture()
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index c8666cc8fd..09ea260d56 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -18,8 +18,8 @@ from tests.utils import get_redirect_location, get_url_path
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_cancel_order_line(admin_client, order_with_items_and_stock):
- lines_before = order_with_items_and_stock.get_lines()
+def test_view_cancel_order_line(admin_client, order_with_lines_and_stock):
+ lines_before = order_with_lines_and_stock.get_lines()
lines_before_count = lines_before.count()
line = lines_before.first()
line_quantity = line.quantity
@@ -28,7 +28,7 @@ def test_view_cancel_order_line(admin_client, order_with_items_and_stock):
url = reverse(
'dashboard:orderline-cancel', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': line.pk})
response = admin_client.get(url)
@@ -36,7 +36,7 @@ def test_view_cancel_order_line(admin_client, order_with_items_and_stock):
response = admin_client.post(url, {'csrfmiddlewaretoken': 'hello'})
assert response.status_code == 302
assert get_redirect_location(response) == reverse(
- 'dashboard:order-details', args=[order_with_items_and_stock.pk])
+ 'dashboard:order-details', args=[order_with_lines_and_stock.pk])
# check ordered item removal
lines_after = Order.objects.get().get_lines()
assert lines_before_count - 1 == lines_after.count()
@@ -44,10 +44,10 @@ def test_view_cancel_order_line(admin_client, order_with_items_and_stock):
assert Stock.objects.first().quantity_allocated == quantity_allocated_before - line_quantity
# check note in the order's history
assert OrderHistoryEntry.objects.get(
- order=order_with_items_and_stock).comment == 'Cancelled item %s' % product
+ order=order_with_lines_and_stock).comment == 'Cancelled item %s' % product
url = reverse(
'dashboard:orderline-cancel', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': OrderLine.objects.get().pk})
response = admin_client.post(
url, {'csrfmiddlewaretoken': 'hello'}, follow=True)
@@ -60,19 +60,19 @@ def test_view_cancel_order_line(admin_client, order_with_items_and_stock):
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_change_order_line_quantity(admin_client, order_with_items_and_stock):
+def test_view_change_order_line_quantity(admin_client, order_with_lines_and_stock):
"""
user goes to order details page
user selects first order line with quantity 3 and changes it to 2
"""
- lines_before_quantity_change = order_with_items_and_stock.get_lines()
+ lines_before_quantity_change = order_with_lines_and_stock.get_lines()
lines_before_quantity_change_count = lines_before_quantity_change.count()
line = lines_before_quantity_change.first()
line_quantity_before_quantity_change = line.quantity
url = reverse(
'dashboard:orderline-change-quantity', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': line.pk})
response = admin_client.get(url)
assert response.status_code == 200
@@ -83,7 +83,7 @@ def test_view_change_order_line_quantity(admin_client, order_with_items_and_stoc
assert redirect_status_code == 302
assert get_url_path(redirected_to) == reverse(
'dashboard:order-details',
- args=[order_with_items_and_stock.pk])
+ args=[order_with_lines_and_stock.pk])
# success messages should appear after redirect
assert response.context['messages']
lines_after = Order.objects.get().get_lines()
@@ -95,10 +95,10 @@ def test_view_change_order_line_quantity(admin_client, order_with_items_and_stoc
# source line quantity should be decreased to 2
assert line.quantity == 2
# order should have the same delivery groups count
- assert order_with_items_and_stock.groups.count() == 1
+ assert order_with_lines_and_stock.groups.count() == 1
# a note in the order's history should be created
assert OrderHistoryEntry.objects.get(
- order=order_with_items_and_stock).comment == (
+ order=order_with_lines_and_stock).comment == (
'Changed quantity for product %(product)s from'
' %(old_quantity)s to %(new_quantity)s') % {
'product': line.product,
@@ -109,17 +109,17 @@ def test_view_change_order_line_quantity(admin_client, order_with_items_and_stoc
@pytest.mark.integration
@pytest.mark.django_db
def test_view_change_order_line_quantity_with_invalid_data(
- admin_client, order_with_items_and_stock):
+ admin_client, order_with_lines_and_stock):
"""
user goes to order details page
user selects the first order line with quantity 3 and try to change it to 0 and -1
user gets an error.
"""
- lines = order_with_items_and_stock.get_lines()
+ lines = order_with_lines_and_stock.get_lines()
line = lines.first()
url = reverse(
'dashboard:orderline-change-quantity', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': line.pk})
response = admin_client.post(
url, {'quantity': 0})
@@ -130,7 +130,7 @@ def test_dashboard_change_quantity_form(request_cart_with_item, order):
cart = request_cart_with_item
group = DeliveryGroup.objects.create(order=order)
fill_group_with_partition(group, cart.lines.all())
- order_line = group.items.get()
+ order_line = group.lines.get()
# Check max quantity validation
form = ChangeQuantityForm({'quantity': 9999}, instance=order_line)
@@ -141,12 +141,12 @@ def test_dashboard_change_quantity_form(request_cart_with_item, order):
# Check minimum quantity validation
form = ChangeQuantityForm({'quantity': 0}, instance=order_line)
assert not form.is_valid()
- assert group.items.get().stock.quantity_allocated == 1
+ assert group.lines.get().stock.quantity_allocated == 1
# Check available quantity validation
form = ChangeQuantityForm({'quantity': 20}, instance=order_line)
assert not form.is_valid()
- assert group.items.get().stock.quantity_allocated == 1
+ assert group.lines.get().stock.quantity_allocated == 1
assert form.errors['quantity'] == ['Only 5 remaining in stock.']
# Save same quantity
@@ -154,25 +154,25 @@ def test_dashboard_change_quantity_form(request_cart_with_item, order):
assert form.is_valid()
form.save()
order_line.stock.refresh_from_db()
- assert group.items.get().stock.quantity_allocated == 1
+ assert group.lines.get().stock.quantity_allocated == 1
# Increase quantity
form = ChangeQuantityForm({'quantity': 2}, instance=order_line)
assert form.is_valid()
form.save()
order_line.stock.refresh_from_db()
- assert group.items.get().stock.quantity_allocated == 2
+ assert group.lines.get().stock.quantity_allocated == 2
# Decrease quantity
form = ChangeQuantityForm({'quantity': 1}, instance=order_line)
assert form.is_valid()
form.save()
- assert group.items.get().stock.quantity_allocated == 1
+ assert group.lines.get().stock.quantity_allocated == 1
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_split_order_line(admin_client, order_with_items_and_stock):
+def test_view_split_order_line(admin_client, order_with_lines_and_stock):
"""
user goes to order details page
user selects first order line with quantity 3 and moves 2 items
@@ -180,7 +180,7 @@ def test_view_split_order_line(admin_client, order_with_items_and_stock):
user selects the line from the new shipment and moves all items
back to the first shipment
"""
- lines_before_split = order_with_items_and_stock.get_lines()
+ lines_before_split = order_with_lines_and_stock.get_lines()
lines_before_split_count = lines_before_split.count()
line = lines_before_split.first()
line_quantity_before_split = line.quantity
@@ -189,7 +189,7 @@ def test_view_split_order_line(admin_client, order_with_items_and_stock):
url = reverse(
'dashboard:orderline-split', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': line.pk})
response = admin_client.get(url)
assert response.status_code == 200
@@ -202,7 +202,7 @@ def test_view_split_order_line(admin_client, order_with_items_and_stock):
assert redirect_status_code == 302
assert get_url_path(redirected_to) == reverse(
'dashboard:order-details',
- args=[order_with_items_and_stock.pk])
+ args=[order_with_lines_and_stock.pk])
# success messages should appear after redirect
assert response.context['messages']
lines_after = Order.objects.get().get_lines()
@@ -214,34 +214,34 @@ def test_view_split_order_line(admin_client, order_with_items_and_stock):
# source line quantity should be decreased to 1
assert line.quantity == line_quantity_before_split - 2
# order should have 2 delivery groups now
- assert order_with_items_and_stock.groups.count() == 2
+ assert order_with_lines_and_stock.groups.count() == 2
# a note in the order's history should be created
new_group = DeliveryGroup.objects.last()
assert OrderHistoryEntry.objects.get(
- order=order_with_items_and_stock).comment == (
+ order=order_with_lines_and_stock).comment == (
'Moved 2 items %(item)s from '
'%(old_group)s to %(new_group)s') % {
'item': line,
'old_group': old_delivery_group,
'new_group': new_group}
- new_line = new_group.items.get()
+ new_line = new_group.lines.get()
# the new line should contain the moved quantity
assert new_line.quantity == 2
url = reverse(
'dashboard:orderline-split', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': new_line.pk})
admin_client.post(
url, {'quantity': 2, 'target_group': old_delivery_group.pk})
# an other note in the order's history should be created
assert OrderHistoryEntry.objects.filter(
- order=order_with_items_and_stock).last().comment ==(
+ order=order_with_lines_and_stock).last().comment ==(
'Moved 2 items %(item)s from removed '
'group to %(new_group)s') % {
'item': line,
'new_group': old_delivery_group}
# the new shipment should be removed
- assert order_with_items_and_stock.groups.count() == 1
+ assert order_with_lines_and_stock.groups.count() == 1
# the related order line should be removed
assert lines_before_split_count == Order.objects.get().get_lines().count()
line.refresh_from_db()
@@ -252,17 +252,17 @@ def test_view_split_order_line(admin_client, order_with_items_and_stock):
@pytest.mark.integration
@pytest.mark.django_db
@pytest.mark.parametrize('quantity', [0, 4])
-def test_view_split_order_line_with_invalid_data(admin_client, order_with_items_and_stock, quantity):
+def test_view_split_order_line_with_invalid_data(admin_client, order_with_lines_and_stock, quantity):
"""
user goes to order details page
user selects first order line with quantity 3 and try move 0 and 4 items to a new shipment
user gets an error and no delivery groups are created.
"""
- lines = order_with_items_and_stock.get_lines()
+ lines = order_with_lines_and_stock.get_lines()
line = lines.first()
url = reverse(
'dashboard:orderline-split', kwargs={
- 'order_pk': order_with_items_and_stock.pk,
+ 'order_pk': order_with_lines_and_stock.pk,
'line_pk': line.pk})
response = admin_client.post(
url, {'quantity': quantity, 'target_group': ''})
@@ -270,24 +270,24 @@ def test_view_split_order_line_with_invalid_data(admin_client, order_with_items_
assert DeliveryGroup.objects.count() == 1
-def test_ordered_item_change_quantity(transactional_db, order_with_items):
- assert list(order_with_items.history.all()) == []
- items = order_with_items.groups.all()[0].items.all()
- change_order_line_quantity(items[0], 0)
- change_order_line_quantity(items[1], 0)
- change_order_line_quantity(items[2], 0)
- history = list(order_with_items.history.all())
+def test_ordered_item_change_quantity(transactional_db, order_with_lines):
+ assert list(order_with_lines.history.all()) == []
+ lines = order_with_lines.groups.all()[0].lines.all()
+ change_order_line_quantity(lines[0], 0)
+ change_order_line_quantity(lines[1], 0)
+ change_order_line_quantity(lines[2], 0)
+ history = list(order_with_lines.history.all())
assert len(history) == 1
assert history[0].status == OrderStatus.CANCELLED
assert history[0].comment == 'Order cancelled. No items in order'
def test_ordered_item_remove_empty_group_with_force(
- transactional_db, order_with_items):
- group = order_with_items.groups.all()[0]
- items = group.items.all()
- OrderLine.objects.remove_empty_groups(items[0], force=True)
- history = list(order_with_items.history.all())
+ transactional_db, order_with_lines):
+ group = order_with_lines.groups.all()[0]
+ lines = group.lines.all()
+ OrderLine.objects.remove_empty_groups(lines[0], force=True)
+ history = list(order_with_lines.history.all())
assert len(history) == 1
assert history[0].status == OrderStatus.CANCELLED
assert history[0].comment == 'Order cancelled. No items in order'
@@ -296,56 +296,56 @@ def test_ordered_item_remove_empty_group_with_force(
@pytest.mark.integration
@pytest.mark.django_db
def test_view_order_invoice(
- admin_client, order_with_items_and_stock, billing_address):
+ admin_client, order_with_lines_and_stock, billing_address):
"""
user goes to order details page
user clicks on Invoice button
user downloads the invoice as PDF file
"""
- order_with_items_and_stock.shipping_address = billing_address
- order_with_items_and_stock.billing_address = billing_address
- order_with_items_and_stock.save()
+ order_with_lines_and_stock.shipping_address = billing_address
+ order_with_lines_and_stock.billing_address = billing_address
+ order_with_lines_and_stock.save()
url = reverse(
'dashboard:order-invoice', kwargs={
- 'order_pk': order_with_items_and_stock.id
+ 'order_pk': order_with_lines_and_stock.id
})
response = admin_client.get(url)
assert response.status_code == 200
assert response['content-type'] == 'application/pdf'
- name = "invoice-%s" % order_with_items_and_stock.id
+ name = "invoice-%s" % order_with_lines_and_stock.id
assert response['Content-Disposition'] == 'filename=%s' % name
@pytest.mark.integration
@pytest.mark.django_db
def test_view_order_packing_slips(
- admin_client, order_with_items_and_stock, billing_address):
+ admin_client, order_with_lines_and_stock, billing_address):
"""
user goes to order details page
user clicks on Packing Slips button
user downloads the packing slips as PDF file
"""
- order_with_items_and_stock.shipping_address = billing_address
- order_with_items_and_stock.billing_address = billing_address
- order_with_items_and_stock.save()
+ order_with_lines_and_stock.shipping_address = billing_address
+ order_with_lines_and_stock.billing_address = billing_address
+ order_with_lines_and_stock.save()
url = reverse(
'dashboard:order-packing-slips', kwargs={
- 'group_pk': order_with_items_and_stock.groups.all()[0].pk
+ 'group_pk': order_with_lines_and_stock.groups.all()[0].pk
})
response = admin_client.get(url)
assert response.status_code == 200
assert response['content-type'] == 'application/pdf'
name = "packing-slip-%s-%s" % (
- order_with_items_and_stock.id,
- order_with_items_and_stock.groups.all()[0].pk)
+ order_with_lines_and_stock.id,
+ order_with_lines_and_stock.groups.all()[0].pk)
assert response['Content-Disposition'] == 'filename=%s' % name
@pytest.mark.integration
@pytest.mark.django_db
def test_view_change_order_line_stock_valid(
- admin_client, order_with_items_and_stock):
- order = order_with_items_and_stock
+ admin_client, order_with_lines_and_stock):
+ order = order_with_lines_and_stock
line = order.get_lines().last()
old_stock = line.stock
variant = ProductVariant.objects.get(sku=line.product_sku)
@@ -375,8 +375,8 @@ def test_view_change_order_line_stock_valid(
@pytest.mark.integration
@pytest.mark.django_db
def test_view_change_order_line_stock_insufficient_stock(
- admin_client, order_with_items_and_stock):
- order = order_with_items_and_stock
+ admin_client, order_with_lines_and_stock):
+ order = order_with_lines_and_stock
line = order.get_lines().last()
old_stock = line.stock
variant = ProductVariant.objects.get(sku=line.product_sku)
@@ -406,8 +406,8 @@ def test_view_change_order_line_stock_insufficient_stock(
def test_view_change_order_line_stock_merges_lines(
- admin_client, order_with_items_and_stock):
- order = order_with_items_and_stock
+ admin_client, order_with_lines_and_stock):
+ order = order_with_lines_and_stock
line = order.get_lines().first()
group = line.delivery_group
old_stock = line.stock
@@ -416,7 +416,7 @@ def test_view_change_order_line_stock_merges_lines(
stock = Stock.objects.create(
variant=variant, cost_price=2, quantity=2, quantity_allocated=2,
location=stock_location)
- line_2 = group.items.create(
+ line_2 = group.lines.create(
delivery_group=group,
product=line.product,
product_name=line.product.name,
@@ -427,7 +427,7 @@ def test_view_change_order_line_stock_merges_lines(
stock=stock,
stock_location=stock.location.name
)
- lines_before = group.items.count()
+ lines_before = group.lines.count()
url = reverse(
'dashboard:orderline-change-stock', kwargs={
@@ -437,7 +437,7 @@ def test_view_change_order_line_stock_merges_lines(
response = admin_client.post(url, data)
assert response.status_code == 200
- assert group.items.count() == lines_before - 1
+ assert group.lines.count() == lines_before - 1
old_stock.refresh_from_db()
assert old_stock.quantity_allocated == 5
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
index db7a5b37b1..649f1e39f0 100644
--- a/tests/dashboard/test_permissions.py
+++ b/tests/dashboard/test_permissions.py
@@ -595,17 +595,17 @@ def test_staff_group_member_can_view_order_list(
def test_staff_group_member_can_view_order_details(
- staff_client, staff_user, staff_group, permission_view_order, order_with_items_and_stock):
+ staff_client, staff_user, staff_group, permission_view_order, order_with_lines_and_stock):
assert not staff_user.has_perm("order.view_order")
response = staff_client.get(reverse('dashboard:order-details',
- args=[order_with_items_and_stock.pk]))
+ args=[order_with_lines_and_stock.pk]))
assert response.status_code == 302
staff_group.permissions.add(permission_view_order)
staff_user.groups.add(staff_group)
staff_user = User.objects.get(pk=staff_user.pk)
assert staff_user.has_perm("order.view_order")
response = staff_client.get(reverse('dashboard:order-details',
- args=[order_with_items_and_stock.pk]))
+ args=[order_with_lines_and_stock.pk]))
assert response.status_code == 200
@@ -671,7 +671,7 @@ def test_staff_group_member_can_view_customers_list(
def test_staff_group_member_can_view_customer_details(
staff_client, staff_user, staff_group, permission_view_user,
- customer_user, order_with_items_and_stock):
+ customer_user, order_with_lines_and_stock):
assert not staff_user.has_perm("userprofile.view_user")
response = staff_client.get(reverse('dashboard:customer-details',
args=[customer_user.pk]))
@@ -684,7 +684,7 @@ def test_staff_group_member_can_view_customer_details(
args=[customer_user.pk]))
assert response.status_code == 200
response = staff_client.get(reverse('dashboard:order-details',
- args=[order_with_items_and_stock.pk]))
+ args=[order_with_lines_and_stock.pk]))
assert response.status_code == 302
diff --git a/tests/test_order.py b/tests/test_order.py
index a4cd87f4b4..d7d35fe0dc 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -36,7 +36,7 @@ def test_stock_allocation(billing_address, product_in_stock):
order = models.Order.objects.create(billing_address=billing_address)
delivery_group = models.DeliveryGroup.objects.create(order=order)
fill_group_with_partition(delivery_group, cart.lines.all())
- order_line = delivery_group.items.get()
+ order_line = delivery_group.lines.get()
stock = order_line.stock
assert stock.quantity_allocated == 2
@@ -46,27 +46,27 @@ def test_order_discount(sale, order, request_cart_with_item):
group = models.DeliveryGroup.objects.create(order=order)
fill_group_with_partition(
group, cart.lines.all(), discounts=cart.discounts)
- item = group.items.first()
- assert item.get_price_per_item() == Price(currency="USD", net=5)
+ line = group.lines.first()
+ assert line.get_price_per_item() == Price(currency="USD", net=5)
-def test_add_variant_to_delivery_group_adds_item_for_new_variant(
- order_with_items, product_in_stock):
- group = order_with_items.groups.get()
+def test_add_variant_to_delivery_group_adds_line_for_new_variant(
+ order_with_lines, product_in_stock):
+ group = order_with_lines.groups.get()
variant = product_in_stock.variants.get()
- items_before = group.items.count()
+ lines_before = group.lines.count()
add_variant_to_delivery_group(group, variant, 1)
- item = group.items.last()
- assert group.items.count() == items_before + 1
- assert item.product_sku == variant.sku
- assert item.quantity == 1
+ line = group.lines.last()
+ assert group.lines.count() == lines_before + 1
+ assert line.product_sku == variant.sku
+ assert line.quantity == 1
def test_add_variant_to_delivery_group_allocates_stock_for_new_variant(
- order_with_items, product_in_stock):
- group = order_with_items.groups.get()
+ order_with_lines, product_in_stock):
+ group = order_with_lines.groups.get()
variant = product_in_stock.variants.get()
stock = variant.select_stockrecord()
stock_before = stock.quantity_allocated
@@ -77,30 +77,30 @@ def test_add_variant_to_delivery_group_allocates_stock_for_new_variant(
assert stock.quantity_allocated == stock_before + 1
-def test_add_variant_to_delivery_group_edits_item_for_existing_variant(
- order_with_items_and_stock):
- order = order_with_items_and_stock
+def test_add_variant_to_delivery_group_edits_line_for_existing_variant(
+ order_with_lines_and_stock):
+ order = order_with_lines_and_stock
group = order.groups.get()
- existing_item = group.items.first()
- variant = existing_item.product.variants.get()
- items_before = group.items.count()
- item_quantity_before = existing_item.quantity
+ existing_line = group.lines.first()
+ variant = existing_line.product.variants.get()
+ lines_before = group.lines.count()
+ line_quantity_before = existing_line.quantity
add_variant_to_delivery_group(group, variant, 1)
- existing_item.refresh_from_db()
- assert group.items.count() == items_before
- assert existing_item.product_sku == variant.sku
- assert existing_item.quantity == item_quantity_before + 1
+ existing_line.refresh_from_db()
+ assert group.lines.count() == lines_before
+ assert existing_line.product_sku == variant.sku
+ assert existing_line.quantity == line_quantity_before + 1
def test_add_variant_to_delivery_group_allocates_stock_for_existing_variant(
- order_with_items_and_stock):
- order = order_with_items_and_stock
+ order_with_lines_and_stock):
+ order = order_with_lines_and_stock
group = order.groups.get()
- existing_item = group.items.first()
- variant = existing_item.product.variants.get()
- stock = existing_item.stock
+ existing_line = group.lines.first()
+ variant = existing_line.product.variants.get()
+ stock = existing_line.stock
stock_before = stock.quantity_allocated
add_variant_to_delivery_group(group, variant, 1)
diff --git a/tests/test_payment.py b/tests/test_payment.py
index 5799f8c277..591afb9c75 100644
--- a/tests/test_payment.py
+++ b/tests/test_payment.py
@@ -5,33 +5,33 @@ from prices import Price
from saleor.order.models import Payment
-def test_get_purchased_items(order_with_items, settings, voucher):
+def test_get_purchased_items(order_with_lines, settings, voucher):
- payment = Payment.objects.create(order=order_with_items, variant='paypal')
+ payment = Payment.objects.create(order=order_with_lines, variant='paypal')
discount = Price('10.0', currency=settings.DEFAULT_CURRENCY)
- assert len(payment.get_purchased_items()) == len(order_with_items.get_lines())
+ assert len(payment.get_purchased_items()) == len(order_with_lines.get_lines())
- for p, o in zip(payment.get_purchased_items(), order_with_items.get_lines()):
+ for p, o in zip(payment.get_purchased_items(), order_with_lines.get_lines()):
assert p.sku == o.product_sku
assert p.quantity == o.quantity
- order_with_items.discount_name = 'Test'
- order_with_items.discount_amount = discount
- order_with_items.voucher = voucher
- order_with_items.save()
+ order_with_lines.discount_name = 'Test'
+ order_with_lines.discount_amount = discount
+ order_with_lines.voucher = voucher
+ order_with_lines.save()
settings.PAYMENT_VARIANTS = { 'paypal': ('PaypalProvider', {})}
- assert len(payment.get_purchased_items()) == len(order_with_items.get_lines()) + 1
+ assert len(payment.get_purchased_items()) == len(order_with_lines.get_lines()) + 1
- for p, o in zip(payment.get_purchased_items()[:-1], order_with_items.get_lines()):
+ for p, o in zip(payment.get_purchased_items()[:-1], order_with_lines.get_lines()):
assert p.sku == o.product_sku
assert p.quantity == o.quantity
discounted = payment.get_purchased_items()[-1]
- assert discounted.name == order_with_items.discount_name
+ assert discounted.name == order_with_lines.discount_name
assert discounted.sku == 'DISCOUNT'
- assert discounted.price == -1 * order_with_items.discount_amount.net
+ assert discounted.price == -1 * order_with_lines.discount_amount.net
assert discounted.quantity == 1