Example #1
0
def step_impl(context, user):
    suppliers = json.loads(context.text)
    for supplier in suppliers:
        data = supplier
        if not 'responsible_person' in data:
            data['responsible_person'] = u'%s的负责人' % data['name']
        if not 'supplier_tel' in data:
            data['supplier_tel'] = '13811223344'
        if not 'supplier_address' in data:
            data['supplier_address'] = u'%s的公司地址' % data['name']

        if 'type' in data:
            if data['type'] == u'固定低价':
                data['type'] = 'fixed'
            elif data['type'] == u'首月55分成':
                data['type'] = 'divide'
                original_divide_info = data.get('divide_info', None)
                data['divide_info'] = json.dumps({
                    "divide_money":
                    original_divide_info['divide_money']
                    if original_divide_info else 1,
                    "basic_rebate":
                    original_divide_info['basic_rebate']
                    if original_divide_info else 2,
                    "rebate":
                    original_divide_info['rebate']
                    if original_divide_info else 3
                })
            elif data['type'] == u'零售返点':
                data['type'] = 'retail'
                original_retail_info = data.get('retail_info', None)
                data['retail_info'] = json.dumps({
                    "rebate":
                    original_retail_info['rebate']
                    if original_retail_info else 3
                })
        data['corp_id'] = context.corp.id
        response = context.client.put('/mall/supplier/', data)
        bdd_util.assert_api_call_success(response)
def __add_product_model_property(context, model_property):
    # 创建product model property
    data = {
        "corp_id": context.corp.id,
        "name": model_property['name'],
        "type": "image" if model_property.get('type', u'文字') == u'图片' else 'text'
    }
    response = context.client.put('/product/model_property/', data)
    bdd_util.assert_api_call_success(response)

    model_property_id = response.data['product_model_property']['id']

    # 处理value
    for value in model_property['values']:
        if 'image' in value:
            value['pic_url'] = value['image']
        else:
            value['pic_url'] = ''
        value['corp_id'] = context.corp.id
        value['model_property_id'] = model_property_id
        response = context.client.put('/product/model_property_value/', value)
        bdd_util.assert_api_call_success(response)
Example #3
0
def step_impl(context, user, shelf_name):
    product_names = json.loads(context.text)
    product_ids = []
    for product_name in product_names:
        db_product = mall_models.Product.select().dj_where(
            name=product_name).get()
        product_ids.append(db_product.id)

    if shelf_name == u'在售':
        data = {
            'corp_id': context.corp.id,
            'product_ids': json.dumps(product_ids)
        }

        response = context.client.put('/product/onshelf_products/', data)
        bdd_util.assert_api_call_success(response)
    elif shelf_name == u'待售':
        data = {
            'corp_id': context.corp.id,
            'product_ids': json.dumps(product_ids)
        }

        response = context.client.put('/product/offshelf_products/', data)
        bdd_util.assert_api_call_success(response)
Example #4
0
def step_impl(context, member_name, code, space_name):
    response = context.client.put('space.member', {
        "space_id": get_space_id(space_name),
        "code": code
    })
    bdd_util.assert_api_call_success(response)
Example #5
0
def step_impl(context, username, space_name):
    response = context.client.put('space.space', {'name': space_name})
    bdd_util.assert_api_call_success(response)
def step_impl(context, user, postage_name):
    config_id = __get_postage_config_id_for(context.corp.id, postage_name)
    data = {'corp_id': context.corp.id, 'id': config_id }
    response = context.client.delete('/mall/postage_config/', data)
    bdd_util.assert_api_call_success(response)
Example #7
0
def step_impl(context, user, corp_name):
	data = json.loads(context.text)
	req_data = __format_request_data(data)
	req_data['corp_id'] = bdd_util.get_user_id_for(corp_name)
	response = context.client.post('/account/corp/', req_data)
	bdd_util.assert_api_call_success(response)
