Esempio n. 1
0
    def test_wrong_api_key(self):
        """
        V5 Test wrong api key
        """
        client = retailcrm.v5(os.getenv('RETAILCRM_URL'), '98sdf9sj8fsd9fjs9answer98')
        response = client.statistic_update()

        self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.')
Esempio n. 2
0
    def test_missing_api_key(self):
        """
        V5 Test missing api key
        """
        client = retailcrm.v5(os.getenv('RETAILCRM_URL'), None)
        response = client.statistic_update()

        self.assertEqual(response.get_error_msg(), '"apiKey" is missing.')
Esempio n. 3
0
    def test_missing_api_key(self):
        """
        V5 Test missing api key
        """
        client = retailcrm.v5(os.getenv('RETAILCRM_URL'), None)
        response = client.statistic_update()

        self.assertEqual(response.get_error_msg(), '"apiKey" is missing.')
Esempio n. 4
0
    def test_wrong_api_key(self):
        """
        V5 Test wrong api key
        """
        client = retailcrm.v5(os.getenv('RETAILCRM_URL'),
                              '98sdf9sj8fsd9fjs9answer98')
        response = client.statistic_update()

        self.assertEqual(response.get_error_msg(), 'Wrong "apiKey" value.')
Esempio n. 5
0
    def test_wrong_api_url(self):
        """
        V5 Test wrong api url
        """
        client = retailcrm.v5(
            'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru', '98sdf9sj8fsd9fjs9answer98')
        response = client.statistic_update()

        self.assertTrue(response.is_successful(), False)
        self.assertEqual(response.get_error_msg(), 'Account does not exist.')
Esempio n. 6
0
    def test_wrong_api_url(self):
        """
        V5 Test wrong api url
        """
        client = retailcrm.v5(
            'https://epoqwieqwpoieqpwoeiqpwoeiq.retailcrm.ru',
            '98sdf9sj8fsd9fjs9answer98')
        response = client.statistic_update()

        self.assertTrue(response.is_successful(), False)
        self.assertEqual(response.get_error_msg(), 'Account does not exist.')
Esempio n. 7
0
import retailcrm
from flask import Flask, request

app = Flask(__name__)
client = retailcrm.v5('https://popova.retailcrm.ru',
                      'h1iKk1Sb0AaM66Ms86mXh7pgMaDz6wrN')


@app.route('/')
def hello_world():
    return 'Hello, World!'


@app.route('/testd')
def service():
    ID = request.args.get('ids[0]')
    exID = request.args.get('externalIds[0]')
    mode = request.args.get('mode')
    if (mode == 'access'):
        result = client.products({'externalId': exID})
        Product_name = result._Response__response_body['products'][0]['name']
        Product_name = (Product_name[Product_name.find(" ") + 1:])
        point = Product_name.find(",") + 1
        n = 0
        tmp = ""
        while n < point:
            tmp += Product_name[n]
            n += 1
        Product_name = tmp
        if Product_name.find('iPhone') > -1:
            Product_name = 'Чехол ' + Product_name
Esempio n. 8
0
 def setUp(self):
     """
     Setup
     """
     self.client = retailcrm.v5(
         os.getenv('RETAILCRM_URL'), os.getenv('RETAILCRM_KEY'))
Esempio n. 9
0
def send_order_to_crm(order):
    items = []
    print('sending to crm')
    for item in order.items.all():
        items.append({
            'productName': item.item_type.item.name,
            'initialPrice': item.item_type.item.price,
            'quantity': item.quantity,
            'offer': {
                'xmlId': f'{item.item_type.item.id_1c.split("#")[0]}#{item.item_type.id_1c}',
                # 'id': item.item_type.id
            }
        })



    if not order.delivery.is_self_delivery:
        delivery = {
            'code': 'sdek' if not order.delivery.is_office_cdek else 'sdekoffice',
            'address':
                {
                    'city': order.city.name,
                    'cityId': order.city.code,
                    'street': order.street,
                    'building': order.house,
                    'flat': order.flat,
                }
        }
    else:
        delivery = {
            'code': 'self-delivery'
        }

    client = retailcrm.v5(f'https://{settings.CRM_URL}.retailcrm.ru', settings.CRM_API)

    order_info = {
        'payments': [
            {
                'type': 'site-u-kassa',
                'status': 'paid'
            }
        ],
        'firstName': order.fio,
        'lastName': '',
        'phone': order.phone,
        'email': order.email,
        'items': items,
        'customerComment': order.comment,
        # 'orderMethod': 'site',
        'source': {
            'source': 'site',
        },

        'delivery': delivery
    }

    print('order', order_info)
    result = client.order_create(order_info)
    print('result.get_errors()', result.get_errors())
    print('result.get_status_code()', result.get_status_code())
    print('result.get_response()', result.get_response())

    msg_html = render_to_string('new_order.html', {'order': order,
                                                   'items': order.items.all()})
    send_mail('Ваш заказ', None, '*****@*****.**', [order.email, '*****@*****.**'],
              fail_silently=False, html_message=msg_html)
    return
Esempio n. 10
0
 def setUp(self):
     """
     Setup
     """
     self.client = retailcrm.v5(os.getenv('RETAILCRM_URL'),
                                os.getenv('RETAILCRM_KEY'))