Пример #1
0
 def add(self):               
     c.form = DictionaryForm(request.POST)
     if request.method == 'POST' and c.form.validate():
         entry = Dictionary()
         c.form.populate_obj(entry, exclude=['id'])
                     
         try:
             entry.save()
             flash(u'Dodano nowe pole.')
             return self.redirect(url(controller='dictionary', action='list'))
         except DictionaryExistsException:
             flash(u'Podany klucz i wartość już istnieją.')                                    
                   
     return render('/dictionaries/add.xhtml')              
Пример #2
0
 def save(self):
     if self.id is None:            
         self.series_year = datetime.datetime.now().year                 
     
     if not self.currency:            
         self.currency = Dictionary.query().get(self.idCurrency)               
     
     if self.currency.value != "PLN":                       
         currencySymbol = self.currency.value
         if self.order and self.order.places:
             currencyDate = str(self.order.places[0].date)
         else:
             '''
             Jeśli nie przypisano zlecenia lub zlecenie
             nie ma miejsc zał./rozł. biorę datę aktualną
             '''
             date = datetime.datetime.now()
             currencyDate = date.strftime('%Y-%m-%d')            
         
         currency = Currency.get(currencySymbol, currencyDate)
         if currency is not None:
             self.currencySymbol = currency.symbol
             self.currencyValue = currency.value
             self.currencyDate = currency.date
             self.currencyTableNumber = currency.tableNumber                
             self.real_value = float(self.freight) * float(self.currencyValue) 
     else:
         self.real_value = self.freight 
     
     meta.Session.add(self)
     meta.Session.commit()                
Пример #3
0
    def save(self):        
        if self.id is None:            
            self.series_year = datetime.datetime.now().year            
            self.idCreator = h.auth.user_id()
        else:
            self.idModUser = h.auth.user_id()

        from pytis.model.invoice import InvoicePosition
        element = InvoicePosition.query.optimized_view().filter_by(order_id = self.id).first()
        if element:        
            element.value = self.freight
            element.currency = self.currency
            element.save()        
            
            element.invoice.save()    
        
        if not self.currency:            
            self.currency = Dictionary.query().get(self.idCurrency)    
        
        if self.currency and self.currency.value != "PLN":                              
            '''Sprawdzam czy brany jest kurs z dnia załadunku czy dnia poprzedzającego'''            
            if self.places:
                if self.isCurrencyDate == YES:
                    '''Kurs z dnia załadunku'''
                    currencyDate = str(self.places[0].date)
                else:
                    '''Kurs z dnia poprzedzającego załadunek'''
                    date = datetime.datetime.strptime(str(self.places[0].date), "%Y-%m-%d")
                    date = date - datetime.timedelta(days = 1)
                    currencyDate = date.strftime('%Y-%m-%d')
            else:
                '''
                Podczas tworzenia nowego zlecenia bez miejsca załadunku
                pobierany jest kurs z dnia utworzenia
                '''
                date = datetime.datetime.now()
                currencyDate = date.strftime('%Y-%m-%d')
            
            '''Symbol waluty'''
            currencySymbol = self.currency.value
            
            '''Pobranie kursu'''
            currency = Currency.get(currencySymbol, currencyDate)
            if currency is not None:
                self.currencySymbol = currency.symbol
                self.currencyValue = currency.value                
                self.currencyDate = currency.date
                self.currencyTableNumber = currency.tableNumber
                self.real_value = float(self.freight) * float(self.currencyValue)                            
        else:
            self.real_value = self.freight                    
            
        meta.Session.add(self)
        meta.Session.commit()