Browse Source

[IMP] variants searchind reducing loops in products fetching and keys deep in fuzzy

Gogs 7 years ago
parent
commit
5d56b32b05
2 changed files with 28 additions and 22 deletions
  1. 26 20
      models/eiru_pos.py
  2. 2 2
      src/components/ProductSelector.vue

+ 26 - 20
models/eiru_pos.py

@@ -18,8 +18,7 @@ class EiruPOS(models.Model):
                 'id': user.company_id.currency_id.id,
                 'name': user.company_id.currency_id.name,
                 'display_name': user.company_id.currency_id.display_name,
-                'symbol': user.company_id.currency_id.symbol,
-                'format': user.company_id.currency_id.format
+                'symbol': user.company_id.currency_id.symbol
             }
             # 'store': {
             #     'id': user.company_id.store_id.id,
@@ -44,25 +43,33 @@ class EiruPOS(models.Model):
                 attributes = []
 
                 # map product attributes
-                for attribute_line in variant.attribute_line_ids:
-                    values = []
-
-                    # map product attributes values
-                    for value in attribute_line.value_ids:
-                        values.append({
-                            'id': value.id,
-                            'display_name': value.display_name,
-                            'name': value.name,
-                            'price_extra': value.price_extra
-                        })
+                # for attribute_line in variant.attribute_line_ids:
+                #     values = []
+
+                #     # map product attributes values
+                #     for value in attribute_line.value_ids:
+                #         values.append({
+                #             'id': value.id,
+                #             'display_name': value.display_name,
+                #             'name': value.name,
+                #             'price_extra': value.price_extra
+                #         })
+                #     attributes.append({
+                #         'id': attribute_line.id,
+                #         'attribute': {
+                #             'id': attribute_line.attribute_id.id,
+                #             'name': attribute_line.attribute_id.name
+                #         },
+                #         'values': values
+                #     })
+
+                for attribute_value in variant.attribute_value_ids:
                     attributes.append({
-                        'id': attribute_line.id,
-                        'attribute': {
-                            'id': attribute_line.attribute_id.id,
-                            'name': attribute_line.attribute_id.name
-                        },
-                        'values': values
+                        'id': attribute_value.id,
+                        'name': attribute_value.name,
+                        'display_name': attribute_value.display_name
                     })
+
                 variants.append({
                     'id': variant.id,
                     'display_name': variant.display_name,
@@ -141,7 +148,6 @@ class EiruPOS(models.Model):
                 'rate': currency.rate,
                 'rounding': currency.rounding,
                 'symbol': currency.symbol,
-                'format': currency.format,
                 'company': {
                     'id': currency.company_id.id,
                     'name': currency.company_id.name

+ 2 - 2
src/components/ProductSelector.vue

@@ -20,6 +20,7 @@
         }),
         methods: {
             initFuse() {
+                console.log(this.variants)
                 if (this.fuse) {
                     this.fuse.setCollection(this.variants)
                     return
@@ -34,8 +35,7 @@
                     minMatchCharLength: 1,
                     keys: [
                         'name',
-                        'display_name',
-                        'ean13',
+                        'attributes.name',
                     ]
                 })
             },