def test_fairfax_marriott_01(self):
        # RAYMOND_85375.pdf
        ocr_text = 'FAIRFIELD\n\nINN & SUITES®\nMatriott.\n\nT. User\n\nArrive: 05Dec18\n\nDate\n\n05Dec18\n05Dec18\n05Dec18\n05Dec18\n05Dec18\n05Dec18\n06Dec18\n\nGuarantee”\n\n \n  \n\n  \n\nFairfield\n—100%—\n\n \n\n  \n\nTime: 01:17PM\n\nDescription\n\nRoom Charge\nState Occupancy Tax\n\nCity Tax\nCounty Tax\n\nValet Parking\n\nSales Tax\nVisa\n\nFairfield Inn & Suites®\n\nDepart: O6Dec18\n\nCard #: VIXXXXXXXXXXXX6779/XXXX\n\nAmount:\nFile\n\nThis card was electronically swiped on 05Dec18\n\n173.09 Auth: 02592D Signature on\n\nBalance:\n\n422 Bonham Street\nSan Antonio, TX 78205\n210.212.6262\n\nRoom: 618\nRoom Type: KING\nNumber of Guests: 1\n\nRate: $126.00 Clerk:\n\nTime: Folio Number: 85375\n\nCharges Credits\n\n126.00\n\n7.56\n\n11.34\n\n2.21\n\n24.00\n\n1.98\n173.09\n\n0.00\n\nRewards Account # XXXXX6492. Your Rewards points/miles earned on your eligible earnings will be credited to your\naccount. Check your Rewards Account Statement or your online Statement for updated activity.\n\nSee our "Privacy & Cookie Statement" on Marriott.com.\n\nOperated under license from Marriott International, Inc. or one of its affiliates.'

        self.helper_function(ocr_text, [
            Charge(126.00, ChargeType.HOTEL, date.fromisoformat("2018-12-05")),
            Charge(7.56, ChargeType.LODGING_TAX,
                   date.fromisoformat("2018-12-05")),
            Charge(11.34, ChargeType.LODGING_TAX,
                   date.fromisoformat("2018-12-05")),
            Charge(2.21, ChargeType.LODGING_TAX,
                   date.fromisoformat("2018-12-05")),
            Charge(1.98, ChargeType.LODGING_TAX,
                   date.fromisoformat("2018-12-05")),
            Charge(24.00, ChargeType.PARKING, date.fromisoformat("2018-12-05"))
        ])
Example #2
0
 def get_expense_charges(self):
     return [Charge(self._cost, ChargeType.AIRPLANE, self._date)]
Example #3
0
 def get_expense_charges(self):
     return [Charge(self.charge, TestVendor.ct, self.date)]
    def __init__(self, ocr_text):
        super(MarriottFairfax, self).__init__(ocr_text)
        self.logger = logging.getLogger(__name__)

        self._set_arrival_and_departure_date()
        self._set_rate()

        # Attempt to find the dates in an easy manner
        unparsable_line = []
        easy_line_pattern = re.compile(
            r'(^(\d{2})(\w{3})(\d{2})(.*?)(\d{1,3}\.\d{2}$))')
        for line in re.findall(r'(^\d{2}\w{3}\d{2}.*?\d{1,3}\.\d{2}$)',
                               ocr_text.replace('O', '0'), re.MULTILINE):
            easy_line_match = easy_line_pattern.search(line)
            self.logger.debug("Easy line parsed: %s",
                              str(easy_line_match.groups()))

            line_date = dateparser.parse(" ".join(
                [x for x in easy_line_match.groups()[1:4]])).date()
            self.logger.debug("Easy line parsed (date): %s", str(line_date))
            line_cost = float(easy_line_match.groups()[5])
            self.logger.debug("Easy line parsed (date): %.2f", line_cost)

            if line.find('Room Charge') > 0:
                self._charges.append(
                    Charge(line_cost, ChargeType.HOTEL, line_date))
            elif line.find('Park') > 0:
                self._charges.append(
                    Charge(line_cost, ChargeType.PARKING, line_date))
            elif line.find('Tax') > 0:
                self._charges.append(
                    Charge(line_cost, ChargeType.LODGING_TAX, line_date))
            else:
                unparsable_line.append(line)
        if len(unparsable_line) > 0:
            self.logger.debug(
                "Didn't find matches for any of the following: %s",
                "; ".join(unparsable_line))

        if len(self._charges) == 0:
            # This won't be precise. We're assuming anything 1%-10% of the rate is taxes, anything about the rate
            # doesn't go on our sheet, and anything else is parking
            self.logger.debug(
                "Attempting to find charges through harder mechanism")

            phoneless_text = re.sub(r'\d{3}\.\d{3}\.\d{4}', '<phone>',
                                    ocr_text)
            all_prices_txt = re.findall(r'\d{1,3}\.\d{2}', phoneless_text)
            price_count = {}

            # First, count all the dollar amounts we've found
            for price in all_prices_txt:
                if float(price) >= self._rate:
                    self.logger.debug("Ignoring price: %s", price)
                    continue

                if price not in price_count:
                    price_count[price] = 0
                price_count[price] = price_count[price] + 1

            # Only include prices which showed up for every night
            stay_duration = (self._departure_date - self._arrival_date).days
            taxes = []
            parking = []
            for price in price_count:
                if price_count[price] != stay_duration:
                    self.logger.debug(
                        "A price (%s) was found, but not for every night of the stay (%d/%d)",
                        price, price_count[price], stay_duration)
                    continue
                if float(price) <= 0:
                    continue
                if float(price) <= self._rate * .1:
                    taxes.append(float(price))
                else:
                    parking.append(float(price))

            for i in range(stay_duration):
                self._charges.append(
                    Charge(self._rate, ChargeType.HOTEL,
                           self._arrival_date + timedelta(days=i)))
                for tax in taxes:
                    self._charges.append(
                        Charge(tax, ChargeType.LODGING_TAX,
                               self._arrival_date + timedelta(days=i)))
                for park in parking:
                    self._charges.append(
                        Charge(park, ChargeType.PARKING,
                               self._arrival_date + timedelta(days=i)))

        self.logger.debug("Charges found: %s",
                          "; ".join([str(x) for x in self._charges]))
