Beispiel #1
0
def test_constructor():
    field_dict = {
        'degrees': 90,
        'probability': 0.1,
    }
    orientation = Orientation(field_dict)
    assert orientation.value == 90
Beispiel #2
0
def test_not_90():
    field_dict = {
        'degrees': 255,
        'probability': 0.1,
    }
    orientation = Orientation(field_dict)
    assert orientation.value == 0
Beispiel #3
0
def test_not_number():
    field_dict = {
        'degrees': "aze",
        'probability': 0.1,
    }
    orientation = Orientation(field_dict)
    assert orientation.value == 0
 def build_from_api_prediction(self, api_prediction, page_n=0):
     """
     :param api_prediction: Raw prediction from HTTP response
     :param page_n: Page number for multi pages pdf input
     :return: (void) set the object attributes with api prediction values
     """
     self.locale = Locale(api_prediction["locale"], page_n=page_n)
     self.total_incl = Amount(api_prediction["total_incl"], value_key="value", page_n=page_n)
     self.date = Date(api_prediction["date"], value_key="value", page_n=page_n)
     self.category = Field(api_prediction["category"], page_n=page_n)
     self.merchant_name = Field(api_prediction["supplier"], value_key="value", page_n=page_n)
     self.time = Field(api_prediction["time"], value_key="value", page_n=page_n)
     self.taxes = [
         Tax(tax_prediction, page_n=page_n, value_key="value", rate_key="rate", code_key="code")
         for tax_prediction in api_prediction["taxes"]]
     self.orientation = Orientation(api_prediction["orientation"], page_n=page_n)
     self.total_tax = Amount({"value": None, "probability": 0.}, value_key="value", page_n=page_n)
     self.total_excl = Amount({"value": None, "probability": 0.}, value_key="value", page_n=page_n)
 def build_from_api_prediction(self, api_prediction, page_n=0):
     """
     :param api_prediction: Raw prediction from HTTP response
     :param page_n: Page number for multi pages pdf input
     :return: (void) set the object attributes with api prediction values
     """
     self.company_number = [
         Field(company_reg, extra_fields={"type"}, page_n=page_n)
         for company_reg in api_prediction["company_registration"]
     ]
     self.invoice_date = Date(api_prediction["date"],
                              value_key="value",
                              page_n=page_n)
     self.due_date = Date(api_prediction["due_date"],
                          value_key="value",
                          page_n=page_n)
     self.invoice_number = Field(api_prediction["invoice_number"],
                                 page_n=page_n)
     self.locale = Locale(api_prediction["locale"],
                          value_key="language",
                          page_n=page_n)
     self.orientation = Orientation(api_prediction["orientation"],
                                    page_n=page_n)
     self.supplier = Field(api_prediction["supplier"], page_n=page_n)
     self.taxes = [
         Tax(tax_prediction, page_n=page_n, value_key="value")
         for tax_prediction in api_prediction["taxes"]
     ]
     self.payment_details = [
         PaymentDetails(payment_detail, page_n=page_n)
         for payment_detail in api_prediction["payment_details"]
     ]
     self.total_incl = Amount(api_prediction["total_incl"],
                              value_key="value",
                              page_n=page_n)
     self.total_excl = Amount(api_prediction["total_excl"],
                              value_key="value",
                              page_n=page_n)
     self.total_tax = Amount({
         "value": None,
         "probability": 0.
     },
                             value_key="value",
                             page_n=page_n)
    def __init__(self,
                 api_prediction=None,
                 input_file=None,
                 locale=None,
                 total_incl=None,
                 total_excl=None,
                 invoice_date=None,
                 invoice_number=None,
                 due_date=None,
                 taxes=None,
                 supplier=None,
                 payment_details=None,
                 company_number=None,
                 vat_number=None,
                 orientation=None,
                 total_tax=None,
                 page_n=0):
        """
        :param api_prediction: Raw prediction from HTTP response
        :param input_file: Input object
        :param locale: locale value for creating Invoice object from scratch
        :param total_incl: total_incl value for creating Invoice object from scratch
        :param total_excl: total_excl value for creating Invoice object from scratch
        :param invoice_date: invoice_date value for creating Invoice object from scratch
        :param invoice_number: invoice_number value for creating Invoice object from scratch
        :param due_date: due_date value for creating Invoice object from scratch
        :param taxes: taxes value for creating Invoice object from scratch
        :param supplier: supplier value for creating Invoice object from scratch
        :param payment_details: payment_details value for creating Invoice object from scratch
        :param company_number: company_number value for creating Invoice object from scratch
        :param vat_number: vat_number value for creating Invoice object from scratch
        :param orientation: orientation value for creating Invoice object from scratch
        :param total_tax: total_tax value for creating Invoice object from scratch
        :param page_n: Page number for multi pages pdf input
        """
        self.type = "Invoice"
        self.locale = None
        self.total_incl = None
        self.total_excl = None
        self.invoice_date = None
        self.invoice_number = None
        self.due_date = None
        self.taxes = []
        self.supplier = None
        self.payment_details = None
        self.company_number = None
        self.orientation = None
        self.total_tax = None

        if api_prediction is not None:
            self.build_from_api_prediction(api_prediction, page_n=page_n)
        else:
            self.locale = Locale({"value": locale},
                                 value_key="value",
                                 page_n=page_n)
            self.total_incl = Amount({"value": total_incl},
                                     value_key="value",
                                     page_n=page_n)
            self.date = Date({"value": invoice_date},
                             value_key="value",
                             page_n=page_n)
            self.invoice_date = Date({"value": invoice_date},
                                     value_key="value",
                                     page_n=page_n)
            self.due_date = Date({"value": due_date},
                                 value_key="value",
                                 page_n=page_n)
            self.supplier = Field({"value": supplier},
                                  value_key="value",
                                  page_n=page_n)
            if taxes is not None:
                self.taxes = [
                    Tax({
                        "value": t[0],
                        "rate": t[1]
                    },
                        page_n=page_n,
                        value_key="value",
                        rate_key="rate") for t in taxes
                ]
            self.orientation = Orientation({"value": orientation},
                                           value_key="value",
                                           page_n=page_n)
            self.total_tax = Amount({"value": total_tax},
                                    value_key="value",
                                    page_n=page_n)
            self.total_excl = Amount({"value": total_excl},
                                     value_key="value",
                                     page_n=page_n)
            self.invoice_number = Field({"value": invoice_number},
                                        value_key="value",
                                        page_n=page_n)
            self.payment_details = Field({"value": payment_details},
                                         value_key="value",
                                         page_n=page_n)
            self.company_number = Field({"value": company_number},
                                        value_key="value",
                                        page_n=page_n)

        # Invoke Document constructor
        super(Invoice, self).__init__(input_file)

        # Run checks
        self._checklist()

        # Reconstruct extra fields
        self._reconstruct()
    def __init__(
            self,
            api_prediction=None,
            input_file=None,
            locale=None,
            total_incl=None,
            date=None,
            category=None,
            merchant_name=None,
            time=None,
            taxes=None,
            orientation=None,
            total_tax=None,
            total_excl=None,
            page_n=0
    ):
        """
        :param api_prediction: Raw prediction from HTTP response
        :param input_file: Input object
        :param locale: locale value for creating Receipt object from scratch
        :param total_incl: total_incl value for creating Receipt object from scratch
        :param date: date value for creating Receipt object from scratch
        :param category: category value for creating Receipt object from scratch
        :param merchant_name: merchant_name value for creating Receipt object from scratch
        :param time: time value for creating Receipt object from scratch
        :param taxes: taxes value for creating Receipt object from scratch
        :param orientation: orientation value for creating Receipt object from scratch
        :param total_tax: total_tax value for creating Receipt object from scratch
        :param total_excl: total_excl value for creating Receipt object from scratch
        :param page_n: Page number for multi pages pdf input
        """
        self.type = "Receipt"
        self.locale = None
        self.total_incl = None
        self.date = None
        self.category = None
        self.merchant_name = None
        self.time = None
        self.taxes = []
        self.orientation = None
        self.total_tax = None
        self.total_excl = None

        if api_prediction is not None:
            self.build_from_api_prediction(api_prediction, page_n=page_n)
        else:
            self.locale = Locale({"value": locale}, value_key="value", page_n=page_n)
            self.total_incl = Amount({"value": total_incl}, value_key="value", page_n=page_n)
            self.date = Date({"value": date}, value_key="value", page_n=page_n)
            self.category = Field({"value": category}, value_key="value", page_n=page_n)
            self.merchant_name = Field({"value": merchant_name}, value_key="value", page_n=page_n)
            self.time = Field({"value": time}, value_key="value", page_n=page_n)
            if taxes is not None:
                self.taxes = [
                    Tax({"value": t[0], "rate": t[1]}, page_n=page_n, value_key="value", rate_key="rate")
                    for t in taxes]
            self.orientation = Orientation({"value": orientation}, value_key="value", page_n=page_n)
            self.total_tax = Amount({"value": total_tax}, value_key="value", page_n=page_n)
            self.total_excl = Amount({"value": total_excl}, value_key="value", page_n=page_n)

        # Invoke Document constructor
        super(Receipt, self).__init__(input_file)

        # Run checks
        self._checklist()

        # Reconstruct extra fields
        self._reconstruct()