Переглянути джерело

[ADD] customer add from customer step ok

Gogs 7 роки тому
батько
коміт
c15dce7991

+ 16 - 1
controllers/main.py

@@ -205,4 +205,19 @@ class Sales(http.Controller):
     def create_customer(self, **kw):
         self.make_info_log('Creating customer')
 
-        print(kw)
+        customer = request.env['res.partner'].create({
+            'name': kw.get('name'),
+            'ruc': kw.get('ruc'),
+            'phone': kw.get('phone'),
+            'customer': True
+        })
+
+        return {
+            'id': customer.id,
+            'name': customer.name,
+            'displayName': customer.display_name,
+            'imageMedium': customer.image_medium,
+            'phone': customer.phone,
+            'mobile': customer.mobile,
+            'email': customer.email
+        }

+ 14 - 4
src/components/forms/CustomerForm.vue

@@ -9,13 +9,13 @@
                 hr
             .form-item(:class="'form-item-' + type")
                 label.form-label(:class="'form-label-' + type") Nombre
-                input.form-input(:class="'form-input-' + type" :value="customer.name || ''" readonly)
+                input.form-input(:class="'form-input-' + type" :value="customer.name || ''" v-model='customer.name' :readonly="mode === 'details'")
             .form-item(:class="'form-item-' + type")
                 label.form-label(:class="'form-label-' + type") R.U.C/C.I.Nº
-                input.form-input(:class="'form-input-' + type" :value="customer.ruc || ''" readonly)
+                input.form-input(:class="'form-input-' + type" :value="customer.ruc || ''" v-model='customer.ruc' :readonly="mode === 'details'")
             .form-item(:class="'form-item-' + type")
                 label.form-label(:class="'form-label-' + type") Celular
-                input.form-input(:class="'form-input-' + type" :value="customer.phone || ''" readonly)
+                input.form-input(:class="'form-input-' + type" :value="customer.phone || ''" v-model='customer.phone' :readonly="mode === 'details'")
             div(v-if="mode === 'details'")
                 .form-item(:class="'form-item-' + type")
                     label.form-label(:class="'form-label-' + type") Teléfono
@@ -71,11 +71,21 @@
         },
         methods: {
             onAccept() {
-                this.$emit('onAccept')
+                this.$emit('onAccept', this.customer)
             },
             onCancel() {
                 this.$emit('onCancel')
             }
+        },
+        mounted() {
+               this.customer = {
+                    name: '',
+                    ruc: '',
+                    phone: '',
+                    mobile: '',
+                    email: '',
+                    credit: 0
+                }
         }
     }
 </script>

+ 2 - 2
src/components/modals/CustomerModal.vue

@@ -36,8 +36,8 @@
                     e.stop()
                 }
             },
