コード例 #1
0
ファイル: hwlookup.py プロジェクト: sungitly/isr
    def refresh(cls, lookup_type, account_info=None):
        if not account_info:
            from application.models.hwaccount import HwjdAccount
            # 如果没有传hwjd账号,则默认使用高德店的账号来获取基本配置信息
            account_info = HwjdAccount.find_by_store_id(11)

        from application.integration.hwjd import get_hwjd_scrb_info
        results = get_hwjd_scrb_info(account_info, lookup_type)

        if len(results) > 0:
            cls.query.filter(cls.type == lookup_type).delete()
            for item in results:
                lookup = HwjdLookup()
                lookup.type = lookup_type
                lookup.code = item['CODE']
                lookup.name = item['NAME']
                lookup.extra = item['GGXH']
                if lookup.type == u'品牌类型':
                    names = lookup.name.split('-')
                    if len(names) >= 2:
                        lookup.make = names[0]
                        lookup.model = names[1]
                db.session.add(lookup)

        return results
コード例 #2
0
ファイル: hwlookup.py プロジェクト: sungitly/isr
    def match_intent_level_lookups(store_ids):
        from application.models.hwaccount import HwjdAccount
        stores = HwjdAccount.find_all_stores()
        if store_ids:
            stores = filter(lambda s: unicode(s.store_id) in store_ids, stores)
        for store_config in stores:
            from application.models.lookup import Lookup
            isr_lookup = Lookup.find_by_name_and_store(store_config.store_id,
                                                       'intent-level')

            hwjd_lookupvalues = HwjdLookup.find_by_type(u'市场-级别')
            for index, item in enumerate(hwjd_lookupvalues):
                from application.models.lookup import LookupValue
                isr_lookupvalue = LookupValue()
                isr_lookupvalue.code = item.name
                isr_lookupvalue.value = item.name
                isr_lookupvalue.lookup_id = isr_lookup.id
                isr_lookupvalue.parent_id = -1
                # order从10开始,按照10步进
                isr_lookupvalue.order = 10 + index * 10
                isr_lookupvalue.version = isr_lookup.version + 1
                isr_lookupvalue.vendor_code = item.code
                isr_lookupvalue.vendor_value = item.name
                db.session.add(isr_lookupvalue)

            isr_lookup.version += 1
コード例 #3
0
ファイル: customer_api.py プロジェクト: sungitly/isr
def update_customer(uid):
    data = request.json
    if data is None:
        abort(400, description=gettext('invalid json request'))

    # do not allow to update customer id and status directly
    Customer.filter_not_updatable_fields(data)
    customer = get_customer(uid)

    # validate mobile. The logic is duplicated with validate method of Customer. Merge the logic later.
    if data.get('mobile',
                None) and '000' != data['mobile'] and validate_mobile(
                    data['mobile']):
        existing_cust_with_same_mobile = Customer.find_by_mobile_exclude(
            customer.store_id, data['mobile'], customer.id)
        existing_cust_with_same_mobile = handle_no_rx_customer(
            existing_cust_with_same_mobile)
        if existing_cust_with_same_mobile:
            if customer.sales_id == existing_cust_with_same_mobile.sales_id:
                raise DuplicatedCustomerException(
                    gettext(u'The mobile is the same as customer %(name)s',
                            name=existing_cust_with_same_mobile.respect_name),
                    existing_customer_id=existing_cust_with_same_mobile.id)
            else:
                raise NoPermissionOnCustomerException(
                    existing_cust_with_same_mobile,
                    gettext(u'The mobile belongs to other sales\' customer'))

    is_defeated = Customer.is_defeated(data)
    if not is_defeated:
        # validate required fields if client ask for it.
        if customer.status != 'draft':
            data['required_validation'] = True
        if not validate_required_fields(data):
            raise EmptyRequiredFields(
                gettext(u'Please fill all required fields'))

    create_or_update_addl_info(customer, data)

    for key, value in data.iteritems():
        if hasattr(customer, key):
            try:
                setattr(customer, key, value)
            except:
                # ignore the errors here
                pass

    if not is_defeated:
        customer.formal()
        from application.models.hwaccount import HwjdAccount
        if customer.store_id in HwjdAccount.find_active_hwjd_store_ids():
            last_rx = Reception.find_last_rx_by_customer_id(customer.id)
            if last_rx:
                from application.queue import async_call
                async_call("sync_hwjd_customer_rx", [last_rx.id])
    else:
        customer.defeated('NA')

    return customer
