Example #1
0
def update_tool(request, id_tool):
    """Manage tools"""
    obj = get_object_or_404(Tools, pk=id_tool)
    if request.method == "POST":
        form = ToolsForm(request.POST, instance=obj)
        if form.is_valid():
            save_with_modifications(request.user, form, obj, Tools)
            return HttpResponseRedirect(reverse(create_tools))
        else:
            show_form = True
    else:
        show_form = True
        form = ToolsForm(instance=obj)
    form_mode = "_update"
    tools_list = Tools.objects.get_all_active()
    return render_to_response("tools/tools.html",
                              locals(),
                              context_instance=RequestContext(request))
Example #2
0
def update_activity(request, id_activity):
    """Manage activities"""
    obj = get_object_or_404(Activities, pk=id_activity)
    if request.method == "POST":
        form = ActivityForm(request.POST, instance=obj)
        if form.is_valid():
            save_with_modifications(request.user, form, obj, Activities)
            return HttpResponseRedirect(reverse(create_activity))
        else:
            show_form = True
    else:
        show_form = True
        form = ActivityForm(instance=obj)
    form_mode = "_update"
    activities_list = Activities.objects.get_all_active()
    return render_to_response("activities/create_activity.html",
                              locals(),
                              context_instance=RequestContext(request))
Example #3
0
def update_general_discount(request, id_general_discount):
    """Manage general discounts"""
    obj = get_object_or_404(GeneralDiscounts, pk=id_general_discount)
    if request.method == "POST":
        form = GeneralDiscountForm(request.POST, instance=obj)
        if form.is_valid():
            save_with_modifications(request.user, form, obj, GeneralDiscounts)
            return HttpResponseRedirect(reverse(create_general_discounts))
        else:
            show_form = True
    else:
        show_form = True
        form = GeneralDiscountForm(instance=obj)
    form_mode = "_update"
    general_discounts_list = GeneralDiscounts.objects.get_all_active()
    return render_to_response("discounts/general_discounts.html",
                              locals(),
                              context_instance=RequestContext(request))
Example #4
0
def update_production_order(request, id_production_order):
    """Manage tools"""
    productionorder_obj = get_object_or_404(ProductionOrder, pk=id_production_order)

    if productionorder_obj.status == 1:
        if request.method == "POST":
            QuantityEmployedToolFormSet = modelformset_factory(QuantityEmployedTool, form=QuantityEmployedToolForm)
            formset =  QuantityEmployedToolFormSet(request.POST)
            form = ProductionOrderForm(request.POST, instance=productionorder_obj)
            if form.is_valid():
                # employedorder_obj = EmployedOrder.objects.filter(production_order=productionorder_obj).order_by('-date_added').last()
                employedorder_obj = EmployedOrder(user_generator = request.user, type_order='Output', status_order="Waiting", details=productionorder_obj.comments )
                for q_form in formset.forms:
                    q_form.add_employed_order(employedorder_obj)
                
                if formset.is_valid():
                    if not is_repeated_tool(formset):
                        # the form and formset are valid, all the last inventory orders must be rejected
                        reject_employedorder_list = EmployedOrder.objects.filter(production_order=productionorder_obj, status_order="Waiting") # .exclude(id=employedorder_obj.id)
                        for reject_employedorder_obj in reject_employedorder_list:
                            reject_employedorder_obj.status_order='Not_Approved_OP'
                            reject_employedorder_obj.user_approver = request.user
                            reject_employedorder_obj.date_approved = datetime.datetime.now()
                            reject_employedorder_obj.save()

                         # Quantity employed order
                        quantityemployedtool_list = formset.save(commit=False)

                        if len(quantityemployedtool_list) > 0:
                            # Employed Order
                            # employedorder_obj = EmployedOrder(user_generator = request.user,  production_order=productionorder_obj, type_order='Output', status_order="Waiting", details=productionorder_obj.comments )
                            employedorder_obj.production_order = productionorder_obj
                            employedorder_obj.save()
                        
                            for quantityemployedtool_obj in quantityemployedtool_list:
                                quantityemployedtool_obj.employed_order = employedorder_obj
                        
                            formset.save()

                        save_with_modifications(request.user, form, productionorder_obj, ProductionOrder)
                        return HttpResponseRedirect(reverse(create_production_order))
                    else:
                        show_form = True
                        error = "No puede haber items repetidos en la orden"
                else:
                    show_form = True
            else:
                show_form = True
        else:
            QuantityEmployedToolFormSet = modelformset_factory(QuantityEmployedTool, form=QuantityEmployedToolForm, extra=10)
            employedorder_obj = EmployedOrder.objects.filter(production_order=productionorder_obj, status_order ='Waiting')
            employedorder_obj = employedorder_obj.last()


            if employedorder_obj:
                qs = QuantityEmployedTool.objects.filter(employed_order=employedorder_obj)
            else:
                qs = QuantityEmployedTool.objects.none()
            
            quantityemployedtool_list = []
            for quantityemployedtool_obj in qs:
                quantityemployedtool_list.append({'tool':quantityemployedtool_obj.tool.id,'quantity':quantityemployedtool_obj.quantity})
            
            formset =  QuantityEmployedToolFormSet(queryset = QuantityEmployedTool.objects.none(), initial=quantityemployedtool_list) # initial=responsible, queryset = qs
            show_form = True
            form = ProductionOrderForm(instance=productionorder_obj)
        form_mode = "_update"
    else:
        return HttpResponseRedirect(reverse(create_production_order))
    object_list = ProductionOrder.objects.get_all_active().filter(status__in = [1,2]).order_by('-date_added')
    return render_to_response("production_order.html", locals(), context_instance=RequestContext(request))