Hi,
In the existing code in the automation for creating invoices you can modify it like this:
The "lines" are the invoice lines. In the dictionary, you can add the appropriate values. like in the product_id you can add the id of specific product.
And the lines are used in the invoice creation as invoice_line_ids. It will create the invoice lines too.
def action_create_invoice_line(self):
lines = [(0, 0, {
'product_id': product_id.id,
'name': description,
'quantity': 1.0,
'price_unit': price,
}) for rec in self]
invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': partner_id.id,
'payment_reference': reference,
'invoice_date': (datetime.now()).date(),
'invoice_line_ids': lines
})
Regards