コード例 #4
0
def change_reception_status(uid):
    status = request.json.get('name')

    if status is None:
        abort(400, description=gettext('status name is empty'))
    elif status not in Reception.valid_status:
        abort(400,
              description=gettext('status %(status)s is not valid',
                                  status=status))
    else:
        result = get_reception(uid)
        if result.status == status or result.status in ('completed',
                                                        'cancelled'):
            return result
        else:
            if status == 'completed' and result.customer.status == 'draft':
                abort(
                    400,
                    description=gettext(
                        'the customer can NOT be draft before completing reception'
                    ))

            if status == 'completed':
                result.complete()
            elif status == 'cancelled':
                if result.appointment_id is not None:
                    abort(
                        400,
                        description=gettext(
                            'the reception comes from appointment, cannot be cancelled'
                        ))
                else:
                    result.status = status
                    cancel_cusstomer(result.customer)
            else:
                result.status = status

            if status in ('completed', 'cancelled'):
                close_appointment_before(result)
                if result.rx_type != 'other':
                    update_customer_status(result.customer, result.sales)
                SalesStatus.update_sales_status(result.store_id,
                                                result.sales_id)

                # commit db before invoke async process
                result.save_and_commit()
                from application.models.hwaccount import HwjdAccount
                if result.customer and result.customer.status != 'defeated' and result.store_id in \
                        HwjdAccount.find_active_hwjd_store_ids():
                    from application.queue import async_call
                    async_call("sync_hwjd_customer_rx", [result.id])

            return result
コード例 #5
0
def publish_rx_to_hwjd():
    result = {}

    store_ids = parse_comma_seperated_args(request.args.get('store_id', None))
    if not store_ids:
        from application.models.hwaccount import HwjdAccount
        store_ids = HwjdAccount.find_active_hwjd_store_ids()
    result['store_ids'] = store_ids

    process_date = parse_date(request.args.get('process_date'),
                              default=datetime.date.today())
    result['process_date'] = process_date

    if not store_ids or len(store_ids) == 0:
        return

    for store_id in store_ids:
        sync_hwjd_customer_rx_by_date(store_id, process_date)

    return result
コード例 #6
0
ファイル: hwjd.py プロジェクト: sungitly/isr
def update_hwjd_oa(hwjd_customer):
    account_info = HwjdAccount.find_by_store_id(hwjd_customer.store_id)

    if account_info:
        params = dict()
        params['Companycode'] = account_info.org_code
        params['Usercode'] = account_info.user_code
        params['Password'] = account_info.password
        params['Version'] = API_VERSION
        params['P_xml'] = hwjd_customer.to_xml()

        try:
            r = requests.post(Config.HWJD_OA_SERVER +
                              HWJD_OA_SYNC_CUSTOMER_API,
                              data=params)
            if r and r.status_code == 200 and 'OK' in r.content:
                return SUCCESS
        except:
            return FAIL

    return FAIL
コード例 #7
0
ファイル: hwlookup.py プロジェクト: sungitly/isr
    def match_intent_car_lookups(store_ids):
        from application.models.hwaccount import HwjdAccount
        stores = HwjdAccount.find_all_stores()
        if store_ids:
            stores = filter(lambda s: unicode(s.store_id) in store_ids, stores)
        for store_config in stores:
            hwjd_lookupvalues = HwjdLookup.find_by_make_models(
                store_config.make, store_config.models_array())

            if hwjd_lookupvalues and len(hwjd_lookupvalues) > 0:
                from application.models.lookup import Lookup
                isr_lookup = Lookup.find_by_name_and_store(
                    store_config.store_id, 'intent-car')

                for index, item in enumerate(hwjd_lookupvalues):
                    # 六位的code证明这个值不是具体车型的值,不做mapping
                    if len(item.code) > 6 and item.name != item.extra:
                        from application.models.lookup import LookupValue
                        isr_lookupvalue = LookupValue()
                        # 没用用hwjd的code是因为在报表里, 有可能直接用code来做显示了
                        from application.utils import underscore_join_str
                        isr_lookupvalue.code = u'%s_%s' % (
                            item.model, underscore_join_str(item.extra))
                        isr_lookupvalue.value = item.extra
                        isr_lookupvalue.lookup_id = isr_lookup.id
                        isr_lookupvalue.parent_id = -1
                        # order从10开始,按照10步进
                        isr_lookupvalue.order = 10 + index * 10
                        isr_lookupvalue.section = item.model
                        isr_lookupvalue.version = isr_lookup.version + 1
                        isr_lookupvalue.vendor_code = item.code
                        isr_lookupvalue.vendor_value = item.extra
                        isr_lookupvalue.vendor_section = item.name
                        db.session.add(isr_lookupvalue)

                isr_lookup.version += 1
