def register_payments(self, person_id, payments, date=None, comments=None):
        """
            Helper function to register payments

            @param person_id: the person record ID
            @param payments: the payments as sent from form
            @param date: the payment date (default utcnow)
            @param comments: comments for the payments

            @return: tuple (updated, failed), number of records
        """

        if isinstance(payments, basestring):
            try:
                payments = json.loads(payments)
            except (ValueError, __HOLE__):
                payments = []

        if not date:
            date = current.request.utcnow

        # Data to write
        data = {"status": 2,
                "paid_on": date,
                }
        if comments:
            data["comments"] = comments

        atable = current.s3db.dvr_allowance

        updated = 0
        failed = 0

        # Customise allowance resource
        r = S3Request("dvr", "allowance",
                      current.request,
                      args = [],
                      get_vars = {},
                      )
        r.customise_resource("dvr_allowance")
        onaccept = current.s3db.onaccept

        db = current.db
        accessible = current.auth.s3_accessible_query("update", atable)
        for payment in payments:
            record_id = payment.get("r")
            query = accessible & \
                    (atable.id == record_id) & \
                    (atable.person_id == person_id) & \
                    (atable.status != 2) & \
                    (atable.deleted != True)
            success = db(query).update(**data)
            if success:
                record = {"id": record_id, "person_id": person_id}
                record.update(data)
                onaccept(atable, record, method="update")
                updated += 1
            else:
                failed += 1

        return updated, failed

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/dvr.py/DVRRegisterPayment.register_payments