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)
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)
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)
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', '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)
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 generate_fake_order(): """ Load a set of fake data to the system * 10 Suppliers and customers * 5 purchase orders and sales_orders """ from tests.object_faker import object_faker from psi.app.models import User from random import randint user = database.session.query(User).get(1) for i in range(5): purchase_order = object_faker.purchase_order(creator=user, number_of_line=randint( 1, 9)) sales_order = object_faker.sales_order(creator=user, number_of_line=randint(1, 9)) database.session.add(purchase_order) database.session.add(sales_order) database.session.commit()
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)
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) 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)