It looks like the company as a whole averages a ~40% gross margin [1]. Tesla's appears to be closer to ~15%, with many highly negative quarters [2].
Of course, net income to revenue is probably more important to look at in this case. Apple's is consistently above ~20%. Tesla's has mostly been negative, and the highest it's ever been is around ~2%.
Tesla would need to sell roughly 10 times as many cars at the same margin to meet Toyota/Volkswagen/GM valuations. If Tesla were based on it's current financials, it would be valued at $5-$10Bn. It wouldn't be valued at $100Bn now if people thought it could be reasonably valued at $100Bn in the future. People must think it could reasonably be valued at $1T in 10 years.
For that to be true, Tesla would need to be selling 200% of cars on the planet. A lot of people think car sales have peaked. It's possible in 10 years there will be less cars sold. It's highly improbable there will be twice as many cars sold, and that all of them will belong to Tesla.
Here's one: https://www.cnbc.com/video/2018/10/02/ron-baron-tesla-could-...
Google "Tesla Trillion Dollar Company" and you can find dozens of predictions.
A 30% COGS is a benchmark for most hardware products and how much you can invest in software depends on how expensive your product is and how many you sell. Since Apple sells a lot at a premium price point, they've got a lot more room in their budget for software R&D. Capital equipment like cars, machinery, power plants, etc are a whole different beast however.
OTOH, if they were able to get margins back to 25%, these valuations would start to look a lot less crazy.