The links that already exist in the system connect sale.order.lines to account.invoice.lines.
This brings a complexity: What happens if one invoice applies to more than one sale order?
If you generally invoice multiple sale orders together, or are happy with just taking the first sale order if this does happen, it makes it a little easier.
To make the link you are after, you should create a new many2one computed field on the account.invoice called sale_order_id. To compute it, get all of the invoice lines, find their associated sale order lines, find all of their associated sale orders, then take the first if there is one.
Example Code:
sale_order_id = fields.Many2one(comodel_name='sale.order', string="Sale Order", compute='_compute_sale_order_id', store=True)
@api.depends('invoice_line_ids.sale_line_ids.order_id')
def _compute_sale_order_id(self):
for rec in self:
rec.sale_order_id = rec.mapped('invoice_line_ids.sale_line_ids.order_id')[:1]
Once you have this field, you can created related fields on the invoice through this field to the sale order.