'Ensure that there is a Certificate created for each Course
- only called when create_certificates_from_courses == True'

@staticmethod
def hrm_course_onaccept(form):

    form_vars = form.vars
    course_id = form_vars.id
    db = current.db
    s3db = current.s3db
    ltable = s3db.hrm_course_certificate
    exists = db((ltable.course_id == course_id)).select(ltable.id, limitby=(0, 1))
    if (not exists):
        name = form_vars.get('name')
        if (not name):
            table = s3db.hrm_course
            name = db((table.id == course_id)).select(table.name, limitby=(0, 1)).first().name
        ctable = s3db.hrm_certificate
        certificate = db((ctable.name == name)).select(ctable.id, limitby=(0, 1)).first()
        if certificate:
            certificate_id = certificate.id
        else:
            certificate_id = ctable.insert(name=name)
        ltable.insert(course_id=course_id, certificate_id=certificate_id)
