Bläddra i källkod

[ADD] payment module and started anhoter step for payment

Gogs 7 år sedan
förälder
incheckning
e06a2aa70f

+ 8 - 0
models/account_journal.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class AccountJournal(models.Model):
+    _inherit = 'account.journal'
+
+    @api.model
+    def _get_journals(models.Model):
+        pass

+ 8 - 0
models/account_payment_term.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class AccountPaymentTerm(models.Model):
+    _inherit = 'account.payment.term'
+
+    @api.model
+    def _get_account_payment_terms(self):
+        pass

+ 8 - 0
models/account_period.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class AccountPeriod(models.Model):
+    _inherit: = 'account.period'
+
+    @api.model
+    def _get_periods(self):
+        pass

+ 8 - 0
models/account_voucher.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class AccountVoucher(models.Model):
+    _inherits = 'account.voucher' 
+
+    @api.model
+    def _perform_payment(self):
+        pass

+ 50 - 2
models/eiru_pos.py

@@ -185,8 +185,56 @@ class EiruPOS(models.Model):
 
         return customers
 
-    def create_order(self):
-        print 'ok'
+    @api.model
+    def process_pos_order(self, cart_items, customer_id):
+        order_line_values = []
+        for item in cart_items:
+            order_line_values.append([0, False, {
+                'product_id': int(item['id']),
+                'product_uom_qty': float(item['qty']),
+                'price_unit': float(item['list_price']),
+                'discount': 0
+            }])
+
+        order_values = {
+            'partner_id': customer_id,
+            'partner_invoice_id': customer_id,
+            'partner_shipping_id': customer_id,
+            'order_line': order_line_values,
+            'picking_policy': 'direct',
+            'order_policy': 'manual'
+        }
+
+        order = self.env['sale.order'].create(order_values)
+
+        # Process order now
+        order.action_button_confirm()
+        invoice_id = order.action_invoice_create()
+        invoice = {}
+
+        if invoice_id:
+            invoice = self.env['account.invoice'].browse(invoice_id)
+            invoice.signal_workflow('invoice_open')
+
+        for picking in order.picking_ids:
+            picking.force_assign()
+            picking.action_done()
+
+        dummy, view_id = self.env['ir.model.data'].get_object_reference('account_voucher', 'view_vendor_receipt_dialog_form')
+
+        return {
+                'id': invoice.id,
+                'view_id': view_id,
+                'name': invoice.name,
+                'display_name': invoice.display_name,
+                'currency_id': invoice.currency_id.id,
+                'partner_account_id': self.env['res.partner']._find_accounting_partner(invoice.partner_id).id,
+                'amount': invoice.type in ('out_refund', 'in_refund') and -invoice.residual or invoice.residual,
+                'reference': invoice.name,
+                'invoice_type': invoice.type,
+                'default_type': invoice.type in ('out_invoice', 'out_refund') and 'receipt' or 'payment',
+                'type': invoice.type in ('out_invoice','out_refund') and 'receipt' or 'payment'
+        } if invoice_id else {}
         
 
 class eiru_pos_session(models.Model):

+ 8 - 0
models/product_template.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class ProductTemplate(models.Model):
+    inherit = 'product.template'
+
+    @api.model
+    def _get_products(self):
+        pass

+ 8 - 0
models/res_company.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class ResCompany(models.Model):
+    inherit = 'res.company'
+
+    @api.model
+    def _get_company(self):
+        pass

+ 8 - 0
models/res_currency.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class ResCurrency(models.Model):
+    inherit = 'res.currency'
+
+    @api.model
+    def _get_currencies(self):
+        pass

+ 8 - 0
models/res_partner.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class ResPartner(models.Model):
+    inherit = 'res.partner'
+
+    @api.model
+    def _get_customers(self):
+        pass

+ 8 - 0
models/sale_order.py

@@ -0,0 +1,8 @@
+from openerp import api, fields, models
+
+class SaleOrder(models.Model):
+    inherit = 'sale.order'
+
+    @api.model
+    def _process_order(self)
+        pass

+ 1 - 1
src/App.vue

@@ -76,7 +76,7 @@
             ])
         },
         mounted() {
-            this.initSale()
+            this.initSale(this.$root.pos_instance)
         }
     }
 </script>

+ 3 - 0
src/index.js

@@ -19,6 +19,9 @@ openerp.eiru_pos = (instance, local) => {
                 template: '<App />',
                 components: {
                     App
+                },
+                data: {
+                    pos_instance: this
                 }
             });
         },

+ 39 - 3
src/store/actions.js

@@ -2,7 +2,9 @@ const actions = {
     notify({ commit }, payload) {
         openerp.web.notification.do_warn('Atención', payload)
     },
-    initSale({ dispatch }) {
+    initSale({ commit, dispatch }, payload) {
+        commit('setPosInstance', payload)
+
         let promises = [
             dispatch('fetchCompany'),
             dispatch('fetchCurrencies'),
@@ -16,8 +18,42 @@ const actions = {
             console.log(error)
         })
     },
-    completeSale({ commit }) {
-        console.log(payload)
+    completeSale({ getters }) {
+        let pos = new openerp.web.Model('eiru.pos')
+        pos.call('process_pos_order', [
+            getters.getCartItems,
+            getters.getSelectedCustomer.id
+        ], {
+            context: new openerp.web.CompoundContext()
+        }).then(response => {
+            let invoice = response
+
+            let promise = getters.getPosInstance.do_action({
+                name: 'Factura ' + invoice.reference,
+                type: 'ir.actions.act_window',
+                res_model: 'account.voucher',
+                views: [[invoice.view_id, 'form']],
+                target: 'new',
+                nodestroy: true,
+                context: {
+                    payment_expected_currency: invoice.currency_id,
+                    default_partner_id: invoice.partner_account_id,
+                    default_amount: invoice.amount,
+                    default_reference: invoice.name,
+                    close_after_process: true,
+                    invoice_type: invoice.invoice_type,
+                    invoice_id: invoice.id,
+                    default_type: invoice.default_type,
+                    type: invoice.type
+                }
+            })
+
+            promise.pipe(() =>  {
+                console.log(' ok')
+            })
+        }).fail(error => {
+            console.log(error)
+        })
     }
 }
 

+ 10 - 0
src/store/getters.js

@@ -0,0 +1,10 @@
+const getters = {
+    isLoading(state) {
+        return state.loading
+    },
+    getPosInstance(state) {
+        return state.pos_instance
+    }
+}
+
+export default getters

+ 5 - 1
src/store/index.js

@@ -1,6 +1,8 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
 
+import state from '@/store/state'
+import getters from '@/store/getters'
 import actions from '@/store/actions'
 import mutations from '@/store/mutations'
 
@@ -14,8 +16,10 @@ import customers from '@/store/modules/customers'
 Vue.use(Vuex)
 
 const Store = new Vuex.Store({
-    actions,
+    state,
+    getters,
     mutations,
+    actions,
     modules: {
         loader,
         company,

+ 3 - 0
src/store/mutations.js

@@ -1,6 +1,9 @@
 const mutations = {
     resetInitialStates(state) {
 
+    },
+    setPosInstance(state, payload) {
+        state.pos_instance = payload
     }
 }
 

+ 3 - 11
src/store/state.js

@@ -1,14 +1,6 @@
 const state = {
-    loading: false
+    loading: false,
+    pos_instance: null
 }
 
-const getters = {
-    isLoading(state) {
-        return state.loading
-    }
-}
-
-export default {
-    state,
-    getters
-}
+export default state