|
@@ -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'
|
|
|
|
|
|
|
|
|
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)
|
|
|
})
|
|
|
|
|
|
|
|
@@ -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
|
|
|
|
|
|
|
|
|
|
|
@@ -99,5 +117,4 @@ class AccountVoucher(models.Model):
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|