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()
Exemplo n.º 2
0
class ProjectPaymentTests(BaseTestCase):

    @classmethod
    def setUpClass(cls):
        super(ProjectPaymentTests, cls).setUpClass()

    def setUp(self):
        super(ProjectPaymentTests, self).setUp()
        self.project_repository = ProjectRepository()

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

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

        project = self.project_repository.find_by_id(1)

        result = self.app.get('/project/payment/' + str(project.id))
        self.assertEqual(result.status_code, 200)
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)
Exemplo n.º 4
0
 def setUp(self):
     super(BpOrderReportTests, self).setUp()
     self.project_repository = ProjectRepository()
     self.user_repository = UserRepository()
     self.project_detail_repository = ProjectDetailRepository()
     self.engineer_repository = EngineerRepository()
     with app.test_request_context():
         project_detail = self.project_detail_repository.find_by_id(1)
         user = self.user_repository.find_by_id(1)
         session['user'] = user.serialize()
         bp_order_report = BpOrderReport(project_detail)
     self.bp_order_report = bp_order_report
class ProjectDetailService(object):
    project_repository = ProjectRepository()
    project_detail_repository = ProjectDetailRepository()
    order_sequence_repository = OrderSequenceRepository()

    def get_project_list_our_company(self, month):
        return self.project_detail_repository.get_project_list_our_company(
            month)

    def get_project_list_bp(self, month):
        return self.project_detail_repository.get_project_list_bp(month)

    def find_by_id(self, project_detail_id):
        return self.project_detail_repository.find_by_id(project_detail_id)

    def save(self, project_detail):

        if project_detail.has_payment(
        ) and project_detail.is_billing_start_day_change:
            fiscal_year = project_detail.get_fiscal_year()

            while True:
                order_sequence = self.order_sequence_repository.take_a_sequence(
                    fiscal_year)
                bp_order_no = order_sequence.get_bp_order_no()

                if not self.project_detail_repository.find_by_bp_order_no(
                        bp_order_no):
                    project_detail.bp_order_no = bp_order_no
                    break

        self.project_detail_repository.save(project_detail)

        # 見積金額合計を再計算する
        estimated_total_amount = 0
        project = self.project_repository.find_by_id(project_detail.project_id)
        for detail in project.project_details:
            estimated_total_amount += detail.billing_money or 0
        project.estimated_total_amount = estimated_total_amount
        self.project_repository.save(project)

    def destroy(self, project_detail):
        # 見積金額合計を再計算する
        estimated_total_amount = 0
        project = self.project_repository.find_by_id(project_detail.project_id)
        for detail in project.project_details:
            if detail.id != project_detail.id:
                estimated_total_amount += detail.billing_money or 0
        project.estimated_total_amount = estimated_total_amount
        self.project_repository.save(project)

        return self.project_detail_repository.destroy(project_detail)
class ProjectBillingService(object):
    project_billing_repository = ProjectBillingRepository()
    project_month_repository = ProjectMonthRepository()
    project_repository = ProjectRepository()

    def find_by_id(self, billing_id):
        return self.project_billing_repository.find_by_id(billing_id)

    def find_billings_at_a_month(self, project_id, billing_month):
        return self.project_billing_repository.find_billings_at_a_month(
            project_id, billing_month)

    def save(self, billing):
        self.project_billing_repository.save(billing)
        project_id = billing.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 == billing.billing_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, billing.billing_month)
        project_month.billing_confirmation_money = billing_confirmation_money
        project_month.billing_transportation = billing_transportation
        self.project_month_repository.save(project_month)

    def destroy(self, billing):
        self.project_billing_repository.destroy(billing)
        project_id = billing.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 == billing.billing_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, billing.billing_month)
        project_month.billing_confirmation_money = billing_confirmation_money
        project_month.billing_transportation = billing_transportation
        self.project_month_repository.save(project_month)
