Esempio n. 1
0
def generate_month_bill(cg, year_month):
    auth_cg = AuthUser(cg.pre_username)
    auth_admin = AuthUser('admin')
    auth_admin.post('/api/v1/monthly_bill',
                    json={
                        'year_month': year_month,
                        'company_id': cg.company_id
                    })
Esempio n. 2
0
def push_engineer():
    es = Engineer.query.all()
    os = Offer.query.all()
    es_num = len(es)
    admin = AuthUser('admin')
    for i in range(es_num - 10):
        one_engineer = es[i]
        one_offer = os[i % len(os)]
        interview_data = dict(offer_id=one_offer.id)
        interview_data['engineer_id'] = one_engineer.id
        admin.post('/api/v1/interview', json=interview_data)
Esempio n. 3
0
def create_engineers():
    for i in range(99):
        e = {}
        for key in engineers:
            e[key] = engineers[key](i)
        admin = AuthUser('admin')
        admin.post('/api/v1/engineer', json=e)
        admin.put(
            "/api/v1/engineer?schema=EngineerPutSchema&pre_username={}".format(
                e['pre_username']),
            json={"welfare_rate": e["welfare_rate"]})
Esempio n. 4
0
def create_company():
    already_company = Company.query.order_by(db.desc(Company.id)).first()
    company_index = already_company.id + 1 if already_company else 1
    name = f.company()
    company_om = f.name()
    email = f.email()
    # phone = '13366556715'  #
    phone = f.phone_number()
    contract_name = '94017386-6fac-11e9-a419-acbc329114cf.r.pdf'
    contract_path = os.path.join(root_path, 'create_fake_data', contract_name)
    site_files = os.path.join(root_path, 'main', 'files', 'tem', contract_name)
    shutil.copyfile(contract_path, site_files)
    om_user = AuthUser('admin', default_password)
    company_data = dict(name=name,
                        contact=company_om,
                        phone=phone,
                        email=email,
                        address='adfa adf',
                        om_name=phone,
                        billing_cycle=1,
                        service_fee_rate=0.1,
                        tax_rate=0.05,
                        hr_fee_rate=0.03,
                        finance_rate=0.01)

    result = om_user.post('/api/v1/company', json=company_data)
    result = json.loads(result)
    return result['id']
Esempio n. 5
0
def create_position_level(com_id):
    u = CompanyOm.query.filter_by(company_id=com_id).first()
    cou = AuthUser(u.username, default_password)
    _position = {
        "name":
        "前端",
        "salary_type":
        0,
        "position_levels": [{
            "name": "p1",
            "money": 500
        }, {
            "name": "p2",
            "money": 600
        }]
    }
    cou.post('/api/v1/position', json=_position)
Esempio n. 6
0
def first_month_daily_log():
    today = get_today()
    _, month_end_date = month_first_end_date(today.year, today.month)
    es = Engineer.query.filter_by(status=EngineerStatus.on_duty).all()
    while today <= month_end_date:
        for e in es:
            if e.career[-1].start < today:
                continue
            auth_e = AuthUser(e.pre_username)
            auth_e.post('/api/v1/daily_log', json={''})

    pms = Pm.query.all()
    for _pm in pms:
        auth_pm = AuthUser(_pm.pre_username)
        leave_audits = auth_pm.get(
            '/api/v1/leaves?audit_type=leave&status=submit')
        for index, la in enumerate(leave_audits[::-1]):
            if index < 2:
                auth_pm.put(
                    '/api/v1/leave?id={}&schema=LeaveCheckPutSchema'.format(
                        la.id))
Esempio n. 7
0
def create_pm_purchase_project(com_id):
    u = CompanyOm.query.filter_by(company_id=com_id).first()
    cou = AuthUser(u.username, default_password)

    _om = AuthUser('admin', default_password)
    from main.api.admin import _create_pre_username
    cg = {
        "pre_username": _create_pre_username(com_id),
        "real_name": f.name(),
        "phone": f.phone_number()
    }
    cou.post('/api/v1/purchase', json=cg)

    _pm = {
        "pre_username": _create_pre_username(com_id),
        "real_name": f.name(),
        "phone": f.phone_number()
    }
    cou.post('/api/v1/pm', json=_pm)

    _pm = {
        "pre_username": _create_pre_username(com_id),
        "real_name": f.name(),
        "phone": f.phone_number()
    }
    cou.post('/api/v1/pm', json=_pm)

    _project = {
        "company_id": com_id,
        "name": "项目{}".format(random.randint(0, 1000))
    }
    cou.post('/api/v1/project', json=_project)

    _project = {
        "company_id": com_id,
        "name": "项目{}".format(random.randint(0, 1000))
    }
    cou.post('/api/v1/project', json=_project)
Esempio n. 8
0
def first_month_audit():
    today = get_today()
    _, month_end_date = month_first_end_date(today.year, today.month)
    es = Engineer.query.filter_by(status=EngineerStatus.on_duty).all()
    pms = Pm.query.all()
    # 请假
    for i, e in enumerate(es):
        e_auth = AuthUser(e.pre_username)
        e_auth.post('/api/v1/leave',
                    json={
                        'leave_type':
                        LeaveType.personal,
                        'start_date':
                        after_some_work_days(i % 5).strftime('%Y-%m-%d'),
                        'end_date':
                        after_some_work_days(i % 5 + 2).strftime('%Y-%m-%d'),
                        'days':
                        3 - 0.5 * (i % 2),
                        'reason':
                        '爱批不批',
                    })
    for _pm in pms:
        pm_auth = AuthUser(_pm.pre_username)
