|
@@ -68,7 +68,7 @@ const mutations = {
|
|
|
}
|
|
|
|
|
|
const actions = {
|
|
|
- initPurchase({ getters, commit, dispatch }, payload) {
|
|
|
+ initProcess({ getters, commit, dispatch }, payload) {
|
|
|
commit('setMode', payload || getters.mode)
|
|
|
|
|
|
commit('setLoading', true)
|
|
@@ -104,9 +104,6 @@ const actions = {
|
|
|
console.log(response)
|
|
|
}).catch(error => console.log(error))
|
|
|
},
|
|
|
- checkSupplier({ getters, dispatch}) {
|
|
|
- return !!getters.selectedSupplier || dispatch('notify', 'Necesitas seleccionar un proveedor para continuar')
|
|
|
- },
|
|
|
checkCart({ getters, dispatch}) {
|
|
|
for (let cartItem of getters.cartItems) {
|
|
|
if (cartItem.price == 0) {
|
|
@@ -116,6 +113,15 @@ const actions = {
|
|
|
|
|
|
return !!getters.cartItems.length || dispatch('notify', 'Necesitar agregar producto al carrito para continuar')
|
|
|
},
|
|
|
+ checkSupplier({ getters, dispatch}) {
|
|
|
+ return !!getters.selectedSupplier || dispatch('notify', 'Necesitas seleccionar un proveedor para continuar')
|
|
|
+ },
|
|
|
+ checkPurchaseOrder({ getters, dispatch }) {
|
|
|
+ return !!getters.selectedPurchaseOrder || dispatch('notify', 'Necesitas seleccionar un presupuesto para continuar')
|
|
|
+ },
|
|
|
+ checkStockPicking({ getters, dispatch }) {
|
|
|
+ return !!getters.selectedStockPicking || dispatch('notify', 'Necesitas seleccionar una entrega para continuar')
|
|
|
+ },
|
|
|
checkAmountReceived({ getters, dispatch }) {
|
|
|
if (getters.paymentType == 'cash') {
|
|
|
return getters.initialPayment >= getters.cartTotal || dispatch('notify', 'El monto recibido no puede ser menor al monto a pagar')
|
|
@@ -123,14 +129,26 @@ const actions = {
|
|
|
return getters.initialPayment < getters.cartTotal || dispatch('notify', 'El monto recibido no puede ser igual o mayor al monto a pagar')
|
|
|
}
|
|
|
},
|
|
|
- createPurchase({ getters, commit, dispatch }) {
|
|
|
+ endProcess({ getters, commit, dispatch }) {
|
|
|
+ const mode = getters.mode;
|
|
|
+
|
|
|
+ if (mode == 'purchase') {
|
|
|
+ if (getters.paymentType == 'cash' && getters.initialPayment < getters.amountToPay) {
|
|
|
+ return dispatch('notify', 'El monto recibido no puede ser menor al monto a pagar')
|
|
|
+ }
|
|
|
+
|
|
|
+ if (getters.paymentType != 'cash' && getters.initialPayment >= getters.amountToPay) {
|
|
|
+ return dispatch('notify', 'El monto recibido no puede ser igual o mayor al monto a pagar')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
commit('setLoading', true)
|
|
|
|
|
|
- const data = {
|
|
|
- jsonrpc: '2.0',
|
|
|
- method: 'call',
|
|
|
- params: {
|
|
|
- mode: getters.mode,
|
|
|
+ let data = { mode }
|
|
|
+
|
|
|
+ if (['purchase', 'expense', 'product_picking'].includes(mode)) {
|
|
|
+ data = {
|
|
|
+ ...data,
|
|
|
items: getters.cartItems.map(item => {
|
|
|
return {
|
|
|
id: item.id,
|
|
@@ -140,23 +158,71 @@ const actions = {
|
|
|
}
|
|
|
}),
|
|
|
supplierId: getters.selectedSupplier.id,
|
|
|
+ currencyId: getters.selectedCurrency.id,
|
|
|
+ supplierInvoiceNumber: getters.supplierInvoiceNumber || null,
|
|
|
+ warehouseId: getters.selectedWarehouse.id
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (['purchase', 'expense', 'payment'].includes(mode)) {
|
|
|
+ data = {
|
|
|
+ ...data,
|
|
|
+ total: getters.cartTotal,
|
|
|
+ purchaseOrderId: (getters.selectedPurchaseOrder && getters.selectedPurchaseOrder.id) || null,
|
|
|
paymentTermId: getters.selectedPaymentTerm.id,
|
|
|
journalId: getters.selectedJournal.id,
|
|
|
payment: getters.initialPayment > getters.cartTotal ? getters.cartTotal : getters.initialPayment,
|
|
|
- supplierInvoiceNumber: getters.supplierInvoiceNumber || null
|
|
|
+ paymentMethod: getters.paymentMethod,
|
|
|
+ supplierId: getters.selectedSupplier.id,
|
|
|
+ currencyId: getters.selectedCurrency.id,
|
|
|
+ warehouseId: getters.selectedWarehouse.id
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mode == 'product_delivery') {
|
|
|
+ data = {
|
|
|
+ ...data,
|
|
|
+ stockPickingId: getters.selectedStockPicking.id
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return axios.post(Urls.PROCESS_PURCHASE_URL, data).then(_ => {
|
|
|
+ // const data = {
|
|
|
+ // jsonrpc: '2.0',
|
|
|
+ // method: 'call',
|
|
|
+ // params: {
|
|
|
+ // mode: getters.mode,
|
|
|
+ // items: getters.cartItems.map(item => {
|
|
|
+ // return {
|
|
|
+ // id: item.id,
|
|
|
+ // name: item.name,
|
|
|
+ // quantity: item.quantity,
|
|
|
+ // price: item.price
|
|
|
+ // }
|
|
|
+ // }),
|
|
|
+ // supplierId: getters.selectedSupplier.id,
|
|
|
+ // paymentTermId: getters.selectedPaymentTerm.id,
|
|
|
+ // journalId: getters.selectedJournal.id,
|
|
|
+ // payment: getters.initialPayment > getters.cartTotal ? getters.cartTotal : getters.initialPayment,
|
|
|
+ // supplierInvoiceNumber: getters.supplierInvoiceNumber || null
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ return axios.post(Urls.PROCESS_PURCHASE_URL, {
|
|
|
+ jsonrpc: '2.0',
|
|
|
+ method: 'call',
|
|
|
+ params: {
|
|
|
+ ...data
|
|
|
+ }
|
|
|
+ }).then(_ => {
|
|
|
dispatch('resetPurchase')
|
|
|
|
|
|
commit('setLoading', false)
|
|
|
commit('setCompleted', true)
|
|
|
}).catch(error => {
|
|
|
- console.log(error)
|
|
|
+ commit('setLoading', false)
|
|
|
})
|
|
|
},
|
|
|
- resetPurchase({ rootState, dispatch }) {
|
|
|
+ resetProcess({ rootState, dispatch }) {
|
|
|
for (let key in rootState) {
|
|
|
if (!(rootState[key] instanceof Object)) {
|
|
|
continue
|
|
@@ -165,7 +231,7 @@ const actions = {
|
|
|
dispatch(`reset${key[0].toUpperCase()}${key.slice(1)}`)
|
|
|
}
|
|
|
|
|
|
- dispatch('initPurchase')
|
|
|
+ dispatch('initProcess')
|
|
|
},
|
|
|
notify({ _ }, payload) {
|
|
|
openerp.web.notification.do_warn('Atención', payload)
|