Generalizing your expression as the products of $m$ sums, where the $i^{th}$ sum has $n_i$ terms represented as $x_{i,j}$ for $j \in [1, n_i]$, we get
$$\prod_{i=1}^m \sum_{j=1}^{n_i} x_{i,j}$$
Then the expansion can be written as choosing one term from each original sum $i$, taking their product, going through all combinations $C$ of choosing, and summing the products
$$\sum_{C} \prod_{i=1}^m x_{i,C(i)}$$
The combinations $C$ can be interpreted as finding all solutions to the following problem,
$$C(i) \in [1, n_i] \quad \forall \; i \in [1,m]$$
where the number of solutions is,
$$\prod_{i=1}^m n_i$$
The following is one pseudo-code approach to generating these combinations, which follows the spirit of generating binary sequences
Initialize C to be 1 for all entries. This is the first combination
Run a loop with number of iterations equal to one less than the product of all entries of n
Find the last entry in C which is not at the corresponding limit from n
Increment the value of this entry in C
Reset all entries occurring afterwards in C to 1
The current value of C is a new combination
end