Example #1
0
 def test_saleable_qty(self):
     from psi.app.services.purchase_order import PurchaseOrderService
     with self.test_client:
         from tests.fixture import login_as_admin
         login_as_admin(self.test_client)
         from psi.app.models import EnumValues
         db = Info.get_db()
         po = of.purchase_order(number_of_line=1,
                                type=EnumValues.get(
                                    const.DIRECT_PO_TYPE_KEY))
         recv = PurchaseOrderService.create_receiving_if_not_exist(po)
         from psi.app.utils import db_util
         db_util.save_objects_commit(po, recv)
         recv.status = EnumValues.get(const.RECEIVING_COMPLETE_STATUS_KEY)
         inv_trans = recv.operate_inv_trans_by_recv_status()
         new_po = recv.update_purchase_order_status()
         db_util.save_objects_commit(new_po, inv_trans)
         self.assertEquals(inv_trans.lines[0].quantity,
                           po.lines[0].quantity)
         self.assertEquals(inv_trans.lines[0].saleable_quantity,
                           po.lines[0].quantity)
         self.assertEquals(inv_trans.lines[0].in_transit_quantity, 0)
         self.assertEqual(inv_trans.date, recv.date)
         self.assertEqual(inv_trans.lines[0].product, po.lines[0].product)
         self.assertEquals(inv_trans.lines[0].quantity,
                           recv.lines[0].quantity)
         self.assertEquals(inv_trans.lines[0].saleable_quantity,
                           recv.lines[0].quantity)
         self.assertEquals(inv_trans.lines[0].in_transit_quantity, 0)
         self.assertEqual(inv_trans.date, recv.date)
         self.assertEqual(inv_trans.lines[0].product, recv.lines[0].product)
Example #2
0
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create',
         'franchise_sales_order_view',
         'franchise_sales_order_edit',
         'product_view'
     ])
     franchise_so_type = EnumValues.get(FRANCHISE_SO_TYPE_KEY)
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1,
                                            type=franchise_so_type)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     shipped_status = EnumValues.get(SO_SHIPPED_STATUS_KEY)
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=shipped_status.id))
     self.assertIn(b'message', rv.data)
     self.assertIn(b'Status update successfully', rv.data)
     self.assertEqual(rv.status_code, 200)
     so_from_db = Info.get_db().session.query(SalesOrder).get(so_id)
     self.assertIsNotNone(so_from_db)
     self.assertEquals(SO_SHIPPED_STATUS_KEY, so_from_db.status.code)
Example #3
0
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create',
         'franchise_sales_order_view',
         'franchise_sales_order_edit',
         'product_view'
     ])
     franchise_so_type = EnumValues.get(FRANCHISE_SO_TYPE_KEY)
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1,
                                            type=franchise_so_type)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     shipped_status = EnumValues.get(SO_SHIPPED_STATUS_KEY)
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=shipped_status.id))
     self.assertIn('message', rv.data)
     self.assertIn('Status update successfully', rv.data)
     self.assertEqual(rv.status_code, 200)
     so_from_db = Info.get_db().session.query(SalesOrder).get(so_id)
     self.assertIsNotNone(so_from_db)
     self.assertEquals(SO_SHIPPED_STATUS_KEY, so_from_db.status.code)
Example #4
0
 def test_view(self):
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         self.assertPageRendered(
             endpoint=url_for('organization.index_view'),
             method=self.test_client.get,
             expect_contents=['betterlife', '1', u'直营店'])
Example #5
0
    def test_create(self):
        from psi.app.models import EnumValues
        type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id

        with self.test_client:
            fixture.login_as_admin(self.test_client)
            org_name = object_faker.faker.name()
            org_desc = object_faker.faker.text(max_nb_chars=20)
            create_url = self.create_endpoint(view='organization')
            self.assertPageRendered(endpoint=create_url,
                                    method=self.test_client.get,
                                    expect_contents=['betterlife', '直营店'])
            self.assertPageRendered(endpoint=create_url,
                                    method=self.test_client.post,
                                    expect_contents=[org_name, org_desc],
                                    data={"type": type_id, "name": org_name, "description": org_desc, "parent": 1})
            self.assertDeleteSuccessful(endpoint=url_for('organization.delete_view', id=2, url=url_for('organization.index_view')),
                                        deleted_data=[org_name, org_desc])

            from psi.app.models import Organization
            user, pwd = object_faker.user(role_names=['organization_create', 'organization_view',
                                                      'organization_delete', 'organization_edit'],
                                          organization=Organization.query.get(1))
            db_util.save_objects_commit(user)
            fixture.login_user(self.test_client, user.email, pwd)
            from psi.app.models import EnumValues
            org_type = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY)
            self.assertCreateFail(endpoint=create_url,
                                  create_data=[org_name, org_desc],
                                  data={"type": org_type.id, "name": org_name,
                                        "description": org_desc, "parent": 1})