Example #8
0
def __get_products(context, corp_name, type_name=u'在售'):
    TYPE2URL = {
        u'待售':
        '/product/offshelf_products/?corp_id=%d' % context.corp.id,
        u'在售':
        '/product/onshelf_products/?corp_id=%d' % context.corp.id,
        u'same_corp_tmpl':
        '/product/unshelf_pooled_products/?corp_id=%d',
        u'different_corp_tmpl':
        '/product/pooled_products/?corp_id=%d',
        u'待销':
        '/product/unshelf_consignment_products/?corp_id=%d' % context.corp.id,
    }

    if u'商品池' in type_name:
        other_corp_name = type_name[:-3]
        other_corp_id = bdd_util.get_user_id_for(other_corp_name)
        if corp_name == other_corp_name:
            url = TYPE2URL['same_corp_tmpl'] % other_corp_id
        else:
            url = TYPE2URL['different_corp_tmpl'] % other_corp_id
    else:
        url = TYPE2URL[type_name]

    response = context.client.get(url)
    bdd_util.assert_api_call_success(response)

    # if hasattr(context, 'query_param'):
    #     for key in context.query_param.keys():
    #         url += '&%s=%s' % (key, context.query_param[key])

    products = []
    for product in response.data["products"]:
        data = {}
        data['name'] = product['name']
        data['create_type'] = product['create_type']
        data['bar_code'] = product['bar_code']

        #分类
        if 'categories' in product:
            data['categories'] = ','.join(
                [category['name'] for category in product['categories']])

        # #规格
        # if 'models_info' in product:
        #     models_info = product['models_info']
        #     if not models_info['is_use_custom_model']:
        #         model = models_info['standard_model']
        #         data['price'] = model['price']
        #         data['stocks'] = u'无限' if model['stock_type'] == 'unlimit' else model['stocks']
        #         data['gross_profit'] = model['price'] - model['purchase_price']
        #     else:
        #         price_items = []
        #         gross_profit_items = []
        #         for model in models_info['custom_models']:
        #             price_items.append(model['price'])
        #             gross_profit_items.append(model['price'] - model['purchase_price'])
        #
        #         price_items.sort()
        #         gross_profit_items.sort()
        #         data['price'] = '%.2f~%.2f' % (price_items[0], price_items[-1])
        #         data['gross_profit'] = '%.2f~%.2f' % (gross_profit_items[0], gross_profit_items[-1])
        #         data['stocks'] = ""

        # 处理规格信息
        product['model'] = {'models': {}}
        resp_models_info = product['models_info']
        product['is_use_custom_model'] = u'是' if resp_models_info[
            'is_use_custom_model'] else u'否'
        if resp_models_info['is_use_custom_model']:
            print(resp_models_info['custom_models'])

            for model in resp_models_info['custom_models']:
                model_name_items = []
                for property_value in model['property_values']:
                    model_name_items.append(property_value['name'])
                model_name = ' '.join(model_name_items)
                product['model']['models'][model_name] = {
                    "price": model['price'],
                    "purchase_price": model['purchase_price'],
                    "weight": model['weight'],
                    "stock_type":
                    u'无限' if model['stock_type'] == 'unlimit' else u'有限',
                    "stocks": model['stocks']
                }
        else:
            model = resp_models_info['standard_model']
            model_name = model['name']
            product['model']['models'][model_name] = {
                "price": model['price'],
                "purchase_price": model['purchase_price'],
                "weight": model['weight'],
                "stock_type":
                u'无限' if model['stock_type'] == 'unlimit' else u'有限',
                "stocks": model['stocks']
            }

        data['model'] = product['model']

        data['image'] = product['image']
        data['sales'] = product.get('sales', 0)
        data['display_index'] = product['display_index']

        #供应商
        data['supplier'] = ""
        data['supplier_type'] = ""
        if product['supplier']:
            data["supplier"] = product['supplier']['name']
            supplier_type = product['supplier']['type']
            if supplier_type == 'fixed':
                data['supplier_type'] = u'固定低价'
            elif supplier_type == 'divide':
                divide_info = product['supplier']['divide_type_info']
                data['supplier_type'] = u'首月55分成(%s%%)' % divide_info[
                    'basic_rebate']
            elif supplier_type == 'retail':
                data['supplier_type'] = u'零售返点'

        #商品分类信息
        if len(product['classifications']) == 0:
            data['classification'] = ''
        else:
            items = []
            for classification in product['classifications']:
                items.append(classification['name'])
            data['classification'] = '-'.join(items)

        products.append(data)

    return products
