2

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 :-)

1 Answers1

0

**1.Invoice Created : You can validate invoice with workflow and journal Entries will create and posted state auto

draft_to_open = self.pool.get('account.invoice').signal_workflow(cr, uid, [inv_id], 'invoice_open')

instead:

wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid, 'account.invoice', inv_id, 'invoice_open', cr)

2.Payment Created : Find 'move_line_id' of invoice(record is receivable account) and then define it in field 'move_line_id' of voucher line and set 'Full Reconcile' is true and 'Amount Allocation' is equal 'Open Balance' for create voucher line and validate voucher to click button_proforma_voucher

self.pool.get('account.voucher').button_proforma_voucher(cr, uid, pay_id, context=None)

3.journal entries of voucher will not post state auto, you have must press post button in journal entries page

  1. invoice will paid state when you validate voucher and voucher line of invoice(move_line_id) is full reconcile and 'Amount Allocation' is equal 'Open Balance'

Sorry, My english so bad. Hope I can help you.

user3583681
  • 39
  • 1
  • 7