Beispiel #1
0
 def save(self, *args, **kwargs):
     self.code = settings.ROUTE_CODE_FUNC(self.source.name,
                                          self.destination.name)
     if not self.roundtrip_price:
         self.roundtrip_price = 2 * self.oneway_price
     if not self.roundtrip_driver_charge:
         self.roundtrip_driver_charge = 2 * self.oneway_driver_charge
     if not self.roundtrip_distance:
         self.roundtrip_distance = 2 * self.roundtrip_distance
     super().save(*args, **kwargs)
Beispiel #2
0
    def save(self, *args, **kwargs):
        if not self.customer_email and not self.customer_mobile:
            raise ValidationError('Either of customer email and mobile is '
                                  'mandatory.')
        if self.id is None:
            self.booking_id = self._create_booking_id()
            rate = self.vehicle_type.rate.get(code=settings.ROUTE_CODE_FUNC(
                self.source.name, self.destination.name))
            fare_details = {
                'tariff_per_km':
                self.vehicle_type.tariff_per_km,
                'after_hour_charges':
                self.vehicle_type.tariff_after_hours,
                'price': (rate.oneway_price if self.booking_type == 'OW' else
                          rate.roundtrip_price),
                'driver_charge':
                (rate.oneway_driver_charge if self.booking_type == 'OW' else
                 rate.roundtrip_driver_charge),
                'discount':
                0,
                'markup':
                0
            }
        else:
            fare_details = json.loads(self.fare_details)

        if timezone.now().timestamp() >= datetime.strptime(
                settings.EXTRA_TAXES_FROM_DATETIME,
                settings.DATETIME_STR_FORMAT).timestamp():
            fare_details['taxes'] = {
                k: v['rate'] * fare_details[settings.TAXABLE_FIELD]
                for k, v in settings.TAXES.items()
            }
            fare_details['taxes']['total'] = sum(
                [fare_details['taxes'][k] for k in settings.TAXES])
            fare_details['total'] = fare_details['price'] + fare_details[
                'taxes']['total']
        else:
            fare_details['total'] = fare_details['price']
        fare_details['total'] += fare_details.get('markup', 0) - \
            fare_details.get('discount', 0)
        self.total_fare = fare_details['total']
        self.payment_due = int(round(self.total_fare)) - int(
            round(self.payment_done))
        self.fare_details = json.dumps(fare_details)

        self.update_payment_summary()

        super().save(*args, **kwargs)
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     source = kwargs.pop('source')
     destination = kwargs.pop('destination')
     booking_type = kwargs.pop('booking_type')
     super().__init__(*args, **kwargs)
     self.fields['vehicle_type'].widget = forms.RadioSelect()
     code = settings.ROUTE_CODE_FUNC(source.name, destination.name)
     choices = []
     for rate in Rate.objects.filter(code=code):
         label = render_to_string(
             'opencabs/partials/vehicle_rate_label.html',
             context={'rate': rate, 'booking_type': booking_type})
         choices.append((rate.vehicle_category_id, label))
     self.fields['vehicle_type'].choices = choices
     self.fields['vehicle_type'].widget.attrs = {'hidden': 'true'}
Beispiel #4
0
 def save(self, *args, **kwargs):
     if not self.booking_id:
         self.booking_id = self._create_booking_id()
     if self.vehicle and not self.driver:
         self.driver = self.vehicle.driver
     rate = self.vehicle_type.rate.get(code=settings.ROUTE_CODE_FUNC(
         self.source.name, self.destination.name))
     fare_details = {
         'tariff_per_km':
         self.vehicle_type.tariff_per_km,
         'after_hour_charges':
         self.vehicle_type.tariff_after_hours,
         'price': (rate.oneway_price
                   if self.booking_type == 'OW' else rate.roundtrip_price),
         'driver_charge': (rate.oneway_driver_charge if self.booking_type
                           == 'OW' else rate.roundtrip_driver_charge)
     }
     self.total_fare = fare_details['price']
     self.fare_details = json.dumps(fare_details)
     super().save(*args, **kwargs)