'Set supply_distribution location, start_date and end_date
from activity
This is for when the data is created after the project_activity
- CSV imports into project_activity
- Inline forms in project_activity'

@staticmethod
def supply_distribution_onaccept(form):

    db = current.db
    dtable = db.supply_distribution
    record_id = form.vars.id
    record = db((dtable.id == record_id)).select(dtable.activity_id, dtable.location_id, dtable.date, dtable.end_date, limitby=(0, 1)).first()
    try:
        location_id = record.location_id
        start_date = record.date
        end_date = record.end_date
    except:
        current.log.warning(('Cannot    find    Distribution:    %s' % record_id))
        return
    activity_id = record.activity_id
    if (not activity_id):
        return
    atable = db.project_activity
    activity = db((atable.id == activity_id)).select(atable.location_id, atable.date, atable.end_date, limitby=(0, 1)).first()
    try:
        a_location_id = activity.location_id
        a_start_date = activity.date
        a_end_date = activity.end_date
    except:
        current.log.warning(('Cannot    find    Activity:    %s' % activity_id))
        return
    data = {}
    if (a_location_id and (a_location_id != location_id)):
        data['location_id'] = a_location_id
    if (a_start_date and (a_start_date != start_date)):
        data['date'] = a_start_date
    if (a_end_date and (a_end_date != end_date)):
        data['end_date'] = a_end_date
    if data:
        db((dtable.id == record_id)).update(**data)
