Forráskód Böngészése

[FIX] amounts to paid in credit step

Gogs 7 éve
szülő
commit
048939e35b

+ 0 - 1
__init__.py

@@ -2,7 +2,6 @@
 from models import account_journal
 from models import account_payment_term
 from models import account_voucher
-from models import eiru_pos
 from models import product_template
 from models import res_company
 from models import res_currency

+ 1 - 1
models/account_voucher.py

@@ -63,7 +63,7 @@ class AccountVoucher(models.Model):
                 total_lines.append([date_now, percent_paid])
                 percent_paid = amount_paid = 0
 
-                if date_format == date_now:
+                if due_date == date_now:
                     distribute_percent = -((total_lines[0] - line.value_amount)  / (len(invoice.payment_term.line_ids) - 1))
                     continue
 

+ 0 - 8
models/eiru_pos.py

@@ -1,8 +0,0 @@
-from openerp import api, fields, models
-
-class EiruPos(models.AbstractModel):
-    _name = 'eiru.pos'
-
-    @api.v8
-    def action_create_order(self, values):
-        print values

+ 2 - 1
models/res_company.py

@@ -15,5 +15,6 @@ class ResCompany(models.Model):
                 'name': user.company_id.currency_id.name,
                 'display_name': user.company_id.currency_id.display_name,
                 'symbol': user.company_id.currency_id.symbol
-            }
+            },
+            'today': fields.Date.context_today(self)
         }

+ 64 - 6
src/components/payment/credit/PaymentCreditAmount.vue

@@ -15,6 +15,10 @@
                     td
                         th Fecha de Pago
                         th Monto a pagar
+                tbody
+                    tr(v-for="line in totalLines")
+                        td {{ line.date }}
+                        td {{ line.total }}
 </template>
 
 <script>
@@ -30,24 +34,74 @@
                     value = accounting.unformat(value, ',')
 
                     this.changeAmountPaid(value)
+                    this.computeAmounts(value)
                 }
             },
             ...mapGetters([
                 'total',
                 'currencySymbol',
-                'amountPaid'
+                'amountPaid',
+                'selectedPaymentTerm',
+                'company'
             ])
         },
         methods: {
             formatTotal() {
                 return accounting.formatMoney(this.total, this.currencySymbol, 0, '.', ',')
             },
+            computeAmounts(value) {
+                this.totalLines = []
+
+                let percentPaid = value / this.total
+                let distributePercent = -(percentPaid / this.selectedPaymentTerm.lines.length)
+                let totals = []
+                let residual = this.total
+
+                for (let line of this.selectedPaymentTerm.lines) {
+                    let dueDate = moment(this.company.today).add(line.days + line.days2, 'days').format('YYYY-MM-DD')
+
+                    if (percentPaid) {
+                        totals.push([this.company.today, percentPaid])
+                        percentPaid = 0
+
+                        if (dueDate === this.company.today) {
+                            distributePercent = -((this.totals[0] - line.value_amount) / (this.selectedPaymentTerm.lines.length - 1))
+                            continue
+                        }
+                    }
+
+                    if (line.value !== 'balance') {
+                        totals.push([dueDate, line.value_amount + distributePercent])
+                        continue
+                    }
+
+                    totals.push([dueDate, line.value_amount])
+
+                    for (let line of totals) {
+                        let currentPrice = (this.total * line[1]).toFixed(2)
+                        residual = residual - currentPrice
+
+                        this.totalLines.push({
+                            date: line[0], 
+                            total: currentPrice !== parseFloat(0).toFixed(2) ? currentPrice : residual.toFixed(2)
+                        })
+                    }
+
+                    totals = []
+                }
+            },
             ...mapActions([
                 'changeAmountPaid'
             ])
         },
+        data() {
+            return {
+                totalLines: []
+            }
+        },
         mounted() {
             this.changeAmountPaid(0)
+            console.log(this.totalLines)
         }
     }
 </script>
@@ -92,19 +146,23 @@
                 width: 100%
                 height: 250px
                 border: 1px solid #d3d3d3
-
                 table
                     width: 100%
-
-                    td
-                        height: 35px
                     thead
                         th
                             line-height: 35px
                             padding-left: 10px
-
                         th:nth-child(1)
                             width: 250px
                         th:nth-child(2)
                             width: 200px
+                    tbody
+                        td
+                            height: 35px
+                            padding-left: 10px
+
+                        td:nth-child(1)
+                            width: 250px
+                        td:nth-child(2)
+                            width: 200px
 </style>