|
|
@@ -5,15 +5,17 @@ from django.db import migrations
|
|
5
|
5
|
from django.db.models import CharField, Count, Value
|
|
6
|
6
|
from django.db.models.functions import Concat
|
|
7
|
7
|
|
|
8
|
|
-from oscar.core.loading import get_model
|
|
9
|
|
-
|
|
10
|
|
-# Needed for calling _get_value, the historical model can't be used for that.
|
|
11
|
|
-NonHistoricalProductAttributeValue = get_model('catalogue', 'ProductAttributeValue')
|
|
12
|
|
-
|
|
13
|
|
-
|
|
14
|
8
|
logger = logging.getLogger(__name__)
|
|
15
|
9
|
|
|
16
|
10
|
|
|
|
11
|
+def get_value(attribute_value):
|
|
|
12
|
+ typ = attribute_value.attribute.type
|
|
|
13
|
+ field_name = "value_%s" % typ
|
|
|
14
|
+ value = getattr(attribute_value, field_name)
|
|
|
15
|
+ if hasattr(value, "all"):
|
|
|
16
|
+ value = value.all()
|
|
|
17
|
+ return value
|
|
|
18
|
+
|
|
17
|
19
|
def remove_duplicate_attributes(apps, schema_editor):
|
|
18
|
20
|
"""
|
|
19
|
21
|
Removes duplicate attributes that have the same code and product class.
|
|
|
@@ -83,8 +85,8 @@ def remove_duplicate_attributes(apps, schema_editor):
|
|
83
|
85
|
""" % (
|
|
84
|
86
|
product.id,
|
|
85
|
87
|
attribute.code,
|
|
86
|
|
- NonHistoricalProductAttributeValue._get_value(to_be_used_attribute_value),
|
|
87
|
|
- NonHistoricalProductAttributeValue._get_value(attribute_value)
|
|
|
88
|
+ get_value(to_be_used_attribute_value),
|
|
|
89
|
+ get_value(attribute_value)
|
|
88
|
90
|
)
|
|
89
|
91
|
logger.warning(msg)
|
|
90
|
92
|
|
|
|
@@ -101,4 +103,4 @@ class Migration(migrations.Migration):
|
|
101
|
103
|
|
|
102
|
104
|
operations = [
|
|
103
|
105
|
migrations.RunPython(remove_duplicate_attributes, migrations.RunPython.noop)
|
|
104
|
|
- ]
|
|
|
106
|
+ ]
|