customers.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const state = {
  2. customers: [],
  3. selectedCustomer: null
  4. }
  5. const getters = {
  6. getCustomers(state) {
  7. return state.customers
  8. },
  9. hasSelectedCustomer(state) {
  10. return !!state.selectedCustomer
  11. }
  12. }
  13. const mutations = {
  14. pushCustomers(state, payload) {
  15. state.customers = [...payload.customers]
  16. },
  17. selectCustomer(state, payload) {
  18. state.selectedCustomer = payload.customer
  19. }
  20. }
  21. const actions = {
  22. fetchCustomers({ commit, dispatch }) {
  23. return new Promise((resolve, reject) => {
  24. let customer = new openerp.web.Model('res.partner')
  25. customer.query(['name', 'display_name', 'image_medium']).filter([['customer', '=', true], ['is_company', '=', false], ['active', '=', true]]).all().then(response => {
  26. commit('pushCustomers', {
  27. customers: response
  28. })
  29. dispatch('loaded', {
  30. module: 'customers'
  31. })
  32. resolve()
  33. }).fail(error => {
  34. console.log(error)
  35. reject(error)
  36. })
  37. })
  38. },
  39. selectCustomer({ commit }, payload) {
  40. commit('selectCustomer', payload)
  41. }
  42. }
  43. export default {
  44. state,
  45. getters,
  46. mutations,
  47. actions
  48. }