Browse Source

[FIX] steps checks

Gogs 7 years ago
parent
commit
b015b21f18
5 changed files with 40 additions and 8 deletions
  1. 10 5
      src/App.vue
  2. 1 1
      src/components/steps/Product.vue
  3. 1 1
      src/components/steps/Supplier.vue
  4. 2 0
      src/index.js
  5. 26 1
      src/store/app.js

+ 10 - 5
src/App.vue

@@ -7,7 +7,7 @@
                 product-step
             tab-content(title='Cómo quieres pagar?')
                 payment-method-step
-            tab-content(title='Qué monto vas a pagar?')
+            tab-content(title='Qué monto vas a pagar?' :before-change='checkAmountReceived')
                 payment-amount-step
 </template>
 
@@ -36,10 +36,15 @@
             'state'
 
         ]),
-        methods: mapActions([
-            'initPurchase',
-            'createPurchase'
-        ]),
+        methods: {
+            ...mapActions([
+                'initPurchase',
+                'checkSupplier',
+                'checkCart',
+                'checkAmountReceived',
+                'createPurchase'
+            ])
+        },
         watch: {
             state(value) {
                 if (value === 'done') {

+ 1 - 1
src/components/steps/Product.vue

@@ -1,7 +1,7 @@
 <template lang="pug">
     .purchase-step
         .products-selector
-            searcher(:items='products' :keys="['name', 'displayName']" @onSearch='filterProducts')
+            searcher(:items='products' :keys="['name', 'displayName', 'ean13']" @onSearch='filterProducts')
             card-grid(:items='visibleProducts' :loading='loadingProducts' @onSelect='selectProduct')
         cart(:items='cartItems' @onIncrementQty='addToCart' @onDecrementQty='decreaseFromCart' @onDeleteItem='removeFromCart' @onTotalComputed='updateCartTotal' :options='selectedCurrency')
 </template>

+ 1 - 1
src/components/steps/Supplier.vue

@@ -2,7 +2,7 @@
     .purchase-step
         .supplier-selection-step
             .supplier-selector
-                searcher(:items='suppliers' :keys="['name', 'displayName']" @onSearch='filterSuplliers')
+                searcher(:items='suppliers' :keys="['name', 'displayName', 'phone', 'mobile', 'email']" @onSearch='filterSuppliers')
                 card-grid(:items='visibleSuppliers' :loading='loadingSuppliers' @onSelect='selectSupplier')
             transition(name='slide-fade')
                 customer-form

+ 2 - 0
src/index.js

@@ -36,6 +36,8 @@ openerp.eiru_purchases = (instance, local) => {
             })
         },
         destroy() {
+            window.alert('destroyed 1')
+
             this.vm.$destroy()
             $(this.vm.$el).remove()
             this.vm = null

+ 26 - 1
src/store/app.js

@@ -4,7 +4,7 @@ import * as Urls from '../constants/resourcePaths'
 
 const state = {
     currentMode: Modes.PURCHASE,
-    currentState: States.NONE
+    currentState: States.NONE,
 }
 
 const getters = {
@@ -106,6 +106,31 @@ const actions = {
             console.log(response)
         }).catch(error => console.log(error))
     },
+    /**
+     * 
+     * @param {*} param0 
+     */
+    checkSupplier({ getters, dispatch}) {
+        return !!getters.selectedSupplier || dispatch('notify', 'Necesitas seleccionar un proveedor para continuar')
+    },
+    /**
+     * 
+     * @param {*} param0 
+     */
+    checkCart({ getters, dispatch}) {
+        return !!getters.cartItems.length || dispatch('notify', 'Necesitar agregar producto al carrito para continuar')
+    },
+    /**
+     * 
+     * @param {*} param0 
+     */
+    checkAmountReceived({ getters, dispatch }) {
+        if (getters.paymentType == 'cash') {
+            return getters.initialPayment >= getters.cartTotal || dispatch('notify', 'El monto recibido no puede ser menor al monto a pagar')
+        } else {
+            return getters.initialPayment < getters.cartTotal || dispatch('notify', 'El monto recibido no puede ser igual o mayor al monto a pagar')
+        }
+    },
     /**
      * 
      * @param {*} param0