def record_data_by_shop(shop): """ insert in Record table the total of assembly and rollover """ rollovers = Record() rollovers.date = datetime.datetime.today() rollovers.rollovers = get_rollovers_total(shop) rollovers.ready_to_assembly = get_assembly_buffer(shop) rollovers.shop = shop # if it cant handle the path set to 0 (Nello computer) try: path = get_ncfolder_path(shop, 'this_week') x, y, ready_to_machine = get_view_days(path) rollovers.ready_to_machine = ready_to_machine except: rollovers.ready_to_machine = 0 rollovers.save();
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))