Example #5
0
 def get_expense_charges(self):
     return [Charge(self._cost, ChargeType.UBER, self._date)]
 def test_fairfax_marriott_03(self):
     # RAYMOND_84523.pdf
     ocr_text = 'Fairfield\n\nFAIRFIELD Fated\n\nINN & SUITES® ,\nGuarantee’\n\nAartriott. |\n\nFairfield Inn & ' \
                'Suites” 422 Bonham Street\nSan Antonio, TX 78205\n210.212.6262\n\nT. User Room: 606\nRoom ' \
                'Type: QNQN\n\nNumber of Guests: 1\n\nRate: $126.00 Clerk:\n\nArrive: 03Dec18 Time: 05:41PM ' \
                'Depart: 05Dec18 Time: Folio Number: 84523\nDate Description Charges Credits\nxxx Room Charge ' \
                '126.00\nxxx State Occupancy Tax 7.56\nxxx City Tax 11.34\nxxx County Tax ' \
                '2.21\nxxxx Valet Parking 24.00\nxxx Sales Tax 1.98\nxxx Room Charge 126.00\nxxx ' \
                'State Occupancy Tax 7.56\nxxx City Tax 11.34\nxxx County Tax 2.21\nxxx Valet Parking ' \
                '24.00\nxxx Sales Tax 1.98\nxxx Visa 346.18\n\nCard #: VIXXXXXXXXXXXX6779/XXXX\n\nAmount: ' \
                '346.18 Auth: 03107D Signature on\n\nFile\nThis card was electronically swiped on ' \
                'xxxx\nBalance: 0.00\n\nRewards Account # XXXXX6492. Your Rewards points/miles earned on your ' \
                'eligible earnings will be credited to your\naccount. Check your Rewards Account Statement or your ' \
                'online Statement for updated activity.\n\nSee our "Privacy & Cookie Statement" on ' \
                'Marriott.com.\n\nOperated under license from Marriott International, Inc. or one of its ' \
                'affiliates. '
     self.helper_function(ocr_text, [
         Charge(126.00, ChargeType.HOTEL, date.fromisoformat("2018-12-03")),
         Charge(7.56, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-03")),
         Charge(11.34, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-03")),
         Charge(2.21, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-03")),
         Charge(1.98, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-03")),
         Charge(24.00, ChargeType.PARKING,
                date.fromisoformat("2018-12-03")),
         Charge(126.00, ChargeType.HOTEL, date.fromisoformat("2018-12-04")),
         Charge(7.56, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-04")),
         Charge(11.34, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-04")),
         Charge(2.21, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-04")),
         Charge(1.98, ChargeType.LODGING_TAX,
                date.fromisoformat("2018-12-04")),
         Charge(24.00, ChargeType.PARKING, date.fromisoformat("2018-12-04"))
     ])