I have a button in a wizard of my custom Module.
When I click on the wizard.
The following fields to be filled up.
Service Product Name(Will get populated automatically)
Amount
Payment Method
Date
Description
Partner Name(Which will get populated automatically)
I have a button named pay at the footer of the wizard.
When I click Pay Button, the following things to be done
1. Create a Invoice
2. Validate the invoice
3. Create a Customer Payment
4. Validate the Payment
5. Invoice Should be in the Paid State
I have written a code like this.
def pay(self, cr, uid, ids, context=None):
if context is None:
context = {}
if context.get('active_id', False):
student_obj = self.pool.get('op.student')
student = student_obj.browse(cr, uid, context.get('active_id', False), context=context)
if student.fee_paid == False:
for fee in self.browse(cr, uid, ids, context=context):
if not student.partner_id:
raise Warning(_('Missing Error!'), _('Please select a customer in Assessment.'))
######### Invoice Creation with Student Line ######################
inv_vals = self._prepare_invoice_vals(cr, uid, student, fee, context=context)
inv_id = self.pool.get('account.invoice').create(cr, uid, inv_vals, context=context)
stud_line_vals = self._prepare_invoice_student_line_vals(cr, uid, fee, inv_id, context=context)
self.pool.get('account.invoice.line').create(cr, uid, stud_line_vals, context=context)
#######################################################################
if fee.transportation_needed == True:
tran_line_vals = self._prepare_invoice_trans_line_vals(cr, uid, fee, inv_id, context=context)
self.pool.get('account.invoice.line').create(cr, uid, tran_line_vals, context=context)
draft_to_open = self.pool.get('account.invoice').signal_workflow(cr, uid, [inv_id], 'invoice_open')
########### Account Voucher creation ######################
pay_vals = self._prepare_voucher_vals(cr, uid, student, fee, context=context)
pay_id = self.pool.get('account.voucher').create(cr, uid, pay_vals, context=context)
#####################################################################
open_to_paid = self.pool.get('account.voucher').signal_workflow(cr, uid, [pay_id], 'proforma_voucher')
student_obj.write(cr, uid, context.get('active_id', False),{'fee_paid': True,'fee_invoice_id' : inv_id}, context=context)
return {'type': 'ir.actions.act_window_close'}
This makes the ** 1. invoice created and validated 2. Payment Created without account_voucher_lines, but also validated 3. Creates Journal Entries for Both (i) Invoice (Validated State) (ii) Payment (Unposted State)**
I want
** 1. Invoice Created and validated 2. Payment Created and validated with Payment lines as well 3. Journal Entries Created for both in posted state 4. After all Invoice should be in the state of Paid **
Thanks in advance :-)