|
@@ -1,7 +1,8 @@
|
|
|
const state = {
|
|
|
customers: [],
|
|
|
filtered: [],
|
|
|
- selectedCustomer: null
|
|
|
+ selectedCustomer: null,
|
|
|
+ addCustomer: false
|
|
|
}
|
|
|
|
|
|
const getters = {
|
|
@@ -13,18 +14,24 @@ const getters = {
|
|
|
},
|
|
|
selectedCustomer(state) {
|
|
|
return state.selectedCustomer
|
|
|
+ },
|
|
|
+ addCustomer(state) {
|
|
|
+ return state.addCustomer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const mutations = {
|
|
|
pushCustomers(state, payload) {
|
|
|
- state.customers = [...payload.customers]
|
|
|
+ state.customers = [...payload, ...state.customers]
|
|
|
},
|
|
|
selectCustomer(state, payload) {
|
|
|
state.selectedCustomer = payload.customer
|
|
|
},
|
|
|
applyCustomersFilter(state, payload) {
|
|
|
state.filtered = payload
|
|
|
+ },
|
|
|
+ addCustomer(state) {
|
|
|
+ state.addCustomer = !state.addCustomer
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -36,9 +43,7 @@ const actions = {
|
|
|
ResPartner.call('get_customers', {
|
|
|
context: new openerp.web.CompoundContext()
|
|
|
}).then(response => {
|
|
|
- commit('pushCustomers', {
|
|
|
- customers: response
|
|
|
- })
|
|
|
+ commit('pushCustomers', response)
|
|
|
|
|
|
dispatch('loaded', 'customers')
|
|
|
|
|
@@ -56,6 +61,31 @@ const actions = {
|
|
|
},
|
|
|
filterCustomers({ commit }, payload) {
|
|
|
commit('applyCustomersFilter', payload)
|
|
|
+ },
|
|
|
+ addCustomer({ commit }) {
|
|
|
+ commit('addCustomer')
|
|
|
+ },
|
|
|
+ saveCustomer({ commit, dispatch }, payload) {
|
|
|
+ if (payload) {
|
|
|
+ if (!payload.name || !payload.ruc || !payload.phone) {
|
|
|
+ dispatch('notify', 'Complete los datos para guardar')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let ResPartner = new openerp.web.Model('res.partner')
|
|
|
+ ResPartner.call('create_from_pos', [
|
|
|
+ payload
|
|
|
+ ], {
|
|
|
+ context: new openerp.web.CompoundContext()
|
|
|
+ }).then(id => {
|
|
|
+ commit('pushCustomers', [{
|
|
|
+ id,
|
|
|
+ ...payload
|
|
|
+ }])
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ commit('addCustomer')
|
|
|
}
|
|
|
}
|
|
|
|