Get the last trade

Hello, In my datapack, I have a custom villager, with custom trades. I would like to test the trades made by the players. More precisely, I want to know what the player has just bought from this villagers to enable stock and bank management in the linked chests. I have the “What a Deal!” advancement in “minecraft:advancement/adventure/trade” to allow me to launch a function once the trade has been completed. i just have to detect what has been bought from the villager. do you have a solution ? Thanks
Continue to help post