Product unit price from a lot

How to make that dolibarr calculate the price of a stone, bought with a lot made up of different stones that have different dimensions, weight and number of pieces, while the purchase price is calculated based on the total weight.

To understand better I have attached an image of how the calculation should be done

Thanks