'Update `taking` amounts based on the difference between `old_takes`
and `new_takes`.'

def update_taking(self, old_takes, new_takes, cursor=None, member=None):

    for participant_id in set(old_takes.keys()).union(new_takes.keys()):
        old = old_takes.get(participant_id, {}).get(u'actual_amount', ZERO)
        new = new_takes.get(participant_id, {}).get(u'actual_amount', ZERO)
        delta = (new - old)
        if (delta != 0):
            taking = (cursor or self.db).one(u'\n                                                                                UPDATE    participants\n                                                                                            SET    taking    =    (taking    +    %(delta)s)\n                                                                                    WHERE    id=%(participant_id)s\n                                                                    RETURNING    taking\n                                                                ', dict(participant_id=participant_id, delta=delta))
            if (member and (participant_id == member.id)):
                member.set_attributes(taking=taking)
