Bläddra i källkod

[ADD] create resource path for customer creation

Gogs 7 år sedan
förälder
incheckning
3842ef06c9
4 ändrade filer med 33 tillägg och 4 borttagningar
  1. 11 1
      controllers/main.py
  2. 3 0
      src/constants/actionTypes.js
  3. 16 0
      src/store/actions.js
  4. 3 3
      src/store/modules/customer.js

+ 11 - 1
controllers/main.py

@@ -195,4 +195,14 @@ class Sales(http.Controller):
             'customers': self.get_customers(),
             'products': self.get_products(),
             'paymentTerms': self.get_payment_terms()
-        })
+        })
+
+    
+    '''
+        Create customer and return data
+    '''
+    @http.route('/eiru_sales/create_customer', auth='user', methods=['POST'], cors='*')
+    def create_customer(self, **kw):
+        self.make_info_log('Creating customer')
+
+        print(kw)

+ 3 - 0
src/constants/actionTypes.js

@@ -18,6 +18,8 @@ const HIDE_CUSTOMER_FORM = 'hideCustomerForm'
 
 const SUBMIT_CUSTOMER = 'submitCustomer'
 
+const CREATE_CUSTOMER = 'createCustomer'
+
 const SELECT_CUSTOMER = 'selectCustomer'
 
 const INIT_CURRENCIES = 'initCurrencies'
@@ -37,6 +39,7 @@ export {
     SHOW_CUSTOMER_FORM,
     HIDE_CUSTOMER_FORM,
     SUBMIT_CUSTOMER,
+    CREATE_CUSTOMER,
     SELECT_CUSTOMER,
     INIT_CURRENCIES,
     ADD_TO_CART,

+ 16 - 0
src/store/actions.js

@@ -1,5 +1,6 @@
 import axios from 'axios'
 import { INIT_SALE_URL, CREATE_CUSTOMER_URL, PROCESS_SALE_URL } from '@/constants/resourcePaths'
+import { CREATE_CUSTOMER } from '@/constants/actionTypes'
 
 const actions = {
     /**
@@ -32,6 +33,21 @@ const actions = {
             dispatch(`init${value[0].toUpperCase()}${value.slice(1)}`, payload[value])
         }
     },
+    [CREATE_CUSTOMER] ({ dispatch }, payload) {
+        const data = {
+            jsonrpc: '2.0',
+            method: 'call',
+            params: {
+                ...payload
+            }
+        }
+
+        return axios.post(CREATE_CUSTOMER_URL, data).then(response => {
+            console.log(response)
+        }).catch(error => {
+            console.log(error)
+        })
+    },
     /**
      * 
      * @param {*} param0 

+ 3 - 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, SELECT_CUSTOMER } from '@/constants/actionTypes'
+import { INIT_CUSTOMERS, SHOW_CUSTOMER_FORM, HIDE_CUSTOMER_FORM, SUBMIT_CUSTOMER, CREATE_CUSTOMER, SELECT_CUSTOMER } from '@/constants/actionTypes'
 
 const initialState = {
     customers: [],
@@ -110,8 +110,8 @@ const actions = {
      * 
      * @param {*} param0 
      */
-    [SUBMIT_CUSTOMER] ({ commit }) {
-        console.log('submit')
+    [SUBMIT_CUSTOMER] ({ dispatch }, payload) {
+        dispatch(CREATE_CUSTOMER, payload)
     },
     /**
      *