Esempio n. 1
0
    def calculate(self):
        c = Converter()

        # print(c.currencies())

        if self.__check_status():

            if self.charge != '' and self.charge_cur != '':
                # print(self.charge_cur)
                # print(self.charge)
                # print(self.currency)

                self.penalty = c.calc(self.charge_cur, float(self.charge),
                                      self.currency)

                # print(self.penalty)

            elif self.charge != '' and self.percent:
                self.penalty = round(self.baseFare * self.percent / 100)

            # print(self.penalty)

            self.non_ref_tax, self.ref_tax = self.__calc_taxes()

            self.total = self.totalFare - self.penalty - self.non_ref_tax

            data = self.__get_data()

            return data
Esempio n. 2
0
    def calculate(self):
        self.__split_rules()
        penalty = []
        check = None
        non_ref_fare = None

        for rule in self.cancelRule:
            if "CANCEL/NO-SHOW/" in rule:
                if "IS NON-REFUNDABLE" in rule:
                    check = False
                    penalty.append(self.baseFare)
                    break
                temp = rule.split()
                penalty[1] = temp[2] + temp[1]
                from converter import Converter
                conv = Converter()
                penalty[0] = conv.calc(temp[1], float(temp[2]), self.currency)
                break

        non_refunded_taxes = self.totalFare - self.baseFare
        refunded_taxes = 0
        if check:
            non_ref_taxes = self.__non_refundable_taxes()
            non_refunded_taxes = 0
            for tax in self.taxes:
                if not tax["Type"] in non_ref_taxes:
                    refunded_taxes += int(tax["Amount"])
                else:
                    non_refunded_taxes += int(tax["Amount"])

        output = {
            'name': "Aeroflot",
            'currency': self.currency,
            'non_refundable taxes': non_refunded_taxes,
            'refunded_taxes': refunded_taxes,
            'refunded_fare': self.baseFare - int(penalty[0])
        }
        if check:
            output['penalty'] = penalty[0]
            output['refunded_total'] = (self.baseFare -
                                        non_ref_fare) + refunded_taxes
        else:
            output['penalty'] = self.baseFare
            output['refunded_total'] = 0

        return output
Esempio n. 3
0
    def calculate(self):
        cancellation = []
        penalty = []
        non_refunded_tax = 0
        non_refunded_taxes = []
        refunded_taxes = 0
        check = 0

        for rule in self.rules.split("\n"):
            if "CHANGES" in rule:
                check = 1
            elif "CANCELLATIONS" in rule:
                check = 2
            if check == 2:
                cancellation.append(rule)

        check = 0
        for rule in cancellation:
            if "NO-SHOW" in rule and "NON-REFUNDABLE" in rule:
                if self.ticketStatus == "NO-SHOW":
                    if not self.dates[0] < self.dates[1]:
                        return None
            if "BEFORE DEPARTURE" in rule:
                check = 1
            elif "AFTER DEPARTURE" in rule:
                check = 2
            if check == 1:
                if "CANCEL/REFUND" in rule:
                    if "NON-REFUNDABLE" in rule:
                        self.check = False
                        break
                    for r in rule.split():
                        if r == "USD" or r == "EUR":
                            penalty.append(r)
                        try:
                            penalty.append(float(r))
                        except:
                            pass
        if self.check:
            for rule in cancellation:
                if "SURCHARGE" in rule or "TAX" in rule:
                    for tax in self.taxes:
                        if tax["Type"] in rule:
                            non_refunded_taxes.append(tax)
        non_refunded_tax = self.totalTaxes
        if len(non_refunded_taxes) != 0:
            non_refunded_tax = self.__non_refundable_taxes(non_refunded_taxes)

        non_ref_fare = 0
        if self.check:
            from converter import Converter
            conv = Converter()
            non_ref_fare = conv.calc(penalty[0], penalty[1], self.currencies)
        else:
            non_ref_fare = self.baseFare

        output = {
            'name': "Turkish AirLine",
            'currency': self.currencies,
            'refunded_fare': self.baseFare - non_ref_fare,
            'refunded_taxes': self.totalTaxes - non_refunded_tax,
            'non_refundable taxes': non_refunded_tax
        }

        if self.check:
            output['penalty'] = str(
                penalty[1]) + " " + penalty[0] + " or " + str(
                    non_ref_fare) + " " + "KZT"
            output['refunded_total'] = (self.baseFare -
                                        non_ref_fare) + refunded_taxes
        else:
            output['penalty'] = self.baseFare
            output['refunded_total'] = 0
        return output