Exemple #1
0
def init_client():
    try:
        message, status_code = HttpClient.get_message('box/init')
        if status_code != 200:
            return message['statusMessage']
        ClientDatabase.init_database()
        box_param = {'id': message['id'], 'name': message['name'], 'orderNo': message['orderNo'],
                     'validateType': message['validateType'], 'operator_id': message['operator']['id'],
                     'syncFlag': message['syncFlag'], 'currencyUnit': message['currencyUnit'],
                     "overdueType": message['overdueType'], "freeHours": ClientTools.get_value("freeHours", message),
                     "freeDays": ClientTools.get_value("freeDays", message),
                     "holidayType": ClientTools.get_value("holidayType", message, None),
                     "receiptNo": ClientTools.get_value("receiptNo", message, 0)}
        CompanyService.init_company(message['operator'])
        BoxDao.init_box(box_param)

        cabinets = message['cabinets']
        for cabinet in cabinets:
            BoxDao.init_cabinet(cabinet)
            mouths = cabinet['mouths']
            for m in mouths:
                __mouth = {'id': m['id'], 'deleteFlag': m['deleteFlag'], 'number': m['number'],
                           'usePrice': m['usePrice'],
                           'overduePrice': m['overduePrice'], 'status': m['status'], 'box_id': message['id'],
                           'cabinet_id': cabinet['id'], 'numberInCabinet': m['numberInCabinet'],
                           'syncFlag': m['syncFlag'], 'openOrder': ClientTools.get_value("openOrder", m)}
                if 'express' in m.keys():
                    __mouth['express_id'] = m['express']['id']
                    express.service.ExpressService.init_express(m['express'], __mouth, box_param)
                else:
                    __mouth['express_id'] = None
                __mouth['mouthType_id'] = m['mouthType']['id']
                mouth_type_param = m['mouthType']
                mouth_type = {'id': mouth_type_param['id'], 'name': mouth_type_param['name'],
                              'defaultUsePrice': mouth_type_param['defaultUsePrice'],
                              'defaultOverduePrice': mouth_type_param['defaultOverduePrice'],
                              'deleteFlag': mouth_type_param['deleteFlag']}
                BoxDao.init_mouth_type(mouth_type)
                BoxDao.init_mouth(__mouth)

        if "holidays" in message.keys():
            holidays = message["holidays"]
            for holiday in holidays:
                holiday_param = {'id': holiday['id'], 'startTime': holiday['startTime'], 'endTime': holiday['endTime'],
                                 'delayDay': holiday['delayDays'], 'holidayType': holiday['holidayType']}
                BoxDao.init_holiday(holiday_param)

        box_signal_handler.init_client_signal.emit("Success")
    except Exception as e:
        logger.error(("init_client ERROR :", e))
        box_signal_handler.init_client_signal.emit("ERROR")
Exemple #2
0
def check_database(data_name):
    if not os.path.exists(sys.path[0] + '/database/' + data_name + '.db'):
        ClientDatabase.init_database()