Exemple #1
0
 def build_freights_list(self, response):
     result = []
     for service_data in response.cServico:
         service = Service.get(service_data.Codigo)
         error_code = to_integer(service_data.Erro)
         if error_code:
             freight = FreightError(
                 service=service,
                 error_code=error_code,
                 error_message=service_data.MsgErro,
             )
         else:
             delivery_time = int(service_data.PrazoEntrega)
             value = to_decimal(service_data.ValorSemAdicionais)
             declared_value = to_decimal(service_data.ValorValorDeclarado)
             ar_value = to_decimal(service_data.ValorAvisoRecebimento)
             mp_value = to_decimal(service_data.ValorMaoPropria)
             saturday = service_data.EntregaSabado or ""
             home = service_data.EntregaDomiciliar or ""
             freight = Freight(
                 service=service,
                 delivery_time=delivery_time,
                 value=value,
                 declared_value=declared_value,
                 ar_value=ar_value,
                 mp_value=mp_value,
                 saturday=saturday.upper() == "S",
                 home=home.upper() == "S",
             )
         result.append(freight)
     return result
Exemple #2
0
    def __init__(
            self,
            contract: Contract,
            number: Union[int, str],  # 10 digits
            administrative_code: Union[int, str]) -> None:  # 8 digits
        self.contract = contract
        self._number = to_integer(number)
        self._administrative_code = to_integer(administrative_code)
        self._start_date = None  # type: Optional[datetime]
        self._end_date = None  # type: Optional[datetime]
        self._status = None  # type: Optional[int]
        self._unit = None  # type: Optional[str]
        self.status_code = None  # type: Optional[str]
        self.services = []  # type: List[Service]

        if self not in self.contract.posting_cards:
            self.contract.add_posting_card(self)
Exemple #3
0
 def _build_freight_response(self, service_data) -> FreightResponse:
     return FreightResponse(
         service=Service.get(service_data.Codigo),
         delivery_time=int(service_data.PrazoEntrega),
         value=to_decimal(service_data.ValorSemAdicionais),
         declared_value=to_decimal(service_data.ValorValorDeclarado),
         mp_value=to_decimal(service_data.ValorMaoPropria),
         ar_value=to_decimal(service_data.ValorAvisoRecebimento),
         saturday=service_data.EntregaSabado
         and service_data.EntregaSabado.lower() == "s" or False,
         home=service_data.EntregaDomiciliar
         and service_data.EntregaDomiciliar.lower() == "s" or False,
         error_code=to_integer(service_data.Erro) or 0,
         error_message=service_data.MsgErro or "",
     )
Exemple #4
0
    def __init__(self, number: int, code: str, name: str) -> None:
        if not number:
            raise InvalidRegionalDirectionError(
                "Invalid regional direction number {!r}".format(number))

        if not code:
            raise InvalidRegionalDirectionError(
                "Invalid regional direction code {!r}".format(code))

        if not name:
            raise InvalidRegionalDirectionError(
                "Invalid regional direction name {!r}".format(name))

        self.number = to_integer(number)
        self.code = code.upper()
        self.name = name
Exemple #5
0
    def __init__(self,
                 name: str,
                 federal_tax_number: Union[str, FederalTaxNumber],
                 state_tax_number: Optional[Union[str, StateTaxNumber]] = None,
                 status_number: Optional[Union[int, str]] = None) -> None:
        self.name = name.strip()
        self.federal_tax_number = _to_federal_tax_number(federal_tax_number)

        if status_number is not None:
            status_number = to_integer(status_number)
        self.status_number = status_number

        if state_tax_number is not None:
            state_tax_number = _to_state_tax_number(state_tax_number)
        self.state_tax_number = state_tax_number

        self.contracts = []  # type: List[Contract]
Exemple #6
0
    def __init__(
            self, user: User, number: Union[int, str],
            regional_direction: Union[str, int, 'RegionalDirection']) -> None:

        self.user = user
        user.add_contract(self)

        self.number = to_integer(number)

        if isinstance(regional_direction, str):
            regional_direction = int(regional_direction)

        if isinstance(regional_direction, int):
            regional_direction = RegionalDirection.get(regional_direction)

        self.regional_direction = regional_direction

        self._customer_code = None  # type: Optional[str]
        self._start_date = None  # type: Optional[datetime]
        self._end_date = None  # type: Optional[datetime]
        self.status_code = None  # type: Optional[str]
        self.posting_cards = []  # type: List[PostingCard]
Exemple #7
0
def test_to_integer(v, r):
    assert to_integer(v) == r
Exemple #8
0
def test_to_integer(v, r):
    assert to_integer(v) == r
Exemple #9
0
 def unit(self, number):
     self._unit = to_integer(number)
Exemple #10
0
 def status(self, number):
     self._status = to_integer(number)
Exemple #11
0
 def customer_code(self, code):
     self._customer_code = to_integer(code)
Exemple #12
0
 def sanitize_code(cls, code: Union[int, str]) -> str:
     code = to_integer("".join(d for d in str(code) if d.isdigit()))
     return "{:05}".format(code)