Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Include quantity in total weight calculation
Pacu28b2851275fca
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.pyindex 8b88945305..e0e4434c4e 100644--- a/saleor/checkout/models.py+++ b/saleor/checkout/models.py@@ -101,7 +101,7 @@ class Cart(models.Model):# Cannot use `sum` as it parses an empty Weight to an intweights = Weight(kg=0)for line in self:- weights += line.variant.get_weight()+ weights += line.variant.get_weight() * line.quantityreturn weightsdef get_line(self, variant):diff --git a/tests/test_cart.py b/tests/test_cart.pyindex 44eebbca68..8e1a0410ec 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -3,19 +3,20 @@ from unittest.mock import MagicMock, Mockfrom uuid import uuid4import pytest+from django.contrib.auth.models import AnonymousUserfrom django.core import signingfrom django.core.exceptions import ObjectDoesNotExistfrom django.http import HttpResponsefrom django.urls import reverse+from measurement.measures import Weightfrom prices import Money, TaxedMoney-from saleor.checkout import forms, utilsfrom saleor.checkout.context_processors import cart_counterfrom saleor.checkout.models import Cartfrom saleor.checkout.utils import (add_variant_to_cart, change_cart_user, find_open_cart_for_user)-from saleor.checkout.views import update_cart_line, clear_cart+from saleor.checkout.views import clear_cart, update_cart_linefrom saleor.core.exceptions import InsufficientStockfrom saleor.core.utils.taxes import ZERO_TAXED_MONEYfrom saleor.discount.models import Sale@@ -681,3 +682,13 @@ def test_clear_cart(request_cart_with_item, client):HTTP_X_REQUESTED_WITH='XMLHttpRequest')assert response.status_code == 200assert len(cart.lines.all()) == 0+++def test_get_total_weight(cart_with_item):+ line = cart_with_item.lines.first()+ variant = line.variant+ variant.weight = Weight(kg=10)+ variant.save()+ line.quantity = 6+ line.save()+ assert cart_with_item.get_total_weight() == Weight(kg=60)