def test_tax_of_estimated_total_amount_fail(self): # set_up project = Project( project_name='test_project', project_name_for_bp='project', status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='M2000', end_user_company_id=1, client_company_id=None, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') # 消費税は必ず0になる。 expected = 0 actual = project.tax_of_estimated_total_amount() self.assertEqual(expected, actual)
def test_has_not_project_billings_true(self): # set_up project = Project( project_name='test_project', project_name_for_bp='project', status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='test_project', end_user_company_id=1, client_company_id=5, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') project_detail = ProjectDetail( detail_type=DetailType.work, work_name='test_project_detail', billing_money='100000', created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') project.project_details.append(project_detail) db.session.add(project) db.session.commit() # project_billingが紐づいていない expected = [] self.assertEqual(project.project_details[0].project_billings, expected) # project_billingが紐づいていなければTrue actual = project.has_not_project_billings() self.assertTrue(actual) # tear_down db.session.delete(project) db.session.delete(project_detail) db.session.commit()
def test_result_search_page2(self): # ログインする self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) today = datetime.today().date() first_day = today.replace(day=1) last_first_day = first_day + relativedelta(months=-1) last_day = first_day + relativedelta(months=1, days=-1) # プロジェクトを新規作成 project = Project( project_name='test_result_search_page2', end_user_company_id=4, client_company_id=3, start_date=last_first_day.strftime('%Y/%m/%d'), end_date=last_day.strftime('%Y/%m/%d'), created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() project_id = project.id # 2ページ目に行くように12件明細情報を登録する for num in range(12): self.app.post('/project/contract/create?project_id=' + str(project_id), data={ 'detail_type': DetailType.engineer, 'engineer_id': num+1, 'billing_money': '100000000', 'billing_start_day': last_first_day.strftime('%Y/%m'), 'billing_end_day': last_day.strftime('%Y/%m'), 'billing_per_month': '100000', 'billing_rule': Rule.fixed.value, 'billing_fraction_rule': '', }) # 契約完了にして、実績データを作成する result = self.app.post('/project/contract/' + str(project_id), data={ 'status': Status.done.value, 'recorded_department_id': '1', 'estimation_no': 'M0024', 'project_name': '日付テスト', 'end_user_company_id': '4', 'client_company_id': '3', 'start_date': last_first_day.strftime('%Y/%m/%d'), 'end_date': last_day.strftime('%Y/%m/%d'), 'contract_form': Contract.blanket.value, 'billing_timing': BillingTiming.billing_at_last.value }) self.assertEqual(result.status_code, 302) result = self.app.get('/search/result/page/2') self.assertEqual(result.status_code, 200)
def test_delete_project(self): # 削除用のプロジェクトを登録 project = Project(project_name='test_delete_project', project_name_for_bp='delete_project', status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='test_delete_project', end_user_company_id=1, client_company_id=5, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() delete_project_id = project.id # ログイン self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) project = self.project_repository.find_by_id(delete_project_id) result = self.app.get('/project/delete/' + str(project.id)) # 削除できることを確認 self.assertEqual(result.status_code, 302) ok_('/project' in result.headers['Location']) # 削除したプロジェクトが存在しないことを確認 project = self.project_repository.find_by_id(delete_project_id) self.assertIsNone(project.id)
def create(project_id=None): if project_id: project = service.find_by_id(project_id) else: project = Project() form = ProjectCreateForm(request.form, obj=project) if form.validate_on_submit(): if project_id: project = service.clone(project_id) if project.inspection_date: project.inspection_date = form.end_date.data project.project_name = form.project_name.data project.project_name_for_bp = form.project_name_for_bp.data project.start_date = form.start_date.data project.end_date = form.end_date.data for detail in project.project_details: # BP注文番号を再発番したいので一旦ブランクで保存する detail.billing_start_day = None detail.billing_end_day = None # 顧客注文書No(BPごと)はブランクにする detail.client_order_no_for_bp = None service.save(project) # BP注文番号を再発番するため、開始日、終了日を設定する for detail in project.project_details: detail.billing_start_day = project.start_date detail.billing_end_day = project.end_date project_detail_service.save(detail) flash(Message.saved.value) return redirect( url_for('project_contract.index', project_id=project.id)) current_app.logger.debug(form.errors) if form.errors: flash(Message.saving_failed.value, 'error') return render_template('project/create.html', form=form)
def test_require_result_true(self): # set_up project = Project( project_name='test_project', project_name_for_bp='project', status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='test_require_result_true', end_user_company_id=1, client_company_id=5, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') project_details = [ ProjectDetail( project_id=project.id, detail_type=DetailType.engineer, engineer_id=1, billing_money=1, remarks=1, billing_start_day=project.start_date, billing_end_day=project.end_date, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******'), ProjectDetail( project_id=project.id, detail_type=DetailType.engineer, engineer_id=2, billing_money=1, remarks=1, billing_start_day=project.start_date, billing_end_day=project.end_date, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') ] project.project_details = project_details db.session.add(project) db.session.commit() # 技術者だけならTrue actual = project.require_result() self.assertTrue(actual)
def test_copy_project(self): # コピー用のプロジェクトを登録 project = Project(project_name='test_copy_project', project_name_for_bp='copy_project', status=Status.done, recorded_department_id=1, sales_person='営業担当', estimation_no='test_copy_project', end_user_company_id=1, client_company_id=5, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=date.today(), responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() original_project_id = project.id # ログイン self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) original = self.project_repository.find_by_id(original_project_id) result = self.app.post('/project/copy/' + str(original.id), data={ 'project_name': 'test_copy_project_after', 'start_date': date.today().strftime('%Y/%m/%d'), 'end_date': '2099/12/31' }) # コピーできることを確認 self.assertEqual(result.status_code, 302) ok_('/contract' in result.headers['Location']) copy_project_id = result.headers['Location'].split('/')[-1] # コピーしたプロジェクトが存在することを確認 copy = self.project_repository.find_by_id(copy_project_id) self.assertIsNotNone(copy.id) # コピーしたプロジェクトのステータスが「01:契約開始」に戻っていることを確認 self.assertEqual(copy.status, Status.start)
def test_copy_project_detail_start_date_and_end_date(self): # コピー用のプロジェクトを登録 project = Project( project_name='test_copy_project', project_name_for_bp='copy_project', status=Status.done, recorded_department_id=1, sales_person='営業担当', estimation_no='test_copy_project_detail_start_date_and_end_date', end_user_company_id=1, client_company_id=5, start_date='2016/9/1', end_date='2016/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') project_details = [ ProjectDetail(project_id=project.id, detail_type=DetailType.engineer, engineer_id=1, billing_money=1, remarks=1, billing_start_day=project.start_date, billing_end_day=project.end_date, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******'), ProjectDetail(project_id=project.id, detail_type=DetailType.engineer, engineer_id=2, billing_money=1, remarks=1, billing_start_day=project.start_date, billing_end_day=project.end_date, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') ] project.project_details = project_details db.session.add(project) db.session.commit() original_project_id = project.id # ログイン self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) original = self.project_repository.find_by_id(original_project_id) result = self.app.post( '/project/copy/' + str(original.id), data={ 'project_name': 'test_copy_project_after', 'start_date': date.today().strftime('%Y/%m/%d'), 'end_date': (date.today() + relativedelta(months=1)).strftime('%Y/%m/%d') }) # コピーできることを確認 self.assertEqual(result.status_code, 302) ok_('/contract' in result.headers['Location']) copy_project_id = result.headers['Location'].split('/')[-1] # コピーしたプロジェクトが存在することを確認 copy = self.project_repository.find_by_id(copy_project_id) self.assertIsNotNone(copy.id) # コピーしたプロジェクト明細の契約開始日、終了日がプロジェクト開始日、終了日になっていることを確認 for detail in copy.project_details: self.assertEqual(copy.start_date, detail.billing_start_day) self.assertEqual(copy.end_date, detail.billing_end_day)
def test_duplicate_copy_project(self): # 今年度のシーケンスを取得 year = int(date.today().strftime('%y')) if int(date.today().strftime('%m')) >= 10: year += 1 estimation_sequence = self.estimation_sequence_repository.find_by_fiscal_year( year) print(estimation_sequence) # これから作成される見積番号を作成 estimation_no = 'M' + str(estimation_sequence.fiscal_year)\ + '-'\ + str(estimation_sequence.fiscal_year)\ + '{0:03d}'.format(estimation_sequence.sequence + 1) # コピー時に発番が期待される見積番号 expected = 'M' + str(estimation_sequence.fiscal_year)\ + '-'\ + str(estimation_sequence.fiscal_year)\ + '{0:03d}'.format(estimation_sequence.sequence + 2) # コピー用のプロジェクトを登録 project = Project(project_name='test_copy_project', project_name_for_bp='copy_project', status=Status.done, recorded_department_id=1, sales_person='営業担当', estimation_no=estimation_no, end_user_company_id=1, client_company_id=5, start_date=date.today(), end_date='2099/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() original_project_id = project.id # ログイン self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) original = self.project_repository.find_by_id(original_project_id) result = self.app.post('/project/copy/' + str(original.id), data={ 'project_name': 'test_copy_project_after', 'start_date': date.today().strftime('%Y/%m/%d'), 'end_date': '2099/12/31' }) # コピーできることを確認 self.assertEqual(result.status_code, 302) ok_('/contract' in result.headers['Location']) copy_project_id = result.headers['Location'].split('/')[-1] # コピーしたプロジェクトが存在することを確認 copy = self.project_repository.find_by_id(copy_project_id) self.assertIsNotNone(copy.id) # コピーしたプロジェクトの見積番号を確認 self.assertEqual(copy.estimation_no, expected)
def create_projects(): for num in range(12): project = Project(project_name='単体テスト' + str(num), project_name_for_bp='テスト' + str(num), status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='test' + str(num), end_user_company_id=1, client_company_id=5, start_date='2017/1/1', end_date='2017/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.parse((num % 2) + 1), estimated_total_amount=1000000, billing_tax=Tax.zero, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() for num in range(30): project = Project(project_name='単体テスト' + str(num), project_name_for_bp='テスト' + str(num), status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='M1' + str(num // 10) + '-000' + str(num)[-1:], end_user_company_id=1, client_company_id=5, start_date='2017/1/1', end_date='2017/12/31', contract_form=Contract.blanket, billing_timing=BillingTiming.parse((num % 2) + 1), estimated_total_amount=1000000, billing_tax=Tax.zero, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit()
def create(self): return Project()
def test_do_not_create_billing_when_billing_confirmation_money_none(self): before = len(self.project_billing_repository.find_all()) # ログイン self.app.post('/login', data={ 'shain_number': 'test1', 'password': '******' }) # set_up project = Project(project_name='テスト', project_name_for_bp='テスト', status=Status.start, recorded_department_id=1, sales_person='営業担当', estimation_no='do_not_create_bill', end_user_company_id=4, client_company_id=3, start_date=date(2017, 1, 1), end_date=date(2017, 12, 31), contract_form=Contract.blanket, billing_timing=BillingTiming.billing_at_last, estimated_total_amount=1000000, scope='test', contents=None, working_place=None, delivery_place=None, deliverables=None, inspection_date=None, responsible_person=None, quality_control=None, subcontractor=None, remarks=None, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(project) db.session.commit() engineer = Engineer(engineer_name='エンジニア', company_id=5, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(engineer) db.session.commit() history = EngineerHistory(engineer_id=engineer.id, payment_start_day=date(2016, 1, 1), payment_end_day=date(2099, 12, 31), payment_per_month=600000, payment_rule=Rule.fixed, payment_site=engineer.company.payment_site, payment_tax=engineer.company.payment_tax, created_at=datetime.today(), created_user='******', updated_at=datetime.today(), updated_user='******') db.session.add(history) db.session.commit() result = self.app.post('/project/contract/create?project_id=' + str(project.id), data={ 'detail_type': DetailType.engineer, 'engineer_id': engineer.id, 'billing_money': '100000000', 'billing_start_day': date(2017, 1, 1).strftime('%Y/%m'), 'billing_end_day': date(2017, 3, 1).strftime('%Y/%m'), 'billing_per_month': '100000', 'billing_rule': Rule.fixed.value, 'billing_fraction_rule': '', }) self.assertEqual(result.status_code, 302) ok_('/project/contract/detail/' in result.headers['Location']) project_detail_id = result.headers['Location'].split('/')[-1] result = self.app.post('/project/contract/' + str(project.id), data={ 'status': Status.done.value, 'recorded_department_id': project.recorded_department_id, 'estimation_no': project.estimation_no, 'project_name': project.project_name, 'end_user_company_id': str(project.end_user_company_id), 'client_company_id': str(project.client_company_id), 'start_date': project.start_date.strftime('%Y/%m/%d'), 'end_date': project.end_date.strftime('%Y/%m/%d'), 'contract_form': project.contract_form.value, 'billing_timing': project.billing_timing.value }) self.assertEqual(result.status_code, 302) ok_('/project/contract' in result.headers['Location']) project_detail = self.project_detail_repository.find_by_id( project_detail_id) project_result_id = project_detail.project_results[0].id # 実績を保存する。 result = self.app.post('/project/result/detail/' + str(project_result_id), data={ 'work_time': '160.0', 'billing_confirmation_money': '' }) self.assertEqual(result.status_code, 302) ok_('/project/result/detail/' + str(project_result_id) in result.headers['Location']) # 請求のレコード数が増えていないことを確認。 after = len(self.project_billing_repository.find_all()) self.assertEqual(before, after)