Ejemplo n.º 1
0
 def remove_delegation(self, id):
     c.order = Order.query.basic_view().get_or_abort(id)
     c.order.delegation = None        
     c.order.save()
     
     c.drivers = [(driver.id, driver.full_name) for driver in Driver.query.filter(Driver.is_active == True).all()]
     c.delegation_form = DelegationForm(prefix='delegation')
     return render_macro('/base/macros.xhtml', 'new_delegation')
Ejemplo n.º 2
0
 def delete_place_order(self, id):
     idOrder = request.params.get('idOrder', 1)        
     
     place_order = PlaceOrder.query.get_or_abort(id)
     place_order.delete()
     
     places = PlaceOrder.query.filter(PlaceOrder.idOrder == idOrder)
     form = OrderPlaceForm()    
     
     return render_macro('/base/macros.xhtml', 'show_places', form=form, places=places)
Ejemplo n.º 3
0
 def delete_transport_order(self):
     transport_order_id = request.params.get('transport-order-id')
     order_id = request.params.get('order-id')
                    
     transport_order = TransportOrder.query.get_or_abort(transport_order_id)
     transport_order.delete()   
     order = Order.query.basic_view().filter(Order.id == order_id).one()                      
              
     form = TransportOrderForm(prefix='transport-order')
     
     return render_macro('/base/macros.xhtml', 'show_transport_order', order=order, form=form)                   
Ejemplo n.º 4
0
 def append_delegation(self):
     order_id = request.params.get('id_order')
     delegation_id = request.params.get('id_delegation')
     
     c.order = Order.query.basic_view().get_or_abort(order_id)
     c.delegation = Delegation.query.get_or_abort(delegation_id)
     
     c.order.delegation = c.delegation
     c.order.save()
     
     return render_macro('/base/macros.xhtml', 'show_delegation')
Ejemplo n.º 5
0
    def edit(self, id):                                          
        c.order = Order.query.get_or_abort(id)               
        
        c.form = OrderForm(request.POST, obj=c.order, prefix='order')
        c.places_form = OrderPlaceForm(request.POST)             
        c.transport_form = TransportOrderForm(request.POST, obj=c.order.transport_order, prefix='transport-order')
        
        c.place_form = PlaceForm(request.POST, idCompany=c.order.idCompany)
        if c.order.delegation is None:
            #c.drivers = [(driver.id, driver.full_name) for driver in Driver.query.filter(Driver.is_active == True).all()]
            c.drivers = [(driver.id, driver.full_name) for driver in Driver.query.filter(Driver.is_active == True).all()]
            c.delegation_form = DelegationForm(request.POST, prefix='delegation')                                               
        
        if request.method == 'POST':
            if request.POST['action'] == 'Save' and c.form.validate():                                        
                c.order.idCompany = c.form.idCompany.data
                c.order.freight = c.form.freight.data
                c.order.currency = c.form.currency.data
                c.order.description = c.form.description.data
                c.order.isCurrencyDate = c.form.isCurrencyDate.data
                c.order.foreignOrder = c.form.foreignOrder.data
                
                c.order.save()                               
                              
                flash(u'Zlecenie pomyślnie edytowane.')
                self.redirect(url(controller='orders', action='edit', id=c.order.id))
                return                
            if request.POST['action'] == 'Add Place':
                if c.places_form.validate():
                    place_order = PlaceOrder()
                    place_order.idOrder = c.order.id
                    place_order.type = c.places_form.idType.data
                    place_order.idPlace = c.places_form.idPlace.data
                    place_order.date = c.places_form.placeDate.data
                    place_order.name = 'PyTiS'
                    
                    place_order.save()
                    
                    return render_macro('/base/macros.xhtml', 'show_places', form=OrderPlaceForm(), places=c.order.places)
                else:
                    return render_macro('/base/macros.xhtml', 'show_places', form=c.places_form, places=c.order.places)
                                            
            if request.POST['action'] == 'Save TO':
                if c.transport_form.validate():
                    if not c.transport_form.id.data:
                        transport_order = TransportOrder()
                    else:                        
                        transport_order = TransportOrder.query.get(c.transport_form.id.data)
                    
                    transport_order.idOrder = c.order.id
                    transport_order.idCompany = c.transport_form.idCompany.data
                    transport_order.currency = c.transport_form.currency.data
                    transport_order.driverName = c.transport_form.driverName.data
                    transport_order.tractorName = c.transport_form.tractorName.data
                    transport_order.freight = c.transport_form.freight.data
                    transport_order.description = c.transport_form.description.data                                       
                    transport_order.save()
                    
                    c.transport_form.id.data = transport_order.id
                    c.transport_form.number.data = transport_order.number
                                                                              
                    return render_macro('/base/macros.xhtml', 'show_transport_order', order=c.order, form=c.transport_form)
                else:
                    return render_macro('/base/macros.xhtml', 'show_transport_order', order=c.order, form=c.transport_form)
            
            if request.POST['action'] == 'Create Place':                
                if c.place_form.validate():
                    place = Place()                    
                    c.place_form.populate_obj(place)
                    place.idCompany = c.order.company.id
                    place.save()                    
                    
                    return render_macro('/base/macros.xhtml', 'new_place', form=PlaceForm())                          
                else:
                    return render_macro('/base/macros.xhtml', 'new_place', form=c.place_form)
            
            if request.POST['action'] == 'Add Delegation':
                if c.delegation_form.validate():
                    delegation = Delegation()                
                    c.delegation_form.populate_obj(delegation)
                    delegation.series_year = h.today().year
                    delegation.series_month = h.today().month
                    delegation.save()
                    
                    c.order.delegation = delegation
                    c.order.save()
                    
                    return render_macro('/base/macros.xhtml', 'show_delegation')
                else:
                    return render_macro('/base/macros.xhtml', 'new_delegation')

        if c.order.isFactured:            
            c.invoice = InvoicePosition.query.filter_by(order_id = c.order.id).first()                        
                   
        return render('/orders/edit.xhtml')
Ejemplo n.º 6
0
 def show_delegations(self, id):
     c.delegations = Delegation.query.filter(Delegation.driver_id == id).order_by(Delegation.created_at.desc()).limit(10)
     return render_macro('/base/macros.xhtml', 'delegation_list')
Ejemplo n.º 7
0
 def show_orders(self, id):
     c.orders = Order.query.filter(Order.delegation_id == id)
     
     return render_macro('/base/macros.xhtml', 'show_orders', delegation_id=id, orders=c.orders)