const state = { customers: [], selectedCustomer: null } const getters = { getCustomers(state) { return state.customers }, hasSelectedCustomer(state) { return !!state.selectedCustomer } } const mutations = { pushCustomers(state, payload) { state.customers = [...payload.customers] }, selectCustomer(state, payload) { state.selectedCustomer = payload.customer } } const actions = { fetchCustomers({ commit, dispatch }) { return new Promise((resolve, reject) => { let customer = new openerp.web.Model('res.partner') customer.query(['name', 'display_name', 'image_medium']).filter([['customer', '=', true], ['is_company', '=', false], ['active', '=', true]]).all().then(response => { commit('pushCustomers', { customers: response }) dispatch('loaded', { module: 'customers' }) resolve() }).fail(error => { console.log(error) reject(error) }) }) }, selectCustomer({ commit }, payload) { commit('selectCustomer', payload) } } export default { state, getters, mutations, actions }