Hi,
For creating an invoice from code, what you have to do is that call the create method of the corresponding model and pass the necessary values as dict to the create method. See,
rslt = self.env['account.invoice'].create({
'partner_id': self.test_partner.id,
'currency_id': self.currency_two.id,
'name': 'customer invoice',
'type': 'out_invoice',
'date_invoice': date,
'account_id': self.account_receivable.id,
'invoice_line_ids': [(0, 0, {
'name': 'test line',
'origin': sale_order.name,
'account_id': self.account_income.id,
'price_unit': self.product_price_unit,
'quantity': 1.0,
'discount': 0.0,
'uom_id': product.uom_id.id,
'product_id': product.id,
'sale_line_ids': [(6, 0, [line.id for line in sale_order.order_line])],
})],
})
For development tutorials and tips see: Odoo Development Tutorials
Thanks