Ejemplo n.º 1
0
def index(request, year, week_nr, shop):
    """
    Progress report - Display one week order details grouped by day.
    Access DB has the order details that we are making.
    Local DB records production events (lamination, machining, assembly and rats).
    Rollovers (OD not ready from past weeks) are displayed on top.
    This view calculates that ETA of the order details planned today.
    This updates the calculation of "rollovers".
    """

    data = {'year': year, 'week_nr': week_nr, 'shop': shop}

    nav_dict = {}
    nav_dict['url_template'] = '/progress_report/%s/%s/%s/'    
    nav_dict['week_nr'] = week_nr    
    nav_dict['year'] = year
    nav_dict['shop'] = shop
    data['navigation'] = get_navigation_url(nav_dict)

    data['tooltips'] = manual.models.get_pr_tooltips()


    rollovers = pr.models.get_rollovers_list(shop)

    #rollovers = list(rollovers)
    # adding orders assembled, planned in the previous weeks, with rat in the current week
    rats = pr.models.get_rollover_rats(shop, 1)


    week = [{'Rollovers': rollovers}]
    
    # Get the week assembly list from Access DB
    url = '%sprogress_report/%s/%s/%s'%(settings.ACCESS_API_URL,year,week_nr,shop)
    f = urllib2.urlopen(url)
    j = f.read()
    f.close()
    week += json.loads(j)

    data['week'] = [] 
    data['total_plan_week'] = 0
    for day in week: 

        if day.keys()[0] is 'Rollovers':
            ods = day['Rollovers']
            date = 'Rollovers'
        else:
            date = day.keys()[0]
            today = datetime.datetime.today().strftime('%A %d %B') 
            if date == today: # calculate the ETA
                ods = production.models.set_day_ETA(day[date])
            else: # set at generic ETA on the morning of the planned date
                date_obj = datetime.datetime.strptime(year + ' ' + date, '%Y %A %d %B')
                ods = []
                for od in day[date]:
                    od['ETA'] = date_obj.strftime('%Y/%m/%d %H:%M:%S')
                    ods.append(od)

        total_plan_day = 0 
        for od in ods:
            # update totals
            total_plan_day += int(od['plan']) 
            # get local info
            od = pr.models.get_pr_od(od, shop)

        data['total_plan_week'] += total_plan_day
        data['week'].append([date, ods, total_plan_day])
    
    data['rollover'] = pr.models.get_rollovers_total(shop)
    data['assembly_buffer'] = pr.models.get_assembly_buffer(shop)
    try:
        path = get_ncfolder_path(shop, 'this_week')
        x, y, data['machining_buffer'] = get_view_days(path)
    except:
        data['machining_buffer'] = 0

    data['home_on_server'] = settings.HOME_ON_SERVER
    data['domain'] = Site.objects.get_current().domain
    data['access_api_url'] = settings.ACCESS_API_URL

    data['rat_reasons'] = pr.models.get_rat_reasons()

    return render_to_response('progress_report.html', data, 
            context_instance=RequestContext(request))
Ejemplo n.º 2
0
def week(request, year, week, shop):
    """
    Week Timer Report
    """

    # get the orders from local table
    wlist = week_range(int(year),int(week))
    monday = wlist[0]
    sunday = wlist[6]
    local_ods = get_timed_product(monday, sunday, shop)
    local_ods = local_ods.order_by('start_time')

    # get the order detail from access db with the id of the local timed order detail
    access_orders = get_access_order(local_ods)

    # definition of the variables for the merging
    date_format = '%A %d %B'
    # the current date has to be iniatialize out of loop with the date of the first order
    current_day = local_ods[0].start_time.strftime(date_format)
    current_day_list = []
    days = {}
    template_data = []

    # merging the two result set
    for od in local_ods:
        ac_order = {}
        for el in access_orders:
            if el['ac_od_id'] == od.ac_od_id:
                ac_order = el
                ac_order['actual'] = od.actual
                ac_order['pause'] = od.pause
                ac_order['total'] = od.pause + od.actual
                ac_order['status'] = od.status
                ac_order['start_time'] = od.start_time.strftime('%Y/%m/%d %H:%M:%S')
                ac_order['class'] = 'product timed'

        if od.start_time.strftime(date_format) == current_day:
            # append the order in the list
            current_day_list.append(ac_order)
        else:
            # append the order in the list, create a new assemble day in the dictionary, clean the temporary variables
            days[current_day] = current_day_list
            template_data.append(days)
            days = {}
            current_day = od.start_time.strftime(date_format)
            current_day_list = [] # empty the current day list
            current_day_list.append(ac_order)

    # last time out the loop
    days[current_day] = current_day_list
    template_data.append(days)
    days = {}

    # navigation url
    nav_dict = {}
    nav_dict['url_template'] = '/records/week/%s/%s/%s/'    
    nav_dict['week_nr'] = week    
    nav_dict['year'] = year    
    nav_dict['shop'] = shop    

    return render_to_response('week_utl_timer.html', 
                                {'week_nr': week,
                                 'week': template_data,
                                 'home_on_server': settings.HOME_ON_SERVER,
                                 'navigation': get_navigation_url(nav_dict),
                                 'shop': shop}, context_instance=RequestContext(request))