You might want to validate your odoo invoices automatically, without bothering your users to go to each vendor/customer bill and validate them, instead triggering based on certain conditions. It’s a 4 step code:
First, we get the invoice:
invoice_id = self.env['account.invoice'].browse(your_invoice_id)
Assign the date to it:
invoice_id.action_date_assign()
Create the invoice moves:
invoice_id.action_move_create()
Now you can validate the invoice:
invoice_id.invoice_validate()