In Odoo first we create existing own module and inherits the account invoice object in your own module. Than fetch all object like as a account.move , account.journal, account.period in your own module and update the account.journal and also invoice_id in your existing module. Than get all the Documents for a Partner and each document and Pay only selected documents and create a single receipt. And the Add Journal Entries than customer make final payments in particular customer.
Using this function given below
@api.multi
def payment_invoice(self, cr, uid, ids, context=None):
if not context:
context = {}
ctx = context.copy()
invoice_object = self.browse(cr,uid,ids[0])
voucher_id = False
invoice_number = invoice_object.number
voucher_pool = self.pool.get('account.voucher')
journal_pool = self.pool.get('account.journal')
period_obj = self.pool.get('account.period')
if ctx.get('journal_type',''):
bank_journal_ids= journal_pool.search(cr, uid, [('type', '=', context.get('journal_type'))])
else:
bank_journal_ids = journal_pool.search(cr, uid, [('type', '=', 'bank')])
if not len(bank_journal_ids):
return True
ctx.update({
'default_partner_id': invoice_object.partner_id.id,
'default_amount': invoice_object.amount_total,
'default_name':invoice_object.name,
'close_after_process': True,
'invoice_type':invoice_object.type,
'invoice_id':invoice_object.id,
'journal_id':bank_journal_ids[0],
'default_type': invoice_object.type in ('out_invoice','out_refund') and 'receipt' or 'payment'
})
if invoice_object.type in ('out_refund','in_refund'):
ctx.update({'default_amount':-invoice_object.amount_total})
tax_id = self._get_tax(cr, uid, context)
account_data = self.get_accounts(cr,uid,invoice_object.partner_id.id,bank_journal_ids[0])
date = time.strftime('%Y-%m-%d')
voucher_data = {
'period_id': invoice_object.period_id.id,
'account_id': account_data['value']['account_id'],
'partner_id': invoice_object.partner_id.id,
'journal_id':bank_journal_ids[0],
'currency_id': invoice_object.currency_id.id,
'reference': invoice_object.name,
'amount': ctx.get('amount',0.0),
'type':account_data['value']['type'],
'state': 'draft',
'pay_now': 'pay_later',
'name': '',
'cheque_number' : ctx.get('cheque_number',0.0),
'bank' : ctx.get('bank', ''),
'branch' : ctx.get('branch', ''),
'chq_date' : ctx.get('chq_date', time.strftime('%Y-%m-%d')),
'date': time.strftime('%Y-%m-%d'),
'company_id': self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=None),
'tax_id': tax_id,
'payment_option': 'without_writeoff',
'comment': _('Write-Off'),
}
if invoice_object.type in ('out_refund','in_refund'):
voucher_data.update({'amount':-invoice_object.amount_total})
if not voucher_data['period_id']:
period_ids = period_obj.find(cr, uid, invoice_object.date_invoice, context=context)
period_id = period_ids and period_ids[0] or False
voucher_data.update({'period_id':period_id})
voucher_id = voucher_pool.create(cr,uid,voucher_data)
if voucher_id:
if invoice_object.type in ('out_refund','in_refund'):
amount=-invoice_object.amount_total
res = voucher_pool.onchange_partner_id(cr, uid, [voucher_id], invoice_object.partner_id.id, bank_journal_ids[0], amount, invoice_object.currency_id.id, account_data['value']['type'], date, context=context)
else:
res = voucher_pool.onchange_partner_id(cr, uid, [voucher_id], invoice_object.partner_id.id, bank_journal_ids[0], invoice_object.amount_total, invoice_object.currency_id.id, account_data['value']['type'], date, context=context)
for line_data in res['value']['line_cr_ids']:
if line_data['name'] in [invoice_number]:
voucher_lines = {
'move_line_id': line_data['move_line_id'],
'amount': ctx.get('amount',0.0),
'name': line_data['name'],
'amount_unreconciled': line_data['amount_unreconciled'],
'type': line_data['type'],
'amount_original': line_data['amount_original'],
'account_id': line_data['account_id'],
'voucher_id': voucher_id,
}
voucher_line_id = self.pool.get('account.voucher.line').create(cr,uid,voucher_lines)
for line_data in res['value']['line_dr_ids']:
if line_data['name'] in [invoice_number]:
voucher_lines = {
'move_line_id': line_data['move_line_id'],
'amount': ctx.get('amount',0.0),
'name': line_data['name'],
'amount_unreconciled': line_data['amount_unreconciled'],
'type': line_data['type'],
'amount_original': line_data['amount_original'],
'account_id': line_data['account_id'],
'voucher_id': voucher_id,
}
voucher_line_id = self.pool.get('account.voucher.line').create(cr,uid,voucher_lines)
voucher_pool.action_move_line_create(cr,uid,[voucher_id])
return voucher_id
0 Comment(s)