Example #6
0
    def test_delete_root_not_allowed(self):
        from psi.app.models import EnumValues
        type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id

        with self.test_client:
            fixture.login_as_admin(self.test_client)
            name = object_faker.faker.name()
            desc = object_faker.faker.text(max_nb_chars=20)
            self.assertPageRendered(endpoint=url_for(
                'organization.edit_view',
                id=1,
                url=url_for('organization.index_view')),
                                    method=self.test_client.post,
                                    expect_contents=[name, desc],
                                    data={
                                        "type": type_id,
                                        "name": name,
                                        "description": desc,
                                        "parent": u'__None'
                                    })
            self.assertPageRendered(endpoint=url_for(
                'organization.delete_view',
                url=url_for('organization.index_view'),
                id=1),
                                    method=self.test_client.post,
                                    expect_contents=[name, desc, "1"],
                                    data={
                                        "type": type_id,
                                        "name": name,
                                        "description": desc,
                                        "parent": u'__None'
                                    })
Example #7
0
 def test_view(self):
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         self.assertPageRendered(
             endpoint=url_for('organization.index_view'),
             method=self.test_client.get,
             expect_contents=['betterlife', '1', u'直营店'])
    def test_delete_root_not_allowed(self):
        from psi.app.models import EnumValues
        type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id

        with self.test_client:
            fixture.login_as_admin(self.test_client)
            name = object_faker.faker.name()
            desc = object_faker.faker.text(max_nb_chars=20)
            self.assertPageRendered(
                endpoint=url_for(
                    'organization.edit_view',
                    id=1,
                    url=url_for('organization.index_view')),
                method=self.test_client.post,
                expect_contents=[name, desc],
                data={
                    "type": type_id,
                    "name": name,
                    "description": desc,
                    "parent": u'__None'
                })
            self.assertPageRendered(
                endpoint=url_for(
                    'organization.delete_view',
                    url=url_for('organization.index_view'),
                    id=1),
                method=self.test_client.post,
                expect_contents=[name, desc, "1"],
                data={
                    "type": type_id,
                    "name": name,
                    "description": desc,
                    "parent": u'__None'
                })
Example #9
0
 def test_not_allowed_if_not_franchise_organization(self):
     from psi.app.models import EnumValues, Organization, PurchaseOrder
     with self.test_client:
         login_as_admin(self.test_client)
         org_type = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY)
         organization = object_faker.organization(
             parent=Organization.query.get(1), type=org_type)
         user, pwd = object_faker.user(role_names=[
             'franchise_purchase_order_create',
             'franchise_purchase_order_edit',
             'franchise_purchase_order_delete',
             'franchise_purchase_order_view'
         ],
                                       organization=organization)
         db_util.save_objects_commit(user, organization)
         login_user(self.test_client, user.email, pwd)
         draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
         order_date = object_faker.faker.date_time_this_year()
         logistic_amount = random.randint(0, 100)
         remark = object_faker.faker.text(max_nb_chars=50)
         rv = self.test_client.post(url_for('fpo.create_view',
                                            url=url_for('fpo.index_view')),
                                    data=dict(
                                        status=draft_status.id,
                                        order_date=order_date,
                                        logistic_amount=logistic_amount,
                                        remark=remark),
                                    follow_redirects=True)
         self.assertEqual(200, rv.status_code)
         self.assertIn(
             'Your organization is not a franchise store and is not allowed to '
             'create franchise purchase order', rv.data)
         po = PurchaseOrder.query.all()
         self.assertEqual(0, len(po))
Example #10
0
 def test_get_next_id_with_existing_one(self):
     from psi.app.utils import db_util
     from psi.app.models import ProductCategory
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         object_faker.category()
         next_id = db_util.get_next_id(ProductCategory)
         self.assertEquals(3, next_id)
Example #11
0
 def test_delete_normal_allowed(self):
     from psi.app.models import EnumValues
     type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         name, desc = self.create_organization(type_id=type_id, parent_id=1)
         self.assertDeleteSuccessful(endpoint=url_for('organization.delete_view', id=2, url=url_for('organization.index_view')),
                                     deleted_data=[name, desc])
