Jelajahi Sumber

[ADD] write method for save sale

Gogs 7 tahun lalu
induk
melakukan
099b921aa0

+ 16 - 3
controllers/main.py

@@ -268,6 +268,19 @@ class Sales(http.Controller):
     '''
         Create sale
     '''
-    @http.route('/eiru_sales/create_sale', type='json', auth='user', methods=['POST'], cors='*')
-    def create_sale(self, **kw):
-        print(kw)
+    @http.route('/eiru_sales/process_sale', type='json', auth='user', methods=['POST'], cors='*')
+    def process_sale(self, **kw):
+        print(kw)
+
+        date_now = datetime.now().strftime('%Y-%m-%d')
+
+
+        return {
+            'message': 'ok'
+        }
+
+    '''
+    '''
+    def get_currency(self, journal_id):
+        journal = request.env['account.journal'].browse(journal_id)
+        return journal.default_credit_account_id.currency_id.id or journal.default_credit_account_id.company_currency_id.id

+ 1 - 1
src/App.vue

@@ -7,7 +7,7 @@
                 customer-step
             tab-content(title="Cómo quieres pagar?")
                 payment-method-step
-            tab-content(title="")
+            tab-content(title="Qué monto vas a entregar?")
                 payment-amount-step
 </template>
 

+ 31 - 11
src/components/steps/PaymentMethod.vue

@@ -25,12 +25,12 @@
                     label(for='credit') Crédito
             transition(name='fade')
                 .form-item(v-if="payment === 'credit'")
-                    select.form-input.input-only
+                    select.form-input.input-only(v-model='paymentTerm')
                         option(v-for='term in paymentTerms' :value='term' v-if="term.lines.length > 0 && (term.lines[0].days !== 0 || term.lines[0].value !==  'balance')") {{ term.displayName }}
                 .form-item(v-else)
                     label.form-label Método de Pago
-                    select.form-input
-                        option(v-for='journal in journals') {{ journal.displayName }}
+                    select.form-input(v-model='journal')
+                        option(v-for='journal in journals' :value='journal') {{ journal.displayName }}
 </template>
 
 <script>
@@ -44,19 +44,39 @@
         components: {
             Ticket
         },
+        computed: {
+            paymentTerm: {
+                get() {
+                    return this.selectedPaymentTerm
+                },
+                set(value) {
+                    console.log(value)
+                }
+            },
+            journal: {
+                get() {
+                    return this.selectedJournal
+                },
+                set(value) {
+                    console.log(value)
+                }
+            },
+            ...mapGetters([
+                'selectedCustomer',
+                'cartItems',
+                'cartTotal',
+                'customerCredit',
+                'paymentTerms',
+                'selectedPaymentTerm',
+                'journals',
+                'selectedJournal'
+            ])
+        },
         watch: {
             payment(value) {
                 this.changePaymentType(value)
             }
         },
-        computed: mapGetters([
-            'selectedCustomer',
-            'cartItems',
-            'cartTotal',
-            'customerCredit',
-            'paymentTerms',
-            'journals'
-        ]),
         methods: mapActions([
             CHANGE_PAYMENT_TYPE
         ]),

+ 1 - 1
src/constants/resourcePaths.js

@@ -6,7 +6,7 @@ const CREATE_PRODUCT_URL = `${BASE_URL}/create_product`
 
 const CREATE_CUSTOMER_URL = `${BASE_URL}/create_customer`
 
-const PROCESS_SALE_URL = `${BASE_URL}/process`
+const PROCESS_SALE_URL = `${BASE_URL}/process_sale`
 
 export {
     INIT_SALE_URL,

+ 24 - 1
src/store/actions.js

@@ -77,8 +77,31 @@ const actions = {
      * 
      * @param {*} param0 
      */
-    [CREATE_SALE] ({ getters , dispatch }) {
+    [CREATE_SALE] ({ getters , dispatch }, payload) {
+        const data = {
+            jsonrpc: '2.0',
+            method: 'call',
+            params: {
+                items: getters.cartItems.map(item => {
+                    return {
+                        id: item.id,
+                        quantity: item.quantity,
+                        price: item.price
+                    }
+                }),
+                total: 0,
+                customerId: getters.selectedCustomer.id,
+                paymentTermId: getters.selectedPaymentTerm.id,
+                journalId: getters.selectedJournal.id,
+                payment: getters.cartTotal
+            }
+        }
 
+        return axios.post(PROCESS_SALE_URL, data).then(response => {
+            console.log(response)
+        }).catch(error => {
+            console.log(error)
+        })
     }
 }