Browse Source

[ADD] Pago con multi divisa

adrielso 7 năm trước cách đây
mục cha
commit
b8841f6dfe

+ 68 - 15
controllers/main.py

@@ -43,7 +43,8 @@ class PaymentsSales(http.Controller):
                     'rateSilent': user.company_id.currency_id.rate_silent,
                     'thousandsSeparator': user.company_id.currency_id.thousands_separator,
                     'decimalSeparator': user.company_id.currency_id.decimal_separator,
-                    'decimalPlaces': user.company_id.currency_id.decimal_places
+                    'decimalPlaces': user.company_id.currency_id.decimal_places,
+                    'position': user.company_id.currency_id.position
             }
         }
 
@@ -72,18 +73,57 @@ class PaymentsSales(http.Controller):
             for invoice in request.env['account.invoice'].search([('id', 'in', partner_invoice),('state', '=', 'open')]):
                 movelines = []
                 moves = []
-                currency_symbol = ""
 
                 for move in invoice.move_id:
                     for moveline in move.line_id:
                         if moveline.amount_residual > 0 and moveline.state != "draft" and moveline.credit <= 0:
+                            currencyAmount = []
+                            decimal_precision = request.env['decimal.precision'].precision_get('Account')
+                            # print("\n\n")
+                            # # accountConfig =  request.env['account.config.settings']
+                            # import web_pdb; web_pdb.set_trace()
+                            # print(request.env.user)
+                            # print("\n")
+
+                            # if (request.env.user.in_group_7):
+                                # domain = [[('active', '=', True)], ['id', '=', user.company_id.currency_id.id]]
+                            # else:
+                            domain = [('active', '=', True)]
+
+
+                            for currency in request.env['res.currency'].search(domain):
+                                amount_currency = moveline.amount_currency
+
+                                if moveline.amount_currency <= 0:
+                                    amount_currency =  moveline.debit
+
+                                currencyAmount.append({
+                                    'id': currency.id,
+                                    'name': currency.name,
+                                    'displayName': currency.display_name,
+                                    'base': currency.base,
+                                    'accuracy': currency.accuracy,
+                                    'rateSilent': currency.rate_silent,
+                                    'rounding': currency.rounding,
+                                    'symbol': currency.symbol,
+                                    'position': currency.position,
+                                    'thousandsSeparator': currency.thousands_separator,
+                                    'decimalSeparator': currency.decimal_separator,
+                                    'decimalPlaces': currency.decimal_places,
+                                    'amountCurency': round(amount_currency * (currency.rate_silent/ invoice.currency_id.rate_silent), decimal_precision),
+                                    'amountCurencyResidual': round((moveline.amount_residual_currency * (currency.rate_silent / invoice.currency_id.rate_silent)), decimal_precision)
+                                })
+
                             movelines.append({
                                 'id': moveline.id,
                                 'amountResidual': moveline.amount_residual,
                                 'credit': moveline.credit,
                                 'debit': moveline.debit,
                                 'dateMaturity': moveline.date_maturity,
-                                'invoice': invoice.id
+                                'invoice': invoice.id,
+                                'amountCurrency': moveline.amount_currency if moveline.amount_currency > 0 else moveline.debit,
+                                'amountResidualCurrency': moveline.amount_residual_currency,
+                                'currencyAmount': currencyAmount
                             })
 
                 invoices.append({
@@ -101,7 +141,8 @@ class PaymentsSales(http.Controller):
                         'rateSilent': invoice.currency_id.rate_silent,
                         'thousandsSeparator': invoice.currency_id.thousands_separator,
                         'decimalSeparator': invoice.currency_id.decimal_separator,
-                        'decimalPlaces': invoice.currency_id.decimal_places
+                        'decimalPlaces': invoice.currency_id.decimal_places,
+                        'position': invoice.currency_id.position
                     }
                 })
 
@@ -125,7 +166,8 @@ class PaymentsSales(http.Controller):
         Get Journal
     '''
     def get_journals(self):
-        domain =[('active', '=', True),('type', 'in',['bank', 'cash']), ('default_credit_account_id.currency_id', '=', False)]
+        # domain =[('active', '=', True),('type', 'in',['bank', 'cash']), ('default_credit_account_id.currency_id', '=', False)]
+        domain =[('active', '=', True),('type', 'in',['bank', 'cash'])]
         paymentsJournals = []
 
         for journal in request.env['account.journal'].search(domain, order="id"):
@@ -144,7 +186,11 @@ class PaymentsSales(http.Controller):
                     'name': journal.currency.name,
                     'displayName': journal.currency.display_name,
                     'symbol': journal.currency.symbol,
-                    'rateSilent': journal.currency.rate_silent
+                    'rateSilent': journal.currency.rate_silent,
+                    'thousandsSeparator':journal.currency.thousands_separator,
+                    'decimalSeparator': journal.currency.decimal_separator,
+                    'decimalPlaces': journal.currency.decimal_places,
+                    'position': journal.currency.position
                 },
                 'defaultCreditAccount':{
                     'id': journal.default_credit_account_id.id,
@@ -256,17 +302,18 @@ class PaymentsSales(http.Controller):
         Create Voucher
     '''
     def create_voucher(self, period, invoice, company_id, amountPayments, date_server, journalId, move_line_Ids, customerId):
-        # get Journal / Currency
+        ## Get Journal
         journal_id = request.env['account.journal'].browse(int(journalId))
         currency_id = journal_id.default_credit_account_id.currency_id.id or journal_id.default_credit_account_id.company_currency_id.id
+        # currency_rateSilent = journal_id.default_credit_account_id.currency_id.rate_silent or journal_id.default_credit_account_id.company_currency_id.rate_silent
         # Get Move Lines
         move_line = request.env['account.move.line'].browse(move_line_Ids).sorted(key=lambda r: r.id)
         # get customer
         customerId = request.env['res.partner'].browse(customerId)
-
+        decimal_precision = request.env['decimal.precision'].precision_get('Account')
         # Create Line  Voucher
         line_cr_ids = []