Example #9
0
def __get_product(context, name):
    LIMIT_ZONE_TYPE_NUMBER2STR = {0: u'不限制', 1: u'禁售', 2: u'仅售'}
    product_model = mall_models.Product.select().dj_where(name=name).get()
    data = {"corp_id": context.corp.id, "id": product_model.id}

    response = context.client.get('/product/product/', data)
    bdd_util.assert_api_call_success(response)

    resp_data = response.data
    base_info = resp_data['base_info']
    product = {
        "id": resp_data['id'],
        "name": base_info['name'],
        "create_type": base_info['create_type'],
        "bar_code": base_info['bar_code'],
        "min_limit": base_info['min_limit'],
        "promotion_title": base_info['promotion_title'],
        "detail": base_info['detail'],
        "is_member_product": base_info['is_member_product'],
        "is_enable_bill": base_info['is_enable_bill'],
        "properties": resp_data['properties'],
        "supplier":
        resp_data['supplier']['name'] if resp_data['supplier'] else ""
    }

    #处理category
    product['categories'] = [
        category['name'] for category in resp_data['categories']
    ]

    #处理图片信息
    image_info = resp_data['image_info']
    product['swipe_images'] = image_info['images']
    product['thumbnails_url'] = image_info['thumbnails_url']

    #处理规格信息
    product['model'] = {'models': {}}
    resp_models_info = resp_data['models_info']
    product['is_use_custom_model'] = u'是' if resp_models_info[
        'is_use_custom_model'] else u'否'
    if resp_models_info['is_use_custom_model']:
        for model in resp_models_info['custom_models']:
            model_name_items = []
            for property_value in model['property_values']:
                model_name_items.append(property_value['name'])
            model_name = ' '.join(model_name_items)
            product['model']['models'][model_name] = {
                "price": model['price'],
                "purchase_price": model['purchase_price'],
                "weight": model['weight'],
                "stock_type":
                u'无限' if model['stock_type'] == 'unlimit' else u'有限',
                "stocks": model['stocks']
            }
    else:
        model = resp_models_info['standard_model']
        model_name = model['name']
        product['model']['models'][model_name] = {
            "price": model['price'],
            "purchase_price": model['purchase_price'],
            "weight": model['weight'],
            "stock_type": u'无限' if model['stock_type'] == 'unlimit' else u'有限',
            "stocks": model['stocks']
        }

    #处理物流信息
    logistics_info = resp_data['logistics_info']
    product['postage_type'] = u'统一运费' if logistics_info[
        'postage_type'] == 'unified_postage_type' else u'运费模板'
    product['unified_postage_money'] = logistics_info['unified_postage_money']
    product['limit_zone_type'] = LIMIT_ZONE_TYPE_NUMBER2STR[
        logistics_info['limit_zone_type']]
    product['limit_zone_name'] = mall_models.ProductLimitZoneTemplate.select(
    ).dj_where(id=logistics_info['limit_zone_id']).first(
    ).name if logistics_info['limit_zone_id'] else ''
    #处理商品分类信息
    if len(resp_data['classifications']) == 0:
        product['classification'] = ''
    else:
        items = []
        for classification in resp_data['classifications']:
            items.append(classification['name'])
        product['classification'] = '-'.join(items)

    return product
Example #10
0
def __create_product(context, product):
    data = __format_product_post_data(context, product)

    response = context.client.put('/product/product/', data)
    bdd_util.assert_api_call_success(response)