Simple Version. Before writing a function that reports how many of a certain thing has been "sold", make sure everybody involved agrees what "sold" means in this specific context and domain. And once you have agreed, make sure that every time a function, variable or database table talks about things "sold" it's using that definition.
How complex your methodology around this has to be depends entirely on how complex the domain is and how many different definitions of "sold" is used with different parts of that domain.