Exemplo n.º 7
0
 def setUp(self):
     super(EstimatedReportTests, self).setUp()
     self.project_repository = ProjectRepository()
     self.user_repository = UserRepository()
     self.project_detail_repository = ProjectDetailRepository()
     self.engineer_repository = EngineerRepository()
     with app.test_request_context():
         project = self.project_repository.find_by_id(1)
         # 明細 = 作業
         project_detail_work = ProjectDetail(
             project_id=project.id,
             detail_type=DetailType.work,
             work_name='project_detail_work',
             billing_money=100000,
             created_at=datetime.today(),
             created_user='******',
             updated_at=datetime.today(),
             updated_user='******')
         project.project_details.append(project_detail_work)
         user = self.user_repository.find_by_id(1)
         session['user'] = user.serialize()
         estimated_report = EstimatedReport(project)
     self.estimated_report = estimated_report
class ProjectService(object):
    repository = ProjectRepository()
    estimation_sequence_repository = EstimationSequenceRepository()

    def find(self, page, project_name, estimation_no, status,
             end_user_company_id, client_company_id, recorded_department_id,
             start_date, end_date):
        return self.repository.find(page, project_name, estimation_no, status,
                                    end_user_company_id, client_company_id,
                                    recorded_department_id, start_date,
                                    end_date)

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

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

    def clone(self, project_id):

        project = self.find_by_id(project_id)
        project_clone = project.clone()
        project_details_clone = [
            detail.clone() for detail in project.project_details
        ]
        project_clone.project_details = project_details_clone
        project_clone.status = Status.start
        project_clone.client_order_no = None

        return project_clone

    def save(self, project):
        if project.is_start_date_change:
            fiscal_year = project.get_fiscal_year()

            while True:
                estimation_sequence = self.estimation_sequence_repository.take_a_sequence(
                    fiscal_year)
                estimation_no = estimation_sequence.get_estimation_no()

                if not self.repository.find_by_estimation_no(estimation_no):
                    project.estimation_no = estimation_no
                    break

        self.repository.save(project)

    def destroy(self, project):
        self.repository.destroy(project)
Exemplo n.º 9
0
 def setUp(self):
     super(ProjectTests, self).setUp()
     self.project_repository = ProjectRepository()