Example #12
0
 def test_get_next_id_with_existing_one(self):
     from psi.app.utils import db_util
     from psi.app.models import ProductCategory
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         object_faker.category()
         next_id = db_util.get_next_id(ProductCategory)
         self.assertEquals(3, next_id)
Example #13
0
 def test_delete_with_child_not_allowed(self):
     from psi.app.models import EnumValues, Organization
     type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         name1, desc1 = self.create_organization(type_id=type_id, parent_id=1)
         self.create_organization(type_id=type_id, parent_id=2)
         self.assertDeleteFail(endpoint=url_for('organization.delete_view', id=2, url=url_for('organization.index_view')),
                               deleted_data=[name1, desc1])
         org = Organization.query.get(2)
         self.assertIsNotNone(org)
Example #14
0
 def setUp(self):
     super(TestInventoryAdvice, self).setUp()
     from psi.app.utils import get_next_code
     fixture.login_as_admin(self.test_client)
     from psi.app.models import Product, User, ProductInventory
     self.product = ProductInventory()
     self.product.organization_id = 1
     self.user = User()
     self.user.organization_id = 1
     self.product.code = get_next_code(Product, user=self.user)
     self.product.id = 1
    def test_create(self):
        from psi.app.models import EnumValues
        type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id

        with self.test_client:
            fixture.login_as_admin(self.test_client)
            org_name = object_faker.faker.name()
            org_desc = object_faker.faker.text(max_nb_chars=20)
            create_url = self.create_endpoint(view='organization')
            self.assertPageRendered(
                endpoint=create_url,
                method=self.test_client.get,
                expect_contents=['betterlife', '直营店'])
            self.assertPageRendered(
                endpoint=create_url,
                method=self.test_client.post,
                expect_contents=[org_name, org_desc],
                data={
                    "type": type_id,
                    "name": org_name,
                    "description": org_desc,
                    "parent": 1
                })
            self.assertDeleteSuccessful(
                endpoint=url_for(
                    'organization.delete_view',
                    id=2,
                    url=url_for('organization.index_view')),
                deleted_data=[org_name, org_desc])

            from psi.app.models import Organization
            user, pwd = object_faker.user(
                role_names=[
                    'organization_create', 'organization_view',
                    'organization_delete', 'organization_edit'
                ],
                organization=Organization.query.get(1))
            db_util.save_objects_commit(user)
            fixture.login_user(self.test_client, user.email, pwd)
            from psi.app.models import EnumValues
            org_type = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY)
            self.assertCreateFail(
                endpoint=create_url,
                create_data=[org_name, org_desc],
                data={
                    "type": org_type.id,
                    "name": org_name,
                    "description": org_desc,
                    "parent": 1
                })
Example #16
0
 def test_render_version(self):
     from psi.app.utils.ui_util import render_version
     import os
     fixture.login_as_admin(self.test_client)
     my_dir = os.path.dirname(os.path.realpath(__file__))
     result = render_version(swtag_file=my_dir + "/../resources/swtag")
     self.assertIn(
         """Build: <a href="{url}/8ab8044" target="_blank">-</a>,""".format(
             url=current_app.config['BUILDER_URL_PREFIX']), result)
     self.assertIn(
         """Commit: <a href="{url}/8ab8044" target="_blank">8ab8044</a>,""".
         format(url=current_app.config['GIT_URL_PREFIX']), result)
     self.assertIn("""Branch: master,""", result)
     self.assertIn("""Tag: V0.6.5,""", result)
     self.assertIn("""Date: 2016.7.14""", result)
 def test_delete_with_child_not_allowed(self):
     from psi.app.models import EnumValues, Organization
     type_id = EnumValues.get(const.DIRECT_SELLING_STORE_ORG_TYPE_KEY).id
     with self.test_client:
         fixture.login_as_admin(self.test_client)
         name1, desc1 = self.create_organization(
             type_id=type_id, parent_id=1)
         self.create_organization(type_id=type_id, parent_id=2)
         self.assertDeleteFail(
             endpoint=url_for(
                 'organization.delete_view',
                 id=2,
                 url=url_for('organization.index_view')),
             deleted_data=[name1, desc1])
         org = Organization.query.get(2)
         self.assertIsNotNone(org)
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create', 'franchise_sales_order_view',
         'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     delivered_status = EnumValues.get(SO_DELIVERED_STATUS_KEY)
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=delivered_status.id))
     self.assertEqual(rv.status_code, 403)
Example #19
0
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create',
         'franchise_sales_order_view',
         'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     delivered_status = EnumValues.get(SO_DELIVERED_STATUS_KEY)
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=delivered_status.id))
     self.assertEqual(rv.status_code, 403)
Example #20
0
 def test_render_version(self):
     from psi.app.utils.ui_util import render_version
     import os
     fixture.login_as_admin(self.test_client)
     my_dir = os.path.dirname(os.path.realpath(__file__))
     result = render_version(swtag_file=my_dir + "/../resources/swtag")
     self.assertIn(
         """Build: <a href="{url}/83772950" target="_blank">48</a>,""".format(
             url=current_app.config['BUILDER_URL_PREFIX']),
         result)
     self.assertIn(
         """Commit: <a href="{url}/7e57e7a" target="_blank">7e57e7a</a>,""".
         format(url=current_app.config['GIT_URL_PREFIX']),
         result)
     self.assertIn("""Branch: master,""", result)
     self.assertIn("""Tag: v0.6.7.post4,""", result)
     self.assertIn("""Date: 2018-09-04""", result)
Example #21
0
    def test_enough_inventory(self):
        from psi.app.services.purchase_order import PurchaseOrderService
        with self.test_client:
            from tests.fixture import login_as_admin
            from psi.app.services import SalesOrderService
            from psi.app.models import EnumValues
            login_as_admin(self.test_client)
            po = of.purchase_order(number_of_line=2,
                                   type=EnumValues.get(
                                       const.DIRECT_PO_TYPE_KEY))
            products = [l.product for l in po.lines]
            receiving = PurchaseOrderService.create_receiving_if_not_exist(po)
            receiving.status = EnumValues.get(
                const.RECEIVING_COMPLETE_STATUS_KEY)
            in_trans_line = receiving.operate_inv_trans_by_recv_status()
            po = receiving.update_purchase_order_status()
            from psi.app.utils import db_util
            db_util.save_objects_commit(po, receiving, in_trans_line)
            so = of.sales_order(products=products, number_of_line=2)
            shipping = SalesOrderService.create_or_update_shipping(so)
            db_util.save_objects_commit(so, shipping)
            out_inv_trans = shipping.inventory_transaction
            self.assertIsNotNone(out_inv_trans)
            self.assertEquals(2, len(out_inv_trans.lines))
            for l in shipping.lines:
                self.assertEquals(1, len(l.inventory_links))
                link = l.inventory_links[0]
                self.assertIsNotNone(link)
                so_line = None
                for l in so.lines:
                    if l.product.id == link.product.id:
                        self.assertEquals(link.out_price, l.unit_price)
                        self.assertEquals(link.out_quantity, l.quantity)
                        so_line = l

                for recv_l in receiving.lines:
                    if recv_l.product.id == link.product.id:
                        self.assertEquals(link.in_price, recv_l.price)
                        in_trans_line = recv_l.inventory_transaction_line
                        remain_qty = recv_l.purchase_order_line.quantity - so_line.quantity
                        if remain_qty < 0:
                            self.assertEquals(0,
                                              in_trans_line.saleable_quantity)
                        else:
                            self.assertEquals(remain_qty,
                                              in_trans_line.saleable_quantity)
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create', 'franchise_sales_order_view',
         'franchise_sales_order_edit', 'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=5000))
     self.assertEqual(rv.status_code, 201)
     self.assertIn(b'message', rv.data)
     self.assertIn(b'Invalid sales order status parameter', rv.data)
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create', 'franchise_sales_order_view',
         'franchise_sales_order_edit', 'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     shipped_status = EnumValues.get(SO_SHIPPED_STATUS_KEY)
     sales_order.status = shipped_status
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=shipped_status.id))
     self.assertEqual(rv.status_code, 201)
     self.assertIn(b'message', rv.data)
     self.assertIn(b'Status update not allowed', rv.data)
Example #24
0
    def test_delete_complete_receiving_not_allowed(self):
        from psi.app.models import Receiving, EnumValues
        from psi.app.views import ReceivingAdmin
        from psi.app import const
        from psi.app.service import Info
        fixture.login_as_admin(self.test_client)
        receiving = Receiving()
        complete_status = EnumValues.get(const.RECEIVING_COMPLETE_STATUS_KEY)
        receiving.status = complete_status
        db_session = Info.get_db().session
        receiving_admin = ReceivingAdmin(Receiving,
                                         db_session,
                                         name=lazy_gettext("Receiving"),
                                         category=lazy_gettext('Purchase'),
                                         menu_icon_type=ICON_TYPE_GLYPH,
                                         menu_icon_value='glyphicon-import')

        self.assertRaises(ValidationError, receiving_admin.on_model_delete,
                          receiving)
Example #25
0
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create',
         'franchise_sales_order_view',
         'franchise_sales_order_edit',
         'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=5000))
     self.assertEqual(rv.status_code, 201)
     self.assertIn(b'message', rv.data)
     self.assertIn(b'Invalid sales order status parameter', rv.data)
    def test_enough_inventory(self):
        from psi.app.services.purchase_order import PurchaseOrderService
        with self.test_client:
            from tests.fixture import login_as_admin
            from psi.app.services import SalesOrderService
            from psi.app.models import EnumValues
            login_as_admin(self.test_client)
            po = of.purchase_order(number_of_line=2, type=EnumValues.get(const.DIRECT_PO_TYPE_KEY))
            products = [l.product for l in po.lines]
            receiving = PurchaseOrderService.create_receiving_if_not_exist(po)
            receiving.status = EnumValues.get(const.RECEIVING_COMPLETE_STATUS_KEY)
            in_trans_line = receiving.operate_inv_trans_by_recv_status()
            po = receiving.update_purchase_order_status()
            from psi.app.utils import db_util
            db_util.save_objects_commit(po, receiving, in_trans_line)
            so = of.sales_order(products=products, number_of_line=2)
            shipping = SalesOrderService.create_or_update_shipping(so)
            db_util.save_objects_commit(so, shipping)
            out_inv_trans = shipping.inventory_transaction
            self.assertIsNotNone(out_inv_trans)
            self.assertEquals(2,len(out_inv_trans.lines))
            for l in shipping.lines:
                self.assertEquals(1, len(l.inventory_links))
                link = l.inventory_links[0]
                self.assertIsNotNone(link)
                so_line = None
                for l in so.lines:
                    if l.product.id == link.product.id:
                        self.assertEquals(link.out_price, l.unit_price)
                        self.assertEquals(link.out_quantity, l.quantity)
                        so_line = l

                for recv_l in receiving.lines:
                    if recv_l.product.id == link.product.id:
                        self.assertEquals(link.in_price, recv_l.price)
                        in_trans_line = recv_l.inventory_transaction_line
                        remain_qty = recv_l.purchase_order_line.quantity - so_line.quantity
                        if remain_qty < 0:
                            self.assertEquals(0, in_trans_line.saleable_quantity)
                        else:
                            self.assertEquals(remain_qty, in_trans_line.saleable_quantity)
Example #27
0
 def test_logic():
     fixture.login_as_admin(self.test_client)
     user, password = object_faker.user(role_names=[
         'franchise_sales_order_create',
         'franchise_sales_order_view',
         'franchise_sales_order_edit',
         'product_view'
     ])
     sales_order = object_faker.sales_order(creator=user,
                                            number_of_line=1)
     shipped_status = EnumValues.get(SO_SHIPPED_STATUS_KEY)
     sales_order.status = shipped_status
     db_util.save_objects_commit(sales_order, user)
     so_id = sales_order.id
     fixture.login_user(self.test_client, user.email, password)
     rv = self.test_client.put('/api/sales_order/' + str(so_id),
                               follow_redirects=True,
                               data=dict(status_id=shipped_status.id))
     self.assertEqual(rv.status_code, 201)
     self.assertIn(b'message', rv.data)
     self.assertIn(b'Status update not allowed', rv.data)
Example #28
0
    def logic_for_detail_edit_page(self, user, password, po, po_url, product_url):
        from psi.app.service import Info
        from psi.app.models.role import Role
        from psi.app.utils import save_objects_commit
        fixture.login_as_admin(self.test_client)
        save_objects_commit(po, user)
        fixture.logout_user(self.test_client)
        fixture.login_user(self.test_client, user.email, password)
        rv = self.test_client.get(po_url, follow_redirects=True)
        self.assertEqual(rv.status_code, 200)
        goods_amount_label = gettext('Goods Amount')
        self.assertIn(goods_amount_label, rv.data)
        total_amount_label = gettext('Total Amount')
        self.assertIn(total_amount_label, rv.data)

        rv = self.test_client.get(product_url, follow_redirects=True)
        self.assertEqual(rv.status_code, 200)
        purchase_price_label = gettext('Purchase Price')
        self.assertIn(purchase_price_label, rv.data)
        fixture.logout_user(self.test_client)
        role = Info.get_db().session.query(Role).filter_by(
            name='purchase_price_view'
        ).first()
        user.roles.remove(role)
        save_objects_commit(user)

        fixture.login_user(self.test_client, user.email, password)
        rv = self.test_client.get(po_url, follow_redirects=True)
        self.assertEqual(rv.status_code, 200)
        goods_amount_label = gettext('Goods Amount')
        self.assertNotIn(goods_amount_label, rv.data)
        total_amount_label = gettext('Total Amount')
        self.assertNotIn(total_amount_label, rv.data)
        rv = self.test_client.get(product_url, follow_redirects=True)
        self.assertEqual(rv.status_code, 200)
        purchase_price_label = gettext('Purchase Price')
        self.assertNotIn(purchase_price_label, rv.data)
        fixture.logout_user(self.test_client)