Esempio n. 9
0
def submit_work_report(ex, year_month):
    auth_e = AuthUser(ex.pre_username)
    auth_e.post('/api/v1/work_report', json={"year_month": year_month})
Esempio n. 10
0
def ex_work_content(ex, start_date):
    pm = Pm.query.get(ex.pm_id)
    auth_pm = AuthUser(pm.pre_username)
    # dls = DailyLog.query.filter_by(engineer_id=ex.id).all()
    # for dl in dls:
    #     dl.delete()
    # 第一天的正常日志
    set_today(start_date)
    auth_e = AuthUser(ex.pre_username)
    _get_latest_daily_logs(auth_e)
    _put_daily_log_for(auth_e, get_today())

    # 提个明天的请假:
    next_work_date = after_some_work_days(1)
    next_work_date = str_date(next_work_date)
    response = auth_e.post('/api/v1/leave',
                           json={
                               "leave_type": "person",
                               "start_date": next_work_date,
                               "end_date": next_work_date,
                               "reason": "约会",
                               "days": 1
                           })
    response = json.loads(response)
    auth_pm.put('/api/v1/leave?id={}&schema=LeaveCheckPutSchema'.format(
        response['id']),
                json={"status": AuditStatus.checked})

    # 请假了,虚度过去这一天
    enter_next_work_date(1)

    # 正常日志
    enter_next_work_date()
    _get_latest_daily_logs(auth_e)
    _put_daily_log_for(auth_e, get_today())

    # 4天忘了写,打开日志,补了4天
    enter_next_work_date(after=4)
    latest_daily_logs = _get_latest_daily_logs(auth_e)
    un_put_latest_daily_logs = list(
        filter(
            lambda x: x['duration'] == 0 and not x['content'] and x[
                'origin_type'] == 'normal_work', latest_daily_logs['data']))
    assert len(un_put_latest_daily_logs) == 4
    for daily in un_put_latest_daily_logs:
        _put_daily_log_for(auth_e, daily['date'])

    # 正常工作到周末之前
    while is_work_day(after_some_days(1)):
        enter_next_date(1)
        _get_latest_daily_logs(auth_e)
        _put_daily_log_for(auth_e, get_today())

    # 明天应该是周末了,申请1。5天的加班
    next_day = after_some_days(1)
    response = auth_e.post('/api/v1/extra_work',
                           json={
                               "start_date": str_date(next_day),
                               "end_date":
                               str_date(after_some_days(1, next_day)),
                               "days": 1.5,
                               "reason": "赶进度"
                           })
    audit_id = json.loads(response)['id']
    auth_pm.put(
        '/api/v1/extra_work?schema=ExtraWorkCheckPutSchema&id={}'.format(
            audit_id),
        json={"status": AuditStatus.checked})

    # 加班
    enter_next_date(1)
    _put_daily_log_for(auth_e, get_today(), content='加班1', duration=1)
    enter_next_date(1)
    _put_daily_log_for(auth_e, get_today(), content="加班2", duration=0.5)

    # 加班这么累,调个休
    next_day = after_some_work_days(1)
    can_shift_duration = auth_e.get('/api/v1/can_shift_duration')
    can_shift_duration = int(can_shift_duration)
    auth_e.post('/api/v1/shift',
                json={
                    'start': next_day,
                    'end_date': next_day
                })
Esempio n. 11
0
def create_company_data():
    admin = AuthUser('admin')

    admin.post('/api/v1/company', json=company1['company_form'])

    company_model = Company.query.filter_by(
        name=company1['company_form']['name']).first()

    for cg in company1['purchases']:
        cg.update({'company_id': company_model.id})
        admin.post('/api/v1/purchase', json=cg)

    for ipm in company1['pms']:
        ipm.update({'company_id': company_model.id})
        admin.post('/api/v1/pm', json=ipm)

    for position in company1['positions']:
        position.update({'company_id': company_model.id})
        admin.post('/api/v1/position', json=position)
    for position_level in company1['position_levels']:
        position_level.update({'company_id': company_model.id})
        admin.post('/api/v1/position_level', json=position_level)

    # 创建报价单
    position_models = Position.query.filter().all()
    position_level_models = PositionLevel.query.filter().all()
    for p in position_models:
        for pl in position_level_models:
            admin.post('/api/v1/offer_sheet', json={'company_id': company_model.id, 'position_id': p.id, \
                                                    'position_level_id': pl.id, 'money': 10000})

    # 创建项目
    ps = company1['projects']
    for p in ps:
        p['company_id'] = company_model.id
        admin.post('/api/v1/project', json=p)

    os = company1['offers']
    all_project = Project.query.all()
    all_positions = Position.query.all()
    all_position_level = PositionLevel.query.all()
    all_pms = Pm.query.all()

    index = 0
    for one_project in all_project[:2]:
        for one_position in all_positions[:2]:
            one_position_level = all_position_level[index %
                                                    len(all_position_level)]
            o_data = {}
            o_data['name'] = os['name'](one_position.name +
                                        one_position_level.name)
            o_data['amount'] = os['amount'](index)
            o_data['position_id'] = one_position.id
            o_data['company_id'] = company_model.id
            o_data['project_id'] = one_project.id
            o_data['pm_id'] = all_pms[index % len(all_pms)].id
            o_data['position_id'] = one_position.id
            o_data['position_level_id'] = one_position_level.id
            o_data['description'] = '一个需求'
            admin.post('/api/v1/offer', json=o_data)
        index += 1