Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
feat: add data mmigration to make order_lineattribute value json comp…
Browse files Browse the repository at this point in the history
…atible
  • Loading branch information
mumarkhan999 committed Jan 30, 2024
1 parent 5e90f5c commit 8e944b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from django.core.paginator import Paginator
from django.db import migrations

Check warning on line 3 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L2-L3

Added lines #L2 - L3 were not covered by tests


def make_lineattribute_value_json_compatible(apps, schema_editor):

Check warning on line 6 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L6

Added line #L6 was not covered by tests
"""
Makes line attribute value json compatible.
"""
LineAttribute = apps.get_model("order", "LineAttribute")
attributes = LineAttribute.objects.order_by('id')
paginator = Paginator(attributes, 1000)

Check warning on line 12 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L10-L12

Added lines #L10 - L12 were not covered by tests

for page_number in paginator.page_range:
page = paginator.page(page_number)
updates = []

Check warning on line 16 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L14-L16

Added lines #L14 - L16 were not covered by tests

for obj in page.object_list:
obj.value = '"{}"'.format(obj.value)
updates.append(obj)

Check warning on line 20 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L18-L20

Added lines #L18 - L20 were not covered by tests

LineAttribute.objects.bulk_update(updates, ['value'])

Check warning on line 22 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L22

Added line #L22 was not covered by tests


class Migration(migrations.Migration):

Check warning on line 25 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L25

Added line #L25 was not covered by tests

dependencies = [

Check warning on line 27 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L27

Added line #L27 was not covered by tests
('order', '0026_auto_20231108_1355'),
]

operations = [

Check warning on line 31 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L31

Added line #L31 was not covered by tests
migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

Check warning on line 7 in ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py#L7

Added line #L7 was not covered by tests

dependencies = [

Check warning on line 9 in ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py#L9

Added line #L9 was not covered by tests
('order', '0026_auto_20231108_1355'),
('order', '0027_make_lineattribute_value_json_compatible'),
]

operations = [

Check warning on line 13 in ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/order/migrations/0028_alter_lineattribute_value.py#L13

Added line #L13 was not covered by tests
Expand Down

0 comments on commit 8e944b0

Please sign in to comment.