Commits

Rafał Kos  committed 9fc41cc

some improvements

  • Participants
  • Parent commits dcc22f5

Comments (0)

Files changed (4)

File pytis/controllers/invoices.py

             c.form.populate_obj(c.invoice, exclude=['company', 'number', 'payment_date'])
             c.invoice.currencyDate = request.params.get('currencyDate')
             c.invoice.save()
+
+            if request.params.get('change_currency_date', False) == 'on':
+                for element in c.invoice.elements:
+                    element.order.change_currency_date(c.invoice.currencyDate, c.invoice.currencySymbol)
+
             
             if not c.invoice.is_exported:
                 flash(u'Faktura pomyślnie zapisana')

File pytis/lib/printer.py

         doc = Document()
         buffer = StringIO.StringIO()
 
-        invoices = Invoice.query.filter(Invoice.created_at.between(date_from, date_to)).order_by(Invoice.series_number).all()
+        invoices = Invoice.query.filter(Invoice.sellDate.between(date_from, date_to)).order_by(Invoice.series_number).all()
 
         columns = [
             'Nr faktury',

File pytis/model/order.py

         if not self.currency:            
             self.currency = Dictionary.query().get(self.idCurrency)    
         
-        if self.currency and self.currency.value != "PLN":                              
+        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:
         meta.Session.add(self)
         meta.Session.commit()
 
+    def change_currency_date(self, currencyDate, currencySymbol):
+        '''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)
+
+        meta.Session.add(self)
+        meta.Session.commit()
+
     def delete(self):
         try:            
             assert self.isFactured == False

File pytis/templates/invoices/edit.xhtml

                         {{ h.text("currencyTableNumber", value=c.invoice.currencyTableNumber) }}
                     </div>
                 </div>
+
+                <div style="display: none;">
+                    <input type="checkbox" id="change_currency_date" name="change_currency_date" />
+                </div>
             </fieldset>            
 	</div>
 
 	    });
 
         $('#currencydate').datepicker({
-            dateFormat: 'yy-mm-dd'
+            dateFormat: 'yy-mm-dd',
+            onSelect: function(dateText, inst) {
+                $('#change_currency_date').attr('checked', true);
+            }
         });
 		
 	    $('#sellDate').datepicker({