Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge branch 'master' into feature/swatch-attribute
IKarbowiak8122e4935c27
diff --cc saleor/attribute/__init__.pyindex 2bd5173026,f4d8521ced..e8818a3761--- a/saleor/attribute/__init__.py+++ b/saleor/attribute/__init__.py@@@ -10,8 -10,9 +10,10 @@@ class AttributeInputTypeREFERENCE = "reference"NUMERIC = "numeric"RICH_TEXT = "rich-text"+ SWATCH = "swatch"BOOLEAN = "boolean"+ DATE = "date"+ DATE_TIME = "date-time"CHOICES = [(DROPDOWN, "Dropdown"),@@@ -20,8 -21,9 +22,10 @@@(REFERENCE, "Reference"),(NUMERIC, "Numeric"),(RICH_TEXT, "Rich Text"),+ (SWATCH, "Swatch"),(BOOLEAN, "Boolean"),+ (DATE, "Date"),+ (DATE_TIME, "Date Time"),]# list of the input types that can be used in variant selection@@@ -47,22 -52,25 +51,28 @@@ ATTRIBUTE_PROPERTIES_CONFIGURATION =AttributeInputType.DROPDOWN,AttributeInputType.MULTISELECT,AttributeInputType.NUMERIC,+ AttributeInputType.SWATCH,AttributeInputType.BOOLEAN,+ AttributeInputType.DATE,+ AttributeInputType.DATE_TIME,],"filterable_in_dashboard": [AttributeInputType.DROPDOWN,AttributeInputType.MULTISELECT,AttributeInputType.NUMERIC,+ AttributeInputType.SWATCH,AttributeInputType.BOOLEAN,+ AttributeInputType.DATE,+ AttributeInputType.DATE_TIME,],"available_in_grid": [AttributeInputType.DROPDOWN,AttributeInputType.MULTISELECT,AttributeInputType.NUMERIC,+ AttributeInputType.SWATCH,AttributeInputType.BOOLEAN,+ AttributeInputType.DATE,+ AttributeInputType.DATE_TIME,],"storefront_search_position": [AttributeInputType.DROPDOWN,diff --cc saleor/attribute/migrations/0015_auto_20210811_0701.pyindex dd47091011,0000000000..af21f58622mode 100644,000000..100644--- a/saleor/attribute/migrations/0015_auto_20210811_0701.py+++ b/saleor/attribute/migrations/0015_auto_20210811_0701.py@@@ -1,36 -1,0 +1,38 @@@- # Generated by Django 3.2.2 on 2021-07-19 09:31++# Generated by Django 3.2.5 on 2021-08-11 07:01++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [- ("attribute", "0013_auto_20210609_2245"),++ ("attribute", "0014_auto_20210619_1836"),+ ]++ operations = [+ migrations.AlterField(+ model_name="attribute",+ name="input_type",+ field=models.CharField(+ choices=[+ ("dropdown", "Dropdown"),+ ("multiselect", "Multi Select"),+ ("file", "File"),+ ("reference", "Reference"),+ ("numeric", "Numeric"),+ ("rich-text", "Rich Text"),+ ("swatch", "Swatch"),+ ("boolean", "Boolean"),++ ("date", "Date"),++ ("date-time", "Date Time"),+ ],+ default="dropdown",+ max_length=50,+ ),+ ),+ migrations.AlterField(+ model_name="attributevalue",+ name="value",+ field=models.CharField(blank=True, default="", max_length=9),+ ),+ ]diff --cc saleor/csv/tests/export/products_data/test_get_products_data.pyindex 7632c187d5,b86b466028..c1a995fb82--- a/saleor/csv/tests/export/products_data/test_get_products_data.py+++ b/saleor/csv/tests/export/products_data/test_get_products_data.py@@@ -241,8 -241,9 +241,10 @@@ def test_get_products_data_for_specifierich_text_attribute,color_attribute,boolean_attribute,+ date_attribute,+ date_time_attribute,variant_with_many_stocks,+ swatch_attribute,):# givenproduct.variants.add(variant_with_many_stocks)@@@ -252,8 -253,9 +254,10 @@@product_type_product_reference_attribute,numeric_attribute,rich_text_attribute,+ swatch_attribute,boolean_attribute,+ date_attribute,+ date_time_attribute,)product.product_type.product_attributes.add(file_attribute,@@@ -261,8 -263,9 +265,10 @@@product_type_product_reference_attribute,numeric_attribute,rich_text_attribute,+ swatch_attribute,boolean_attribute,+ date_attribute,+ date_time_attribute,)# add boolean attributediff --cc saleor/csv/tests/export/products_data/test_handle_relations_data.pyindex d491bd4ae3,2917b4bb06..3c54000987--- a/saleor/csv/tests/export/products_data/test_handle_relations_data.py+++ b/saleor/csv/tests/export/products_data/test_handle_relations_data.py@@@ -1046,6 -1038,60 +1057,64 @@@ def test_add_reference_info_to_data_updassert result[pk][expected_header] == values+ def test_add_date_time_attribute_info_to_data(product, date_time_attribute):+ # given+ pk = product.pk+ date_time = datetime(2021, 7, 15, 2, 3)+ attribute_data = AttributeData(+ slug=date_time_attribute.slug,++ value_slug=None,++ value_name=None,+ value=None,+ file_url=None,+ input_type="date-time",+ entity_type=None,+ unit=None,+ rich_text=None,+ boolean=None,+ date_time=date_time,+ )+ input_data = {pk: {}}++ # when+ result = add_attribute_info_to_data(+ product.pk, attribute_data, "product attribute", input_data+ )++ # then+ expected_header = f"{date_time_attribute.slug} (product attribute)"+ assert result[pk][expected_header] == {f"{date_time}"}+++ def test_add_date_attribute_info_to_data(product, date_attribute):+ # given+ pk = product.pk+ date = datetime(2021, 8, 10, 5, 3)+ attribute_data = AttributeData(+ slug=date_attribute.slug,++ value_slug=None,++ value_name=None,+ value=None,+ file_url=None,+ input_type="date",+ entity_type=None,+ unit=None,+ rich_text=None,+ boolean=None,+ date_time=date,+ )+ input_data = {pk: {}}++ # when+ result = add_attribute_info_to_data(+ product.pk, attribute_data, "product attribute", input_data+ )++ # then+ expected_header = f"{date_attribute.slug} (product attribute)"+ assert result[pk][expected_header] == {f"{date.date()}"}++def test_add_numeric_attribute_info_to_data(product, numeric_attribute):# givenpk = product.pk@@@ -1101,35 -1143,6 +1172,36 @@@ def test_add_numeric_attribute_info_to_# thenexpected_header = f"{numeric_attribute.slug} (product attribute)"+ assert result[pk][expected_header] == {name}+++def test_add_swatch_attribute_file_info_to_data(product, swatch_attribute):+ # given+ pk = product.pk+ slug = "white"+ value = "#ffffff"+ attribute_data = AttributeData(+ slug=swatch_attribute.slug,+ value_slug=slug,+ value_name=None,+ value=value,+ file_url=None,+ input_type="swatch",+ entity_type=None,+ unit=None,+ rich_text=None,+ boolean=None,++ date_time=None,+ )+ input_data = {pk: {}}++ # when+ result = add_attribute_info_to_data(+ product.pk, attribute_data, "product attribute", input_data+ )++ # then+ expected_header = f"{swatch_attribute.slug} (product attribute)"assert result[pk][expected_header] == {value}@@@ -1137,12 -1150,10 +1209,12 @@@ def test_add_attribute_info_to_data_no_# givenpk = product.pkslug = "test_attribute_slug"- value = "test value"+ value_slug = "test-value"attribute_data = AttributeData(+ value_slug=value_slug,slug=slug,- value=None,- value=value,+ value_name=None,++ value=None,file_url=None,input_type="file",entity_type=None,@@@ -1247,35 -1255,6 +1323,36 @@@ def test_add_attribute_info_to_data_no_assert result[pk][expected_header] == {""}+def test_add_swatch_attribute_value_info_to_data(product, numeric_attribute):+ # given+ pk = product.pk+ slug = "Logo"+ test_url = "test.txt"+ attribute_data = AttributeData(+ slug=numeric_attribute.slug,+ value_slug=slug,+ value_name=None,+ value=None,+ file_url=test_url,+ input_type="swatch",+ entity_type=None,+ unit=None,+ rich_text=None,+ boolean=None,++ date_time=None,+ )+ input_data = {pk: {}}++ # when+ result = add_attribute_info_to_data(+ product.pk, attribute_data, "product attribute", input_data+ )++ # then+ expected_header = f"{numeric_attribute.slug} (product attribute)"+ assert result[pk][expected_header] == {"http://mirumee.com/media/" + test_url}++def test_add_warehouse_info_to_data(product):# givenpk = product.pkdiff --cc saleor/csv/tests/export/products_data/utils.pyindex 0b6c98a756,51e7cc5fbe..63b94aca7c--- a/saleor/csv/tests/export/products_data/utils.py+++ b/saleor/csv/tests/export/products_data/utils.py@@@ -44,14 -44,14 +44,18 @@@ def get_attribute_value(assigned_attribvalue += f" {attribute.unit}"elif attribute.input_type == AttributeInputType.RICH_TEXT:value = clean_editor_js(value_instance.rich_text, to_string=True)+ elif attribute.input_type == AttributeInputType.SWATCH:+ value = (+ value_instance.file_url if value_instance.file_url else value_instance.value+ )elif attribute.input_type == AttributeInputType.BOOLEAN:value = str(value_instance.boolean)+ elif attribute.input_type == AttributeInputType.DATE:+ value = str(value_instance.date_time.date())+ elif attribute.input_type == AttributeInputType.DATE_TIME:+ value = str(value_instance.date_time)else:- value = value_instance.slug+ value = value_instance.name or value_instance.slugreturn valuediff --cc saleor/csv/utils/__init__.pyindex f1c12fdfdf,36efc13eb2..74f8710e58--- a/saleor/csv/utils/__init__.py+++ b/saleor/csv/utils/__init__.py@@@ -21,12 -21,11 +21,13 @@@ class ProductExportFields}PRODUCT_ATTRIBUTE_FIELDS = {- "value": "attributes__values__slug",+ "value_slug": "attributes__values__slug",+ "value_name": "attributes__values__name","file_url": "attributes__values__file_url","rich_text": "attributes__values__rich_text",+ "value": "attributes__values__value","boolean": "attributes__values__boolean",+ "date_time": "attributes__values__date_time","slug": "attributes__assignment__attribute__slug","input_type": "attributes__assignment__attribute__input_type","entity_type": "attributes__assignment__attribute__entity_type",@@@ -51,12 -50,11 +52,13 @@@}VARIANT_ATTRIBUTE_FIELDS = {- "value": "variants__attributes__values__slug",+ "value_slug": "variants__attributes__values__slug",+ "value_name": "variants__attributes__values__name","file_url": "variants__attributes__values__file_url","rich_text": "variants__attributes__values__rich_text",+ "value": "variants__attributes__values__value","boolean": "variants__attributes__values__boolean",+ "date_time": "variants__attributes__values__date_time","slug": "variants__attributes__assignment__attribute__slug","input_type": "variants__attributes__assignment__attribute__input_type","entity_type": "variants__attributes__assignment__attribute__entity_type",diff --cc saleor/csv/utils/products_data.pyindex b47c4b02b4,97ce4218af..93af8fe536--- a/saleor/csv/utils/products_data.py+++ b/saleor/csv/utils/products_data.py@@@ -298,12 -298,11 +298,13 @@@ AttributeData = namedtuple"input_type","entity_type","unit",+ "value_slug",+ "value_name",+ "value",+ "file_url","rich_text","boolean",+ "date_time",],)@@@ -400,55 -398,41 +402,59 @@@ def add_attribute_info_to_data"""slug = attribute_data.slugheader = None- if slug:- header = f"{slug} ({attribute_owner})"- input_type = attribute_data.input_type- if input_type == AttributeInputType.FILE:- file_url = attribute_data.file_url- value = (- build_absolute_uri(urljoin(settings.MEDIA_URL, file_url))- if file_url- else ""++ if not slug:+ return result_data++ header = f"{slug} ({attribute_owner})"+ value = prepare_attribute_value(attribute_data)++ if header in result_data[pk]:+ result_data[pk][header].add(value) # type: ignore+ else:+ result_data[pk][header] = {value}++ return result_data+++def prepare_attribute_value(attribute_data: AttributeData):+ """Prepare value of attribute value depending on the attribute input type."""+ input_type = attribute_data.input_type+ if input_type == AttributeInputType.FILE:+ file_url = attribute_data.file_url+ value = (+ build_absolute_uri(urljoin(settings.MEDIA_URL, file_url))+ if file_url+ else ""+ )+ elif input_type == AttributeInputType.REFERENCE and attribute_data.value_slug:+ reference_id = attribute_data.value_slug.split("_")[1]+ value = f"{attribute_data.entity_type}_{reference_id}"+ elif input_type == AttributeInputType.NUMERIC:+ value = f"{attribute_data.value_name}"+ if attribute_data.unit:+ value += f" {attribute_data.unit}"+ elif input_type == AttributeInputType.RICH_TEXT:+ value = clean_editor_js(attribute_data.rich_text, to_string=True)+ elif (+ input_type == AttributeInputType.BOOLEAN and attribute_data.boolean is not None+ ):+ value = str(attribute_data.boolean)++ elif input_type == AttributeInputType.DATE:++ value = str(attribute_data.date_time.date())++ elif input_type == AttributeInputType.DATE_TIME:++ value = str(attribute_data.date_time)+ elif input_type == AttributeInputType.SWATCH:+ if attribute_data.file_url:+ value = build_absolute_uri(+ urljoin(settings.MEDIA_URL, attribute_data.file_url))- elif input_type == AttributeInputType.REFERENCE and attribute_data.value:- reference_id = attribute_data.value.split("_")[1]- value = f"{attribute_data.entity_type}_{reference_id}"- elif input_type == AttributeInputType.NUMERIC:- value = f"{attribute_data.value}"- if attribute_data.unit:- value += f" {attribute_data.unit}"- elif input_type == AttributeInputType.RICH_TEXT:- value = clean_editor_js(attribute_data.rich_text, to_string=True)- elif (- input_type == AttributeInputType.BOOLEAN- and attribute_data.boolean is not None- ):- value = str(attribute_data.boolean)- elif input_type == AttributeInputType.DATE:- value = str(attribute_data.date_time.date())- elif input_type == AttributeInputType.DATE_TIME:- value = str(attribute_data.date_time)else:- value = attribute_data.value if attribute_data.value else ""- if header in result_data[pk]:- result_data[pk][header].add(value) # type: ignore- else:- result_data[pk][header] = {value}- return result_data+ value = attribute_data.value+ else:+ value = attribute_data.value_name or attribute_data.value_slug or ""++ return valuedef add_warehouse_info_to_data(diff --cc saleor/graphql/attribute/descriptions.pyindex 875fca5afd,f3fabfb466..856e531f5b--- a/saleor/graphql/attribute/descriptions.py+++ b/saleor/graphql/attribute/descriptions.py@@@ -28,11 -29,9 +29,13 @@@ class AttributeValueDescriptionsSLUG = "Internal representation of a value (unique per attribute)."TYPE = "Type of value (used only when `value` field is set)."FILE = "Represents file URL and content type (if attribute value is a file)."+ VALUE = (+ "Represent value of the attribute value "+ "(e.g. color values for swatch attributes)."+ )VALUES_RANGE = "The range that the returned values should be in."+ DATE_TIME_RANGE = "The date time range that the returned values should be in."+ DATE_RANGE = "The date range that the returned values should be in."VALUE = "Represents the value of the attribute value."RICH_TEXT = "Represents the text (JSON) of the attribute value."BOOLEAN = "Represents the boolean value of the attribute value."diff --cc saleor/graphql/schema.graphqlindex cbf39f042a,ef2c6c3ad5..6f06f7d33b--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@@ -528,8 -532,9 +532,10 @@@ enum AttributeInputTypeEnumREFERENCENUMERICRICH_TEXT+ SWATCHBOOLEAN+ DATE+ DATE_TIME}type AttributeReorderValues {@@@ -698,17 -706,10 +709,18 @@@ type AttributeValueUpdateattributeValue: AttributeValue}+input AttributeValueUpdateInput {+ value: String+ richText: JSONString+ fileUrl: String+ contentType: String+ name: String+}+input BulkAttributeValueInput {id: ID- values: [String!]!+ values: [String!]+ boolean: Boolean}type BulkProductError {