Пример #1
0
    def calculate(self, basket, postcode):
        # If the charge is free then tax must be free (musn't it?) and so we
        # immediately set the tax to zero
        package = Package(formato=CAIXA_PACOTE)
        tax = D(0)
        ret = {}
        try:
            for line in basket.lines.all():
                product = line.product
                weight = product.weight
                height = product.height
                width = product.width
                length = product.length
                if all([weight, height, width, length]):

                    for qty in range(line.quantity):
                        package.add_item(
                            weight=weight,  # Peso
                            height=height,  # Altura
                            width=width,  # Largura
                            length=length  # Comprimento
                        )
            client = Client(cep_origem='31330-130')
            servicos = client.calc_preco_prazo(package, postcode, SEDEX)
            ret.update(service=servicos[0])
            for servico in servicos:
                tax += D(servico.valor)
        except Exception as e:
            print('*******ERRO:', e)
        price = prices.Price(currency=basket.currency,
                             excl_tax=D('0.00'),
                             tax=tax)
        ret.update(price=price)
        return ret
Пример #2
0
        def topic(self):
            cep_origem = '00000-000'
            cep_destino = '11111-111'
            client = Client(cep_origem=cep_origem)
            package = Package()
            package.add_item(weight=1, height=2, width=3, length=4)

            expected = (
                '',  # nCdEmpresa
                '',  # sDsSenha
                '40010,41106',  # nCdServico
                cep_origem,  # sCepOrigem
                cep_destino,  # sCepDestino
                1,  # nVlPeso
                CAIXA_PACOTE,  # nCdFormato
                4,  # nVlComprimento
                2,  # nVlAltura
                3,  # nVlLargura
                0,  # nVlDiametro
                False,  # sCdMaoPropria
                0.0,  # nVlValorDeclarado
                False  # sCdAvisoRecebimento
            )

            result = client.build_web_service_call_args(
                package, cep_destino, *(SEDEX, PAC))

            for expected_value, actual_value in zip(expected, result):
                yield (expected_value, actual_value)
Пример #3
0
def get_client():
    settings = config_get_group('satchmo_correios_shipping')

    return Client(
        settings.CEP_ORIGEM.value,
        codigo_empresa=settings.CODIGO_EMPRESA.value,
        senha=settings.SENHA.value
    )
Пример #4
0
    def topic(self):
        client = Client(cep_origem='01310-200')
        package = Package()
        package.add_item(weight=0.5, height=6.0, width=16.0, length=16.0)
        result = client.calc_preco_prazo(package, '52020-010', SEDEX, PAC)

        for code, service in zip([SEDEX, PAC], result):
            yield code, service
Пример #5
0
            def topic(self):
                cep_origem = '00000-000'
                kwargs = [('codigo_empresa', ''), ('senha', ''),
                          ('valor_declarado', 0.0), ('mao_propria', False),
                          ('aviso_recebimento', False)]
                client = Client(cep_origem=cep_origem)

                return (cep_origem, kwargs, client)
Пример #6
0
        def topic(self):
            cep_origem = '00000-000'
            cep_destino = '11111-111'
            method_name = 'methodName'
            args = (1, 2, 3)
            client = Client(cep_origem=cep_origem)
            package = Package()
            services = (SEDEX, PAC)
            client.build_web_service_call_args = Mock(return_value=args)
            client.ws_client.service = Mock()
            response = Mock(Servicos=[[create_sudsobject_mock()]])
            getattr(client.ws_client.service, method_name).return_value =\
                    response
            client.call_web_service(method_name, package, cep_destino,
                                    *services)

            return (method_name, package, cep_destino, services, args, client)
Пример #7
0
def calculate_shipping(cep, offers):
	offers = offers.split(',')
	package = Package(formato=CAIXA_PACOTE)
	for offer in offers:
		option_id = offer.split(':')[0]
		qtd = offer.split(':')[1]
		option = get_object_or_404(Option, id=option_id)
		if option.offer.delivery:
			client = Client(cep_origem='01310-200')
			for i in range(int(qtd)):
				package.add_item(
					weight = float(option.weight) if option.weight else 0,
					height = float(option.height) if option.height else 0,
					width  = float(option.width) if option.width else 0,
					length = float(option.length) if option.length else 0
				)
		else:
			return {'error': 1, 'data': 'Oferta não possui a opção de entrega'}
	services = client.calc_preco_prazo(package, cep, PAC)
	if services[0].erro == 0:
		return {'error': services[0].erro, 'data': services[0].valor}
	else:
		return {'error': 1, 'data': services[0].msg_erro}
Пример #8
0
                def topic(self):
                    cep_origem = '00000-000'
                    client = Client(cep_origem=cep_origem)
                    client._ws_client = Mock()

                    return client.ws_client
Пример #9
0
 def topic(self):
     return Client()