Ver Fonte

[IMP] pricelist show

robert há 6 anos atrás
pai
commit
002b9cd7cc

+ 2 - 1
controllers/product_pricelist.py

@@ -33,7 +33,8 @@ def get_pricelists(type='sale'):
                             'priceSurcharge': i.price_surcharge,
                             'productId': i.product_id.id or None,
                             'productTmplId': i.product_tmpl_id.id or None,
-                            'categoryId': i.categ_id or None
+                            'categoryId': i.categ_id or None,
+                            'companyId': i.company_id.id or None
                         } for i in v.items_id
                     ],
                 } for v in p.version_id

+ 3 - 9
src/components/steps/Product.vue

@@ -28,15 +28,8 @@
                 @onCancel='hideProductForm'
             )
             variant-modal
-            //- discount-modal(
-            //-     :item='itemToDiscount' 
-            //-     :options='baseCurrency'
-            //-     :show='!!itemToDiscount'
-            //-     @onAccept='applyPrice'
-            //-     @onCancel='applyPrice'
-            //- )
             pricelist-modal(
-                :show='!!itemToDiscount'
+                :show='showPricelists'
                 :items='pricelistsForProduct'
                 @onApply='applyPrice'
                 @onCancel='applyPrice'
@@ -86,7 +79,8 @@
                 'showingProductForm',
                 'cartItems',
                 'itemToDiscount',
-                'baseCurrency'
+                'baseCurrency',
+                'showPricelists'
             ])
         },
         methods: mapActions([

+ 10 - 2
src/store/modules/cart.js

@@ -85,15 +85,23 @@ const actions = {
     undoPrice ({ commit }, payload) {
         commit('resetPrice', payload)
     },
-    changePrice ({ commit }, payload) {
+    changePrice ({ commit, getters, dispatch }, payload) {
         commit('setItemToDiscount', payload)
+
+        if (getters.pricelistsForProduct.length === 0) {
+            dispatch('notify', 'Este producto no posee lista de precios')
+            return
+        }
+
+        dispatch('togglePricelists')
     },
-    applyPrice ({ commit }, payload) {
+    applyPrice ({ commit, dispatch }, payload) {
         if (payload) {
             commit('setItemPrice', payload)
         }
 
         commit('setItemToDiscount', null)
+        dispatch('togglePricelists')
     },
     removeFromCart ({ commit }, payload) {
         commit('pullFromCart', {

+ 9 - 8
src/store/modules/pricelist.js

@@ -12,12 +12,13 @@ const getters = {
         return state.pricelists
     },
     pricelistsForProduct(state, getters) {
-        let item = getters.itemToDiscount
+        let product = getters.itemToDiscount
 
-        if (!item) {
+        if (!product) {
             return []
         }
 
+        let companyId = getters.selectedUser.company.id
         let pricelists = []
 
         for (let p of state.pricelists) {
@@ -27,7 +28,11 @@ const getters = {
 
             for (let v of p.versions) {
                 for (let i of v.items) {
-                    if (i.productId !== item.id && i.productTmplId !== item.tmplId && i.categoryId !== item.categoryId) {
+                    if (i.productId !== product.id && i.productTmplId !== product.tmplId && i.categoryId !== product.categoryId) {
+                        continue
+                    }
+
+                    if (!i.productId && i.productId !== companyId) {
                         continue
                     }
 
@@ -55,11 +60,7 @@ const mutations = {
     setPricelists(state, pricelists) {
         state.pricelists = pricelists
     },
-    togglePricelists(state, pricelistId) {
-        if (!pricelistId) {
-            return
-        }
-
+    togglePricelists(state) {
         state.showPricelists = !state.showPricelists
     }
 }