When I create a sales Invoice from scheduler, its status is showing as draft

When I create a sales Invoice from scheduler, its status is showing as draft. But I am submitting it from scheduler
how can solve it

@Govind_Gupta add invoice.submit() after creating it .

The Sales Invoice has been submitted, but the status is still showing as ‘Draft’.
( Using scheduler )

@Govind_Gupta share screenshot of the code and invoice later

def create_sales_invoice_3daysafter_submission_of_sales_order():
try:
# Log the start of the process
frappe.log_error(“Sales Invoice Process”, f"Started on {frappe.utils.getdate()}")

    # Calculate the date three days ago
    date_three_days_ago = frappe.utils.add_to_date(frappe.utils.getdate(), days=-3)
    frappe.log_error("Debugging Date", str(date_three_days_ago))

    # Fetch Sales Orders matching the criteria
    sales_orders = frappe.db.get_list('Sales Order', 
        filters={
            'per_billed': ['!=', 100],
            'custom_submit_date': date_three_days_ago,
            'status': ['!=', 'Cancelled'],
            
        }, 
        fields=['name', 'customer', 'custom_participant', 'custom_participant_name_', 'custom_contact_for_invoice', 'custom_email_for_invoice']
    )
    frappe.log_error("Fetched Sales Orders", str(sales_orders))

    # Process each Sales Order
    for so_data in sales_orders:
        try:
            so = frappe.get_doc('Sales Order', so_data['name'])

            # Create a new Sales Invoice
            invoice = frappe.new_doc('Sales Invoice')
            invoice.customer = so.customer
            invoice.due_date = frappe.utils.add_to_date(frappe.utils.getdate(), days=7)
            invoice.custom_email_for_invoice = so.custom_email_for_invoice
            invoice.custom_contact_for_invoice = so.custom_contact_for_invoice
          
            

           

            
            
            

            # Insert and submit the invoice
            
            
            invoice.submit()
            frappe.db.commit()  
            
            
            
            
            frappe.log_error("Invoice Created", f"Sales Invoice {invoice.name} created for Sales Order {so.name}")

        except Exception as e:
            frappe.log_error("Error Creating Invoice", f"Sales Order {so_data['name']} failed: {str(e)}")
            continue

except Exception as e:
    frappe.log_error("Script Execution Error", str(e))

@Govind_Gupta the invoice is created but not submitted ?

The invoice is created and submitted, but the status still shows as “Draft.”

@Govind_Gupta I am so confused . it’s submitted but the status says Draft ? show us .

Yes

@Govind_Gupta what is the docstatus in the database ? of in the console with frm.doc.docstatus?

1

@Govind_Gupta then it’s submitted . can you see GL entries when you click view ledger ?
do you have a custom sales invoice list js ?

No.