Bläddra i källkod

[FIX] compute prices recursively

robert 6 år sedan
förälder
incheckning
b2d5d9c06d

+ 1 - 4
controllers/product_template.py

@@ -44,8 +44,6 @@ def get_products(image_type='small', location_ids=None):
             'variantCount': p.product_variant_count,
             'quantity': 1,
             'price': p.list_price,
-            'minimumPrice': p.minimum_price,
-            'maximumPrice': p.maximum_price,
             'discount': 0,
             'categoryId': p.categ_id.id or None,
             'variants': [{
@@ -55,10 +53,9 @@ def get_products(image_type='small', location_ids=None):
                 'defaultCode': p.default_code,
                 'image': v.image_small if image_type == 'small' else v.image_medium,
                 'listPrice': v.list_price,
+                'standardPrice': v.standard_price,
                 'quantity': 1,
                 'price': v.list_price,
-                'minimumPrice': p.minimum_price,
-                'maximumPrice': p.maximum_price,
                 'discount': 0,
                 'pricelistId': v.pricelist_id.id or None,
                 'locations': in_locations.get(v.id, []),

+ 47 - 5
src/components/modals/PricelistModal.vue

@@ -2,8 +2,8 @@
     modal(
         name='pricelist-modal'
         transition='nice-modal-fade'
-        width='400px'
-        height='600px'
+        width='300px'
+        height='500px'
         :classes="['v--modal', 'pricelist-modal']"
         @before-close='beforeClose'
     )
@@ -34,6 +34,10 @@
             items: {
                 type: Array,
                 default: []
+            },
+            pricelists: {
+                type: Array,
+                default: []
             }
         },
         watch: {
@@ -53,7 +57,45 @@
                 }
             },
             computePrice(item) {
-                return (item.productPrice * (1 + item.priceDiscount)) + item.priceSurcharge
+                let price = 0
+
+                switch (item.base) {
+                    case 1:
+                        price = item.productPrice
+                        break
+                    case 2:
+                        price = item.standardPrice
+                        break
+                    case -1:
+                        let basePrice = 0
+
+                        for (let p of this.pricelists) {
+                            if (p.id !== item.basePricelistId) {
+                                continue
+                            }
+
+                            for (let v of p.versions) {
+                                for (let i of v.items) {
+                                    basePrice = this.computePrice({
+                                        pricelistName: p.name,
+                                        versionName: v.name,
+                                        productPrice: item.productPrice,
+                                        productCost: item.standardPrice,
+                                        ...i                
+                                    })
+                                }
+                            }
+
+                            break
+                        }
+
+                        price = basePrice
+                        break
+                    // case -2:
+                    //     break;
+                }
+                
+                return (price * (1 + item.priceDiscount)) + item.priceSurcharge
             },
             onApply(item) {
                 const price = this.computePrice(item)
@@ -74,7 +116,7 @@
             height: 100%
             padding: 15px
             h1
-                font-size: 12pt
+                font-size: 10pt
                 color: #757575
             .pricelist-items-wrapper
                 width: 100%
@@ -96,7 +138,7 @@
             .pricelist-options
                 float: right
                 .pricelist-option
-                    width: 160px
+                    width: 100px
                     height: 40px
                     border: none
                     box-shadow: none

+ 2 - 0
src/components/steps/Product.vue

@@ -31,6 +31,7 @@
             pricelist-modal(
                 :show='showPricelists'
                 :items='pricelistsForProduct'
+                :pricelists='pricelists'
                 @onApply='applyPrice'
                 @onCancel='applyPrice'
             )
@@ -69,6 +70,7 @@
             ...mapGetters([
                 'products',
                 'pricelistsForProduct',
+                'pricelists',
                 'visibleProducts',
                 'variants',
                 'stores',

+ 2 - 1
src/store/modules/pricelist.js

@@ -39,7 +39,8 @@ const getters = {
                     pricelists.push({
                         pricelistName: p.name,
                         versionName: v.name,
-                        productPrice: getters.itemToDiscount.listPrice,
+                        productPrice: product.listPrice,
+                        productCost: product.standardPrice,
                         ...i
                     })
                 }