Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improvements
Piotr Grundas9f272c5f7da6
diff --cc CHANGELOG.mdindex 2577cfba38,97ba371dca..5972b6ba79--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -29,8 -29,11 +29,12 @@@ All notable, unreleased changes to thi- Validate discount value for percentage vouchers and sales - #7033 by @d-wysocki- Optimize children field on Category type - #7045 by @IKarbowiak- Added support for querying objects by metadata fields - #6683 by @LeOndaz+- Add text attribute input - #7059 by @piotrgrundas- Avoid using `get_plugins_manager` method - #7052 by @IKarbowiak+ - Add benchmarks for triggered product and variants webhooks - #7061 by @d-wysocki+ - Extend `Transaction` type with gateway response and `Payment` type with filter - #7062 by @IKarbowiak+ - Fix invalid tax rates for lines - #7058 by @IKarbowiak+ - Allow seeing unconfirmed orders - #7072 by @IKarbowiak### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --cc saleor/graphql/attribute/utils.pyindex b0065d55e5,955092ce97..a2684d26bc--- a/saleor/graphql/attribute/utils.py+++ b/saleor/graphql/attribute/utils.py@@@ -256,30 -252,6 +256,29 @@@ class AttributeAssignmentMixinif errors:raise ValidationError(errors)+ @classmethod+ def _pre_save_text_values(+ cls,+ instance: T_INSTANCE,+ attribute: attribute_models.Attribute,+ attr_values: AttrValuesInput,+ ):+ """Lazy-retrieve or create the database object from the supplied raw value."""+ value_model = attribute.values.model+ text = attr_values.values[0] if attr_values.values else ""- # don't create ne value when assignment already exists++ # don't create new value when assignment already exists+ value = cls._get_assigned_attribute_value_if_exists(+ instance, attribute, "name", text+ )++ if value is None:+ value = value_model.objects.create(+ attribute=attribute,+ name=text,+ slug=slugify(text, allow_unicode=True),+ )-+ return (value,)+@classmethoddef clean_input(cls,diff --cc saleor/graphql/product/tests/test_variant.pyindex c702ea4b80,fdbfcc5f09..332292732a--- a/saleor/graphql/product/tests/test_variant.py+++ b/saleor/graphql/product/tests/test_variant.py@@@ -1050,114 -1050,7 +1050,114 @@@ def test_create_variant_invalid_variantassert error in errors+@patch("saleor.plugins.manager.PluginsManager.product_variant_created")+def test_create_variant_with_text_attribute(+ created_webhook_mock,+ permission_manage_products,+ product,+ product_type,+ staff_api_client,+ text_attribute,+ warehouse,+):+ product_type.variant_attributes.add(text_attribute)+ query = CREATE_VARIANT_MUTATION+ product_id = graphene.Node.to_global_id("Product", product.pk)+ sku = "1"+ price = 1.32+ cost_price = 3.22+ weight = 10.22+ attr_id = graphene.Node.to_global_id("Attribute", text_attribute.id)+ text = "Sample text"+ stocks = [+ {+ "warehouse": graphene.Node.to_global_id("Warehouse", warehouse.pk),+ "quantity": 20,+ }+ ]+ variables = {+ "productId": product_id,+ "sku": sku,+ "stocks": stocks,+ "costPrice": cost_price,+ "price": price,+ "weight": weight,+ "attributes": [+ {"id": attr_id, "values": text},+ ],+ "trackInventory": True,+ }++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)["data"]["productVariantCreate"]+ flush_post_commit_hooks()+ data = content["productVariant"]++ assert not content["productErrors"]+ assert data["name"] == sku+ assert data["sku"] == sku+ assert data["attributes"][-1]["attribute"]["slug"] == text_attribute.slug+ assert data["attributes"][-1]["values"][0]["name"] == text+ created_webhook_mock.assert_called_once_with(product.variants.last())++- def test_create_variant_attributes_save_error(++def test_create_variant_with_text_attribute_length_exceeded(+ permission_manage_products,+ product,+ product_type,+ staff_api_client,+ text_attribute,+ warehouse,+):+ query = CREATE_VARIANT_MUTATION+ product_id = graphene.Node.to_global_id("Product", product.pk)+ sku = "1"+ price = 1.32+ cost_price = 3.22+ weight = 10.22++ product_type.variant_attributes.add(text_attribute)+ attr_id = graphene.Node.to_global_id("Attribute", text_attribute.id)++ stocks = [+ {+ "warehouse": graphene.Node.to_global_id("Warehouse", warehouse.pk),+ "quantity": 20,+ }+ ]+ variables = {+ "productId": product_id,+ "sku": sku,+ "stocks": stocks,+ "costPrice": cost_price,+ "price": price,+ "weight": weight,+ "attributes": [+ {"id": attr_id, "values": ["long text" * 100]},+ ],+ "trackInventory": True,+ }+ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)++ data = content["data"]["productVariantCreate"]+ errors = data["productErrors"]++ assert not data["productVariant"]+ assert len(errors) == 1+ assert errors[0] == {+ "attributes": [attr_id],+ "code": ProductErrorCode.INVALID.name,+ "field": "attributes",- "message": ANY,++ "message": "Attribute value length is exceeded.",+ }++- def test_create_product_variant_update_with_new_attributes(+ def test_product_variant_update_with_new_attributes(staff_api_client, permission_manage_products, product, size_attribute):query = """