-        amount = float(amountPayments)
+        amount = round(float(amountPayments), decimal_precision)
 
         for line in move_line:
             line_cr_ids.append([0, False, {
@@ -277,25 +324,30 @@ class PaymentsSales(http.Controller):
                 'amount_original': abs(line.credit or line.debit or 0.0),
                 'amount_unreconciled': abs(line.amount_residual),
                 'amount': min(abs(amount), line.amount_residual),
-                'reconcile': line.move_id.date <= line.date_maturity,
+                'reconcile': True if abs(line.amount_residual) == min(abs(amount), line.amount_residual) else False,
                 'currency_id': currency_id
             }])
             amount -= min(abs(amount), line.amount_residual)
 
+        company_currency = request.env.user.company_id.currency_id
+        currencyVocuher = request.env['res.currency'].browse(currency_id)
+
         values = {
                 'reference': invoice.number,
                 'type': 'receipt',
                 'journal_id': journal_id.id,
                 'company_id': company_id,
                 'pre_line': True,
-                'amount': float(amountPayments),
+                'amount': round(float(amountPayments), decimal_precision),
                 'period_id': period.id,
                 'date': date_server,
                 'partner_id': customerId.id,
                 'account_id': journal_id.default_credit_account_id.id,
                 'currency_id': currency_id,
-                'line_cr_ids': line_cr_ids
+                'line_cr_ids': line_cr_ids,
+                'payment_rate_currency_id': currency_id
             }
+
         account_voucher = request.env['account.voucher'].create(values)
         account_voucher.action_move_line_create()
 
@@ -311,6 +363,7 @@ class PaymentsSales(http.Controller):
             invoice.write({
                 'state': 'paid'
             })
