|
@@ -1,6 +1,5 @@
|
|
|
const state = {
|
|
|
journals: [],
|
|
|
- periods: [],
|
|
|
payment: 'cash',
|
|
|
paymentTerms: [],
|
|
|
selectedJournal: null,
|
|
@@ -12,9 +11,6 @@ const getters = {
|
|
|
journals(state) {
|
|
|
return state.journals
|
|
|
},
|
|
|
- periods(state) {
|
|
|
- return state.periods
|
|
|
- },
|
|
|
payment(state) {
|
|
|
return state.payment
|
|
|
},
|
|
@@ -36,9 +32,6 @@ const mutations = {
|
|
|
setJournals(state, payload) {
|
|
|
state.journals = payload
|
|
|
},
|
|
|
- setPeriods(state, payload) {
|
|
|
- state.periods = payload
|
|
|
- },
|
|
|
setPaymentTerms(state, payload) {
|
|
|
state.paymentTerms = payload
|
|
|
},
|
|
@@ -65,6 +58,8 @@ const actions = {
|
|
|
context: new openerp.web.CompoundContext()
|
|
|
}).then(response => {
|
|
|
commit('setJournals', response)
|
|
|
+
|
|
|
+ dispatch('autoSelectJournal', response)
|
|
|
dispatch('loaded', 'journals')
|
|
|
|
|
|
resolve()
|
|
@@ -74,22 +69,11 @@ const actions = {
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- fetchPeriods({ commit, dispatch }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let AccountPeriod = new openerp.web.Model('account.period')
|
|
|
-
|
|
|
- AccountPeriod.call('get_periods', {
|
|
|
- context: new openerp.web.CompoundContext()
|
|
|
- }).then(response => {
|
|
|
- commit('setPeriods', response)
|
|
|
- dispatch('loaded', 'periods')
|
|
|
-
|
|
|
- resolve()
|
|
|
- }).fail(error => {
|
|
|
- console.log(error)
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
+ autoSelectJournal({ dispatch }, payload) {
|
|
|
+ dispatch('selectJournal', payload.find(j => j.type === 'cash'))
|
|
|
+ },
|
|
|
+ selectJournal({ commit }, payload) {
|
|
|
+ commit('setSelectedJournal', payload)
|
|
|
},
|
|
|
fetchPaymentTerms({ commit, dispatch }) {
|
|
|
return new Promise((resolve, reject) => {
|
|
@@ -98,7 +82,10 @@ const actions = {
|
|
|
AccountPaymentTerm.call('get_account_payment_terms', {
|
|
|
context: new openerp.web.CompoundContext()
|
|
|
}).then(response => {
|
|
|
+ console.table(response)
|
|
|
commit('setPaymentTerms', response)
|
|
|
+
|
|
|
+ dispatch('autoSelectPaymentTerm', response)
|
|
|
dispatch('loaded', 'paymentTerms')
|
|
|
|
|
|
resolve()
|
|
@@ -108,7 +95,14 @@ const actions = {
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- togglePayment({ commit }, payload) {
|
|
|
+ autoSelectPaymentTerm({ dispatch }, payload) {
|
|
|
+ dispatch('selectPaymentTerm', payload.find(t => t.lines.length === 1 && t.lines[0].days === 0) || payload.find(t => t.lines.length === 1 && t.lines[0].days >= 0))
|
|
|
+ },
|
|
|
+ selectPaymentTerm({ commit }, payload) {
|
|
|
+ commit('setSelectedPaymentTerm', payload)
|
|
|
+ },
|
|
|
+ togglePayment({ commit, dispatch, getters }, payload) {
|
|
|
+ dispatch('autoSelectPaymentTerm', payload === 'cash' ? getters.paymentTerms : getters.paymentTerms.filter(t => t.id !== getters.selectedPaymentTerm.id))
|
|
|
commit('togglePayment', payload)
|
|
|
},
|
|
|
changeAmountPaid({ commit }, payload) {
|