def setUp(self):
     super(ProjectResultTests, self).setUp()
     self.project_repository = ProjectRepository()
     self.project_result_repository = ProjectResultRepository()
     self.project_detail_repository = ProjectDetailRepository()
     self.project_billing_repository = ProjectBillingRepository()
     self.project_month_repository = ProjectMonthRepository()
class ProjectMonthService(object):
    repository = ProjectMonthRepository()
    result_repository = ProjectResultRepository()
    billing_sequence_repository = BillingSequenceRepository()

    def get_billing_department_report(self, month):
        return self.repository.get_billing_department_report(month)

    def get_project_result_form(self, project_id):
        project_result_forms = self.repository.get_project_result_form(
            project_id)
        for project_result_form in project_result_forms:
            self.result_repository.get_project_results(project_result_form)
        return project_result_forms

    def get_project_payment_form(self, project_id):
        project_payment_forms = self.repository.get_project_payment_form(
            project_id)
        for project_payment_form in project_payment_forms:
            self.result_repository.get_project_payments(project_payment_form)
        return project_payment_forms

    def find_by_id(self, project_month_id):
        return self.repository.find_by_id(project_month_id)

    def find_by_billing(self, page, project_name, estimation_no,
                        billing_input_flag, deposit_input_flag,
                        end_user_company_id, client_company_id,
                        recorded_department_id, deposit_date_from,
                        deposit_date_to):
        return self.repository.find_by_billing(
            page, project_name, estimation_no, billing_input_flag,
            deposit_input_flag, end_user_company_id, client_company_id,
            recorded_department_id, deposit_date_from, deposit_date_to)

    def find_project_month_at_a_month(self, project_id, project_month):
        return self.repository.find_project_month_at_a_month(
            project_id, project_month)

    def find_incomplete_billings(self):
        return self.repository.find_incomplete_billings()

    def find_incomplete_deposits(self):
        return self.repository.find_incomplete_deposits()

    def save(self, project_month):
        if project_month.is_month_to_billing():
            fiscal_year = project_month.get_fiscal_year()

            while True:
                billing_sequence = self.billing_sequence_repository.take_a_sequence(
                    fiscal_year)
                client_billing_no = billing_sequence.get_client_billing_no()

                if not self.repository.find_by_client_billing_no(
                        client_billing_no):
                    project_month.client_billing_no = client_billing_no
                    break

        return self.repository.save(project_month)
class ProjectResultService(object):
    project_repository = ProjectRepository()
    project_month_repository = ProjectMonthRepository()
    project_result_repository = ProjectResultRepository()
    project_billing_repository = ProjectBillingRepository()

    def find_by_id(self, result_id):
        return self.project_result_repository.find_by_id(result_id)

    def find_by_payment(self, page, project_name, estimation_no, input_flag,
                        end_user_company_id, client_company_id,
                        recorded_department_id, engineer_name,
                        payment_expected_date_from, payment_expected_date_to):
        return self.project_result_repository.find_by_payment(
            page, project_name, estimation_no, input_flag, end_user_company_id,
            client_company_id, recorded_department_id, engineer_name,
            payment_expected_date_from, payment_expected_date_to)

    def find_by_result(self, page, project_name, estimation_no,
                       result_input_flag, end_user_company_id,
                       client_company_id, recorded_department_id,
                       engineer_name, result_month_from, result_month_to):
        return self.project_result_repository.find_by_result(
            page, project_name, estimation_no, result_input_flag,
            end_user_company_id, client_company_id, recorded_department_id,
            engineer_name, result_month_from, result_month_to)

    def find_incomplete_results(self):
        return self.project_result_repository.find_incomplete_results()

    def find_incomplete_payments(self):
        return self.project_result_repository.find_incomplete_payments()

    def save(self, result):
        if result.billing_confirmation_money:
            self.project_billing_repository.copy_and_save(result)
            project_id = result.project_detail.project_id

            # 請求明細金額と請求明細交通費を再計算する
            project = self.project_repository.find_by_id(project_id)
            billing_confirmation_money = 0
            billing_transportation = 0
            for project_detail in project.project_details:
                for project_billing in project_detail.project_billings:
                    if project_billing.billing_month == result.result_month:
                        billing_confirmation_money += project_billing.billing_confirmation_money or 0
                        billing_transportation += project_billing.billing_transportation or 0

            project_month = self.project_month_repository.find_project_month_at_a_month(
                project_id, result.result_month)
            project_month.billing_confirmation_money = billing_confirmation_money
            project_month.billing_transportation = billing_transportation
            self.project_month_repository.save(project_month)

        return self.project_result_repository.save(result)
