How to make payment for purchased item only if it is sold

Hello ,
Business View:
We sell products in partnership with other companies- To that end we get products from companies to sell it as our own but only make payment to them for whats sold.

e.g)a company gives me 10 pieces of item1 to sell at my shop - after 1 month(or any certain time) they come to collect the payment of their goods sold from my shop. i.e if i sold 6 of their product item1 - then i pay them only for 6 items (their rate is fixed per item -i m free to sell at whatever profit) and return the rest or keep them for the next duration .

is there a way to handle this scenario in ERPNext?- any suggestions welcomed

my method:
so currently i handle this by creating a purchase invoice(payment pending ) for the items and placing the items in a separate warehouse(update stock) labeled as that company.
then whenever i make a sale of their product i simply make sale from that warehouse so i can keep track of how many their items i sold.

Then when the come for payment , i simply check that warehouse to see items sold - calculate the payment price and make a partial/complete payment against that purchase invoice.

but i have to do this manually.

IS there any way to get the items sold in payment for a purchase invoice - or the items sold from a particular warehouse , so it calculates the amount payable automatically.
eg) how much items that were purchased from a invoice have been sold - an purchase invoice has item1=5, item2=10–
while making payment i should be able to see that item1-2 sold, item2-5sold …payable amount based on sales is 25units.

I m open to any possible customizations ways or any alternatives to the approach .
please advice.

Thanks in advance.

no advice or suggestions?
any wold be helpfull