Browse Source

[FIX] some styles in components. [IMP] recompute payment terms based on amount paid

Gogs 7 years ago
parent
commit
832f1ac586

+ 27 - 10
models/account_voucher.py

@@ -3,7 +3,8 @@ from openerp import api, fields, models, cli
 from openerp.exceptions import except_orm
 
 from datetime import datetime
-from dateutil.relativedelta import relativedelta
+from dateutil.relativedelta import relativedelta as rd
+from dateutil.parser import parse
 
 from operator import itemgetter
 
@@ -13,6 +14,7 @@ class AccountVoucher(models.Model):
     @api.model
     def create_from_pos(self, values):
         date_now = fields.Date.context_today(self)
+        date_format = '%Y-%m-%d'
 
         # Step 1: Create Sale Order and Confirm
         sale_order_line_values = [
@@ -29,7 +31,7 @@ class AccountVoucher(models.Model):
             'picking_policy': 'direct',
             'state': 'manual',
             'date_confirm': date_now,
-            'payment_term': 4
+            'payment_term': 5
         }
 
         sale_order = self.env['sale.order'].create(sale_order_values)
@@ -40,11 +42,11 @@ class AccountVoucher(models.Model):
         invoice = self.env['account.invoice'].browse(invoice_id)
 
         days_to_due = max(invoice.payment_term.line_ids.mapped(lambda x: x.days + x.days2))
-        due_date = datetime.strptime(date_now, '%Y-%m-%d') + relativedelta(days=days_to_due)
+        due_date = parse(date_now) + rd(days=days_to_due)
 
         invoice.write({
             'date_invoice': date_now,
-            'date_due': due_date.strftime('%Y-%m-%d')
+            'date_due': due_date.strftime(date_format)
         })
 
         # Step 3: Create invoice move lines
@@ -61,13 +63,29 @@ class AccountVoucher(models.Model):
 
         same_currency = invoice.currency_id != invoice.company_id.currency_id
         percent_paid = amount_paid / total
-        distribute_percent = percent_paid / len(invoice.payment_term.line_ids)
+        distribute_percent = -(percent_paid / len(invoice.payment_term.line_ids))
+
+        total_lines = []
 
         for line in invoice.payment_term.line_ids:
-            due_date = datetime.strptime('%Y-%m-%d') + relativedelta(days=line.days)
+            due_date = (parse(date_now) + rd(days=line.days + line.days2)).strftime(date_format)
+
+            if percent_paid:
+                total_lines.append((date_now, round(percent_paid, decimal_precision)))
+                percent_paid = 0
+
+                if date_format == date_now:
+                    distribute_percent = -((total_lines[0] - line.value_amount)  / (len(invoice.payment_term.line_ids) - 1))
+                    continue
+
+            if line.value != 'balance':
+                total_lines.append((due_date, round(line.value_amount + distribute_percent, decimal_precision)))
+                continue
+            
+            total_lines.append((due_date, line.value_amount))
 
-            if percent_paid and due_date == date_now:
-                distribute_percent = (line.value_amount  - percent_paid)  / (len(invoice.payment_term.line_ids) - 1)
+        import pdb; pdb.set_trace()
+        print total_lines
 
 # -----------------------------------------------------------------------------------------------------        
 #  def compute(self, cr, uid, id, value, date_ref=False, context=None):
@@ -99,5 +117,4 @@ class AccountVoucher(models.Model):
 #         dist = round(value-amount, prec)
 #         if dist:
 #             result.append( (time.strftime('%Y-%m-%d'), dist) )
-#         return result
-        
+#         return result

+ 0 - 1
src/components/cart/CartContainer.vue

@@ -2,7 +2,6 @@
     .cart-container
         cart-total
         cart-items
-        
 </template>
 
 <script>

+ 2 - 2
src/components/cart/ProductSelector.vue

@@ -97,6 +97,6 @@
 
         .product-variants
             width: 100%;
-            height: calc(100% - 70px);
-            overflow-y: auto;
+            height: calc(100% - 70px)
+            overflow-y: auto
 </style>

+ 0 - 1
src/components/cart/ProductsContainer.vue

@@ -22,6 +22,5 @@
         height: 100%
         padding-right: 5px
         display: inline-block
-
 </style>