浏览代码

[FIX] Format currency

adrielso 7 年之前
父节点
当前提交
ea264b0dba

+ 4 - 4
controllers/main.py

@@ -124,7 +124,7 @@ class PaymentsSales(http.Controller):
         Get Journal
     '''
     def get_journals(self):
-        domain =[('active', '=', True),('type', 'in',['bank', 'cash'])]
+        domain =[('active', '=', True),('type', 'in',['bank', 'cash']), ('default_credit_account_id.currency_id', '=', False)]
         paymentsJournals = []
 
         for journal in request.env['account.journal'].search(domain, order="id"):
@@ -234,7 +234,7 @@ class PaymentsSales(http.Controller):
         return self.make_gzip_response({
             'date': self.get_server_date(),
             'user': self.get_user(),
-            'customers': self.get_customers()
-            # 'journals': self.get_journals(),
-            # 'currencies': self.get_currency()
+            'customers': self.get_customers(),
+            'journals': self.get_journals(),
+            'currencies': self.get_currency()
         })

+ 33 - 0
src/components/filters/currency.js

@@ -0,0 +1,33 @@
+/**
+ * 
+ */
+const currency = (value = 0, symbol = '$', symbolPosition = 'before', thousandsSeparator = '.', decimalPlaces = 2, decimalSeparator = ',', decimalZeros = false) => {
+    value = value.toString()
+
+    if (decimalPlaces > 2) {
+        decimalPlaces = 2
+    }
+
+    if (!!(`${thousandsSeparator}${decimalSeparator}`).replace(/\.,|,\./g, '')) {
+        throw new Error('Same thousands and decimal separator is not allowed')
+    }
+
+    value = value.split('.')
+
+    value[0] = value[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, `$1${thousandsSeparator}`)
+
+    if (!!value[1]) {
+        value[1] = Number.parseFloat(`1.${value[1]}e${decimalPlaces}`)
+        value[1] = Math.round(value[1]).toString().replace(/^1/, '')
+    }
+
+    value = value.join(decimalSeparator)
+
+    if (!decimalZeros) {
+        value = value.replace(/([\.|,]\d)0$/, '$1')
+    }
+
+    return symbolPosition === 'before' ? `${symbol} ${value}` : `${value} ${symbol}`
+}
+
+export default currency

+ 0 - 163
src/components/payments/Ticket.vue

@@ -1,163 +0,0 @@
-<template lang="pug">
-    .ticket-payments
-        .ticket-summary-payments
-            .ticket-payments-header
-                //- h3 {{ companyName || 'No company' }}
-                h3 {{ customerName}}
-                //-
-                //- table
-                //-     tbody
-                //-         tr
-                //-             td Producto
-                //-             td Precio
-                //-             td Cant
-                //-             td Subtotal
-            //- .ticket-items-wrapper
-            //-     table
-            //-         tbody
-            //-             tr(v-for='item in items' :key='item.id')
-            //-                 td {{ item.name || 'no data' }}
-            //-                 td {{ item.price || 'no data' }}
-            //-                 td {{ item.quantity || 'no data' }}
-            //-                 td {{ ((item.price || 0) * (item.quantity || 0)) || 'no data'  }}
-            //- .ticket-summary-footer
-            //-     table
-            //-         tbody
-            //-             tr
-            //-                 td Total:
-            //-                 td {{ total || 'no data' }}
-            //-             tr
-            //-                 td Cliente:
-            //-                 td {{ customerName || 'no data' }}
-</template>
-
-<script>
-    export default {
-        props: {
-            customerName: {
-                type: String,
-                default: ''
-            },
-            invoiceNumber: {
-                type: String,
-                default: ''
-            },
-            paymentBalance: {
-                type: Number,
-                default: 0
-            },
-            paymentTotal: {
-                type: Number,
-                default: 0
-            },
-            totalPayments: {
-                type: Number,
-                default: 0
-            },
-            items: {
-                type: [],
-                default: []
-            }
-        }
-    }
-</script>
-
-<style lang="sass">
-    @import '../../assets/variables'
-    .ticket-payments
-        width: 500px
-        height: 100%
-        background: #e9e9e9
-        .ticket-summary
-            width: 350px
-            height: 450px
-            border: 1px solid $app-border-color
-            margin: auto
-            box-shadow: -2px 2px 5pc $app-border-color, 2px 2px 5px $app-border-color
-            position: relative
-            .ticket-summary-header, .ticket-summary-footer
-                width: 100%
-                position: absolute
-            .ticket-summary-header
-                height: 65px
-                top: 0
-                h3
-                    text-align: center
-                    font-size: 14pt
-                    margin: 0 15px
-                    padding: 30px 0 15px 0
-                    color: $app-dark-color
-                table
-                    width: 308px
-                    height: 30px
-                    margin: 0 20px
-                    font-size: 7.5pt
-                    font-weight: bold
-                    tbody
-                        tr
-                            line-height: 30px
-                            border-top: 1px solid $app-border-color
-                            border-bottom: 1px solid $app-border-color
-                            td
-                                &:nth-child(1)
-                                    width: 180px
-                                    text-align: left
-
-                                &:nth-child(2)
-                                    width: 50px
-                                    text-align: right
-
-                                &:nth-child(3)
-                                    width: 30px
-                                    text-align: right
-
-                                &:nth-child(4)
-                                    width: 50px
-                                    text-align: right
-            .ticket-items-wrapper
-                width: 310px
-                height: 280px
-                margin: 95px 20px 75px 20px
-                padding-top: 5px
-                overflow-y: auto
-                table
-                    width: 100%
-                    font-size: 7.5pt
-                    tbody
-                        tr
-                            height: 28px
-                            line-height: 30px
-
-                            td
-                                &:nth-child(1)
-                                    width: 180px
-
-                                &:nth-child(2)
-                                    width: 50px
-                                    text-align: right
-
-                                &:nth-child(3)
-                                    width: 30px
-                                    text-align: right
-
-                                &:nth-child(4)
-                                    width: 50px
-                                    text-align: right
-            .ticket-summary-footer
-                width: 348px
-                height: 75px
-                bottom: 0
-                padding: 15px 25px
-                background: $app-bg-color
-                table
-                    width: 100%
-                    tbody
-                        tr
-                            height: 25px
-                            line-height: 20px
-                            td
-                                &:nth-child(1)
-                                    font-weight: bold
-                                &:nth-child(2)
-                                    text-align: right
-</style>

+ 6 - 8
src/components/payments/VoucherTicket.vue

@@ -67,14 +67,12 @@
         height: 100%
         font-size: 8pt
         display: flex
-
-
         .voucher-ticket-wrapper
             width: 100%
             height: 460px
             margin: 10px
             border: 1px solid #d3d3d3
-            background: $app-light-color
+            // background: $app-light-color
             display: inline-block
             .voucher-ticket-from
                 width: 100%
@@ -103,7 +101,7 @@
                             weight: bold
                         padding-left: 10px
                     .voucher-ticket-from-input
-                        width: 290px
+                        width: calc(100% - 150px)
                         height: 25px
                         font:
                             size: 10pt
@@ -119,7 +117,7 @@
                     border: 1px solid #d3d3d3
                     background: #f5f5f5
                     .voucher-ticket-from-grid-header-left, .voucher-ticket-from-grid-header-right
-                        width: 213px
+                        width: calc(50% - 10px)
                         height: 30px
                         font:
                             size: 10pt
@@ -145,7 +143,7 @@
                         margin-left: 5px
                         margin-right: 5px
                         .voucher-ticket-from-grid-item-left, .voucher-ticket-from-grid-item-right
-                            width: 205px
+                            width: calc(50% - 10px)
                             height: 30px
                             font:
                                 size: 10pt
@@ -160,7 +158,7 @@
                     width: 100%
                     height: 25px
                     .voucher-ticket-from-label-total
-                        width: 300px
+                        width: 60%
                         height: 25px
                         margin-top: 15px
                         font:
@@ -169,7 +167,7 @@
                         text-align: right
                         padding-right: 15px
                     .voucher-ticket-from-input-total
-                        width: 150px
+                        width: calc(40% - 10px)
                         height: 25px
                         margin-top: 15px
                         text-align: right

+ 83 - 17
src/components/steps/MethodPayment.vue

@@ -1,33 +1,80 @@
 <template lang="pug">
     .payments-step
         //- .method-payment-step
-        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :paymentBalance='movesPaymentsBalance' :paymentTotal='paymentTotal' :totalPayments='movesPaymentsTotal')
+        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :paymentBalance='movesPaymentsBalance' :paymentTotal='paidTotal' :totalPayments='movesPaymentsTotal')
         form.method-payment
+            .method-form-separator
+                h3 Detalle de Cliente
+                hr
+            .method-form-item
+                label.method-form-label Cliente
+                input.method-form-input(readonly :value="selectedCustomer && selectedCustomer.displayName")
+            .method-form-separator
+                h3 Detalle de pago
+                hr
+            .method-form-item
+                label.method-form-label Método de pago
+                select.method-form-input(v-model="paymentJournals")
+                    option(v-for="journal in journals" :value="journal") {{ journal.displayName }}
+            .method-form-item
+                label.method-form-label Total
+                input.method-form-input(readonly :value="movesPaymentsTotal")
+            .method-form-item
+                label.method-form-label  Monto a Pagar
+                input.method-form-input(v-model='paid' autofocus)
+            .method-form-item
+                label.method-form-label Monto a Devolver
+                input.method-form-input(readonly :value="0")
 </template>
 
 <script>
 
     import { mapGetters, mapActions } from 'vuex'
     import Ticket from '@@/payments/VoucherTicket'
-    import MethodPayment from '@@/payments/Payment'
-
+    import { SELECT_JOURNAL }from '@/constants/actionTypes'
     export default {
         components: {
             Ticket,
-            MethodPayment,
         },
-        computed: mapGetters([
-            'selectedCustomer',
-            'selectedInvoice',
-            'movesPayments',
-            'movesPaymentsBalance',
-            'movesPaymentsTotal',
-            'paymentTotal',
-            'selectedMoveLine'
+        computed:{
+            paymentJournals: {
+                get() {
+                    return this.selectedJournal
+                },
+                set(value) {
+                    this.selectJournal(value)
+                }
+            },
+            paid: {
+                get() {
+
+                },
+                set(value) {
+                    let value2 = this.$options.filters.currency(value)
+                    let value3 = value2.replace(/[\.|,](\d{0,2}$)/, '?$1').split(/\?/)
+                    value3[0] = value3[0].replace(/[^0-9]/g, '')
+                    value3 = Number.parseFloat(value3.join('.')) || 0
+
+                }
+            },
+
+            ...mapGetters([
+                'selectedCustomer',
+                'selectedInvoice',
+                'movesPayments',
+                'movesPaymentsBalance',
+                'movesPaymentsTotal',
+                'paidTotal',
+                'selectedMoveLine',
+                'journals',
+                'selectedJournal'
+            ])
+        },
+
+
+        methods: mapActions([
+            SELECT_JOURNAL
         ])
-        // methods: mapActions([
-        //     ''
-        // ])
     }
 </script>
 
@@ -44,6 +91,25 @@
             margin-right: 50px
             padding:  15px 35px
             background: $app-light-color
-
-
+            .method-form-separator
+               h3
+                   color: #9e9e9e
+                   font-size: 8pt
+               hr
+                   margin-top: 5px
+            .method-form-item
+                width: 100%
+                height: 45px
+                margin-bottom: 15px
+                .method-form-label
+                    width: 250px
+                    height: 45px
+                    font-size: 14pt
+                .method-form-input, .method-form-input-number
+                    width: 350px
+                    height: 45px
+                    font-size: 14pt
+                    border-radius: 0
+                .method-form-input-number
+                    text-align: right
 </style>

+ 2 - 1
src/constants/actionTypes.js

@@ -30,6 +30,7 @@ const REMOVE_MOVE_PAYMENTS_ALL = 'removeMovePaymentsAll'
  * [JOURNALS]
  */
 const INIT_PAYMENTS_JOURNALS = 'initPaymentsJournals'
+const SELECT_JOURNAL = 'selectJournal'
 /**
  * [CURRENCIES]
  */
@@ -43,6 +44,6 @@ export {
     INIT_PAYMENTS_CUSTOMERS, SELECT_PAYMENTS_CUSTOMER, //customer
     SELECT_CUSTOMER_INVOICES, SELECT_INVOICE, ADD_MOVE_IN_INVOICE, //Customer -invoice
     SELECT_MOVE_INVOICE, SELECT_MOVE,REMOVE_MOVE_PAYMENTS, REMOVE_MOVE_PAYMENTS_ALL, //Customer -Move
-    INIT_PAYMENTS_JOURNALS, //Journal
+    INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL,//Journal
     INIT_PAYMENTS_CURRENCIES //currency
 }

+ 2 - 1
src/constants/mutationTypes.js

@@ -37,6 +37,7 @@ const SET_TOTAL_MOVE_PAYMENTS = 'setTotalMovePayments'
  */
 const SET_JOURNALS = 'setJournals'
 const SET_LOADING_JOURNALS = 'setLoadingJournals'
+const SET_SELECTED_JOURNAL = 'setSelectedJournal'
 /**
  * [CURRENCIES]
  * @type {String}
@@ -50,6 +51,6 @@ export {
     SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SELECTED_CUSTOMER, //customer
     SET_INVOICES, SET_SELECTED_INVOICE, SET_SELECTED_CURRENCY_INVOICE, SET_MOVE_IN_INVOICE, //customer - invoice
     SET_MOVES, SET_SELECTED_MOVE_LINE, SET_SELECTED_MOVE_PAYMENTS, REMOVE_MOVE_LINE, REMOVE_PAYMENTS_MOVE, SET_TOTAL_MOVE_PAYMENTS,//customer -Move
-    SET_JOURNALS, SET_LOADING_JOURNALS, //Journal
+    SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL,//Journal
     SET_CURRENCIES, SET_LOADING_CURRENCIES //Currency
 }

+ 3 - 0
src/index.js

@@ -2,6 +2,9 @@ import Vue from 'vue'
 import Payments from '@/Payments'
 import VModal from 'vue-js-modal'
 import store from '@/store'
+
+import currency from '@@/filters/currency'
+Vue.filter('currency', currency)
 // vue.use
 Vue.use(VModal)
 // Vue.config.

+ 3 - 3
src/store/index.js

@@ -27,9 +27,9 @@ const store = new Vuex.Store({
         company,
         customers,
         invoices,
-        moveLines
-        // journals,
-        // currency
+        moveLines,
+        journals,
+        currency
     },
     strict: true
 })

+ 34 - 5
src/store/modules/journals.js

@@ -1,13 +1,15 @@
-import { INIT_PAYMENTS_JOURNALS } from '@/constants/actionTypes'
-import { SET_JOURNALS, SET_LOADING_JOURNALS} from '@/constants/mutationTypes'
+import { INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL } from '@/constants/actionTypes'
+import { SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL } from '@/constants/mutationTypes'
 
 const initialState ={
     journals: null,
-    loadingJournal: false
+    loadingJournal: false,
+    selectedJournal: null
 }
 const state = {
     journals: initialState.journals,
-    loadingJournal: initialState.loadingJournal
+    loadingJournal: initialState.loadingJournal,
+    selectedJournal: initialState.selectedJournal
 }
 const getters = {
     /**
@@ -25,7 +27,17 @@ const getters = {
      */
     loadingJournal(state) {
         return state.loadingJournal
+    },
+    /**
+     * [selectedJournal description]
+     * @method selectedJournal
+     * @param  {[type]}        state [description]
+     * @return {[type]}              [description]
+     */
+    selectedJournal (state) {
+        return state.selectedJournal
     }
+
 }
 const mutations = {
     /**
@@ -43,19 +55,36 @@ const mutations = {
      */
     [SET_LOADING_JOURNALS] (state, payload) {
         state.loadingJournal = !!payload
+    },
+    /**
+     * [selectedJournal description]
+     * @type {[type]}
+     * @param  {[type]} state [description]
+     * @param  {[type]} payload [description]
+     */
+    [SET_SELECTED_JOURNAL] (state, payload) {
+        state.selectedJournal = payload
     }
 
 }
 
 const actions = {
     /**
-     *
+     * [INIT_PAYMENTS_JOURNALS]
      * @param {*} param0
      * @param {*} payload
      */
     [INIT_PAYMENTS_JOURNALS] ({ commit },payload ) {
         commit(SET_JOURNALS, payload)
         commit(SET_LOADING_JOURNALS, payload)
+    },
+    /**
+     * [SELECT_JOURNAL]
+     * @param {*} param0
+     * @param {*} payload
+     */
+    [SELECT_JOURNAL] ({ commit },payload ) {
+        commit(SET_SELECTED_JOURNAL, payload)
     }
 
 }

+ 6 - 6
src/store/modules/moveLines.js

@@ -7,7 +7,7 @@ const initialState = {
     movesPayments: [],
     movesPaymentsTotal: 0,
     movesPaymentsBalance: 0,
-    paymentTotal: 0
+    paidTotal: 0
 }
 
 const state = {
@@ -16,7 +16,7 @@ const state = {
     movesPayments: initialState.movesPayments,
     movesPaymentsTotal: initialState.movesPaymentsTotal,
     movesPaymentsBalance: initialState.movesPaymentsBalance,
-    paymentTotal: initialState.paymentTotal
+    paidTotal: initialState.paidTotal
 }
 
 const getters = {
@@ -61,13 +61,13 @@ const getters = {
         return state.movesPaymentsBalance
     },
     /**
-     * [paymentTotal description]
-     * @method paymentTotal
+     * [paidTotal description]
+     * @method paidTotal
      * @param  {[type]}     state [description]
      * @return {[type]}     [description]
      */
-    paymentTotal (state) {
-        return state.paymentTotal
+    paidTotal (state) {
+        return state.paidTotal
     }
 }