-            onAccept() {
-                this.$emit('onAccept')
+            onAccept(e) {
+                this.$emit('onAccept', e)
             },
             onCancel() {
                 this.$emit('onCancel')

+ 3 - 0
src/constants/actionTypes.js

@@ -28,6 +28,8 @@ const SUBMIT_CUSTOMER = 'submitCustomer'
 
 const CREATE_CUSTOMER = 'createCustomer'
 
+const RECEIVE_CUSTOMER = 'receiveCustomer'
+
 const SELECT_CUSTOMER = 'selectCustomer'
 
 const INIT_CURRENCIES = 'initCurrencies'
@@ -52,6 +54,7 @@ export {
     HIDE_CUSTOMER_FORM,
     SUBMIT_CUSTOMER,
     CREATE_CUSTOMER,
+    RECEIVE_CUSTOMER,
     SELECT_CUSTOMER,
     INIT_CURRENCIES,
     ADD_TO_CART,

+ 10 - 20
src/constants/mutationTypes.js

@@ -30,6 +30,8 @@ const SET_SHOW_CUSTOMER_FORM = 'setShowCustomerForm'
 
 const SET_SELECTED_CUSTOMER = 'setSelectedCustomer'
 
+const ADD_CUSTOMER = 'addCustomer'
+
 const SET_CURRENCIES = 'setCurrencies'
 
 const SET_LOADING_CURRENCIES = 'setLoadingCurrencies'
@@ -39,24 +41,12 @@ const PUSH_TO_CART = 'pushToCart'
 const SET_CART_TOTAL = 'setCartTotal'
 
 export {
-    SET_USER,
-    SET_LOADING_USER,
-    SET_PRODUCTS,
-    SET_LOADING_PRODUCTS,
-    SELECT_PRODUCT,
-    SET_PRODUCT_WITH_VARIANT,
-    SET_PAYMENT_TERMS,
-    SET_LOADING_PAYMENT_TERMS,
-    SET_JOURNALS,
-    SET_LOADING_JOURNALS,
-    SET_DATE,
-    SET_LOADING_DATE,
-    SET_CUSTOMERS,
-    SET_LOADING_CUSTOMERS,
-    SET_SHOW_CUSTOMER_FORM,
-    SET_SELECTED_CUSTOMER,
-    SET_CURRENCIES,
-    SET_LOADING_CURRENCIES,
-    PUSH_TO_CART,
-    SET_CART_TOTAL
+    SET_USER, SET_LOADING_USER, // User
+    SET_PRODUCTS, SET_LOADING_PRODUCTS, SELECT_PRODUCT, SET_PRODUCT_WITH_VARIANT, // Product
+    SET_PAYMENT_TERMS, SET_LOADING_PAYMENT_TERMS, // Payment Term
+    SET_JOURNALS, SET_LOADING_JOURNALS, // Journal
+    SET_DATE, SET_LOADING_DATE, // Date
+    SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SHOW_CUSTOMER_FORM, SET_SELECTED_CUSTOMER, ADD_CUSTOMER, // Customer
+    SET_CURRENCIES, SET_LOADING_CURRENCIES, // Currency
+    PUSH_TO_CART, SET_CART_TOTAL // Cart
 }

+ 2 - 2
src/store/actions.js

@@ -1,6 +1,6 @@
 import axios from 'axios'
 import { INIT_SALE_URL, CREATE_CUSTOMER_URL, PROCESS_SALE_URL } from '@/constants/resourcePaths'
-import { INIT_SALE, NOTIFY, EXPLODE_DATA, CREATE_CUSTOMER, CREATE_SALE } from '@/constants/actionTypes'
+import { INIT_SALE, NOTIFY, EXPLODE_DATA, CREATE_CUSTOMER, RECEIVE_CUSTOMER, CREATE_SALE } from '@/constants/actionTypes'
 
 const actions = {
     /**
@@ -43,7 +43,7 @@ const actions = {
         }
 
         return axios.post(CREATE_CUSTOMER_URL, data).then(response => {
-            console.log(response)
+            dispatch(RECEIVE_CUSTOMER, response.data.result)
         }).catch(error => {
             console.log(error)
         })

+ 22 - 3
src/store/modules/customer.js

@@ -1,5 +1,5 @@
-import { SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SHOW_CUSTOMER_FORM, SET_SELECTED_CUSTOMER } from '@/constants/mutationTypes'
-import { INIT_CUSTOMERS, SHOW_CUSTOMER_FORM, HIDE_CUSTOMER_FORM, SUBMIT_CUSTOMER, CREATE_CUSTOMER, SELECT_CUSTOMER } from '@/constants/actionTypes'
+import { SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SHOW_CUSTOMER_FORM, SET_SELECTED_CUSTOMER, ADD_CUSTOMER } from '@/constants/mutationTypes'
+import { INIT_CUSTOMERS, SHOW_CUSTOMER_FORM, HIDE_CUSTOMER_FORM, SUBMIT_CUSTOMER, CREATE_CUSTOMER, RECEIVE_CUSTOMER, SELECT_CUSTOMER } from '@/constants/actionTypes'
 
 const initialState = {
     customers: [],
@@ -71,6 +71,14 @@ const mutations = {
     [SET_SHOW_CUSTOMER_FORM] (state, payload) {
         state.showingCustomerForm = !!payload
     },
+    /**
+     * 
+     * @param {*} state 
+     * @param {*} payload 
+     */
+    [ADD_CUSTOMER] (state, payload) {
+        state.customers = [payload, ...state.customers]
+    },
     /**
      * 
      * @param {*} state 
@@ -110,8 +118,19 @@ const actions = {
      * 
      * @param {*} param0 
      */
-    [SUBMIT_CUSTOMER] ({ dispatch }, payload) {
+    [SUBMIT_CUSTOMER] ({ commit, dispatch }, payload) {
+        commit(SET_LOADING_CUSTOMERS, true)
         dispatch(CREATE_CUSTOMER, payload)
+        dispatch(HIDE_CUSTOMER_FORM)
+    },
+    /**
+     * 
+     * @param {*} param0 
+     * @param {*} payload 
+     */
+    [RECEIVE_CUSTOMER] ({ commit }, payload) {
+        commit(ADD_CUSTOMER, payload)
+        commit(SET_LOADING_CUSTOMERS, false)
     },
     /**
      *