45
45
'credit_account_id': fields.many2one('account.account', 'Credit Account'),
46
46
'debit_account_id': fields.many2one('account.account', 'Debit Account'),
47
47
'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'),
48
'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True),
49
'sup_discount_account_id': fields.many2one('account.account', 'Supplier Discount Account',required=True),
49
51
account_cash_discount()
61
63
_inherit = "account.invoice"
63
65
def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None):
66
67
This function return the Amount to paid according to the payment term cash discount payment term lines
69
69
if context is None:
72
71
tax_obj = self.pool.get('account.tax')
73
72
invoice = self.browse(cr, uid, ids[0], context=context)
204
203
for discount_line in payment_term_lines.cash_discount_ids:
205
204
if diff_day >= dis and diff_day <= discount_line.delay:
206
account_id = discount_line.discount_account_id.id
205
if invoice.type in ('in_invoice', 'in_refund'):
206
account_id = discount_line.sup_discount_account_id.id
208
account_id = discount_line.discount_account_id.id
207
209
dis = discount_line.delay
208
210
return account_id
210
212
def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''):
212
213
if context is None:
214
215
#TODO check if we can use different period for payment and the writeoff line
220
221
move_line_obj = self.pool.get('account.move.line')
221
222
move_obj = self.pool.get('account.move')
223
if 'amount_currency' in context and context['amount_currency']:
224
amount_currency = context['amount_currency']
226
amount_currency = invoice.residual
227
224
amount_discount = 0.0
228
225
if invoice.payment_term:
229
226
# Return the discount on for the payment term
230
amount_discount = self._get_payment(cr, uid, ids, amount_currency, invoice.payment_term.id, context=context)
227
amount_discount = self._get_payment(cr, uid, ids, pay_amount, invoice.payment_term.id, context=context)
232
230
src_account_id = invoice.account_id.id
233
231
# Take the seq as name for move
234
232
types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}
291
290
l1['name'] = name
292
291
l2['name'] = name
293
292
lines = [(0, 0, l1), (0, 0, l2)]
294
### When we make payment by pay invoice wizard and if found the taxes move then directly take the entry from the wizard
295
295
if 'tax_move_ids' in context and context['tax_move_ids']:
296
296
move_line = context['tax_move_ids']
297
297
for move_line_id in move_line:
338
338
l3['name'] = name
339
339
lines.append((0, 0, l3))
341
### When we make payment by pay invoice wizard and if found the discount moves in wizard discount move then directly take the entry from the wizard
341
342
if 'discount_move_ids' in context and context['discount_move_ids']:
342
dis_move_id = context['discount_move_ids'][0]
343
move_id = move_line_obj.search(cr, uid,[('move_id','=',dis_move_id)])
344
move_line_data = move_line_obj.browse(cr, uid, move_id[0])
346
'debit': move_line_data.debit,
347
'credit':move_line_data.credit,
348
'account_id': move_line_data.account_id.id,
349
'partner_id': move_line_data.partner_id.id,
350
'ref':move_line_data.ref,
351
'date': move_line_data.date,
352
'currency_id':currency_id,
353
'amount_currency':amount_currency and direction * amount_currency or 0.0,
354
'name':move_line_data.name,
356
lines.append((0, 0, l4))
358
move_obj.unlink(cr, uid, context['discount_move_ids'])
343
move_line = context['discount_move_ids']
344
for move_line_id in move_line:
345
move_line_data = move_line_obj.browse(cr, uid,move_line_id)
347
'debit': move_line_data.debit,
348
'credit':move_line_data.credit,
349
'account_id': move_line_data.account_id.id,
350
'partner_id': move_line_data.partner_id.id,
351
'ref':move_line_data.ref,
352
'date': move_line_data.date,
353
'currency_id':currency_id,
354
'amount_currency':amount_currency and direction * amount_currency or 0.0,
355
'name':move_line_data.name,
356
'tax_code_id':move_line_data.tax_code_id.id,
357
'tax_amount':move_line_data.tax_amount,
359
lines.append((0, 0, l4))
360
move_line_obj.unlink(cr, uid,[move_line_id])
361
move_obj.unlink(cr, uid,[move_line_data.move_id.id])
360
363
if amount_discount>0:
361
364
if 'account_id' in context and context['account_id']: