Exemplo n.º 1
0
 def setUp(self):
     super(BillingBaseReportTests, self).setUp()
     self.project_month_repository = ProjectMonthRepository()
     self.user_repository = UserRepository()
     with app.test_request_context():
         project_month = self.project_month_repository.find_by_id(1)
         project_month.remarks = 'test'
         user = self.user_repository.find_by_id(1)
         session['user'] = user.serialize()
         billing_base_report = BillingBaseReport(project_month)
     self.billing_base_report = billing_base_report
 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)
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.º 6
0
class BillingBaseReportTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(BillingBaseReportTests, cls).setUpClass()

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

    def setUp(self):
        super(BillingBaseReportTests, self).setUp()
        self.project_month_repository = ProjectMonthRepository()
        self.user_repository = UserRepository()
        with app.test_request_context():
            project_month = self.project_month_repository.find_by_id(1)
            project_month.remarks = 'test'
            user = self.user_repository.find_by_id(1)
            session['user'] = user.serialize()
            billing_base_report = BillingBaseReport(project_month)
        self.billing_base_report = billing_base_report

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

    def test_write_estimated_content_rows_if_blanket(self):
        # テスト対象のメソッドを実行
        self.billing_base_report.create_billing_details()

    def test_remark(self):
        locale.setlocale(locale.LC_ALL, '')
        deposit_date = self.billing_base_report.project_month.deposit_date.strftime(
            '%Y年%m月%d日')

        expected = "お支払いは下記口座に{}までにお支払い願います。\n\n".format(deposit_date)
        if self.billing_base_report.project_month.remarks:
            expected += self.billing_base_report.project_month.remarks + '\n'
        if self.billing_base_report.project_month.project.client_order_no:
            expected += "※作業内容及び納品物等の詳細はご注文書(No.{})の通り"\
                 .format(self.billing_base_report.project_month.project.client_order_no)

        # テスト対象のメソッドを実行
        actual = self.billing_base_report.remark()
        self.assertEqual(expected, actual)
Exemplo n.º 7
0
 def setUp(self):
     super(ProjectBillingTests, self).setUp()
     self.project_billing_repository = ProjectBillingRepository()
     self.project_month_repository = ProjectMonthRepository()
     self.billing_sequence_repository = BillingSequenceRepository()
     self.project_detail_repository = ProjectDetailRepository()
Exemplo n.º 8
0
class ProjectBillingTests(BaseTestCase):

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

    def setUp(self):
        super(ProjectBillingTests, self).setUp()
        self.project_billing_repository = ProjectBillingRepository()
        self.project_month_repository = ProjectMonthRepository()
        self.billing_sequence_repository = BillingSequenceRepository()
        self.project_detail_repository = ProjectDetailRepository()

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

    # 請求タブに遷移する。
    def test_get_project_billing(self):
        # ログインする
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        project_billing = self.project_month_repository.find_all()[0]

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

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

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

    # 請求詳細画面に遷移する。
    def test_get_project_billing_month(self):
        # ログインする
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        project_billing = self.project_month_repository.find_all()[0]

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

    # 存在しないプロジェクト年月の場合はnot_found
    def test_get_project_billing_month_fail(self):
        # ログインする
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

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

    # 請求詳細画面を保存できる
    def test_save_project_billing_month(self):
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        project_month = self.project_month_repository.find_all()[0]

        expected = '単体テスト_変更'
        project_billing_id = project_month.id

        result = self.app.post('/project/billing/month/' + str(project_billing_id), data={
            'client_billing_no': expected,
            'billing_confirmation_money': project_month.billing_confirmation_money,
            'billing_tax': project_month.billing_tax.value,
            'billing_transportation': project_month.billing_transportation,
            'deposit_date': project_month.deposit_date.strftime('%Y/%m/%d'),
            'remarks': project_month.remarks
        })
        # 保存できることを確認
        self.assertEqual(result.status_code, 302)
        ok_('/project/billing/month/' + str(project_month.id) in result.headers['Location'])

        project_month = self.project_month_repository.find_by_id(project_billing_id)
        actual = project_month.client_billing_no
        self.assertEqual(actual, expected)

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

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

    # 請求情報を保存できる
    def test_save_project_billing_detail(self):
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        billing = self.project_billing_repository.find_all()[0]

        expected = '単体テスト_変更'
        billing_id = billing.id

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

        billing = self.project_billing_repository.find_by_id(billing_id)
        actual = billing.billing_content
        self.assertEqual(actual, expected)

    # 請求情報を削除できる
    def test_delete_billing(self):
        # 削除用の請求情報を登録
        billing = ProjectBilling(
            project_detail_id=1,
            billing_month=date(2017, 1, 1).strftime('%Y/%m/%d'),
            billing_amount='1人月',
            billing_content='削除用請求',
            billing_confirmation_money=1000,
            billing_transportation=100,
            remarks='テスト',
            created_at=datetime.today(),
            created_user='******',
            updated_at=datetime.today(),
            updated_user='******')
        db.session.add(billing)
        db.session.commit()

        delete_billing_id = billing.id

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

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

        # 削除した請求が存在しないことを確認
        billing = self.project_billing_repository.find_by_id(delete_billing_id)
        self.assertIsNone(billing.id)

    # 存在しない会社は削除できない
    def test_delete_billing_fail(self):
        before = len(self.project_billing_repository.find_all())
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

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

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

    # 請求詳細画面に遷移する。
    def test_get_detail_billing(self):
        # ログインする
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        billing = self.project_billing_repository.find_all()[0]

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

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

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

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

        project_month_id = 5
        project_month = self.project_month_repository.find_by_id(project_month_id)

        # 請求入力済みフラグをチェック有りで更新する。
        excepted = InputFlag.done.value

        headers = [('X-Requested-With', 'XMLHttpRequest')]
        result = self.app.post('/project/billing/save_flag',
                               headers=headers,
                               data={
                                    'month_id': project_month.id,
                                    'input_flag': excepted
                               })
        self.assertEqual(result.status_code, 200)

        # DBのbilling_input_flag値が1になっていることを確認。
        project_month = self.project_month_repository.find_by_id(5)
        actual_input_flag = project_month.billing_input_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('/project/billing/save_flag', data={
                                    'month_id': '2',
                                    'input_flag': InputFlag.done.value
                               })
        self.assertEqual(result.status_code, 404)

    # client_billing_noが発番されることを確認。
    def test_create_client_billing_no(self):
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        project_month = self.project_month_repository.find_all()[0]
        project_billing_id = project_month.id

        result = self.app.post('/project/billing/month/' + str(project_billing_id), data={
            'client_billing_no': '',
            'billing_confirmation_money': project_month.billing_confirmation_money,
            'billing_tax': Tax.eight.value,
            'billing_transportation': project_month.billing_transportation,
            'deposit_date': project_month.deposit_date.strftime('%Y/%m/%d'),
            'remarks': project_month.remarks
        })
        # 保存できることを確認
        self.assertEqual(result.status_code, 302)
        ok_('/project/billing/month/' + str(project_month.id) in result.headers['Location'])

        project_month = self.project_month_repository.find_by_id(project_billing_id)
        actual = project_month.client_billing_no
        self.assertIsNotNone(actual)

    # 請求番号が重複しない
    def test_duplicate_client_billing_no(self):
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        # 2017年度のシーケンスを取得
        billing_sequence = self.billing_sequence_repository.find_by_fiscal_year(17)

        # 連番が一つ先の注文書番号を登録しておく。
        client_billing_no = 'B' + str(billing_sequence.fiscal_year)\
                            + '-'\
                            + '{0:03d}'.format(billing_sequence.sequence + 1)

        project_month = ProjectMonth(
                            project_id=1,
                            project_month='2016/10/1',
                            billing_input_flag=InputFlag.yet,
                            deposit_input_flag=InputFlag.yet,
                            deposit_date='2016/10/1',
                            billing_estimated_money=10000,
                            billing_confirmation_money=10000,
                            billing_transportation=100,
                            remarks='remarks',
                            client_billing_no=client_billing_no,
                            created_at=datetime.today(),
                            created_user='******',
                            updated_at=datetime.today(),
                            updated_user='******')
        db.session.add(project_month)
        db.session.commit()

        # 新規作成時に発番が期待される注文書番号
        expected = 'B' + str(billing_sequence.fiscal_year)\
                   + '-'\
                   + '{0:03d}'.format(billing_sequence.sequence + 2)

        project_month = self.project_month_repository.find_all()[4]
        project_month.project_month = date(2016, 10, 1)
        db.session.add(project_month)
        db.session.commit()

        result = self.app.post('/project/billing/month/' + str(project_month.id), data={
            'client_billing_no': '',
            'billing_confirmation_money': project_month.billing_confirmation_money,
            'billing_tax': project_month.billing_tax.value,
            'billing_transportation': project_month.billing_transportation,
            'deposit_date': project_month.deposit_date.strftime('%Y/%m/%d'),
            'remarks': project_month.remarks
        })
        # 保存できることを確認
        self.assertEqual(result.status_code, 302)
        ok_('/project/billing/month/' + str(project_month.id) in result.headers['Location'])

        # 更新後のデータを確認する。
        actual = project_month.client_billing_no

        self.assertEqual(actual, expected)

    # 同じ顧客請求Noは登録できない
    def test_not_register_duplicate_client_billing_no(self):
        duplicate_client_billing_no = 'duplicate_client_billing_no'
        project_month = ProjectMonth(
                            project_id=1,
                            project_month='2016/10/1',
                            billing_input_flag=InputFlag.yet,
                            deposit_input_flag=InputFlag.yet,
                            deposit_date='2016/10/1',
                            billing_estimated_money=10000,
                            billing_confirmation_money=10000,
                            billing_transportation=100,
                            remarks='remarks',
                            client_billing_no=duplicate_client_billing_no,
                            created_at=datetime.today(),
                            created_user='******',
                            updated_at=datetime.today(),
                            updated_user='******')
        db.session.add(project_month)
        db.session.commit()

        project_month = self.project_month_repository.find_all()[4]
        project_month.project_month = date(2016, 10, 1)
        db.session.add(project_month)
        db.session.commit()

        result = self.app.post('/project/billing/month/' + str(project_month.id), data={
            'client_billing_no': duplicate_client_billing_no,
            'billing_confirmation_money': project_month.billing_confirmation_money,
            'billing_transportation': project_month.billing_transportation,
            'deposit_date': project_month.deposit_date.strftime('%Y/%m/%d'),
            'remarks': project_month.remarks
        })
        # 保存できない事を確認
        self.assertEqual(result.status_code, 200)

    # 請求明細登録画面に遷移する。
    def test_get_billing_create(self):
        # ログインする
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        project_month = self.project_month_repository.find_all()[0]

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

    # 存在しないプロジェクト年月の場合はnot_found
    def test_create_billing_fail(self):
        # ログインする
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

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

    # 請求明細を新規登録できる
    def test_create_billing(self):
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        billing = self.project_billing_repository.find_all()[0]
        project_month = self.project_month_repository.find_project_month_at_a_month(billing.project_detail.project.id,
                                                                                    billing.billing_month)

        expected = '単体テスト_登録'
        result = self.app.post('/project/billing/create/' + str(project_month.id), data={
            'billing_content': expected,
            'billing_amount': billing.billing_amount,
            'billing_confirmation_money': billing.billing_confirmation_money,
            'billing_transportation': billing.billing_transportation
        })
        # 保存できることを確認
        self.assertEqual(result.status_code, 302)
        billing_id = result.headers['Location'].split('/')[-1]
        ok_('/project/billing/detail/' + str(billing_id) in result.headers['Location'])

        billing = self.project_billing_repository.find_by_id(billing_id)
        actual = billing.billing_content
        self.assertEqual(actual, expected)

    # validationチェックに引っかかって請求明細を保存できない。
    def test_create_billing_validation_error(self):
        shain_number = 'test1'
        self.app.post('/login', data={
            'shain_number': shain_number,
            'password': '******'
        })
        billing = self.project_billing_repository.find_all()[0]
        project_month = self.project_month_repository.find_project_month_at_a_month(billing.project_detail.project.id,
                                                                                    billing.billing_month)

        result = self.app.post('/project/billing/create/' + str(project_month.id), data={
            'billing_content': '',
            'billing_amount': '',
            'billing_confirmation_money': '',
            'billing_transportation': ''
        })
        # 保存できないことを確認
        self.assertEqual(result.status_code, 200)

    # 請求書をダウンロード
    def test_billing_report_download(self):
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        project_month = self.project_month_repository.find_all()[0]
        project_month.billing_printed_date = None

        # 帳票作成実行
        result = self.app.get('/project/billing/billing_report_download/' + str(project_month.id))
        self.assertEqual(result.status_code, 200)

    # 請求明細が大量に存在する請求書をダウンロード
    def test_billing_report_download_when_project_detail_over_15(self):
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        # set_up
        project_month = self.project_month_repository.find_by_id(4)
        project_month.deposit_date = None
        project_month.project.client_order_no = '11111-0170'
        project_month.project.client_company.billing_tax = Tax.eight
        project_detail = self.project_detail_repository.find_by_id(1)
        project_month.billing_printed_date = date(2017, 1, 1)

        for i in range(20):
            project_billing = ProjectBilling(
                project_detail_id=project_detail.id,
                billing_month=date(2017, 4, 1).strftime('%Y/%m/%d'),
                billing_amount='1人月',
                billing_content='削除用請求',
                billing_confirmation_money=1000,
                billing_transportation=100,
                remarks='テスト',
                created_at=datetime.today(),
                created_user='******',
                updated_at=datetime.today(),
                updated_user='******')
            project_detail.project_billings.append(project_billing)

        # 帳票作成実行
        result = self.app.get('/project/billing/billing_report_download/' + str(project_month.id))
        self.assertEqual(result.status_code, 200)

    # 納品書をダウンロードする
    def test_delivery_report_download(self):
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        project_month = self.project_month_repository.find_all()[0]
        project_month.billing_printed_date = None

        # 帳票作成実行
        result = self.app.get('/project/billing/delivery_report_download/' + str(project_month.id))
        self.assertEqual(result.status_code, 200)

    # 請求明細が大量に存在する納品書をダウンロード
    def test_delivery_report_download_when_project_detail_over_15(self):
        # ログイン
        self.app.post('/login', data={
            'shain_number': 'test1',
            'password': '******'
        })

        # set_up
        project_month = self.project_month_repository.find_by_id(4)
        project_month.deposit_date = None
        project_month.project.client_order_no = '11111-0170'
        project_month.project.client_company.billing_tax = Tax.eight
        project_detail = self.project_detail_repository.find_by_id(1)
        project_month.billing_printed_date = date(2017, 1, 1)

        for i in range(20):
            project_billing = ProjectBilling(
                project_detail_id=project_detail.id,
                billing_month=date(2017, 4, 1).strftime('%Y/%m/%d'),
                billing_amount='1人月',
                billing_content='削除用請求',
                billing_confirmation_money=1000,
                billing_transportation=100,
                remarks='テスト',
                created_at=datetime.today(),
                created_user='******',
                updated_at=datetime.today(),
                updated_user='******')
            project_detail.project_billings.append(project_billing)

        # 帳票作成実行
        result = self.app.get('/project/billing/delivery_report_download/' + str(project_month.id))
        self.assertEqual(result.status_code, 200)
Exemplo n.º 9
0
 def setUp(self):
     super(SearchResultTests, self).setUp()
     self.project_month_repository = ProjectMonthRepository()
Exemplo n.º 10
0
class SearchBillingTests(BaseTestCase):
    @classmethod
    def setUpClass(cls):
        super(SearchBillingTests, cls).setUpClass()

    def setUp(self):
        super(SearchBillingTests, self).setUp()
        self.project_month_repository = ProjectMonthRepository()

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

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

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

    # 2ページ目に遷移する。
    def test_billing_search_page2(self):
        # データセットアップ
        for num in range(12):
            project_month = ProjectMonth(
                project_id=1,
                project_month=date(2017, num + 1, 1),
                deposit_date=datetime.today().date(),
                billing_estimated_money=100000,
                billing_confirmation_money=100100,
                billing_transportation=100,
                remarks=None,
                client_billing_no='test_billing_search_page2' + str(num + 1),
                created_at=datetime.today(),
                created_user='******',
                updated_at=datetime.today(),
                updated_user='******')
            db.session.add(project_month)
        db.session.commit()

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

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

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

        query_string = urlencode({
            'project_name': 'test',
            'estimation_no': 'test',
            'billing_input_flag': '1',
            'deposit_input_flag': '1',
            'end_user_company_id': '1',
            'client_company_id': '1',
            'recorded_department_id': '1',
            'deposit_date_from': '2016/1/1',
            'deposit_date_to': '2017/1/1'
        })
        result = self.app.get('/search/billing/?' + query_string)

        self.assertEqual(result.status_code, 200)

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

        query_string = urlencode({
            'project_name': 'test',
            'estimation_no': 'test',
            'billing_input_flag': '1',
            'deposit_input_flag': '1',
            'end_user_company_id': '1',
            'client_company_id': '1',
            'recorded_department_id': '1',
            'deposit_date_from': '',
            'deposit_date_to': ''
        })
        result = self.app.get('/search/billing/?' + 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',
            'deposit_date_from': '',
            'deposit_date_to': ''
        })
        result = self.app.get('/search/billing/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',
            'deposit_date_from': '',
            'deposit_date_to': ''
        })
        result = self.app.get('/search/billing/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',
            'deposit_date_from': '',
            'deposit_date_to': ''
        })
        result = self.app.get('/search/billing/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_month = self.project_month_repository.find_by_id(3)
        self.assertEqual(project_month.deposit_input_flag, InputFlag.yet)

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

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

        # DBのdeposit_input_flag値が1になっていることを確認。
        project_result = self.project_month_repository.find_by_id(3)
        actual_input_flag = project_result.deposit_input_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/billing/save_flag',
                               data={
                                   'month_id': '2',
                                   'input_flag': InputFlag.done.value
                               })
        self.assertEqual(result.status_code, 404)
class ProjectMonthRepositoryTests(BaseTestCase):
    def setUp(self):
        super(ProjectMonthRepositoryTests, self).setUp()
        self.project_month_repository = ProjectMonthRepository()

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

    def test_find_by_estimation_no_including_comma_in_billing_search(self):
        # 'M11-0001,M12-0001'で検索するとM11-0001とM12-0001の計2件がヒットする
        expect = 2
        pagination = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11-0001,M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result = len([project_month for project_month in pagination.items])
        self.assertEquals(expect, result)

    def test_find_over_ten_by_estimation_no_including_comma_in_billing_search(
            self):
        # 'M11,M12-0001'で検索するとM11-0000〜M11-0009、M12-0001の計11件がヒットする
        expect = 11
        pagination_1 = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11,M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_1 = len([project_month for project_month in pagination_1.items])
        pagination_2 = self.project_month_repository.find_by_billing(
            page=2,
            project_name='',
            estimation_no='M11,M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_2 = len([project_month for project_month in pagination_2.items])
        self.assertEquals(expect, result_1 + result_2)

    def test_find_by_estimation_no_including_space_in_billing_search(self):
        # 'M11-0001 M12-0001'で検索するとM11-0001とM12-0001の計2件がヒットする
        expect = 2
        pagination = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11-0001 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result = len([project_month for project_month in pagination.items])
        self.assertEquals(expect, result)

    def test_find_over_ten_by_estimation_no_including_space_in_billing_search(
            self):
        # 'M11 M12-0001'で検索するとM11-0000〜M11-0009、M11-0001の計11件がヒットする
        expect = 11
        pagination_1 = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_1 = len([project_month for project_month in pagination_1.items])
        pagination_2 = self.project_month_repository.find_by_billing(
            page=2,
            project_name='',
            estimation_no='M11 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_2 = len([project_month for project_month in pagination_2.items])
        self.assertEquals(expect, result_1 + result_2)

    def test_find_by_estimation_no_including_half_space_in_billing_search(
            self):
        # 'M11-0001 M12-0001'で検索するとM11-0001とM12-0001の計2件がヒットする
        expect = 2
        pagination = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11-0001 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result = len([project_month for project_month in pagination.items])
        self.assertEquals(expect, result)

    def test_find_over_ten_by_estimation_no_including_half_space_in_billing_search(
            self):
        # 'M11 M12-0001'で検索するとM11-0000〜M11-0009、M11-0001の計11件がヒットする
        expect = 11
        pagination_1 = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='M11 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_1 = len([project_month for project_month in pagination_1.items])
        pagination_2 = self.project_month_repository.find_by_billing(
            page=2,
            project_name='',
            estimation_no='M11 M12-0001',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result_2 = len([project_month for project_month in pagination_2.items])
        self.assertEquals(expect, result_1 + result_2)

    def test_find_by_estimation_no_including_comma_or_space_in_front_and_behind_in_billing_search(
            self):
        # '  ,M11-0001,M12-0001 , '(前後にスペースや,あり)で検索してもM11-0001とM12-0001の計2件がヒットする
        expect = 2
        pagination = self.project_month_repository.find_by_billing(
            page=1,
            project_name='',
            estimation_no='  ,M11-0001,M12-0001 , ',
            billing_input_flag='',
            deposit_input_flag='',
            end_user_company_id='',
            client_company_id='',
            recorded_department_id='',
            deposit_date_from='',
            deposit_date_to='')
        result = len([project_month for project_month in pagination.items])
        self.assertEquals(expect, result)

    def test_create(self):
        project_result = self.project_month_repository.create()
        self.assertIsNone(project_result.id)
from flask_wtf import FlaskForm
from wtforms import TextAreaField, StringField, ValidationError, DateTimeField, SelectField

from application.controllers.form.fields import IntegerField, DateField
from application.controllers.form.validators import Length, DataRequired, NumberRange
from application.domain.model.immutables.tax import Tax
from application.domain.repository.project_month_repository import ProjectMonthRepository

project_month_repository = ProjectMonthRepository()


class ProjectMonthForm(FlaskForm):
    id = IntegerField('プロジェクト年月ID')
    project_id = IntegerField('プロジェクトID')
    client_billing_no = StringField('顧客請求書No', [Length(max=64)],
                                    filters=[lambda x: x or None])
    billing_confirmation_money = IntegerField(
        '請求確定金額(請求明細金額の合計)', [NumberRange(min=-1000000000, max=1000000000)],
        render_kw={"readonly": "readonly"})
    billing_tax = SelectField('消費税', [DataRequired()],
                              choices=Tax.get_type_for_select(),
                              render_kw={"title": "消費税"})
    billing_transportation = IntegerField(
        '請求交通費等(請求明細交通費等の合計)', [NumberRange(min=-1000000000, max=1000000000)],
        render_kw={"readonly": "readonly"})
    billing_printed_date = DateField('請求書発行日',
                                     format='%Y/%m/%d',
                                     render_kw={"autocomplete": "off"})
    deposit_date = DateField('入金予定日',
                             format='%Y/%m/%d',
                             render_kw={"autocomplete": "off"})