From eda647c97a39842f9d7d53003f9c03451938c1b7 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Mon, 9 Aug 2010 23:18:01 +0530 Subject: [PATCH] [FIX]: improve payment terms, need to improve relativedelta(day=-1) as it will not work like RelativeDateTime(day=-1) is working -ve val now working with relativedelta with day params [IMP]: improve the code remove TABs bzr revid: mga@tinyerp.com-20100809174801-slgotvx5f194fen1 --- addons/account/account.py | 17 ++++-- addons/account/invoice.py | 2 +- .../wizard/account_statement_from_invoice.py | 8 +-- .../account_statement_from_invoice_view.xml | 53 +++++++++---------- 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 5f83dd4582f..11ee236a567 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -19,7 +19,7 @@ # ############################################################################## import time -from datetime import datetime +from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from operator import itemgetter @@ -79,9 +79,20 @@ class account_payment_term(osv.osv): elif line.value == 'balance': amt = round(amount, prec) if amt: - next_date = datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days) + next_date = (datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days)) if line.days2 < 0: - next_date += relativedelta(day=line.days2) + nyear = next_date.strftime("%Y") + nmonth = str(int(next_date.strftime("%m"))% 12+2) + nday = "1" + + ndate = "%s-%s-%s" % (nyear, nmonth, nday) + nseconds = time.mktime(time.strptime(ndate, '%Y-%m-%d')) + next_month = datetime.fromtimestamp(nseconds) + + delta = timedelta(seconds=1) + next_date = next_month - delta + + next_date = next_date + relativedelta(days=line.days2) if line.days2 > 0: next_date += relativedelta(day=line.days2, months=1) result.append( (next_date.strftime('%Y-%m-%d'), amt) ) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index d40d4037c97..35437fa019a 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -462,7 +462,7 @@ class account_invoice(osv.osv): date_invoice = time.strftime('%Y-%m-%d') pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice) - + if pterm_list: pterm_list = [line[0] for line in pterm_list] pterm_list.sort() diff --git a/addons/account/wizard/account_statement_from_invoice.py b/addons/account/wizard/account_statement_from_invoice.py index 0523b5f60ca..a409bb77f89 100644 --- a/addons/account/wizard/account_statement_from_invoice.py +++ b/addons/account/wizard/account_statement_from_invoice.py @@ -92,7 +92,7 @@ class account_statement_from_invoice_lines(osv.osv_memory): 'ref': line.ref, 'reconcile_id': reconcile_id, 'date': time.strftime('%Y-%m-%d'), #time.strftime('%Y-%m-%d'), #line.date_maturity or, - }, context=context) + }, context=context) return {} account_statement_from_invoice_lines() @@ -107,10 +107,10 @@ class account_statement_from_invoice(osv.osv_memory): 'date': fields.date('Date payment',required=True), 'journal_ids': fields.many2many('account.journal', 'account_journal_relation', 'account_id', 'journal_id', 'Journal'), 'line_ids': fields.many2many('account.move.line', 'account_move_line_relation', 'move_id', 'line_id', 'Invoices'), - } + } _defaults = { 'date':lambda *a: time.strftime('%Y-%m-%d'), - } + } def search_invoices(self, cr, uid, ids, context=None): @@ -167,4 +167,4 @@ class account_statement_from_invoice(osv.osv_memory): } account_statement_from_invoice() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account/wizard/account_statement_from_invoice_view.xml b/addons/account/wizard/account_statement_from_invoice_view.xml index b1c0e68534e..c5f42851e69 100644 --- a/addons/account/wizard/account_statement_from_invoice_view.xml +++ b/addons/account/wizard/account_statement_from_invoice_view.xml @@ -1,33 +1,33 @@ - + account.statement.from.invoice.form account.statement.from.invoice form
- - - - - + + + + + -