Example #29
0
 def create_sales_order(self, status_key):
     from psi.app.models import EnumValues
     from psi.app.services.purchase_order import PurchaseOrderService
     user, password = of.user(
         role_names=['direct_sales_order_create',
                     'direct_sales_order_view',
                     'direct_sales_order_edit',
                     'direct_sales_order_delete']
     )
     db_util.save_objects_commit(user)
     fixture.login_as_admin(self.test_client)
     fixture.login_user(self.test_client, user.email, password)
     direct_po = EnumValues.get(const.DIRECT_PO_TYPE_KEY)
     po = of.purchase_order(number_of_line=2, type=direct_po,
                            creator=user)
     po.status = EnumValues.get(const.PO_ISSUED_STATUS_KEY)
     fixture.login_as_admin(self.test_client)
     l_e, g_e, recv = PurchaseOrderService.create_expense_receiving(po)
     customer = of.customer(creator=user)
     db_util.save_objects_commit(po, l_e, g_e, recv, customer)
     fixture.logout_user(self.test_client)
     fixture.login_user(self.test_client, user.email, password)
     order_status = EnumValues.get(status_key)
     order_date = of.faker.date_time_this_year()
     logistic_amount = random.randint(0, 100)
     remark = of.faker.text(max_nb_chars=50)
     data = dict(customer=customer.id, status=order_status.id,
                 order_date=order_date, logistic_amount=logistic_amount,
                 remark=remark)
     total, data = self.prepare_so_lines_data_from_po(po, data)
     expect = [customer.name, order_status.display,
               order_date.strftime("%Y-%m-%d"), remark, str(total)]
     self.assertPageRendered(method=self.test_client.post, data=data,
                             endpoint=url_for('salesorder.create_view',
                                              url=url_for(
                                                  'salesorder.index_view')),
                             expect_contents=expect)
     return data, expect
Example #30
0
 def create_sales_order(self, status_key):
     from psi.app.models import EnumValues
     from psi.app.services.purchase_order import PurchaseOrderService
     user, password = of.user(
         role_names=['direct_sales_order_create',
                     'direct_sales_order_view',
                     'direct_sales_order_edit',
                     'direct_sales_order_delete']
     )
     db_util.save_objects_commit(user)
     fixture.login_as_admin(self.test_client)
     fixture.login_user(self.test_client, user.email, password)
     direct_po = EnumValues.get(const.DIRECT_PO_TYPE_KEY)
     po = of.purchase_order(number_of_line=2, type=direct_po,
                            creator=user)
     po.status = EnumValues.get(const.PO_ISSUED_STATUS_KEY)
     fixture.login_as_admin(self.test_client)
     l_e, g_e, recv = PurchaseOrderService.create_expense_receiving(po)
     customer = of.customer(creator=user)
     db_util.save_objects_commit(po, l_e, g_e, recv, customer)
     fixture.logout_user(self.test_client)
     fixture.login_user(self.test_client, user.email, password)
     order_status = EnumValues.get(status_key)
     order_date = of.faker.date_time_this_year()
     logistic_amount = random.randint(0, 100)
     remark = of.faker.text(max_nb_chars=50)
     data = dict(customer=customer.id, status=order_status.id,
                 order_date=order_date, logistic_amount=logistic_amount,
                 remark=remark)
     total, data = self.prepare_so_lines_data_from_po(po, data)
     expect = [customer.name, order_status.display,
               order_date.strftime("%Y-%m-%d"), remark, str(total)]
     self.assertPageRendered(method=self.test_client.post, data=data,
                             endpoint=self.create_endpoint(view='salesorder'),
                             expect_contents=expect)
     return data, expect
