Example #1
0
    def edit(self, id):                                                       
        c.company = Company.query.get_or_abort(id)               
        c.form = EditCompanyForm(request.POST, obj=c.company, prefix='company')
        c.place_form = PlaceForm(request.POST, prefix='place', idCompany=c.company.id)

        if request.method == 'POST' and 'action' in request.POST:
            
            if request.POST['action'] == 'company' and c.form.validate(c.company):
                c.form.populate_obj(c.company)
                c.company.save()
                
                flash(u'Kontrahent pomyślnie edytowany.')
                return self.redirect(url(controller='companies', action='edit', id=c.company.id))                
            if request.POST['action'] == 'place' and c.place_form.validate():
                place = Place()
                c.place_form.populate_obj(place)
                place.save()
                
                flash(u'Miejsce pomyślnie dodane.')
                return self.redirect(url(controller='companies', action='edit', id=c.company.id))
                
        return render('/companies/edit.xhtml')
Example #2
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')