'Transfer existing due value to newly inserted record'

def _update_due(self, team_id, id, cursor=None):

    (cursor or self.db).run(u'\n                                                UPDATE    payment_instructions    p\n                                                            SET    due    =    COALESCE((\n                                                                                        SELECT    due\n                                                                                                FROM    payment_instructions    s\n                                                                                            WHERE    participant_id    =    %(participant_id)s\n                                                                                                    AND    team_id    =    %(team_id)s\n                                                                                                    AND    due    >    0\n                                                                            ),    0)\n                                                    WHERE    p.id    =    %(id)s\n                                ', dict(participant_id=self.id, team_id=team_id, id=id))
    self._reset_due(team_id, except_for=id, cursor=cursor)
    (cursor or self.db).run(u'\n                                                UPDATE    payment_instructions    p\n                                                            SET    due    =    0\n                                                    WHERE    participant_id    =    %(participant_id)s\n                                                            AND    team_id    =    %(team_id)s\n                                                            AND    due    >    0\n                                                            AND    p.id    !=    %(id)s\n                                ', dict(participant_id=self.id, team_id=team_id, id=id))
