Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote freight calculation using Correios API #71

Merged
merged 21 commits into from
Apr 28, 2017
Merged

Conversation

osantana
Copy link
Contributor

No description provided.

@osantana osantana added wip and removed wip labels Apr 19, 2017
@osantana
Copy link
Contributor Author

Finalmente consegui finalizar isso aqui...

@osantana
Copy link
Contributor Author

todo mundo ignorando meu PR gigante :(

@osantana
Copy link
Contributor Author

valeu @adlermedrado! estou anotando no meu caderninho de amigos aqui o nome das pessoas que revisaram meu PR :P

@osantana
Copy link
Contributor Author

opa! mais um do @cacarrara! :) queria um review do @lamenezes que já trabalhou bastante por aqui também... :)

if extra_services is None:
extra_services = []
else:
extra_services = [ExtraService.get(es) for es in extra_services]
Copy link
Contributor

@georgeyk georgeyk Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eu removeria esse if/else e usaria or numa linha só, mas é 💄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eu preciso da list comprehension e do [], ou seja, preciso do if e do else... ou faria um if-expression ou teria que usar and e or:

extra_services = [ES.get(es) for es in extra_services] if extra_services else []
# or...
extra_services = extra_services and [ES.get(es) for es in extra_services] or []

Mas acho a legibilidade em ambos os casos bem ruim.

(além disso deve ter um bug no mypy que alerta para uma iteração em um objeto None)

from_zip: Union[ZipCode, int, str], to_zip: Union[ZipCode, int, str],
package: Package,
value: Union[Decimal, float] = 0.00,
extra_services: Optional[Sequence[Union[ExtraService, int]]] = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tetris mode!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lisp com [] :)

@@ -336,6 +337,10 @@ def volumetric_weight(self) -> int:
def posting_weight(self) -> int:
return Package.calculate_posting_weight(self.weight, self.volumetric_weight)

@property
def freight_package_type(self) -> int:
return [3, 1, 2][self.package_type - 1] # see documentation for freight calculation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eita.. meio esquisitinho isso daqui

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correios amigo... correios... package_type para uma API são 1, 2, 3 e para outra API é 2, 1, 3 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pensei em explicar isso nos comentários mas a coisa é tão idiota que só apontei para a documentação dos correios...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É fácil de achar isso lá ? pq não é nada óbvio isso

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tá... vou explicar nos comentários então... melhor, né?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refiz a implementação... acho que ficou um pouco melhor agora...


def calculate_freights(self,
posting_card: PostingCard,
services: List[Union[Service, int]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

será que não seria uma boa ter algum default de serviço ?

Copy link
Contributor Author

@osantana osantana Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qual você sugeriria? :/ poderia ser PAC... mas tem uns 500 tipos de PAC :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

é, deixa sem então =/

@@ -294,6 +332,9 @@ def __init__(self, username, password, timeout=8, environment="production"):
self.websro_client = SoapClient(self.websro_url, timeout=self.timeout)
self.websro = self.websro_client.service

self.freight_client = SoapClient(self.freight_url, timeout=self.timeout)
self.freight = self.freight_client.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

será que não seria interessante isolar essa parte de frete em outra classe ?
Se eu entendi bem, o acesso é público pra frete e pra instanciar essa classe eu preciso ter um username/password.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não é público. Também achei que era... pode ver que no método de calculo eu passo self.password para a api...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shit..

service: Union[Service, int],
error_code: Union[str, int],
error_message: str) -> None:
super().__init__(service, 0, Decimal("0.00"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💄 eu particularmente prefiro usar o formato com nome=valor, acho que fica mais simples de ler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@lamenezes lamenezes merged commit f0b86b5 into master Apr 28, 2017
@lamenezes lamenezes deleted the remote-freight branch April 28, 2017 16:25
osantana pushed a commit that referenced this pull request Apr 28, 2017
Remote freight calculation using Correios API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants