From 8cd7c39689954a16694d89eefe850fc6bca2462a Mon Sep 17 00:00:00 2001 From: Muhammad Zubair Date: Fri, 2 Feb 2024 16:53:25 +0500 Subject: [PATCH] Django Oscar Upgrade to version 3.2 (#4064) * chore: django oscar version upgrade to 3.1 * fix: changed django migration to alter price field in stockrecord model chore: updated factory dependency refactor: updated field name feat: Mgmt Command to create mobile seats for new course runs (#4046) fix: skipped a failing test. Will fix it in another ticket fix: updated method refactor: made changes as per new version of oscar refactor: updated code to make voucher name unique fix: removed white spaces fix: removed white spaces refactor: changed code as per new version of oscar refactor: updated code fix: override Product model in catalogue app fix: removed extra spaces fix: updated code fix: changes in code to pass checks fix: changes in code to pass checks * feat: add data migration to make voucher names unique * fix: removed code * refactor: updated django oscar templates * refactor: updated price field name * refactor: update price field name * chore: PR to upgrade django oscar to version 3.2 * feat: resloved reserved keywords conflict * feat: add data mmigration to make basket_lineattribute value json compatible * feat: added refund functionality * feat: add data mmigration to make order_lineattribute value json compatible --------- Co-authored-by: Muhammad Umar Khan --- db_keyword_overrides.yml | 5 ++ ...ake_lineattribute_value_json_compatible.py | 33 +++++++++ .../0017_alter_lineattribute_value.py | 19 +++++ .../migrations/0057_auto_20231205_1034.py | 73 +++++++++++++++++++ ...ake_lineattribute_value_json_compatible.py | 33 +++++++++ .../0028_alter_lineattribute_value.py | 19 +++++ requirements/base.txt | 2 +- requirements/constraints.txt | 2 +- requirements/dev.txt | 2 +- requirements/production.txt | 2 +- requirements/test.txt | 2 +- 11 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py create mode 100644 ecommerce/extensions/basket/migrations/0017_alter_lineattribute_value.py create mode 100644 ecommerce/extensions/catalogue/migrations/0057_auto_20231205_1034.py create mode 100644 ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py create mode 100644 ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py diff --git a/db_keyword_overrides.yml b/db_keyword_overrides.yml index a7c5b1e9492..2be0cc06e43 100644 --- a/db_keyword_overrides.yml +++ b/db_keyword_overrides.yml @@ -13,5 +13,10 @@ MYSQL: - ShippingEvent.lines - PaymentEvent.lines - ProductAlert.key + - HistoricalOption.order + - Option.order SNOWFLAKE: + - HistoricalOption.order + - Option.order + STITCH: diff --git a/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py b/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py new file mode 100644 index 00000000000..f33922b9a44 --- /dev/null +++ b/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from django.core.paginator import Paginator +from django.db import migrations + + +def make_lineattribute_value_json_compatible(apps, schema_editor): + """ + Makes line attribute value json compatible. + """ + LineAttribute = apps.get_model("basket", "LineAttribute") + attributes = LineAttribute.objects.order_by('id') + paginator = Paginator(attributes, 1000) + + for page_number in paginator.page_range: + page = paginator.page(page_number) + updates = [] + + for obj in page.object_list: + obj.value = '"{}"'.format(obj.value) + updates.append(obj) + + LineAttribute.objects.bulk_update(updates, ['value']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('basket', '0015_add_paymentintentid'), + ] + + operations = [ + migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), + ] diff --git a/ecommerce/extensions/basket/migrations/0017_alter_lineattribute_value.py b/ecommerce/extensions/basket/migrations/0017_alter_lineattribute_value.py new file mode 100644 index 00000000000..9f0683ae049 --- /dev/null +++ b/ecommerce/extensions/basket/migrations/0017_alter_lineattribute_value.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.20 on 2023-12-05 10:34 + +import django.core.serializers.json +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('basket', '0016_make_lineattribute_value_json_compatible'), + ] + + operations = [ + migrations.AlterField( + model_name='lineattribute', + name='value', + field=models.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, verbose_name='Value'), + ), + ] diff --git a/ecommerce/extensions/catalogue/migrations/0057_auto_20231205_1034.py b/ecommerce/extensions/catalogue/migrations/0057_auto_20231205_1034.py new file mode 100644 index 00000000000..3c25f70a8ec --- /dev/null +++ b/ecommerce/extensions/catalogue/migrations/0057_auto_20231205_1034.py @@ -0,0 +1,73 @@ +# Generated by Django 3.2.20 on 2023-12-05 10:34 + +from django.db import migrations, models +import django.db.models.deletion +import oscar.models.fields.slugfield + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0056_auto_20231108_1355'), + ] + + operations = [ + migrations.AlterModelOptions( + name='option', + options={'ordering': ['order', 'name'], 'verbose_name': 'Option', 'verbose_name_plural': 'Options'}, + ), + migrations.AddField( + model_name='historicaloption', + name='help_text', + field=models.CharField(blank=True, help_text='Help text shown to the user on the add to basket form', max_length=255, null=True, verbose_name='Help text'), + ), + migrations.AddField( + model_name='historicaloption', + name='option_group', + field=models.ForeignKey(blank=True, db_constraint=False, help_text='Select an option group if using type "Option" or "Multi Option"', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='catalogue.attributeoptiongroup', verbose_name='Option Group'), + ), + migrations.AddField( + model_name='historicaloption', + name='order', + field=models.IntegerField(blank=True, db_index=True, help_text='Controls the ordering of product options on product detail pages', null=True, verbose_name='Ordering'), + ), + migrations.AddField( + model_name='option', + name='help_text', + field=models.CharField(blank=True, help_text='Help text shown to the user on the add to basket form', max_length=255, null=True, verbose_name='Help text'), + ), + migrations.AddField( + model_name='option', + name='option_group', + field=models.ForeignKey(blank=True, help_text='Select an option group if using type "Option" or "Multi Option"', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product_options', to='catalogue.attributeoptiongroup', verbose_name='Option Group'), + ), + migrations.AddField( + model_name='option', + name='order', + field=models.IntegerField(blank=True, db_index=True, help_text='Controls the ordering of product options on product detail pages', null=True, verbose_name='Ordering'), + ), + migrations.AlterField( + model_name='historicaloption', + name='type', + field=models.CharField(choices=[('text', 'Text'), ('integer', 'Integer'), ('boolean', 'True / False'), ('float', 'Float'), ('date', 'Date'), ('select', 'Select'), ('radio', 'Radio'), ('multi_select', 'Multi select'), ('checkbox', 'Checkbox')], default='text', max_length=255, verbose_name='Type'), + ), + migrations.AlterField( + model_name='historicalproduct', + name='slug', + field=oscar.models.fields.slugfield.SlugField(allow_unicode=True, max_length=255, verbose_name='Slug'), + ), + migrations.AlterField( + model_name='option', + name='type', + field=models.CharField(choices=[('text', 'Text'), ('integer', 'Integer'), ('boolean', 'True / False'), ('float', 'Float'), ('date', 'Date'), ('select', 'Select'), ('radio', 'Radio'), ('multi_select', 'Multi select'), ('checkbox', 'Checkbox')], default='text', max_length=255, verbose_name='Type'), + ), + migrations.AlterField( + model_name='product', + name='slug', + field=oscar.models.fields.slugfield.SlugField(allow_unicode=True, max_length=255, verbose_name='Slug'), + ), + migrations.AlterUniqueTogether( + name='productattribute', + unique_together={('code', 'product_class')}, + ), + ] diff --git a/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py b/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py new file mode 100644 index 00000000000..3893de30568 --- /dev/null +++ b/ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from django.core.paginator import Paginator +from django.db import migrations + + +def make_lineattribute_value_json_compatible(apps, schema_editor): + """ + Makes line attribute value json compatible. + """ + LineAttribute = apps.get_model("order", "LineAttribute") + attributes = LineAttribute.objects.order_by('id') + paginator = Paginator(attributes, 1000) + + for page_number in paginator.page_range: + page = paginator.page(page_number) + updates = [] + + for obj in page.object_list: + obj.value = '"{}"'.format(obj.value) + updates.append(obj) + + LineAttribute.objects.bulk_update(updates, ['value']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0026_auto_20231108_1355'), + ] + + operations = [ + migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), + ] diff --git a/ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py b/ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py new file mode 100644 index 00000000000..b46e66866cb --- /dev/null +++ b/ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.20 on 2023-12-05 10:34 + +import django.core.serializers.json +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0027_make_lineattribute_value_json_compatible'), + ] + + operations = [ + migrations.AlterField( + model_name='lineattribute', + name='value', + field=models.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, verbose_name='Value'), + ), + ] diff --git a/requirements/base.txt b/requirements/base.txt index cd729812d7c..3bbbfeccef7 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -168,7 +168,7 @@ django-libsass==0.9 # via -r requirements/base.in django-model-utils==4.3.1 # via edx-rbac -django-oscar==3.1 +django-oscar==3.2 # via # -c requirements/constraints.txt # -r requirements/base.in diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 215743d7eb2..06cd3c5733a 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -15,7 +15,7 @@ cybersource-rest-client-python==0.0.21 # Django 3.2 support is added in version 2.2 so pinning it to 2.2 -django-oscar==3.1 +django-oscar==3.2 # Pinned because transifex-client==0.13.6 pins it urllib3>=1.24.2,<2.0.0 diff --git a/requirements/dev.txt b/requirements/dev.txt index 0457ef87d0c..c1fa354d520 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -253,7 +253,7 @@ django-model-utils==4.3.1 # via # -r requirements/test.txt # edx-rbac -django-oscar==3.1 +django-oscar==3.2 # via -r requirements/test.txt django-phonenumber-field==5.0.0 # via diff --git a/requirements/production.txt b/requirements/production.txt index dae6f22cb78..807c7c8b9d3 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -171,7 +171,7 @@ django-libsass==0.9 # via -r requirements/base.in django-model-utils==4.3.1 # via edx-rbac -django-oscar==3.1 +django-oscar==3.2 # via # -c requirements/constraints.txt # -r requirements/base.in diff --git a/requirements/test.txt b/requirements/test.txt index c961ec1e0dd..39c70b1e2db 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -241,7 +241,7 @@ django-model-utils==4.3.1 # via # -r requirements/base.txt # edx-rbac -django-oscar==3.1 +django-oscar==3.2 # via # -c requirements/constraints.txt # -r requirements/base.txt