Example #31
0
    def test_franchise_purchase_order_pages(self):
        from psi.app.models import EnumValues, Organization
        with self.test_client:
            login_as_admin(self.test_client)
            org_type = EnumValues.get(const.FRANCHISE_STORE_ORG_TYPE_KEY)
            organization = object_faker.organization(
                parent=Organization.query.get(1), type=org_type)
            user, pwd = object_faker.user(role_names=[
                'franchise_purchase_order_create',
                'franchise_purchase_order_edit',
                'franchise_purchase_order_delete',
                'franchise_purchase_order_view'
            ],
                                          organization=organization)
            self.test_client.post('/login',
                                  data=dict(email_or_login=user.email,
                                            password=pwd),
                                  follow_redirects=True)
            db_util.save_objects_commit(user, organization)
            login_user(self.test_client, user.email, pwd)
            self.assertPageRendered(url_for('fpo.index_view'))
            self.assertPageRendered(url_for('fpo.create_view'))
            draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
            order_date = object_faker.faker.date_time_this_year()
            logistic_amount = random.randint(0, 100)
            remark = object_faker.faker.text(max_nb_chars=50)

            expect_contents = [
                draft_status.display,
                str(logistic_amount),
                order_date.strftime("%Y-%m-%d"), remark
            ]
            self.assertPageRendered(method=self.test_client.post,
                                    data=dict(status=draft_status.id,
                                              order_date=order_date,
                                              logistic_amount=logistic_amount,
                                              remark=remark),
                                    endpoint=url_for(
                                        'fpo.create_view',
                                        url=url_for('fpo.index_view')),
                                    expect_contents=expect_contents)

            self.assertPageRendered(expect_contents=expect_contents,
                                    endpoint=url_for('fpo.edit_view',
                                                     url=url_for(
                                                         'fpo.details_view',
                                                         id=1),
                                                     id=1))

            new_remark = object_faker.faker.text(max_nb_chars=50)
            new_logistic_amount = random.randint(0, 100)
            new_order_date = object_faker.faker.date_time_this_year()
            new_expect_contents = [
                draft_status.display,
                str(new_logistic_amount),
                new_order_date.strftime("%Y-%m-%d"), new_remark
            ]
            self.assertPageRendered(
                method=self.test_client.post,
                endpoint=url_for('fpo.edit_view',
                                 url=url_for('fpo.index_view'),
                                 id=1),
                data=dict(status=draft_status.id,
                          order_date=new_order_date,
                          logistic_amount=new_logistic_amount,
                          remark=new_remark),
                expect_contents=new_expect_contents)

            rv = self.assertDeleteSuccessful(
                endpoint=url_for('fpo.delete_view'),
                deleted_data=[
                    draft_status.display, new_remark,
                    new_order_date.strftime("%Y-%m-%d")
                ],
                data=dict(url=url_for('fpo.index_view'), id='1'))
Example #32
0
    def test_import(self):
        from psi.app.models import SalesOrder, SalesOrderLine, Product, Supplier
        from psi.app.utils import db_util
        import os
        fixture.login_as_admin(self.test_client)
        file_name = os.path.dirname(os.path.realpath(__file__)) + "/../resources/store_data.csv"
        content = codecs.open(file_name, "r", "utf-8").read()
        from psi.app.models.user import User
        from psi.app.models.role import Role
        from psi.app.service import Info
        user = Info.get_db().session.query(User).filter_by(login='******').first()
        role = Info.get_db().session.query(Role).filter_by(name='import_store_data').first()
        user.roles.append(role)
        from psi.app.service import Info
        Info.get_db().session.add(user)
        Info.get_db().session.commit()
        rv = self.test_client.get('/admin/import_store_data/', follow_redirects=True)
        self.assertEqual(200, rv.status_code)
        self.assertIn(u'导入店铺运营数据', rv.data)
        self.test_client.post('/admin/import_store_data/', data={
            'file': (file_name, content),
        }, follow_redirects=True)

        self.assertIsNotNone(db_util.get_by_external_id(SalesOrder, '01201503090002', user=user))

        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '11', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '15', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '16', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '17', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '18', user=user))

        self.assertIsNotNone(db_util.get_by_name(Product, '产品1', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品2', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品3', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品4', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品5', user=user))

        self.assertEqual(3, SalesOrder.query.count())
        self.assertEqual(5, SalesOrderLine.query.count())
        self.assertEqual(5, Product.query.count())
        self.assertEqual(3, Supplier.query.count())

        sales_order = db_util.get_by_external_id(SalesOrder, '01201503130003', user=user)
        """:type: SalesOrder"""
        self.assertEqual(3, len(sales_order.lines))
        self.assertEqual(const.DIRECT_SO_TYPE_KEY, sales_order.type.code)

        sales_order = db_util.get_by_external_id(SalesOrder, '01201503130001', user=user)
        self.assertEqual(const.DIRECT_SO_TYPE_KEY, sales_order.type.code)
        self.assertEqual(user.organization_id, sales_order.organization_id)
        self.assertEqual(1, len(sales_order.lines))
        line = sales_order.lines[0]
        """:type: SalesOrderLine"""

        self.assertEqual('15', line.external_id)
        self.assertEqual('产品2', line.product.name)
        self.assertEquals(user.organization_id, line.product.organization_id)
        self.assertEqual('000010', line.product.external_id)
        self.assertEquals('000016', line.product.supplier.external_id)
        self.assertEquals('供应商2', line.product.supplier.name)
        self.assertEquals(user.organization_id, line.product.supplier.organization_id)
        self.assertEquals(16.5000, line.product.purchase_price)
        self.assertEquals(33, line.product.retail_price)
        self.assertEqual(33, line.unit_price)
        self.assertEquals(1, line.quantity)
        self.assertEquals(datetime.strptime('2015-03-13 11:04:11.063', '%Y-%m-%d %H:%M:%S.%f'), line.sales_order.order_date)
        self.assertEqual(0, line.sales_order.logistic_amount)
