123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- const actions = {
- notify({ commit }, payload) {
- openerp.web.notification.do_warn('Atención', payload)
- return false
- },
- initSale({ commit, dispatch }, payload) {
- commit('setPosInstance', payload)
- let promises = [
- dispatch('fetchCompany'),
- dispatch('fetchCurrencies'),
- dispatch('fetchProducts'),
- dispatch('fetchCustomers'),
- dispatch('fetchJournals'),
- dispatch('fetchPaymentTerms')
- ]
- Promise.all(promises).then(() => {
- console.info('loaded')
- }).catch(error => {
- console.error(error)
- })
- },
- checkCart({ getters, dispatch }) {
- return getters.cartIsEmpty || dispatch('notify', 'Necesitas agregar productos al carrito para continuar')
- },
- checkCustomer({ getters, dispatch }) {
- return getters.hasSelectedCustomer || dispatch('notify', 'Necesitas seleccionar un cliente para continuar')
- },
- checkAmountPaid({ getters, dispatch }) {
- return (getters.payment === 'cash' && getters.amountPaid >= getters.total) || dispatch('notify', 'El monto recibido no puede ser menor al monto a pagar')
- },
- completeSale({ getters, dispatch }) {
- return new Promise((resolve, reject) => {
- let AccountVoucher = new openerp.web.Model('account.voucher')
- AccountVoucher.call('create_from_pos', [
- {
- customer_id: getters.selectedCustomer.id,
- payment_term_id: getters.selectedPaymentTerm.id,
- journal_id: getters.selectedJournal.id,
- account_id: getters.selectedJournal.default_credit_account.id,
- cart_items: getters.cartItems.map(item => {
- return {
- id: item.id,
- qty: item.qty,
- price: item.list_price,
- discount: item.price >= item.list_price ? 1.0 : item.price / item.list_price
- }
- }),
- cart_total: getters.total,
- amount_paid: getters.amountPaid > getters.total ? getters.total : getters.amountPaid
- }
- ], {
- context: new openerp.web.CompoundContext()
- }).then(response => {
- window.location.reload()
- dispatch('printInvoice', response)
- resolve(response)
- }).fail(error => {
- reject(error)
- })
- })
- },
- printInvoice({ getters }, payload) {
- let self = getters.posInstance
- let active_ids = {
- active_id: payload.invoice_id,
- active_ids: [payload.invoice_id],
- active_model: 'account.invoice'
- }
-
- self.rpc('/web/action/load', {
- action_id: payload.action_id,
- context: new openerp.web.CompoundContext(active_ids).eval()
- }).then(result => {
- result.context = new openerp.web.CompoundContext(result.context || {}, active_ids).eval();
- result.flags = result.flags || {};
- result.flags.inline = true;
-
- self.do_action(result, {
- on_close: function () {
- self.getParent().reload();
- }
- })
- })
- }
- }
- export default actions
|