[FIX] account_invoice: due date is reset to current date when we have no payment term and due date is manually defined

bzr revid: ado@tinyerp.com-20130603061602-h6q0y0vzl2atm9jy
This commit is contained in:
Amit Dodiya 2013-06-03 11:46:02 +05:30
commit a9cdc75326
1 changed files with 19 additions and 9 deletions

View File

@ -557,17 +557,27 @@ class account_invoice(osv.osv):
def onchange_payment_term_date_invoice(self, cr, uid, ids, payment_term_id, date_invoice):
res = {}
if isinstance(ids, int):
ids = [ids]
if not date_invoice:
date_invoice = time.strftime('%Y-%m-%d')
if not payment_term_id:
return {'value':{'date_due': date_invoice}} #To make sure the invoice has a due date when no payment term
pterm_list = self.pool.get('account.payment.term').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()
res = {'value':{'date_due': pterm_list[-1]}}
else:
raise osv.except_osv(_('Insufficient Data!'), _('The payment term of supplier does not have a payment term line.'))
for invoice_record in self.browse(cr, uid, ids):
if not payment_term_id:
if invoice_record.date_due:
return {'value':{'date_due': invoice_record.date_due}} #To make sure the invoice due date should contain due date which is entered by user when there is no payment term defined
else:
return {'value':{'date_due': date_invoice}} #To make sure that the invoice due date contain current date when there is no payment term and no due date defined
else:
if not invoice_record.date_due:
return {'value':{'date_due': invoice_record.date_due}} #To make sure the invoice due date should contain due date which is entered by user when there is no payment term defined
else:
pterm_list = self.pool.get('account.payment.term').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()
res = {'value':{'date_due': pterm_list[-1]}}
else:
raise osv.except_osv(_('Insufficient Data!'), _('The payment term of supplier does not have a payment term line.'))
return res
def onchange_invoice_line(self, cr, uid, ids, lines):