Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Rework add_variant_to_order function, renumber migration
Pacu222cdbc8fa7cd
diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 36178d3c37..9676d8dbfb 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -140,30 +140,24 @@ def add_variant_to_order(Order lines are created by increasing quantity of lines,as long as total_quantity of variant will be added."""- quantity_left = add_variant_to_existing_lines(+ quantity_not_fulfilled = add_variant_to_existing_lines(order, variant, total_quantity) if add_to_existing else total_quantity++ if not quantity_not_fulfilled:+ return+ if quantity_not_fulfilled > variant.quantity_available:+ raise InsufficientStock(variant)+price = variant.get_price_per_item(discounts)- while quantity_left > 0:- quantity_available = variant.quantity_available- if not quantity_available:- raise InsufficientStock(variant)- quantity = (- quantity_available- if quantity_left > quantity_available- else quantity_left- )- order.lines.create(- product_name=variant.display_product(),- product_sku=variant.sku,- is_shipping_required=(- variant.product.product_type.is_shipping_required),- quantity=quantity,- unit_price=price,- variant=variant)- allocate_stock(variant, quantity)- # refresh stock for accessing quantity_allocated- variant.refresh_from_db()- quantity_left -= quantity+ order.lines.create(+ product_name=variant.display_product(),+ product_sku=variant.sku,+ is_shipping_required=(+ variant.product.product_type.is_shipping_required),+ quantity=quantity_not_fulfilled,+ unit_price=price,+ variant=variant)+ allocate_stock(variant, quantity_not_fulfilled)def add_variant_to_existing_lines(order, variant, total_quantity):diff --git a/saleor/product/migrations/0056_auto_20180329_0142.py b/saleor/product/migrations/0057_auto_20180329_0142.pysimilarity index 96%rename from saleor/product/migrations/0056_auto_20180329_0142.pyrename to saleor/product/migrations/0057_auto_20180329_0142.pyindex 5094b6dbef..d432b3818a 100644--- a/saleor/product/migrations/0056_auto_20180329_0142.py+++ b/saleor/product/migrations/0057_auto_20180329_0142.py@@ -10,7 +10,7 @@ class Migration(migrations.Migration):dependencies = [('order', '0044_auto_20180329_0142'),- ('product', '0055_auto_20180321_0417'),+ ('product', '0056_auto_20180330_0321'),]operations = [