Esempio n. 4
0
class PaymentListService(object):
    project_result_repository = ProjectResultRepository()
    department_repository = DepartmentRepository()
    company_repository = CompanyRepository()

    def get_payment_lists_by_department(self, month):
        payment_lists = []

        # 部署ごとにまとめたpayment_listを取得する。
        for department in self.department_repository.find_all():
            payment_list = self.project_result_repository.get_payment_list_by_department(
                month, department)
            payment_lists.append(payment_list)
        return payment_lists

    def get_payment_list_order_by_payment_date(self, month):
        return self.project_result_repository.get_payment_list_order_by_payment_date(
            month)
Esempio n. 5
0
class PaymentListByDepartmentTests(BaseTestCase):
    def setUp(self):
        super(PaymentListByDepartmentTests, self).setUp()
        self.department_repository = DepartmentRepository()
        self.project_result_repository = ProjectResultRepository()

    def tearDown(self):
        super(PaymentListByDepartmentTests, self).tearDown()

    def test___repr__(self):
        payment_list = PaymentListByDepartment(
            department=self.department_repository.find_all()[0],
            month=date(2017, 1, 1),
            project_results=self.project_result_repository.find_all())

        expected = "<PaymentListByDepartment:"\
                   + "'department_name='{}".format(payment_list.department.department_name)\
                   + "', month='{}".format(payment_list.month)\
                   + "', project_results='{}".format(payment_list.project_results)\
                   + "'>"

        actual = str(payment_list)
        self.assertEqual(actual, expected)
class ProjectPaymentFormTests(BaseTestCase):
    def setUp(self):
        super(ProjectPaymentFormTests, self).setUp()
        self.project_result_repository = ProjectResultRepository()

    def tearDown(self):
        super(ProjectPaymentFormTests, self).tearDown()

    def test_has_project_results(self):
        project_payment_form = ProjectPaymentForm(project_id=1,
                                                  project_month_id=1,
                                                  month=date(2017, 1, 1))

        self.assertFalse(project_payment_form.has_project_results())

        self.project_result_repository.get_project_results(
            project_payment_form)
        self.assertTrue(project_payment_form.has_project_results())

    def test_has_not_project_results(self):
        project_payment_form = ProjectPaymentForm(project_id=1,
                                                  project_month_id=1,
                                                  month=date(2017, 1, 1))

        self.assertTrue(project_payment_form.has_not_project_results())

        self.project_result_repository.get_project_results(
            project_payment_form)
        self.assertFalse(project_payment_form.has_not_project_results())

    def test_is_closed(self):
        project_result_form = ProjectPaymentForm(project_id=1,
                                                 project_month_id=1,
                                                 month=date(2017, 1, 1))
        project_result_form.project_results = \
            [
                ProjectResult(payment_expected_date=None),
                ProjectResult(payment_flag=InputFlag.done, payment_expected_date=date.today() + timedelta(days=1))
            ]
        self.assertFalse(project_result_form.is_closed())

        project_result_form.project_results = \
            [
                ProjectResult(payment_flag=InputFlag.done, payment_expected_date=date.today() + timedelta(days=-1)),
                ProjectResult(payment_flag=InputFlag.done, payment_expected_date=date.today() + timedelta(days=-2)),
                ProjectResult(payment_flag=InputFlag.done, payment_expected_date=date.today() + timedelta(days=-3))
            ]
        self.assertTrue(project_result_form.is_closed())

    def test___repr__(self):
        project_payment_form = ProjectPaymentForm(project_id=1,
                                                  project_month_id=1,
                                                  month=date(2017, 1, 1))

        expected = "<ProjectPaymentForm:" + \
                   "'project_id='{}".format(project_payment_form.project_id) + \
                   "', project_month_id='{}".format(project_payment_form.project_month_id) + \
                   "', month='{}".format(project_payment_form.month) + \
                   "', project_results='{}".format(project_payment_form.project_results) + \
                   "'>"

        actual = str(project_payment_form)
        self.assertEqual(actual, expected)
 def setUp(self):
     super(ProjectPaymentFormTests, self).setUp()
     self.project_result_repository = ProjectResultRepository()