Exemplo n.º 10
0
class ProjectTests(BaseTestCase):

    def setUp(self):
        super(ProjectTests, self).setUp()
        self.project_repository = ProjectRepository()

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

    def test_has_not_project_results_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_resultが紐づいていない
        expected = []
        self.assertEqual(project.project_details[0].project_results, expected)

        # project_resultが紐づいていなければTrue
        actual = project.has_not_project_results()
        self.assertTrue(actual)

        # tear_down
        db.session.delete(project)
        db.session.delete(project_detail)
        db.session.commit()

    def test_has_not_project_results_false(self):
        project = self.project_repository.find_by_id(1)

        # project_resultが紐づいている
        self.assertIsNotNone(project.project_details[0].project_results[0])

        # 1件でもproject_resultが紐づいているならFalse
        actual = project.has_not_project_results()
        self.assertFalse(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_has_not_project_billings_false(self):
        project = self.project_repository.find_by_id(1)

        # project_billingが紐づいている
        self.assertIsNotNone(project.project_details[0].project_billings[0])

        # 1件でもproject_ billingが紐づいているならFalse
        actual = project.has_not_project_billings()
        self.assertFalse(actual)

    def test_has_not_project_months_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='******')
        db.session.add(project)
        db.session.commit()

        # project_monthが紐づいていない
        expected = []
        self.assertEqual(project.project_months, expected)

        # project_monthが紐づいていなければTrue
        actual = project.has_not_project_months()
        self.assertTrue(actual)

        # tear_down
        db.session.delete(project)
        db.session.commit()

    def test_has_not_project_months_false(self):
        project = self.project_repository.find_by_id(1)

        # project_monthが紐づいている
        self.assertIsNotNone(project.project_months[0])

        # 1件でもproject_monthが紐づいているならFalse
        actual = project.has_not_project_months()
        self.assertFalse(actual)

    def test_has_payment_true(self):
        project = self.project_repository.find_by_id(1)

        # project_detailが紐づいている
        self.assertIsNotNone(project.project_details[0])

        # bp所属ならTrue
        actual = project.has_payment()
        self.assertTrue(actual)

    def test_has_payment_false(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()

        # 作業だけならFalse
        actual = project.has_payment()
        self.assertFalse(actual)

    def test_tax_of_estimated_total_amount(self):
        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=1,
                    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のとき、消費税は0円となる。
        expected = 0
        project.billing_tax = Tax.zero
        actual = project.tax_of_estimated_total_amount()
        self.assertEqual(expected, actual)

        # estimated_total_amountが1000000なので、消費税率が8%のときは消費税が80000円となる。
        expected = 80000
        project.billing_tax = Tax.eight
        actual = project.tax_of_estimated_total_amount()
        self.assertEqual(expected, actual)

        # estimated_total_amountが1000000なので、消費税率が10%のときは消費税が100000円となる。
        expected = 100000
        project.billing_tax = Tax.ten
        actual = project.tax_of_estimated_total_amount()
        self.assertEqual(expected, actual)

    # 顧客会社を登録していない状態で、消費税計算を行った場合
    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_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_require_result_false(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_false',
                    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()

        # 作業だけならFalse
        actual = project.require_result()
        self.assertFalse(actual)
Exemplo n.º 11
0
 def setUp(self):
     super(ProjectTests, self).setUp()
     self.project_repository = ProjectRepository()
     self.estimation_sequence_repository = EstimationSequenceRepository()
Exemplo n.º 12
0
class ProjectTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(ProjectTests, cls).setUpClass()

    def setUp(self):
        super(ProjectTests, self).setUp()
        self.project_repository = ProjectRepository()
        self.estimation_sequence_repository = EstimationSequenceRepository()

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

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

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

    # 2ページ目に遷移する。
    def test_project_page2(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

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

    # プロジェクトを検索する。
    def test_search_project(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        query_string = urlencode({
            'project_name': 'test',
            'estimation_no': 'M17-17001',
            'status': '99',
            'end_user_company_id': '1',
            'client_company_id': '1',
            'recorded_department_id': '1',
            'start_date': '2016/1/1',
            'end_date': '2017/1/1'
        })
        result = self.app.get('/project/?' + query_string)

        self.assertEqual(result.status_code, 200)

    # プロジェクト登録画面に遷移する。
    def test_get_project_create(self):
        # ログインする
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.get('/project/create')
        self.assertEqual(result.status_code, 200)

    # プロジェクトをコピーできる
    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_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 test_delete_project_fail(self):
        before = len(self.project_repository.find_all())
        # ログイン
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.get('/project/delete/0')
        # 削除できることを確認
        self.assertEqual(result.status_code, 302)
        ok_('/project' in result.headers['Location'])

        after = len(self.project_repository.find_all())
        # 前後で件数が変わっていないことを確認
        self.assertEqual(before, after)

    # コピー時に見積番号が重複しない
    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 test_start_date_less_than_end_date(self):
        before = len(self.project_repository.find_all())
        # ログイン
        self.app.post('/login',
                      data={
                          'shain_number': 'test1',
                          'password': '******'
                      })

        result = self.app.post('/project/create',
                               data={
                                   'project_name':
                                   'テスト',
                                   'start_date':
                                   date(2017, 4, 1).strftime('%Y/%m/%d'),
                                   'end_date':
                                   date(2017, 3, 31).strftime('%Y/%m/%d'),
                               })
        self.assertEqual(result.status_code, 200)

        # 件数が変わっていないことを確認。
        after = len(self.project_repository.find_all())
        self.assertEqual(before, after)

    # プロジェクトをコピー時に開始日、終了日がプロジェクト明細にもコピーされる
    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)
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)
from flask_wtf import FlaskForm
from wtforms import ValidationError, DateTimeField
from wtforms import validators, StringField, SelectField, TextAreaField

from application.controllers.form.fields import IntegerField, DateField, SelectFieldWithSubtext
from application.controllers.form.validators import Length, DataRequired, LessThan
from application.domain.model.immutables.billing_timing import BillingTiming
from application.domain.model.immutables.contract import Contract
from application.domain.model.immutables.status import Status
from application.domain.model.immutables.tax import Tax
from application.domain.repository.project_repository import ProjectRepository

repository = ProjectRepository()


class ProjectContractForm(FlaskForm):
    id = IntegerField('プロジェクトコード')
    project_name = StringField(
        'プロジェクト名称(必須)', [DataRequired(), Length(max=128)])
    project_name_for_bp = StringField('BP向けプロジェクト名称', [Length(max=128)],
                                      filters=[lambda x: x or None])
    status = SelectField('契約ステータス(必須)', [DataRequired()],
                         choices=Status.get_status_for_select(),
                         render_kw={"title": "契約ステータス(必須)"})
    recorded_department_id = SelectField('計上部署(必須)', [DataRequired()],
                                         render_kw={"title": "計上部署(必須)"})
    sales_person = StringField('営業担当者名称', [Length(max=128)],
                               filters=[lambda x: x or None])
    estimation_no = StringField('見積No(必須)', [DataRequired(), Length(max=64)])
    end_user_company_id = SelectFieldWithSubtext('エンドユーザー(必須)',
                                                 [DataRequired()],
Exemplo n.º 15
0
class EstimatedReportTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(EstimatedReportTests, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        super(EstimatedReportTests, cls).tearDownClass()

    def setUp(self):
        super(EstimatedReportTests, self).setUp()
        self.project_repository = ProjectRepository()
        self.user_repository = UserRepository()
        self.project_detail_repository = ProjectDetailRepository()
        self.engineer_repository = EngineerRepository()
        with app.test_request_context():
            project = self.project_repository.find_by_id(1)
            # 明細 = 作業
            project_detail_work = ProjectDetail(
                project_id=project.id,
                detail_type=DetailType.work,
                work_name='project_detail_work',
                billing_money=100000,
                created_at=datetime.today(),
                created_user='******',
                updated_at=datetime.today(),
                updated_user='******')
            project.project_details.append(project_detail_work)
            user = self.user_repository.find_by_id(1)
            session['user'] = user.serialize()
            estimated_report = EstimatedReport(project)
        self.estimated_report = estimated_report

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

    def test_write_estimated_content_rows_if_blanket(self):
        # set_up
        self.estimated_report.project.contract_form = Contract.blanket

        # テスト対象のメソッドを実行
        self.estimated_report.write_estimated_content_rows()

        # 指定のセルに値が入っていることを確認。
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "estimation_no")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.estimation_no)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "printed_date")
        self.assertIsNotNone(
            self.estimated_report.ws[defined_name_range].value)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "client_company_name")
        self.assertEqual(
            self.estimated_report.ws[defined_name_range].value,
            self.estimated_report.project.client_company.company_name)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "project_name")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.project_name)
        start_date = datetime(self.estimated_report.project.start_date.year,
                              self.estimated_report.project.start_date.month,
                              self.estimated_report.project.start_date.day)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "start_date")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         strjpftime(start_date, '  %O%E年%m月%d日'))
        end_date = datetime(self.estimated_report.project.end_date.year,
                            self.estimated_report.project.end_date.month,
                            self.estimated_report.project.end_date.day)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "end_date")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         strjpftime(end_date, '  %O%E年%m月%d日'))
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "billing_timing")
        self.assertEqual(
            self.estimated_report.ws[defined_name_range].value,
            self.estimated_report.project.billing_timing.name_for_report)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "contract_form")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.contract_form.name)

    def test_write_estimated_content_rows_if_not_blanket(self):
        # set_up
        self.estimated_report.project.contract_form = Contract.time_and_material

        # テスト対象のメソッドを実行
        self.estimated_report.write_estimated_content_rows()

        # 指定のセルに値が入っていることを確認。
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "estimation_no")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.estimation_no)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "printed_date")
        self.assertIsNotNone(
            self.estimated_report.ws[defined_name_range].value)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "client_company_name")
        self.assertEqual(
            self.estimated_report.ws[defined_name_range].value,
            self.estimated_report.project.client_company.company_name)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "project_name")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.project_name)
        start_date = datetime(self.estimated_report.project.start_date.year,
                              self.estimated_report.project.start_date.month,
                              self.estimated_report.project.start_date.day)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "start_date")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         strjpftime(start_date, '  %O%E年%m月%d日'))
        end_date = datetime(self.estimated_report.project.end_date.year,
                            self.estimated_report.project.end_date.month,
                            self.estimated_report.project.end_date.day)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "end_date")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         strjpftime(end_date, '  %O%E年%m月%d日'))
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "billing_timing")
        self.assertEqual(
            self.estimated_report.ws[defined_name_range].value,
            self.estimated_report.project.billing_timing.name_for_report)
        defined_name_range = self.estimated_report.excel.get_defined_name_range(
            "contract_form")
        self.assertEqual(self.estimated_report.ws[defined_name_range].value,
                         self.estimated_report.project.contract_form.name)

    def test_create_project_detail_rows_if_project_details_over_3(self):
        # テスト対象のメソッドを実行
        self.estimated_report.create_project_detail_rows()

        # プロジェクト明細が指定のセルに値が入っていることを確認(※1行のみ)。
        self.assertEqual(self.estimated_report.ws['B24'].value, 1)
        self.assertEqual(
            self.estimated_report.ws['C24'].value, self.estimated_report.
            project.project_details[0].engineer.engineer_name)
        self.assertEqual(
            self.estimated_report.ws['G24'].value,
            self.estimated_report.project.project_details[0].billing_money)
        self.assertEqual(
            self.estimated_report.ws['H24'].value,
            self.estimated_report.project.project_details[0].remarks)
        # 消費税が指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['C30'].value, '消費税(なし)')
        self.assertEqual(
            self.estimated_report.ws['G30'].value,
            self.estimated_report.project.tax_of_estimated_total_amount())
        # 合計が指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['C31'].value, '合計')
        self.assertEqual(
            self.estimated_report.ws['G31'].value,
            self.estimated_report.project.estimated_total_amount +
            self.estimated_report.project.tax_of_estimated_total_amount())

    def test_create_project_detail_rows_if_project_details_below_2(self):
        # set_up
        project = self.project_repository.find_by_id(2)
        project_detail = self.project_detail_repository.find_all()[1]
        project.project_details.append(project_detail)
        self.estimated_report.project = project

        # テスト対象のメソッドを実行
        self.estimated_report.create_project_detail_rows()

        # プロジェクト明細が指定のセルに値が入っていることを確認(※1行のみ)。
        self.assertEqual(self.estimated_report.ws['B24'].value, 1)
        self.assertEqual(
            self.estimated_report.ws['C24'].value, self.estimated_report.
            project.project_details[0].engineer.engineer_name)
        self.assertEqual(
            self.estimated_report.ws['G24'].value,
            self.estimated_report.project.project_details[0].billing_money)
        self.assertEqual(
            self.estimated_report.ws['H24'].value,
            self.estimated_report.project.project_details[0].remarks)
        # 消費税が指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['C25'].value, '消費税(なし)')
        self.assertEqual(
            self.estimated_report.ws['G25'].value,
            self.estimated_report.project.tax_of_estimated_total_amount())
        # 合計が指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['C26'].value, '合計')
        self.assertEqual(
            self.estimated_report.ws['G26'].value,
            self.estimated_report.project.estimated_total_amount +
            self.estimated_report.project.tax_of_estimated_total_amount())

    def test_create_contract_content_rows(self):
        # テスト対象のメソッドを実行
        self.estimated_report.current_row = 32
        self.estimated_report.create_contract_content_rows()

        # 指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['B32'].value, '作業内容')
        self.assertEqual(self.estimated_report.ws['E32'].value,
                         self.estimated_report.project.contents)
        self.assertEqual(self.estimated_report.ws['B33'].value, '納品物')
        self.assertEqual(self.estimated_report.ws['E33'].value,
                         self.estimated_report.project.deliverables)
        self.assertEqual(self.estimated_report.ws['B34'].value, '作業場所')
        self.assertEqual(self.estimated_report.ws['E34'].value,
                         self.estimated_report.project.working_place)
        self.assertEqual(self.estimated_report.ws['B35'].value, '検査完了日')
        self.assertEqual(self.estimated_report.ws['E35'].value,
                         self.estimated_report.project.inspection_date)
        self.assertEqual(self.estimated_report.ws['B36'].value, '作業責任者')
        self.assertEqual(self.estimated_report.ws['E36'].value,
                         self.estimated_report.project.responsible_person)
        self.assertEqual(self.estimated_report.ws['B37'].value, '品質管理担当者')
        self.assertEqual(self.estimated_report.ws['E37'].value,
                         self.estimated_report.project.quality_control)
        self.assertEqual(self.estimated_report.ws['B38'].value, '再委託先')
        self.assertEqual(self.estimated_report.ws['E38'].value,
                         self.estimated_report.project.subcontractor)
        self.assertEqual(self.estimated_report.ws['B39'].value, '備考')
        self.assertEqual(self.estimated_report.ws['E39'].value,
                         self.estimated_report.project.remarks)

    def test_create_contract_content_rows_if_billing_by_month(self):
        # set_up
        project = self.project_repository.find_by_id(2)
        project_detail = self.project_detail_repository.find_all()[1]
        project.project_details.append(project_detail)
        self.estimated_report.project = project

        # テスト対象のメソッドを実行
        self.estimated_report.current_row = 32
        self.estimated_report.create_contract_content_rows()

        # 指定のセルに値が入っていることを確認。
        self.assertEqual(self.estimated_report.ws['B32'].value, '作業内容')
        self.assertEqual(self.estimated_report.ws['E32'].value,
                         self.estimated_report.project.contents)
        self.assertEqual(self.estimated_report.ws['B33'].value, '納品物')
        self.assertEqual(self.estimated_report.ws['E33'].value,
                         self.estimated_report.project.deliverables)
        self.assertEqual(self.estimated_report.ws['B34'].value, '作業場所')
        self.assertEqual(self.estimated_report.ws['E34'].value,
                         self.estimated_report.project.working_place)
        self.assertEqual(self.estimated_report.ws['B35'].value, '検査完了日')
        self.assertEqual(self.estimated_report.ws['E35'].value, '毎月月末')
        self.assertEqual(self.estimated_report.ws['B36'].value, '作業責任者')
        self.assertEqual(self.estimated_report.ws['E36'].value,
                         self.estimated_report.project.responsible_person)
        self.assertEqual(self.estimated_report.ws['B37'].value, '品質管理担当者')
        self.assertEqual(self.estimated_report.ws['E37'].value,
                         self.estimated_report.project.quality_control)
        self.assertEqual(self.estimated_report.ws['B38'].value, '再委託先')
        self.assertEqual(self.estimated_report.ws['E38'].value,
                         self.estimated_report.project.subcontractor)
        self.assertEqual(self.estimated_report.ws['B39'].value, '備考')
        self.assertEqual(self.estimated_report.ws['E39'].value,
                         self.estimated_report.project.remarks)