Browse Source

[IMP] check methods

Gogs 7 years ago
parent
commit
20263d0972
2 changed files with 51 additions and 52 deletions
  1. 8 24
      src/App.vue
  2. 43 28
      src/store/actions.js

+ 8 - 24
src/App.vue

@@ -7,7 +7,7 @@
                 customer-step
             tab-content(title="Cómo quieres pagar?")
                 payment-method-step
-            tab-content(v-if="payment === 'cash'" title="Qué monto quieres pagar?")
+            tab-content(v-if="payment === 'cash'" title="Qué monto quieres pagar?" :before-change="checkAmountPaid")
                 payment-cash-step
             tab-content(v-else title="Quieres hacer alguna entrega?")
                 payment-credit-step
@@ -41,31 +41,15 @@
             Loader,
         },
         computed: mapGetters([
-            'cartIsEmpty',
-            'hasSelectedCustomer',
             'payment'
         ]),
-        methods: {
-            checkCart() {
-                if (!this.cartIsEmpty) {
-                    this.notify('Necesitas agregar productos al carrito para continuar')
-                }
-
-                return this.cartIsEmpty
-            },
-            checkCustomer() {
-                if (!this.hasSelectedCustomer) {
-                    this.notify('Necesitas seleccionar un cliente para continuar')
-                }
-
-                return this.hasSelectedCustomer
-            },
-            ...mapActions([
-                'initSale',
-                'notify',
-                'completeSale'
-            ])
-        },
+        methods: mapActions([
+            'initSale',
+            'checkCart',
+            'completeSale',
+            'checkCustomer',
+            'checkAmountPaid'
+        ]),
         mounted() {
             this.initSale(this.$root.pos_instance)
         }

+ 43 - 28
src/store/actions.js

@@ -1,6 +1,7 @@
 const actions = {
     notify({ commit }, payload) {
         openerp.web.notification.do_warn('Atención', payload)
+        return false
     },
     initSale({ commit, dispatch }, payload) {
         commit('setPosInstance', payload)
@@ -20,36 +21,50 @@ const actions = {
             console.error(error)
         })
     },
-    completeSale({ getters }) {
-        return new Promise((resolve, reject) => {
-            let AccountVoucher = new openerp.web.Model('account.voucher')
+    checkCart({ getters, dispatch }) {
+        return getters.cartIsEmpty ||  dispatch('notify', 'Necesitas agregar productos al carrito para continuar')
+    },
+    checkCustomer({ getters, dispatch }) {
+        return getters.hasSelectedCustomer || dispatch('notify', 'Necesitas seleccionar un cliente para continuar')
+    },
+    checkAmountPaid({ getters, dispatch }) {
+        return (getters.payment === 'cash' && getters.amountPaid >= getters.total) || dispatch('notify', 'Necesitar entregar un monto igual o mayor al total')
+    },
+    completeSale({ getters, dispatch }) {
+        // return new Promise((resolve, reject) => {
+        //     let AccountVoucher = new openerp.web.Model('account.voucher')
 
-            AccountVoucher.call('create_from_pos', [
-                {
-                    customer_id: getters.selectedCustomer.id,
-                    payment_term_id: getters.selectedPaymentTerm.id,
-                    journal_id: getters.selectedJournal.id,
-                    account_id: getters.selectedJournal.default_credit_account.id,
-                    cart_items: getters.cartItems.map(item => {
-                        return {
-                            id: item.id,
-                            qty: item.qty,
-                            price: item.list_price
-                        }
-                    }),
-                    cart_total: getters.total,
-                    amount_paid: getters.amountPaid > getters.total ? getters.total : getters.amountPaid
-                }
-            ], {
-                context: new openerp.web.CompoundContext()
-            }).then(response => {
-                console.log(response)
+        //     AccountVoucher.call('create_from_pos', [
+        //         {
+        //             customer_id: getters.selectedCustomer.id,
+        //             payment_term_id: getters.selectedPaymentTerm.id,
+        //             journal_id: getters.selectedJournal.id,
+        //             account_id: getters.selectedJournal.default_credit_account.id,
+        //             cart_items: getters.cartItems.map(item => {
+        //                 return {
+        //                     id: item.id,
+        //                     qty: item.qty,
+        //                     price: item.list_price
+        //                 }
+        //             }),
+        //             cart_total: getters.total,
+        //             amount_paid: getters.amountPaid > getters.total ? getters.total : getters.amountPaid
+        //         }
+        //     ], {
+        //         context: new openerp.web.CompoundContext()
+        //     }).then(response => {
+        //         console.log(response)
 
-                resolve(response)
-            }).fail(error => {
-                reject(error)
-            })
-        })
+        //         resolve(response)
+        //     }).fail(error => {
+        //         reject(error)
+        //     })
+        // })
+
+        dispatch('reset')
+    },
+    reset({ state }) {
+        console.log(state)
     }
 }