35
35
class account_invoice(osv.osv):
36
36
_inherit='account.invoice'
38
'next_payment_date': fields.date('Next Payment Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},),
38
'next_payment_date': fields.date('Next Payment Date', states={'open': [('readonly', True)], 'close': [('readonly', True)]},),
41
41
def action_date_assign(self, cr, uid, ids, *args):
42
data = super(account_invoice,self).action_date_assign(cr, uid, ids, *args)
42
data = super(account_invoice, self).action_date_assign(cr, uid, ids, *args)
43
43
for inv in self.browse(cr, uid, ids):
44
44
if inv.payment_term.id:
45
45
payment_data = self.pool.get('account.payment.term').browse(cr, uid, inv.payment_term.id).cash_discount_ids
47
47
delay = payment_data[0].delay
48
48
if inv.date_invoice:
49
date_invoice =inv.date_invoice
49
date_invoice = inv.date_invoice
51
51
date_invoice = time.strftime('%Y-%m-%d')
52
self.write(cr, uid, [inv.id], {'next_payment_date':(DateTime.strptime(date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=delay)).strftime('%Y-%m-%d')})
52
self.write(cr, uid, [inv.id], {'next_payment_date': (DateTime.strptime(date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days = delay)).strftime('%Y-%m-%d')})
55
55
def _next_date(self, cr, uid, ids, context=None):
56
56
payment_term_obj = self.pool.get('account.payment.term')
57
57
current_date = time.strftime('%Y-%m-%d')
58
ids = self.search(cr, uid, [('state','=','open')])
58
ids = self.search(cr, uid, [('state', '=', 'open')])
60
60
invoice_data = self.browse(cr, uid, id, context=context)
61
61
next_pay_date = invoice_data.next_payment_date
65
65
if next_pay_date < current_date:
66
66
for dis_line in payment_data.cash_discount_ids:
67
discount_date = (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d')
67
discount_date = (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d')
68
68
if discount_date > current_date:
69
self.write(cr, uid, [id], {'next_payment_date':discount_date})
69
self.write(cr, uid, [id], {'next_payment_date': discount_date})
98
98
'property_customer_cash_discount_account': fields.property(
101
relation='account.account',
102
string="Customer Cash Discount Account",
101
relation = 'account.account',
102
string = "Customer Cash Discount Account",
106
106
'property_supplier_cash_discount_account': fields.property(
107
107
'account.account',
109
relation='account.account',
110
string="Supplier Cash Discount Account",
109
relation = 'account.account',
110
string = "Supplier Cash Discount Account",