Example #33
0
    def test_import(self):
        from psi.app.models import SalesOrder, SalesOrderLine, Product, Supplier
        from psi.app.utils import db_util
        import os
        fixture.login_as_admin(self.test_client)
        file_name = os.path.dirname(os.path.realpath(__file__)) + "/../resources/store_data.csv"
        content = codecs.open(file_name, "r", "utf-8").read()
        from psi.app.models.user import User
        from psi.app.models.role import Role
        from psi.app.service import Info
        user = Info.get_db().session.query(User).filter_by(login='******').first()
        role = Info.get_db().session.query(Role).filter_by(name='import_store_data').first()
        user.roles.append(role)
        from psi.app.service import Info
        Info.get_db().session.add(user)
        Info.get_db().session.commit()
        rv = self.test_client.get('/admin/import_store_data/', follow_redirects=True)
        self.assertEqual(200, rv.status_code)
        self.assertIn('导入店铺运营数据'.encode('utf-8'), rv.data)
        self.test_client.post('/admin/import_store_data/', data={
            'file': (file_name, content),
        }, follow_redirects=True)

        self.assertIsNotNone(db_util.get_by_external_id(SalesOrder, '01201503090002', user=user))

        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '11', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '15', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '16', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '17', user=user))
        self.assertIsNotNone(db_util.get_by_external_id(SalesOrderLine, '18', user=user))

        self.assertIsNotNone(db_util.get_by_name(Product, '产品1', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品2', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品3', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品4', user=user))
        self.assertIsNotNone(db_util.get_by_name(Product, '产品5', user=user))

        self.assertEqual(3, SalesOrder.query.count())
        self.assertEqual(5, SalesOrderLine.query.count())
        self.assertEqual(5, Product.query.count())
        self.assertEqual(3, Supplier.query.count())

        sales_order = db_util.get_by_external_id(SalesOrder, '01201503130003', user=user)
        """:type: SalesOrder"""
        self.assertEqual(3, len(sales_order.lines))
        self.assertEqual(const.DIRECT_SO_TYPE_KEY, sales_order.type.code)

        sales_order = db_util.get_by_external_id(SalesOrder, '01201503130001', user=user)
        self.assertEqual(const.DIRECT_SO_TYPE_KEY, sales_order.type.code)
        self.assertEqual(user.organization_id, sales_order.organization_id)
        self.assertEqual(1, len(sales_order.lines))
        line = sales_order.lines[0]
        """:type: SalesOrderLine"""

        self.assertEqual('15', line.external_id)
        self.assertEqual('产品2', line.product.name)
        self.assertEquals(user.organization_id, line.product.organization_id)
        self.assertEqual('000010', line.product.external_id)
        self.assertEquals('000016', line.product.supplier.external_id)
        self.assertEquals('供应商2', line.product.supplier.name)
        self.assertEquals(user.organization_id, line.product.supplier.organization_id)
        self.assertEquals(16.5000, line.product.purchase_price)
        self.assertEquals(33, line.product.retail_price)
        self.assertEqual(33, line.unit_price)
        self.assertEquals(1, line.quantity)
        self.assertEquals(datetime.strptime('2015-03-13 11:04:11.063', '%Y-%m-%d %H:%M:%S.%f'), line.sales_order.order_date)
        self.assertEqual(0, line.sales_order.logistic_amount)