Fix:  [ bug #698 ] Bad calculation of totals of associated documents

Cherrypick from 3.3