|
@@ -1,136 +0,0 @@
|
|
|
-const state = {
|
|
|
- journals: [],
|
|
|
- payment: 'cash',
|
|
|
- paymentTerms: [],
|
|
|
- paymentReference: '',
|
|
|
- selectedJournal: null,
|
|
|
- selectedPaymentTerm: null,
|
|
|
- amountPaid: 0
|
|
|
-}
|
|
|
-
|
|
|
-const getters = {
|
|
|
- journals(state) {
|
|
|
- return state.journals
|
|
|
- },
|
|
|
- payment(state) {
|
|
|
- return state.payment
|
|
|
- },
|
|
|
- paymentTerms(state) {
|
|
|
- return state.paymentTerms
|
|
|
- },
|
|
|
- paymentReference(state) {
|
|
|
- return state.paymentReference
|
|
|
- },
|
|
|
- selectedJournal(state) {
|
|
|
- return state.selectedJournal
|
|
|
- },
|
|
|
- selectedPaymentTerm(state) {
|
|
|
- return state.selectedPaymentTerm
|
|
|
- },
|
|
|
- amountPaid(state) {
|
|
|
- return state.amountPaid
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-const mutations = {
|
|
|
- setJournals(state, payload) {
|
|
|
- state.journals = payload
|
|
|
- },
|
|
|
- setPaymentTerms(state, payload) {
|
|
|
- state.paymentTerms = payload
|
|
|
- },
|
|
|
- setSelectedJournal(state, payload) {
|
|
|
- state.selectedJournal = payload
|
|
|
- },
|
|
|
- setSelectedPaymentTerm(state, payload) {
|
|
|
- state.selectedPaymentTerm = payload
|
|
|
- },
|
|
|
- setPaymentReference(state, payload) {
|
|
|
- state.paymentReference = payload
|
|
|
- },
|
|
|
- togglePayment(state, payload) {
|
|
|
- state.payment = payload
|
|
|
- },
|
|
|
- setAmountPaid(state, payload) {
|
|
|
- state.amountPaid = payload
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-const actions = {
|
|
|
- fetchJournals({ commit, dispatch }) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let AccountJournal = new openerp.web.Model('account.journal')
|
|
|
-
|
|
|
- AccountJournal.call('get_journals', {
|
|
|
- context: new openerp.web.CompoundContext()
|
|
|
- }).then(response => {
|
|
|
- commit('setJournals', response)
|
|
|
-
|
|
|
- dispatch('autoSelectJournal', response)
|
|
|
- dispatch('loaded', 'journals')
|
|
|
-
|
|
|
- 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) => {
|
|
|
- let AccountPaymentTerm = new openerp.web.Model('account.payment.term')
|
|
|
-
|
|
|
- AccountPaymentTerm.call('get_account_payment_terms', {
|
|
|
- context: new openerp.web.CompoundContext()
|
|
|
- }).then(response => {
|
|
|
- commit('setPaymentTerms', response)
|
|
|
-
|
|
|
- dispatch('autoSelectPaymentTerm', response)
|
|
|
- dispatch('loaded', 'paymentTerms')
|
|
|
-
|
|
|
- resolve()
|
|
|
- }).fail(error => {
|
|
|
- console.log(error)
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- 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)
|
|
|
- },
|
|
|
- setPaymentReference({ commit }, payload) {
|
|
|
- commit('setPaymentReference', payload)
|
|
|
- },
|
|
|
- changeAmountPaid({ commit, getters, dispatch }, payload) {
|
|
|
- if (getters.payment === 'cash') {
|
|
|
- commit('setAmountPaid', payload)
|
|
|
- } else {
|
|
|
- if (payload <= (getters.total * 0.7)) {
|
|
|
- commit('setAmountPaid', payload)
|
|
|
- } else {
|
|
|
- commit('setAmountPaid', getters.total * 0.7)
|
|
|
- dispatch('notify', 'El monto entregado no puede sobrepasar el 70% del total')
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export default {
|
|
|
- state,
|
|
|
- getters,
|
|
|
- mutations,
|
|
|
- actions
|
|
|
-}
|