コード例 #8
0
ファイル: hwcustomer.py プロジェクト: sungitly/isr
    def convert_from_reception(cls, reception):
        hc = cls.find_by_reception_id(reception.id)

        if not hc:
            hc = cls()
            hc.reception_id = reception.id
            hc.customer_id = reception.customer_id
            hc.store_id = reception.store_id
            hc.uuid = str(uuid.uuid4())

        customer = reception.customer

        from application.models.hwaccount import HwjdAccount
        hwjd_account = HwjdAccount.find_by_store_id(hc.store_id)
        hc.company_code = hwjd_account.org_code if hwjd_account else ''
        hc.created_date = reception.rx_date
        hc.intent_car_code, hc.intent_car_model, hc.intent_car_name = convert_car_code(
            hc.store_id, customer.intent_car_ids)
        hc.visit_type = convert_visit_type(reception.rx_type)
        hc.rx_start = reception.created_on.strftime(TIME_FORMAT_WO_SEC)
        hc.rx_end = (reception.created_on + timedelta(
            seconds=reception.rx_duration)).strftime(TIME_FORMAT_WO_SEC)
        hc.rx_duration = reception.rx_duration
        hc.rx_type = convert_rx_type(reception.rx_type)
        hc.channel = u'其他'
        hc.sales = reception.sales.username
        hc.intent_car_color = customer.intent_car_colors.split(
            ',')[0] if customer.intent_car_colors and len(
                customer.intent_car_colors) > 0 else ''
        hc.intent_order_date = None
        hc.budget = customer.budget
        hc.payment = customer.payment
        hc.purchase_type = convert_purchase_type(customer)
        hc.intent_level = LookupValue.get_vendor_code_by_code(
            customer.intent_level, hc.store_id, 'intent-level')
        hc.on_file = convert_boolean(customer.mobile
                                     and len(customer.mobile) >= 11)
        hc.has_trail = convert_boolean(
            customer.test_drive_car_ids
            and customer.test_drive_car_ids != 'none'
            and len(customer.test_drive_car_ids) > 0)
        hc.name = customer.respect_name
        hc.age_group = LookupValue.get_vendor_code_by_code(
            customer.channel, hc.store_id, 'age-group')
        hc.gender = customer.gender_str
        hc.mobile = customer.mobile if customer.mobile and customer.mobile != '000' else ''
        hc.has_order = convert_boolean(
            Order.has_valid_orders_by_customer(hc.customer_id))
        hc.discount = ''
        hc.price = ''
        hc.gadgets_gift = u'否'
        hc.gadgets_purchase = u'否'
        hc.competing_car_brand = u'未定'
        hc.competing_car_name = u'未定'
        hc.used_car_model = u'无'
        hc.remark = customer.remark

        from application.models.customer import CustomerAddlInfo
        addl_info = CustomerAddlInfo.find_by_customer_id(reception.customer_id)
        if addl_info:
            hc.purpose = addl_info.purpose
            hc.industry = addl_info.industry
            hc.district = addl_info.district
            hc.dealership = addl_info.dealership
            hc.used_car_value = addl_info.used_car_value
            hc.has_used_car_assess = addl_info.has_used_car_assessed

        return hc
コード例 #9
0
def refresh_hwjd_accounts():
    from application.models.hwaccount import HwjdAccount
    cache.delete_memoized(HwjdAccount.find_active_hwjd_store_ids)
    return HwjdAccount.find_active_hwjd_store_ids()