class ProjectResultTests(BaseTestCase):

    def setUp(self):
        super(ProjectResultTests, self).setUp()
        self.project_result_repository = ProjectResultRepository()

    def tearDown(self):
        super(ProjectResultTests, self).tearDown()

    def test___repr__(self):
        project_result = ProjectResult(
                 project_detail_id=1,
                 result_month='2017/1/1',
                 work_time=1,
                 billing_transportation=2,
                 billing_adjustments=3,
                 billing_confirmation_number=4,
                 billing_confirmation_money=5,
                 payment_transportation=6,
                 payment_adjustments=7,
                 payment_confirmation_money=8,
                 remarks='test',
                 billing_receipted_date=None,
                 payment_expected_date=None,
                 payment_flag=None,
                 created_at=None,
                 created_user=None,
                 updated_at=None,
                 updated_user=None)
        
        expected = "<ProjectResult:" + \
                   "'id='{}".format(project_result.id) + \
                   "', project_detail_id='{}".format(project_result.project_detail_id) + \
                   "', result_month='{}".format(project_result.result_month) + \
                   "', work_time='{}".format(project_result.work_time) + \
                   "', billing_transportation='{}".format(project_result.billing_transportation) + \
                   "', billing_adjustments='{}".format(project_result.billing_adjustments) + \
                   "', billing_confirmation_number='{}".format(project_result.billing_confirmation_number) + \
                   "', billing_confirmation_money='{}".format(project_result.billing_confirmation_money) + \
                   "', payment_transportation='{}".format(project_result.payment_transportation) + \
                   "', payment_adjustments='{}".format(project_result.payment_adjustments) + \
                   "', payment_confirmation_money='{}".format(project_result.payment_confirmation_money) + \
                   "', remarks='{}".format(project_result.remarks) + \
                   "', billing_receipted_date='{}".format(project_result.billing_receipted_date) + \
                   "', payment_expected_date='{}".format(project_result.payment_expected_date) + \
                   "', payment_flag='{}".format(project_result.payment_flag) + \
                   "', created_at='{}".format(project_result.created_at) + \
                   "', created_user='******', updated_at='{}".format(project_result.updated_at) + \
                   "', updated_user='******'>"
        actual = str(project_result)
        self.assertEqual(actual, expected)

    # 技術者履歴がない場合、taxの値は0になる
    def test_tax_of_payment_confirmation_money_if_no_history(self):
        project_result = self.project_result_repository.find_all()[0]
        expected = 0

        actual = project_result.tax_of_payment_confirmation_money(engineer_history=None)

        self.assertEqual(expected, actual)
 def setUp(self):
     super(SearchPaymentTests, self).setUp()
     self.project_result_repository = ProjectResultRepository()
class SearchPaymentTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(SearchPaymentTests, cls).setUpClass()

    def setUp(self):
        super(SearchPaymentTests, self).setUp()
        self.project_result_repository = ProjectResultRepository()

    def tearDown(self):
        super(SearchPaymentTests, self).tearDown()

    # 支払の検索画面に遷移する。
    def test_get_payment(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.get('/search/payment/')
        self.assertEqual(result.status_code, 200)

    # 2ページ目に遷移する。
    def test_payment_page2(self):
        # データセットアップ
        for num in range(12):
            project_result = ProjectResult(
                project_detail_id=2,
                result_month=date(2016, num + 1, 1),
                work_time=160.5,
                billing_transportation=0,
                billing_confirmation_number='1人月',
                billing_confirmation_money=1000000,
                payment_transportation=1000,
                payment_confirmation_money=701000,
                remarks='テスト',
                payment_expected_date=datetime.today().date(),
                created_at=datetime.today(),
                created_user='******',
                updated_at=datetime.today(),
                updated_user='******')
            db.session.add(project_result)
        db.session.commit()

        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.get('/search/payment/page/2')
        self.assertEqual(result.status_code, 200)

    # 支払を検索する。
    def test_search_payment(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': 'test',
            'estimation_no': 'test',
            'input_flag': '0',
            'end_user_company_id': '1',
            'client_company_id': '1',
            'recorded_department_id': '1',
            'engineer_name': 'test',
            'payment_expected_date_from': '2016/1/1',
            'payment_expected_date_to': '2017/1/1'
        })
        result = self.app.get('/search/payment/?' + query_string)

        self.assertEqual(result.status_code, 200)

    # 日付をブランクで支払を検索する。
    def test_search_payment_blank_day(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': 'test',
            'estimation_no': 'test',
            'input_flag': '0',
            'end_user_company_id': '1',
            'client_company_id': '1',
            'recorded_department_id': '1',
            'engineer_name': 'test',
            'payment_expected_date_from': '',
            'payment_expected_date_to': ''
        })
        result = self.app.get('/search/payment/?' + query_string)

        self.assertEqual(result.status_code, 200)

    # 見積Noをカンマ区切りで検索し、2ページ目に遷移する。
    def test_search_billing_by_searching_in_comma(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': '',
            'estimation_no': 'M11,M12',
            'engineer_name': '',
            'payment_expected_date_from': '',
            'payment_expected_date_to': ''
        })
        result = self.app.get('/search/payment/page/2?' + query_string)
        self.assertEqual(result.status_code, 200)

    # 見積Noを全角スペース区切りで検索し、2ページ目に遷移する。
    def test_search_billing_by_searching_in_space(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': '',
            'estimation_no': 'M11 M12',
            'engineer_name': '',
            'payment_expected_date_from': '',
            'payment_expected_date_to': ''
        })
        result = self.app.get('/search/payment/page/2?' + query_string)
        self.assertEqual(result.status_code, 200)

    # 見積Noを半角スペース区切りで検索し、2ページ目に遷移する。
    def test_search_billing_by_searching_in_half_space(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': '',
            'estimation_no': 'M11 M12',
            'engineer_name': '',
            'payment_expected_date_from': '',
            'payment_expected_date_to': ''
        })
        result = self.app.get('/search/payment/page/2?' + query_string)
        self.assertEqual(result.status_code, 200)

    # 支払済みフラグが更新されることを確認する
    def test_save_flag(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        project_result = self.project_result_repository.find_by_id(3)
        self.assertEqual(project_result.payment_flag, InputFlag.yet)

        # 実支払済みフラグをチェック有りで更新する。
        excepted = InputFlag.done.value

        headers = [('X-Requested-With', 'XMLHttpRequest')]
        result = self.app.post('/search/payment/save_flag',
                               headers=headers,
                               data={
                                   'payment_id': project_result.id,
                                   'input_flag': excepted
                               })
        self.assertEqual(result.status_code, 200)

        # DBのpayment_flag値が1になっていることを確認。
        project_result = self.project_result_repository.find_by_id(3)
        actual_input_flag = project_result.payment_flag.value
        self.assertEqual(actual_input_flag, excepted)

    def test_save_flag_fail(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        # xhrではない場合
        result = self.app.post('/search/payment/save_flag',
                               data={
                                   'payment_id': '2',
                                   'input_flag': InputFlag.done.value
                               })
        self.assertEqual(result.status_code, 404)
Esempio n. 11
0
 def setUp(self):
     super(PaymentListByDepartmentTests, self).setUp()
     self.department_repository = DepartmentRepository()
     self.project_result_repository = ProjectResultRepository()
class ProjectResultTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(ProjectResultTests, cls).setUpClass()

    def setUp(self):
        super(ProjectResultTests, self).setUp()
        self.project_repository = ProjectRepository()
        self.project_result_repository = ProjectResultRepository()
        self.project_detail_repository = ProjectDetailRepository()
        self.project_billing_repository = ProjectBillingRepository()
        self.project_month_repository = ProjectMonthRepository()

    def tearDown(self):
        super(ProjectResultTests, self).tearDown()

    # 実績一覧に遷移する。
    def test_get_project_result(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        project = self.project_repository.find_by_id(1)

        result = self.app.get('/project/result/' + str(project.id))
        self.assertEqual(result.status_code, 200)

    # 実績登録画面に遷移する。
    def test_get_result(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        project_result = self.project_result_repository.find_all()[0]

        result = self.app.get('/project/result/detail/' +
                              str(project_result.id))
        self.assertEqual(result.status_code, 200)

    # 存在しない実績の場合はnot_found
    def test_get_result_fail(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.get('/project/result/detail/0')
        self.assertEqual(result.status_code, 404)

    # 実績を保存できる
    def test_save_result(self):
        shain_number = 'test1'
        self.app.post('/login',
                      data={
                          'shain_number': shain_number,
                          'password': '******'
                      })
        project_result = self.project_result_repository.find_all()[0]

        expected = Decimal(300)
        project_result_id = project_result.id

        result = self.app.post('/project/result/detail/' +
                               str(project_result_id),
                               data={'work_time': expected})
        # 保存できることを確認
        self.assertEqual(result.status_code, 302)
        ok_('/project/result/detail/' +
            str(project_result.id) in result.headers['Location'])

        project_result = self.project_result_repository.find_by_id(
            project_result_id)
        actual = project_result.work_time
        self.assertEqual(actual, expected)

    # 明細がengineerの場合、実績を更新すると同月の請求情報が新規作成される。
    def test_create_engineer_billing_when_update_result(self):
        before = len(self.project_billing_repository.find_all())
        # ログイン
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        # set_up
        project = Project(project_name='test_copy_project',
                          project_name_for_bp='copy_project',
                          status=Status.start,
                          recorded_department_id=1,
                          sales_person='営業担当',
                          estimation_no='M0001-11',
                          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': '1000'
                               })
        self.assertEqual(result.status_code, 302)
        ok_('/project/result/detail/' +
            str(project_result_id) in result.headers['Location'])

        # 請求のレコードが増えていることを確認する。
        after1 = len(self.project_billing_repository.find_all())
        self.assertEqual(before + 1, after1)

        # もう一度実績を保存すると既存の請求情報が更新されるため、請求のレコードが増えないことを確認する。
        result = self.app.post('/project/result/detail/' +
                               str(project_result_id),
                               data={
                                   'work_time': '160.0',
                                   'billing_confirmation_money': '1000'
                               })
        self.assertEqual(result.status_code, 302)
        ok_('/project/result/detail/' +
            str(project_result_id) in result.headers['Location'])

        # 請求のレコード数が増えていないことを確認。
        after2 = len(self.project_billing_repository.find_all())
        self.assertEqual(after1, after2)

    # 請求確定金額がブランクの場合、請求情報が作成されるない
    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)

    # validationチェックに引っかかって実績を保存できない。
    def test_save_result_validation_error(self):
        shain_number = 'test1'
        self.app.post('/login',
                      data={
                          'shain_number': shain_number,
                          'password': '******'
                      })
        project_result = self.project_result_repository.find_all()[0]

        project_result_id = project_result.id

        result = self.app.post('/project/result/detail/' +
                               str(project_result_id),
                               data={
                                   'work_time': 'aaa',
                                   'payment_transportation': 10000000000,
                                   'payment_adjustments': -10000000000
                               })
        # 保存できないことを確認
        self.assertEqual(result.status_code, 200)