+            # invoice.confirm_paid()
         return invoice
 
     '''
@@ -371,13 +424,13 @@ class PaymentsSales(http.Controller):
         # Get Company
         company_id = request.env.user.company_id.id
         self.make_info_log('[OK] Getting Company')
-        # create voucher
+            # create voucher
         voucher = self.create_voucher(period, invoice, company_id, kw.get('amountPayments', 0), date_server, kw.get('journalId'), kw.get('moveLines'), kw.get('customerId'))
         self.make_info_log('[OK] creating voucher...')
-        # close invoice
+            # close invoice
         close_invoice = self.close_invoice(kw.get('invoiceId'))
         self.make_info_log('[OK] closing invoice...')
-        #  Create bank statement
+            #  Create bank statement
         bank_statement = self.create_bank_statement(date_server, user_id, voucher)
         self.make_info_log('[OK] creating bank statement')
 

+ 4 - 3
src/components/invoices/InvoiceCard.vue

@@ -5,10 +5,10 @@
         .invoice-amount
             .invoice-total
                 h2.amount-label Total
-                h2.invoice-total-value {{ amountTotal | currency(...currencyCompany) }}
+                h2.invoice-total-value {{ amountTotal | currency(...currency) }}
             .invoice-total
                 h2.amount-label  Saldo
-                h2.invoice-saldo-value {{ residual | currency(...currencyCompany)}}
+                h2.invoice-saldo-value {{ residual | currency(...currency)}}
 </template>
 
 <script>
@@ -34,11 +34,12 @@
                 type: Boolean,
                 default: true
             },
-            currencyCompany: {
+            currency: {
                 type: Object,
                 default: {
                     name: '',
                     symbol: '',
+                    position:'before',
                     rateSilent: 0,
                     thousandsSeparator: '.',
                     decimalSeparator: ',',

+ 1 - 13
src/components/invoices/InvoicesGrid.vue

@@ -1,7 +1,7 @@
 <template lang="pug">
     .card-grid-wrapper
         card-grid
-            card(v-for='item in items' :key='item.id' :dateInvoice ='item.dateInvoice' :number='item.number' :amountTotal='item.amountTotal' :residual='item.residual' :isSelected='item.id === selectedId' @onClick='onClickCard(item)' :currencyCompany='currencyCompany')
+            card(v-for='item in items' :key='item.id' :dateInvoice ='item.dateInvoice' :number='item.number' :amountTotal='item.amountTotal' :residual='item.residual' :isSelected='item.id === selectedId' @onClick='onClickCard(item)' :currency='item.currency')
 </template>
 
 <script>
@@ -14,18 +14,6 @@
                 type: Array,
                 default: []
             },
-            currencyCompany: {
-                type: Object,
-                default: {
-                    name: '',
-                    symbol: '',
-                    position:'before',
-                    rateSilent: 0,
-                    thousandsSeparator: '.',
-                    decimalSeparator: ',',
-                    decimalPlaces: 0
-                }
-            }
         },
         components: {
             card

+ 5 - 7
src/components/moveLine/MoveLineCard.vue

@@ -1,15 +1,13 @@
 <template lang="pug">
-    //- .card-move-line(@click='onClick' :class="{ 'selected-move': isSelected }")
-        //- (v-bind:class="{'move-card-disable': moveDisable() }")
     .card-move-line(@click='onClick' :class="{ 'move-card-disable': isDisable}")
         h2.move-date Vencimiento {{ dateMaturity | dateFormat}}
         .move-amount
             .move-total
                 h2.move-amount-label Total
-                h2.move-total-value {{ debit | currency(...currencyCompany)}}
+                h2.move-total-value {{ debit | currency(...currency)}}
             .move-total
                 h2.move-amount-label  Saldo
-                h2.move-saldo-value {{ amountResidual | currency(...currencyCompany)}}
+                h2.move-saldo-value {{ amountResidual | currency(...currency)}}
 </template>
 
 <script>
@@ -35,12 +33,12 @@
                 type: Boolean,
                 default: true
             },
-            currencyCompany: {
+            currency: {
                 type: Object,
                 default: {
                     name: '',
-                    symbol: '',
-                    position: 'before',
+                    symbol: '',
+                    position:'before',
                     rateSilent: 0,
                     thousandsSeparator: '.',
                     decimalSeparator: ',',

+ 4 - 4
src/components/moveLine/MovePaymentsCard.vue

@@ -1,7 +1,7 @@
 <template lang="pug">
     li.move-lines-item
         h3.move-lines-item-maturity Venc. {{ item.dateMaturity | dateFormat}}
-        span.move-lines-item-subtotal {{ item.amountResidual | currency(...currencyCompany)}}
+        span.move-lines-item-subtotal {{ item.amountResidualCurrency | currency(...currency)}}
         .move-lines-item-options-wrapper(class="fa fa-trash" @click='onClickDelete' v-bind:class="{'move-payments-disable': moveDisable(item.dateMaturity) }")
 </template>
 
@@ -31,12 +31,12 @@
                 type: Object,
                 default: []
             },
-            currencyCompany: {
+            currency: {
                 type: Object,
                 default: {
                     name: '',
-                    symbol: '',
-                    position: 'before',
+                    symbol: '',
+                    position:'before',
                     rateSilent: 0,
                     thousandsSeparator: '.',
                     decimalSeparator: ',',

+ 3 - 4
src/components/moveLine/MovesGrid.vue

@@ -1,11 +1,9 @@
 <template lang="pug">
     .card-grid-wrapper-move
         .card-grid-move
-            card(v-for='item in items' :key='item.id' :amountResidual='item.amountResidual' :dateMaturity='item.dateMaturity' :debit='item.debit' :isSelected='item.id === selectedId' :isDisable='moveDisable(item.dateMaturity)' @onClick='onClickCard(item)')
+            card(v-for='item in items' :key='item.id' :amountResidual='item.amountResidualCurrency' :dateMaturity='item.dateMaturity' :debit='item.amountCurrency' :currency='currency' :isSelected='item.id === selectedId' :isDisable='moveDisable(item.dateMaturity)' @onClick='onClickCard(item)')
 </template>
-
 <script>
-
     import card from '@@/moveLine/MoveLineCard'
 
     export default {
@@ -14,11 +12,12 @@
                 type: Array,
                 default: []
             },
-            currencyCompany: {
+            currency: {
                 type: Object,
                 default: {
                     name: '',
                     symbol: '',
+                    position:'before',
                     rateSilent: 0,
                     thousandsSeparator: '.',
                     decimalSeparator: ',',

+ 6 - 6
src/components/moveLine/SelectedMovesGrid.vue

@@ -1,10 +1,10 @@
 <template lang="pug">
     .move-Lines-wrapper
         .move-line-Card-items
-            card(v-for='(item, index) in items' :key='index' :index='index' :item='item' :items='items'  @onClickDelete="onDeleteIntem" )
+            card(v-for='(item, index) in items' :key='index' :index='index' :item='item' :items='items' :currency='currency' @onClickDelete="onDeleteIntem" )
         .move-line-payments-total
             label.form-label-move-payments Total
-            input.form-input-move-payments(:value="total | currency(...currencyCompany)" readonly)
+            input.form-input-move-payments(:value="total | currency(...currency)" readonly)
 </template>
 
 <script>
@@ -21,18 +21,18 @@
                 type: Number,
                 default: 0
             },
-            currencyCompany: {
+            currency: {
                 type: Object,
                 default: {
                     name: '',
-                    symbol: '',
-                    position: 'before',
+                    symbol: '',
+                    position:'before',
                     rateSilent: 0,
                     thousandsSeparator: '.',
                     decimalSeparator: ',',
                     decimalPlaces: 0
                 }
-            },
+            }
         },
         components: {
             card

+ 102 - 48
src/components/payments/VoucherTicket.vue

@@ -17,16 +17,21 @@
                 .voucher-ticket-from-grid
                     .voucher-ticket-from-grid-item(v-for="line in items")
                         label.voucher-ticket-from-grid-item-left {{ line.dateMaturity | dateFormat}}
-                        label.voucher-ticket-from-grid-item-right {{ line.amountResidual | currency(...currencyCompany) }}
+                        label.voucher-ticket-from-grid-item-right {{ line.amountResidualCurrency | currency(...invoice.currency) }}
                 .voucher-ticket-from-item-total
                     label.voucher-ticket-from-label-total Total
-                    label.voucher-ticket-from-input-total {{ totalPayments | currency(...currencyCompany) }}
-                .voucher-ticket-from-item-total
-                    label.voucher-ticket-from-label-total Pagado
-                    label.voucher-ticket-from-input-total {{ paymentTotal | currency(...currencyCompany) }}
-                .voucher-ticket-from-item-total
-                    label.voucher-ticket-from-label-total Saldo
-                    label.voucher-ticket-from-input-total {{ paymentBalance | currency(...currencyCompany) }}
+                    .ticket-currency-total-wrapper
+                        .ticket-currency-total-item(v-for="item in currencyAmount")
+                            h3.currency-total-symbol {{ item.symbolCurrency }}
+                            input.currency-total-amount(readonly :value='item.amount | currency( ...item)')
+                        //- .ticket-currency-total-item
+                    //- label.voucher-ticket-from-input-total {{ totalPayments | currency(...invoice.currency) }}
+                //- .voucher-ticket-from-item-total
+                //-     label.voucher-ticket-from-label-total Pagado
+                //-     label.voucher-ticket-from-input-total {{ paymentTotal | currency(...invoice.currency) }}
+                //- .voucher-ticket-from-item-total
+                //-     label.voucher-ticket-from-label-total Saldo
+                //-     label.voucher-ticket-from-input-total {{ paymentBalance | currency(...invoice.currency) }}
 </template>
 
 <script>
@@ -40,34 +45,48 @@
                 type: String,
                 default: ''
             },
-            paymentBalance: {
-                type: Number,
-                default: 0
-            },
-            paymentTotal: {
-                type: Number,
-                default: 0
-            },
-            totalPayments: {
-                type: Number,
-                default: 0
+            currencyAmount :{
+                    type: Array,
+                    default: [],
+                    // default: [{
+                    //     symbolCurrency: 'G$',
+                    //     amount: 999999999,
+                    //     symbol: ' ',
+                    //     position: 'before',
+                    //     rateSilent: 0,
+                    //     thousandsSeparator: '.',
+                    //     decimalSeparator: ',',
+                    //     decimalPlaces: 0
+                    // }],
+                    // {
+                    //     symbolCurrency: '$',
+                    //     amount: 999999999,
+                    //     symbol: ' ',
+                    //     position: 'before',
+                    //     rateSilent: 0,
+                    //     thousandsSeparator: '.',
+                    //     decimalSeparator: ',',
+                    //     decimalPlaces: 0,
+                    //     decimalZeros: false
+                    // }
+
             },
+            // paymentBalance: {
+            //     type: Number,
+            //     default: 0
+            // },
+            // paymentTotal: {
+            //     type: Number,
+            //     default: 0
+            // },
+            // totalPayments: {
+            //     type: Number,
+            //     default: 0
+            // },
             items: {
                 type: [],
                 default: []
             },
-            currencyCompany: {
-                type: Object,
-                default: {
-                    name: '',
-                    symbol: '',
-                    position: 'before',
-                    rateSilent: 0,
-                    thousandsSeparator: '.',
-                    decimalSeparator: ',',
-                    decimalPlaces: 0
-                }
-            }
         }
     }
 </script>
@@ -92,10 +111,11 @@
                 .voucher-ticket-from-separator
                     h3
                         color: #9e9e9e
-                        font:
-                            size: 16pt
+                        font-size: 16pt
                         margin-left: 10px
                         margin-right: 10px
+                        margin-top: 10px
+                        margin-bottom: 5px
                         text-align: center
                     hr
                         margin-top: 3px
@@ -103,7 +123,7 @@
                         margin-right: 10px
                 .voucher-ticket-from-item
                     width: 100%
-                    height: 40px
+                    height: 35px
                     margin-bottom: 5px
                     .voucher-ticket-from-label
                         width: 150px
@@ -113,7 +133,7 @@
                             weight: bold
                         padding-left: 10px
                     .voucher-ticket-from-input
-                        width: calc(100% - 150px)
+                        width: calc(100% - 160px)
                         height: 25px
                         font:
                             size: 10pt
@@ -170,22 +190,56 @@
                     width: 100%
                     height: 25px
                     .voucher-ticket-from-label-total
-                        width: 60%
+                        width: 40%
                         height: 25px
-                        margin-top: 15px
+                        margin-top: 10px
                         font:
-                            size: 10pt
+                            size: 15pt
                             weight: bold
                         text-align: right
                         padding-right: 15px
-                    .voucher-ticket-from-input-total
-                        width: calc(40% - 10px)
-                        height: 25px
-                        margin-top: 15px
-                        text-align: right
-                        padding-right: 15px
-                        font:
-                            size: 10pt
-                            weight: bold
-                        border-bottom: 1px solid #dedede
+                        float: left
+                    .ticket-currency-total-wrapper
+                        width: 50%
+                        height: 115px
+                        float: right
+                        margin: 5px 10px 10px 10px
+                        overflow-y: auto
+                        border-left: 1px solid #d3d3d3
+                        .ticket-currency-total-item
+                            width: 100%
+                            height: 25px
+                            margin-top: 2px
+                            .currency-total-symbol
+                                width: 30px
+                                height: 100%
+                                font-size: 15pt
+                                text-align: center
+                                float: left
+                                margin: 0px
+                                padding-left: 5px
+                                padding-right: 5px
+                            .currency-total-amount
+                                width: calc(100% - 35px)
+                                height: 100%
+                                float: right
+                                font-size: 15pt
+                                text-align: right
+                                margin-right: 5px
+                                padding-right: 10px
+                                border-top: 0px
+                                border-left: 0px
+                                border-right: 0px
+
+                        // display: inline-block
+                    // .voucher-ticket-from-input-total
+                    //     width: calc(40% - 10px)
+                    //     height: 25px
+                    //     margin-top: 15px
+                    //     text-align: right
+                    //     padding-right: 15px
+                    //     font:
+                    //         size: 10pt
+                    //         weight: bold
+                    //     border-bottom: 1px solid #dedede
 </style>

+ 1 - 2
src/components/steps/Invoices.vue

@@ -2,7 +2,7 @@
     .payments-step
         .invoice-step
             searcher(:items='invoices' :keys="['number']" @onSearch="filterPaymentsInvoice")
-            grid(:items='invoicesVisible' @onSelect='selectInvoice' :currencyCompany='currencyCompany')
+            grid(:items='invoicesVisible' @onSelect='selectInvoice')
 </template>
 
 <script>
@@ -19,7 +19,6 @@
         },
         computed: mapGetters([
             'invoices',
-            'currencyCompany',
             'invoicesVisible'
         ]),
         methods: mapActions([

+ 27 - 14
src/components/steps/MethodPayment.vue

@@ -4,7 +4,7 @@
             .form-overlay-payments
             .form-spinner-payments
                 spinner(type='wave')
-        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :paymentBalance='paymentsResidual' :paymentTotal='paidTotal' :totalPayments='movesPaymentsTotal' :currencyCompany='currencyCompany')
+        ticket(v-if="!!selectedMoveLine" :items="movesPayments" :customer='selectedCustomer' :invoice='selectedInvoice' :currencyAmount='currencyAmount')
         form.method-payment
             .method-form-separator
                 h3 Detalle de Cliente
@@ -21,19 +21,18 @@
                     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 | currency(...currencyCompany)")
+                input.method-form-input-number(readonly :value="paymentCurrencyTotal | currency(...currency)")
             .method-form-item
                 label.method-form-label  Monto a Pagar
-                input.method-form-input(v-model='paid' autofocus)
+                input.method-form-input-number(v-model='paid' autofocus)
             .method-form-item
                 label.method-form-label Monto a Devolver
-                input.method-form-input(readonly :value='paymentsReturned | currency(...currencyCompany)')
+                input.method-form-input-number(readonly :value='paymentsReturned | currency(...currency)')
 </template>
 
 <script>
     import { mapGetters, mapActions } from 'vuex'
     import Ticket from '@@/payments/VoucherTicket'
-    // import Spinner from '@/components/common/Spinner'
     import Spinner from '@@/common/Spinner'
     import { SELECT_JOURNAL, CHANGE_INITIAL_PAID }from '@/constants/actionTypes'
 
@@ -45,15 +44,17 @@
         computed:{
             paymentJournals: {
                 get() {
-                    return this.selectedJournal
+                    return (this.selectedJournal) || -1
                 },
                 set(value) {
-                    this.selectJournal(value)
+                    if (value)
+                        this.selectJournal(value)
+                        this.paymentsReturned = 0
                 }
             },
             paid: {
                 get() {
-                    let formatted = this.$options.filters.currency(this.paidTotal, {...this.currencyCompany})
+                    let formatted = this.$options.filters.currency(this.paidTotal, {...this.currency})
                     return !!this.paidTotal ? formatted : formatted.replace(/\d/, '')
                 },
                 set(value) {
@@ -65,25 +66,37 @@
                     this.computePayment(value)
                 },
             },
+            currency:{
+                get() {
+                    return !!this.currencyJournal.id ? this.currencyJournal : this.currencyInvoice
+                }
+            },
+    
             ...mapGetters([
                 'selectedCustomer',
                 'selectedInvoice',
                 'selectedMoveLine',
                 'journals',
                 'selectedJournal',
-                'currencyCompany',
+                // 'currencyCompany',
+                'currencyJournal',
+                'currencyInvoice',
                 'movesPayments',
                 'movesPaymentsTotal',
+                // payments
                 'paidTotal',
                 'paymentsReturned',
-                'paymentsResidual',
-                'processingPayments'
+                'paymentCurrencyTotal',
+                // 'paymentsResidual',
+                'processingPayments',
+                //Currency
+                'currencyAmount'
             ]),
         },
         methods: {
             computePayment(value) {
-                this.paymentsReturned = value < this.movesPaymentsTotal ? 0 : value - this.movesPaymentsTotal
-                this.paymentsResidual = value > this.movesPaymentsTotal ? 0 : this.movesPaymentsTotal - value
+                this.paymentsReturned = value < this.paymentCurrencyTotal ? 0 : value - this.paymentCurrencyTotal
+                // this.paymentsResidual = value > this.movesPaymentsTotal ? 0 : this.movesPaymentsTotal - value
             },
             ...mapActions([
                 SELECT_JOURNAL,
@@ -93,7 +106,7 @@
         data() {
             return {
                 paymentsReturned: 0,
-                paymentsResidual: 0
+
             }
         }
     }

+ 3 - 3
src/components/steps/MoveLine.vue

@@ -1,8 +1,8 @@
 <template lang="pug">
     .payments-step
         .move-step
-            grid(:items='moves' @onSelect='selectMove' :currencyCompany='currencyCompany')
-            select-moves(:items='movesPayments' :total="movesPaymentsTotal" @onDeleteIntem='removeMovePayments' )
+            grid(:items='moves' @onSelect='selectMove' :currency='currencyInvoice')
+            select-moves(:items='movesPayments' :total="movesPaymentsTotal" @onDeleteIntem='removeMovePayments' :currency='currencyInvoice')
 </template>
 <script>
     import Grid from '@@/moveLine/MovesGrid'
@@ -20,7 +20,7 @@
             'moves',
             'movesPayments',
             'movesPaymentsTotal',
-            'currencyCompany',
+            'currencyInvoice',
         ]),
         methods: mapActions([
             SELECT_MOVE,

+ 7 - 1
src/constants/actionTypes.js

@@ -42,6 +42,11 @@ const CHANGE_INITIAL_PAID ='changeInitialPaid'
  * [CURRENCIES]
  */
 const INIT_PAYMENTS_CURRENCIES = 'initPaymentsCurrencies'
+const INIT_CURRENCIES_AMOUNT = 'initCurenciesAmount'
+/**
+ * [payments]
+ */
+const CALCULATE_CURRENCY_TOTAL = 'calculateCurrencyTotal'
 /*
     Check
  */
@@ -70,7 +75,8 @@ export {
     SELECT_CUSTOMER_INVOICES, SELECT_INVOICE, ADD_MOVE_IN_INVOICE,FILTER_PAYMENTS_INVOICE, //Customer -invoice
     SELECT_MOVE_INVOICE, SELECT_MOVE,REMOVE_MOVE_PAYMENTS, REMOVE_MOVE_PAYMENTS_ALL, SET_MOVE_PAYMENTS, //Customer -Move
     INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL, CHANGE_INITIAL_PAID,//Journal
-    INIT_PAYMENTS_CURRENCIES, //currency
+    INIT_PAYMENTS_CURRENCIES, INIT_CURRENCIES_AMOUNT,//currency
+    CALCULATE_CURRENCY_TOTAL, //payments
     CHECK_CUSTOMER, CHECK_INVOICE, CHECK_MOVE, CHECK_PAYMENTS, //Check
     RESET_PAYMENT_CUSTOMER, RESET_DATE, RESET_USER, RESET_COMPANY, RESET_CUSTOMERS, RESET_INVOICES, RESET_MOVE_LINES, RESET_JOURNALS, RESET_CURRENCY, RESET_PAYMENTS //RESET STATE
 }

+ 10 - 14
src/constants/mutationTypes.js

@@ -49,6 +49,8 @@ const SET_JOURNALS = 'setJournals'
 const SET_LOADING_JOURNALS = 'setLoadingJournals'
 const SET_SELECTED_JOURNAL = 'setSelectedJournal'
 const SET_PAID_TOTAL = 'setPaidTotal'
+const SET_CURRENCY_JOURNAL = 'setCurrencyJournal'
+// const SET_PAYMENTS_RETURNED = 'setPaymentsReturned'
 
 /**
  * [CURRENCIES]
@@ -56,19 +58,13 @@ const SET_PAID_TOTAL = 'setPaidTotal'
  */
 const SET_CURRENCIES = 'setCurrencies'
 const SET_LOADING_CURRENCIES = 'setLoadingCurrencies'
+const SET_CURRENCIES_AMOUNT = 'setCurrenciesAmount'
 /**
- * Reset
+ * [Payments]
  */
-/*const SET_RESET_DATE = 'setResetDate'
-const SET_RESET_USER = 'setResetUser'
-const SET_RESET_COMPANY = 'setResetCompany'
-const SET_RESET_CUSTOMERS = 'setResetCustomers'
-const SET_RESET_INVOICES = 'setResetInvoices'
-const SET_RESET_MOVE_LINES = 'setResetMoveLines'
-const SET_RESET_JOURNALS = 'setResetJournals'
-const SET_RESET_CURRENCY = 'setResetCurrency'
-const SET_RESET_PAYMENTS = 'setResetPayments'
-*/
+const SET_CALCULATE_CURRENCY_TOTAL = 'setCalculateCurencytotal'
+const SET_CURRENCY_TOTAL = 'setCurrencyTotal'
+
 export {
     SET_PROCESSING_PAYMENTS, SET_COMPLETED_PAYMENTS,
     SET_DATE, SET_LOADING_DATE, //Date
@@ -76,7 +72,7 @@ export {
     SET_CUSTOMERS, SET_LOADING_CUSTOMERS, SET_SELECTED_CUSTOMER, SET_FILTER_PAYMENTS_CUSTOMERS, //customer
     SET_INVOICES, SET_SELECTED_INVOICE, SET_SELECTED_CURRENCY_INVOICE, SET_MOVE_IN_INVOICE,SET_FILTER_PAYMENTS_INVOICE, //customer - invoice
     SET_MOVES, SET_SELECTED_MOVE_LINE, SET_SELECTED_MOVE_PAYMENTS, REMOVE_MOVE_LINE, REMOVE_PAYMENTS_MOVE, SET_TOTAL_MOVE_PAYMENTS,SET_ORDER_MOVE_LINE ,SET_ORDER_PAYMENTS_MOVE, //customer -Move
-    SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL, SET_PAID_TOTAL,//Journal
-    SET_CURRENCIES, SET_LOADING_CURRENCIES//Currency
-//    SET_RESET_DATE, SET_RESET_USER, SET_RESET_COMPANY, SET_RESET_CUSTOMERS, SET_RESET_INVOICES, SET_RESET_MOVE_LINES, SET_RESET_JOURNALS, SET_RESET_CURRENCY, SET_RESET_PAYMENTS //RESET
+    SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL, SET_PAID_TOTAL, SET_CURRENCY_JOURNAL,//Journal
+    SET_CURRENCIES, SET_LOADING_CURRENCIES, SET_CURRENCIES_AMOUNT,//Currency
+    SET_CALCULATE_CURRENCY_TOTAL, SET_CURRENCY_TOTAL // payments
 }

+ 3 - 3
src/index.js

@@ -2,17 +2,17 @@ import Vue from 'vue'
 import Payments from '@/Payments'
 import VModal from 'vue-js-modal'
 import store from '@/store'
-
 import currency from '@@/filters/currency'
 import dateFormat from '@@/filters/dateFormat'
+
 Vue.filter('currency', currency)
 Vue.filter('dateFormat', dateFormat)
-// vue.use
+
 Vue.use(VModal)
 // Vue.config.
 Vue.config.productionTip = false
 Vue.config.silent = true
-// Vue.config.devtools = true
+Vue.config.devtools =
 
 openerp.eiru_payments = (instance, local) => {
 

+ 1 - 11
src/store/actions.js

@@ -111,7 +111,7 @@ const actions = {
                 invoiceId: getters.selectedInvoice.id,
                 journalId: getters.selectedJournal.id,
                 customerId: getters.selectedCustomer.id,
-                amountPayments: getters.paidTotal <= getters.movesPaymentsTotal ? getters.paidTotal : getters.movesPaymentsTotal,
+                amountPayments: getters.paidTotal <= getters.paymentCurrencyTotal ? getters.paidTotal : getters.paymentCurrencyTotal,
                 moveLines: getters.movesPayments.map(item => {
                     return item.id
                 })
@@ -143,16 +143,6 @@ const actions = {
             }
             dispatch(`reset${key[0].toUpperCase()}${key.slice(1)}`)
         }
-        // dispatch(RESET_DATE)
-        // dispatch(RESET_USER)
-        // dispatch(RESET_COMPANY)
-        // dispatch(RESET_CUSTOMERS)
-        // dispatch(RESET_INVOICES)
-        // dispatch(RESET_MOVE_LINES)
-        // dispatch(RESET_JOURNALS)
-        // dispatch(RESET_CURRENCY)
-        // dispatch(RESET_PAYMENTS)
-
         dispatch(INIT_PAYMENTS)
     }
 }

+ 60 - 6
src/store/modules/currency.js

@@ -1,14 +1,17 @@
-import { INIT_PAYMENTS_CURRENCIES, RESET_CURRENCY } from '@/constants/actionTypes'
-import { SET_CURRENCIES, SET_LOADING_CURRENCIES } from '@/constants/mutationTypes'
+import { INIT_PAYMENTS_CURRENCIES, RESET_CURRENCY, INIT_CURRENCIES_AMOUNT, RESET_PAYMENTS } from '@/constants/actionTypes'
+import { SET_CURRENCIES, SET_LOADING_CURRENCIES, SET_CURRENCIES_AMOUNT } from '@/constants/mutationTypes'
+
 
 const initialState = {
     currency: [],
-    loadingCurrency: false
+    loadingCurrency: false,
+    currencyAmount: []
 }
 
 const state = {
     currency: initialState.currency,
-    loadingCurrency: initialState.loadingCurrency
+    loadingCurrency: initialState.loadingCurrency,
+    currencyAmount: initialState.currencyAmount
 }
 
 const getters = {
@@ -27,6 +30,14 @@ const getters = {
      */
     loadingCurrency(state) {
         return state.loadingCurrency
+    },
+    /**
+     * [currencyAmount description]
+     * @param  {[type]} state [description]
+     * @return {[type]}       [description]
+     */
+    currencyAmount (state) {
+        return state.currencyAmount
     }
 }
 
@@ -46,10 +57,38 @@ const mutations = {
      */
     [SET_LOADING_CURRENCIES] (state, payload) {
         state.loadingCurrency = !!payload
-    }
-
+    },
+    /**
+     * [actions description]
+     * @type {Object}
+     */
+    [SET_CURRENCIES_AMOUNT] (state, payload) {
+        let currency = payload.currency
+        let currencyMove = payload.currencyMovePayments
+        let amountCurrency = []
 
+        currency.forEach(item => {
+            let amount = 0
+            currencyMove.forEach(currency =>{
+                let currencyMoveLine = currency.currencyAmount.find(move => move.id === item.id)
+                amount = amount + currencyMoveLine.amountCurencyResidual
+            })
+            amountCurrency.push({
+                    id: item.id, 
+                    symbolCurrency: item.symbol,
+                    amount: amount,
+                    symbol: ' ',
+                    position: 'before',
+                    thousandsSeparator: item.thousandsSeparator,
+                    decimalSeparator: item.decimalSeparator,
+                    decimalPlaces: item.decimalPlaces,
+                    rateSilent: item.rateSilent
+            })
+        })
+        state.currencyAmount = amountCurrency
+    }
 }
+
 const actions = {
     /**
      * [INIT_CURRENCIES]
@@ -60,8 +99,23 @@ const actions = {
         commit(SET_CURRENCIES, payload)
         commit(SET_LOADING_CURRENCIES, payload)
     },
+    /**
+     * [currencyInvoiceRate description]
+     * @type {[type]}
+     */
     [RESET_CURRENCY] ({ commit }) {
         commit(SET_CURRENCIES, [] )
+    },
+    /**
+     * [currencyInvoiceRate description]
+     * @type {[type]}
+     */
+    [INIT_CURRENCIES_AMOUNT] ({ commit, getters, dispatch}) {
+        commit(SET_CURRENCIES_AMOUNT, {
+            currencyMovePayments: getters.movesPayments,
+            currency: getters.currency
+        })
+        dispatch(RESET_PAYMENTS)
     }
 }
 

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

@@ -1,15 +1,17 @@
-import { INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL, RESET_JOURNALS } from '@/constants/actionTypes'
-import { SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL } from '@/constants/mutationTypes'
+import { INIT_PAYMENTS_JOURNALS, SELECT_JOURNAL, RESET_JOURNALS, CALCULATE_CURRENCY_TOTAL } from '@/constants/actionTypes'
+import { SET_JOURNALS, SET_LOADING_JOURNALS, SET_SELECTED_JOURNAL, SET_CURRENCY_JOURNAL } from '@/constants/mutationTypes'
 
 const initialState ={
     journals: [],
     loadingJournal: false,
-    selectedJournal: null
+    selectedJournal: null,
+    currencyJournal: []
 }
 const state = {
     journals: initialState.journals,
     loadingJournal: initialState.loadingJournal,
-    selectedJournal: initialState.selectedJournal
+    selectedJournal: initialState.selectedJournal,
+    currencyJournal: initialState.currencyJournal
 }
 const getters = {
     /**
@@ -36,9 +38,18 @@ const getters = {
      */
     selectedJournal (state) {
         return state.selectedJournal
+    },
+    /**
+     * [currencyJournal description]
+     * @param  {[type]} state [description]
+     * @return {[type]}       [description]
+     */
+    currencyJournal (state) {
+        return state.currencyJournal
     }
 
 }
+
 const mutations = {
     /**
      * [journals description]
@@ -64,6 +75,13 @@ const mutations = {
      */
     [SET_SELECTED_JOURNAL] (state, payload) {
         state.selectedJournal = payload
+    },
+    /**
+     * [currencyJournal description]
+     * @type {[type]}
+     */
+    [SET_CURRENCY_JOURNAL] (state, payload) {
+        state.currencyJournal = payload
     }
 
 }
@@ -83,8 +101,19 @@ const actions = {
      * @param {*} param0
      * @param {*} payload
      */
-    [SELECT_JOURNAL] ({ commit },payload ) {
+    [SELECT_JOURNAL] ({ commit, dispatch, getters },payload ) {
+        let currency = []
         commit(SET_SELECTED_JOURNAL, payload)
+
+        dispatch(CALCULATE_CURRENCY_TOTAL, payload)
+
+        if (payload.currency.id){
+            currency = payload.currency
+        } else {
+            currency = getters.currencyCompany
+        }
+
+        commit(SET_CURRENCY_JOURNAL, currency)
     },
     [RESET_JOURNALS] ({ commit }) {
         commit(SET_JOURNALS, [] )

+ 17 - 10
src/store/modules/moveLines.js

@@ -5,7 +5,8 @@ import {
     ADD_MOVE_IN_INVOICE,
     REMOVE_MOVE_PAYMENTS_ALL,
     RESET_MOVE_LINES,
-    SET_MOVE_PAYMENTS
+    SET_MOVE_PAYMENTS,
+    INIT_CURRENCIES_AMOUNT
 } from '@/constants/actionTypes'
 
 import {
@@ -24,8 +25,6 @@ const initialState = {
     selectedMoveLine: null,
     movesPayments: [],
     movesPaymentsTotal: 0,
-    movesPaymentsBalance: 0,
-
 }
 
 const state = {
@@ -33,7 +32,6 @@ const state = {
     selectedMoveLine: initialState.selectedMoveLine,
     movesPayments: initialState.movesPayments,
     movesPaymentsTotal: initialState.movesPaymentsTotal,
-    movesPaymentsBalance: initialState.movesPaymentsBalance,
 }
 
 const getters = {
@@ -74,9 +72,9 @@ const getters = {
      * @param  {[type]} state [description]
      * @return {[type]}       [description]
      */
-    movesPaymentsBalance (state) {
-        return state.movesPaymentsBalance
-    }
+    // movesPaymentsBalance (state) {
+    //     return state.movesPaymentsBalance
+    // }
 }
 
 const mutations = {
@@ -89,6 +87,10 @@ const mutations = {
     [SET_MOVES] (state, payload) {
         state.moves =  payload
     },
+    /**
+     * [movesPayments description]
+     * @type {[type]}
+     */
     [SET_MOVE_PAYMENTS] (state, payload) {
         state.movesPayments = payload
     },
@@ -154,10 +156,11 @@ const mutations = {
      */
     [SET_TOTAL_MOVE_PAYMENTS] (state) {
         let total = 0
+
         state.movesPayments.forEach(item => {
-            total = total + item.amountResidual
-            // total = total + !!item.amountResidual ? item.amountResidual : 0
+            total = total + item.amountResidualCurrency
         })
+
         state.movesPaymentsTotal = total
     },
     /**
@@ -197,13 +200,15 @@ const actions = {
      * @param {*} param0
      * @param {*} payload
      */
-    [SELECT_MOVE] ({ commit }, payload) {
+    [SELECT_MOVE] ({ commit, dispatch }, payload) {
         commit(SET_SELECTED_MOVE_PAYMENTS, payload)
         commit(SET_SELECTED_MOVE_LINE, payload)
         /* Remover Move Line */
         commit(REMOVE_MOVE_LINE, payload)
         commit(SET_TOTAL_MOVE_PAYMENTS)
         commit(SET_ORDER_PAYMENTS_MOVE)
+
+        dispatch(INIT_CURRENCIES_AMOUNT)
     },
     /**
      *
@@ -223,6 +228,8 @@ const actions = {
 
         commit(SET_ORDER_MOVE_LINE)
         commit(SET_TOTAL_MOVE_PAYMENTS)
+
+        dispatch(INIT_CURRENCIES_AMOUNT)
     },
     /**
      * [length description]

+ 50 - 13
src/store/modules/payments.js

@@ -1,16 +1,15 @@
-import { CHANGE_INITIAL_PAID, RESET_PAYMENTS } from '@/constants/actionTypes'
-import { SET_PAID_TOTAL } from '@/constants/mutationTypes'
+import { CHANGE_INITIAL_PAID, RESET_PAYMENTS, CALCULATE_CURRENCY_TOTAL } from '@/constants/actionTypes'
+import { SET_PAID_TOTAL, SET_CALCULATE_CURRENCY_TOTAL, SET_CURRENCY_TOTAL } from '@/constants/mutationTypes'
 
 const initialState = {
     paidTotal: 0,
     paymentsReturned: 0,
-    paymentsResidual: 0
-
+    paymentCurrencyTotal: 0
 }
 const state = {
     paidTotal: initialState.paidTotal,
     paymentsReturned: initialState.paymentsReturned,
-    paymentsResidual: initialState.paymentsResidual
+    paymentCurrencyTotal: initialState.paymentCurrencyTotal
 }
 const getters = {
     /**
@@ -32,33 +31,71 @@ const getters = {
         return state.paymentsReturned
     },
     /**
-     * [paymentsResidual description]
-     * @method paymentsResidual
-     * @param  {[type]}         state [description]
-     * @return {[type]}               [description]
+     * [paymentCurrencyTotal description]
+     * @param  {[type]} state [description]
+     * @return {[type]}       [description]
      */
-    paymentsResidual (state) {
-        return state.paymentsResidual
+    paymentCurrencyTotal (state) {
+        return state.paymentCurrencyTotal
     }
 }
+
 const mutations = {
     /**
      * [paidTotal description]
      * @type {[type]}
      */
     [SET_PAID_TOTAL] (state, payload) {
-        state.paidTotal =payload
+        state.paidTotal = payload
+    },
+    /**
+     * [paymentCurrencyTotal description]
+     * @type {[type]}
+     */
+    [SET_CURRENCY_TOTAL] (state, payload) {
+        state.paymentCurrencyTotal = payload
+    },
+    /**
+     * [SET_CALCULATE_CURRENCY_TOTAL]
+     * @type {[type]}
+     */
+    [SET_CALCULATE_CURRENCY_TOTAL] (state, payload) {
+        let currencyJournal = payload.movesCurrencyAmount.find(item => item.id ===payload.currency.id)
+        let total = currencyJournal.amount
+        if (!currencyJournal)
+            total = 0
+        state.paymentCurrencyTotal = total
     }
 }
 const actions = {
     /**
-     *
+     * [CHANGE_INITIAL_PAID]
      */
     [CHANGE_INITIAL_PAID] ({ commit },payload) {
         commit(SET_PAID_TOTAL, payload)
     },
+    /**
+     * [CALCULATE_CURRENCY_TOTAL]
+     */
+    [CALCULATE_CURRENCY_TOTAL] ({commit, getters}, payload) {
+        let currency = []
+        if (payload.currency.id){
+            currency = payload.currency
+        } else {
+            currency = getters.currencyCompany
+        }
+        commit(SET_CALCULATE_CURRENCY_TOTAL, {
+            currency: currency,
+            movesCurrencyAmount: getters.currencyAmount
+        })
+        commit(SET_PAID_TOTAL, 0)
+    },
+    /**
+     * [RESET_PAYMENTS]
+     */
     [RESET_PAYMENTS] ({ commit }) {
         commit(SET_PAID_TOTAL, 0)
+        commit(SET_CURRENCY_TOTAL, 0)
     }
 }
 

+ 5 - 6
src/store/modules/user.js

@@ -1,15 +1,13 @@
 import { INIT_PAYMENTS_USER, INIT_PAYMENTS_COMPANY, RESET_USER} from '@/constants/actionTypes'
 import { SET_USER, SET_LOADING_USER } from '@/constants/mutationTypes'
 
-const initialState ={
+const initialState = {
     user: null,
     loadingUser: false,
-
 }
 const state = {
     user: initialState.user,
     loadingUser: initialState.loadingUser,
-
 }
 
 const getters = {
@@ -18,7 +16,7 @@ const getters = {
      * @param  {[type]} state [description]
      * @return {[type]}       [description]
      */
-    user(state) {
+    user (state) {
         return state.user
     },
     /**
@@ -26,7 +24,7 @@ const getters = {
      * @param  {[type]} state [description]
      * @return {[type]}       [description]
      */
-    loadingUser(state) {
+    loadingUser (state) {
         return state.loadingUser
     }
 }
@@ -51,6 +49,7 @@ const mutations = {
 
 const actions ={
     /**
+    * [INIT_PAYMENTS_USER]
     * @param {*} param0
     * @param {*} payload
      */
@@ -62,7 +61,7 @@ const actions ={
 
     },
     /**
-     *
+     * [INIT_PAYMENTS_USER]
      */
     [RESET_USER] ({ commit }) {
         commit(SET_USER, [])

+ 1 - 1
views/template.xml

@@ -14,6 +14,6 @@
             <field name="tag">eiru_payments.action_launch</field>
         </record>
 
-        <menuitem id="eiru_payments.launch" name="Pagos" parent="eiru_dashboard.eiru_dashboard_pagos_cliente" action="eiru_payments.client_action_launch" sequence="13"/>
+        <menuitem id="eiru_payments.launch" name="Nuevo pago de ventas" parent="eiru_dashboard.eiru_dashboard_pagos_cliente" action="eiru_payments.client_action_launch" sequence="13"/>
     </data>
 </openerp>