def test_get_device_items(self): self.assertCountEqual( self.rebate.get_device_items(self.rebate.rebated_items), []) self.assertCountEqual( self.rebate.get_device_items(self.rebate.eligible_items), []) item_1 = ItemFactory(device=DeviceFactory(client=self.rebate.client, product=self.product_1), purchased_date=date(2018, 7, 16), is_used=False, purchase_type=BULK_PURCHASE) item_2 = ItemFactory(device=DeviceFactory(client=self.rebate.client, product=self.product_2), purchased_date=date(2018, 7, 31), is_used=True, purchase_type=BULK_PURCHASE) ItemFactory(device=DeviceFactory(client=self.rebate.client, product=ProductFactory()), purchased_date=date(2018, 7, 16), is_used=False, purchase_type=CONSIGNMENT_PURCHASE) ItemFactory(device=item_2.device, purchased_date=date(2017, 12, 31), is_used=False, purchase_type=CONSIGNMENT_PURCHASE) self.assertCountEqual( self.rebate.get_device_items(self.rebate.eligible_items), [item_1]) self.assertCountEqual( self.rebate.get_device_items(self.rebate.rebated_items), [item_1, item_2]) self.assertCountEqual( self.rebate.get_device_items(RebatableItem.objects.none()), [item_1, item_2])
def test_physician_app(self): item_3 = ItemFactory(device=DeviceFactory(client=self.client_1), cost=randint(350, 370)) item_5 = ItemFactory(device=DeviceFactory(client=self.client_1), cost=randint(100, 200)) RepCaseFactory(client=self.client_1, physician=self.physician_1, items=[self.item_1, self.item_2]) RepCaseFactory(client=self.client_1, physician=self.physician_3, items=[item_3]) RepCaseFactory(client=self.client_1, physician=self.physician_3, items=[item_5]) self.assertCountEqual( self.client_1.items, [self.item_1, self.item_2, item_3, self.item_4, item_5]) self.assertCountEqual( self.client_1.items.physician_app(), [{ 'app': float((self.item_1.cost + self.item_2.cost) / 2), 'physician_id': self.physician_1.id, 'physician_name': self.physician_1.user.name, }, { 'app': float((item_3.cost + item_5.cost) / 2), 'physician_id': self.physician_3.id, 'physician_name': self.physician_3.user.name, }, { 'app': float(self.item_4.cost), 'physician_id': None, 'physician_name': None, }])
def setUp(self): self.client_1, self.client_2 = ClientFactory.create_batch(2) manufacturer = ManufacturerFactory(image=ImageField( filename='biotronik.jpg')) product = ProductFactory(manufacturer=manufacturer) self.item_1 = ItemFactory(cost=randint(110, 150), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1, product=product)) self.item_2 = ItemFactory(cost=randint(210, 290), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1)) self.item_3 = ItemFactory(cost=randint(400, 500), device=DeviceFactory(client=self.client_2)) self.item_4 = ItemFactory(cost=1000, cost_type=UNIT_COST, device=DeviceFactory( client=self.client_1, product=ProductFactory( manufacturer=manufacturer, category=product.category))) physician_role = RoleFactory(priority=RolePriority.PHYSICIAN.value) self.physician_1 = AccountFactory(client=self.client_1, role=physician_role) self.physician_2 = AccountFactory(client=self.client_2, role=physician_role, user=self.physician_1.user) self.physician_3 = AccountFactory(client=self.client_1, role=physician_role)
def test_add_duplicated_serial_number_item(self): item = ItemFactory( rep_case=self.rep_case, device=self.client.device_set.get(product=self.product_1)) ItemFactory(rep_case=self.rep_case, device=self.client.device_set.get(product=self.product_2)) self.visit_reverse('admin:tracker_repcase_change', self.rep_case.id) self.wait_for_element_contains_text('#content h1', 'Change rep case') self.assert_elements_count('.form-row.dynamic-item_set', 2) self.find_link('Add another Item').click() self.select_option('#item_set-2 .item-purchase_type > select', 'Consignment') self.find_element( '#item_set-2 .item-identifier .select2-container').click() self.find_elements('.select2-search__field')[-1].send_keys( item.identifier, Keys.ENTER) self.click_save_and_continue() self.wait_for_error_message(message='Please correct the error below.') self.wait_for_element_contains_text( '#item_set-2 .field-identifier', f'Item with this identifier {item.identifier} exists') self.find_element( '#item_set-2 .item-identifier .select2-container').click() self.find_elements('.select2-search__field')[-1].send_keys( 'NEW SERIAL', Keys.ENTER) self.click_save_and_continue() self.wait_for_success_message( 'The rep case "New case at NSINC on 2018-09-10" was changed successfully.' ) self.assert_elements_count('.form-row.dynamic-item_set', 3)
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.today = datetime.utcnow().date() self.path = reverse('api:hospital:tracker:saving_by_date', args=(self.client_1.id, '2017-08')) physician = AccountFactory( user=self.user, client=self.client_1, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) device_1 = DeviceFactory(client=self.client_1) self.item_1, self.item_2 = ItemFactory.create_batch(2, device=device_1, saving=200, cost=1000) RepCaseFactory(client=self.client_1, physician=physician, items=[self.item_1, self.item_2], procedure_date=date(2017, 8, 1)) device_2 = DeviceFactory(client=self.client_1) self.item_3 = ItemFactory(device=device_2, saving=150, cost=1000) RepCaseFactory(client=self.client_1, physician=physician, items=[self.item_3], procedure_date=date(2017, 7, 5)) self.item_4 = ItemFactory(device=device_2, saving=200, cost=900) RepCaseFactory(client=self.client_1, items=[self.item_4], procedure_date=date(2015, 1, 1))
def test_return_marketshare_with_procedure_date(self): device = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_1)) device_2 = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_2)) item_1, item_2 = ItemFactory.create_batch(2, device=device) item_3, item_4 = ItemFactory.create_batch(2, device=device_2) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_1, item_3], procedure_date=date(2018, 5, 1)) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_2, item_4], procedure_date=date(2018, 4, 30)) path = reverse('api:hospital:device:marketshare_by_date', args=(self.client_1.id, '2018-5')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': 'May, 2018', 'marketshare': [{ 'spend': f'{item_1.cost:.2f}', 'units': 1, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{item_3.cost:.2f}', 'units': 1, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], }, { 'name': f'2018 to Date', 'marketshare': [{ 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{(item_3.cost + item_4.cost):.2f}', 'units': 2, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], } ]) path = reverse('api:hospital:device:marketshare_by_date', args=(self.client_1.id, '2018-04')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': 'April, 2018', 'marketshare': [{ 'spend': f'{item_2.cost:.2f}', 'units': 1, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{item_4.cost:.2f}', 'units': 1, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], }, { 'name': f'2018 to Date', 'marketshare': [{ 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{(item_3.cost + item_4.cost):.2f}', 'units': 2, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], } ])
def test_update_prices(self): product = ProductFactory(level=self.purchase_price.level, category=self.purchase_price.category) device = DeviceFactory(client=self.purchase_price.client, product=product) item_1, item_2 = ItemFactory.create_batch(2, device=device, is_used=True, cost_type=UNIT_COST, cost=100) item_3, item_4 = ItemFactory.create_batch(2, device=device, is_used=True, cost_type=UNIT_COST, cost=400) RepCaseFactory(procedure_date=date(2018, 1, 2), items=[item_1, item_2]) RepCaseFactory(procedure_date=date(2018, 12, 11), items=[item_3]) self.purchase_price.update_prices() self.assertEqual(self.purchase_price.min, item_1.cost) self.assertEqual(self.purchase_price.max, item_3.cost) self.assertEqual(self.purchase_price.avg, (item_1.cost + item_2.cost + item_3.cost) / 3)
def setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory() self.item_1, self.item_2 = ItemFactory.create_batch( 2, device=DeviceFactory(client=self.client), is_used=False, purchase_type=BULK_PURCHASE) ItemFactory(device=self.item_1.device, is_used=True, purchase_type=BULK_PURCHASE) ItemFactory(device=self.item_2.device, is_used=True, purchase_type=CONSIGNMENT_PURCHASE)
def test_property_discounts_as_table(self): discount_1, discount_2, discount_3 = DiscountFactory.create_batch(3) item = ItemFactory(discounts=[discount_1, discount_2]) discounts_table = item.discounts_as_table self.assertTrue(discount_1.name in discounts_table) self.assertTrue(discount_2.name in discounts_table) self.assertFalse(discount_3.name in discounts_table)
def test_used_by_physician_queryset(self): physician_3 = AccountFactory(client=self.client_2, role=self.physician_2.role) self.assertEqual( Item.objects.used_by_physician(self.physician_1).count(), 0) self.assertEqual( Item.objects.used_by_physician(self.physician_2).count(), 0) self.assertEqual( Item.objects.used_by_physician(physician_3).count(), 0) RepCaseFactory(items=[self.item_1], physician=self.physician_1, client=self.client_1) RepCaseFactory(items=[self.item_2], physician=self.physician_1, client=self.client_1) RepCaseFactory(items=[self.item_3, self.item_4], physician=self.physician_2, client=self.client_2) RepCaseFactory(items=ItemFactory.create_batch(2), physician=physician_3, client=self.client_2) self.assertCountEqual(Item.objects.used_by_physician(self.physician_1), [self.item_1, self.item_2]) self.assertCountEqual(Item.objects.used_by_physician(self.physician_2), [self.item_3, self.item_4])
def setUp(self): super().setUp() self.category = CategoryFactory() self.client_1 = ClientFactory() AccountFactory.create(user=self.user, client=self.client_1) self.product_1, self.product_2 = ProductFactory.create_batch(2, category=self.category) self.feature_1 = FeatureFactory(name='Wireless', product=self.product_2, shared_image=SharedImageFactory(image=ImageField(filename='wireless.jpg'))) self.feature_2, self.feature_3 = FeatureFactory.create_batch(2, product=self.product_2) price_1 = ClientPriceFactory(client=self.client_1, product=self.product_1, unit_cost=200, system_cost=300) price_2 = ClientPriceFactory(client=self.client_1, product=self.product_2, unit_cost=250, system_cost=300) ClientPriceFactory(client=self.client_1, unit_cost=250, system_cost=300, product=ProductFactory(enabled=False),) self.discount_1 = DiscountFactory( client_price=price_1, discount_type=VALUE_DISCOUNT, value=50, name='CCO', order=1, percent=0, apply_type=ON_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=SharedImageFactory(image=ImageField(filename='CCO.png')) ) self.discount_2 = DiscountFactory( client_price=price_2, discount_type=PERCENT_DISCOUNT, percent=10, cost_type=SYSTEM_COST, order=2, apply_type=ON_DOCTOR_ORDER, name='Repless', shared_image=SharedImageFactory(image=ImageField(filename='repless.png')) ) self.discount_3 = DiscountFactory( client_price=price_1, discount_type=PERCENT_DISCOUNT, value=0, name='Bulk', order=2, percent=15, apply_type=PRE_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=None) device = self.client_1.device_set.get(product=self.product_1) ItemFactory(device=device, discounts=[self.discount_3], purchase_type=BULK_PURCHASE, is_used=False, cost_type=UNIT_COST) self.path = reverse('api:hospital:device:products', args=(self.client_1.id, self.category.id,))
def test_class_method_update_purchase_price(self): def update_client_purchase_price(): PurchasePrice.update(category=self.purchase_price.category, client=self.purchase_price.client, year=self.purchase_price.year, level=self.purchase_price.level, cost_type=self.purchase_price.cost_type) self.purchase_price.refresh_from_db() self.assertEqual(self.purchase_price.avg, Decimal(1000)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) update_client_purchase_price() self.assertEqual(self.purchase_price.avg, Decimal(0)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) item = ItemFactory(cost_type=self.purchase_price.cost_type, is_used=True, device=DeviceFactory(client=self.purchase_price.client, product=ProductFactory(category=self.purchase_price.category, level=self.purchase_price.level))) rep_case = RepCaseFactory(procedure_date=date(2017, 12, 31), items=[item]) update_client_purchase_price() self.assertEqual(self.purchase_price.avg, Decimal(0)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) rep_case.procedure_date = date(2018, 1, 1) rep_case.save() update_client_purchase_price() self.assertEqual(self.purchase_price.avg, item.cost) self.assertEqual(self.purchase_price.min, item.cost) self.assertEqual(self.purchase_price.max, item.cost)
def setUp(self): self.client = ClientFactory(name='UVMC') manufacturer = ManufacturerFactory(name='Medtronic') self.product = ProductFactory(model_number='SESR01', manufacturer=manufacturer) client_price = ClientPriceFactory(product=self.product, client=self.client) self.bulk_discount = DiscountFactory(name='Bulk', client_price=client_price, apply_type=PRE_DOCTOR_ORDER, cost_type=UNIT_COST, discount_type=PERCENT_DISCOUNT, percent=10, value=0, order=1) self.discount_2 = DiscountFactory(client_price=client_price, apply_type=ON_DOCTOR_ORDER, cost_type=SYSTEM_COST) self.device = self.product.device_set.get(client=self.client) self.device.hospital_number = '70669' self.device.save() self.item = ItemFactory(device=self.device, serial_number='PJN7204267', cost_type=SYSTEM_COST, discounts=[self.discount_2]) self.xls_file_path = os.path.join(FIXTURE_DIR, 'items.xls') self._prepare_xls_file()
def test_return_marketshare_without_specify_procedure_date(self): device = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_1)) item_1, item_2 = ItemFactory.create_batch(2, device=device) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_1, item_2], procedure_date=self.today) response = self.authorized_client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': f'{month_name[self.today.month]}, {self.today.year}', 'marketshare': [ { 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, ], }, { 'name': f'{self.today.year} to Date', 'marketshare': [ { 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, ], } ])
def test_session_authorized_staff_user(self): ItemFactory(is_used=True) item_1, item_2 = ItemFactory.create_batch(2, device=self.device, is_used=False) response = self.authorized_admin_client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'id': item_1.id, 'identifier': item_1.identifier, 'cost_type': item_1.cost_type, }, { 'id': item_2.id, 'identifier': item_2.identifier, 'cost_type': item_2.cost_type, }, ])
def test_marketshare(self): self.assertEqual(self.tier.marketshare(self.eligible_purchased_items), 100) ItemFactory.create_batch(3, device=DeviceFactory( client=self.rebate.client, product=ProductFactory()), cost=160, purchased_date=date(2018, 12, 23), is_used=True) self.assertEqual(self.tier.marketshare(self.eligible_purchased_items), 60) self.rebate.client = ClientFactory() self.rebate.save() self.assertEqual(self.tier.marketshare(RebatableItem.objects.none()), 0)
def test_unused_bulk_items_count_by_client_queryset(self): client = ClientFactory() ClientPriceFactory(client=client, product=self.product_1, unit_cost=100, system_cost=120) ItemFactory.create_batch( 3, device=client.device_set.get(product=self.product_1)) ItemFactory.create_batch(2, device=DeviceFactory(product=self.product_2)) products = Product.objects.unused_bulk_items_count_by_client(client) product = products.first() self.assertEqual(products.count(), 1) self.assertEqual(product, self.product_1) self.assertEqual(product.bulk, 3)
def test_save_method_auto_generate_identifier(self): self.assertEqual(ItemFactory(serial_number='Serial-NUMBER', lot_number='LOT').identifier, 'Serial-NUMBER') ItemFactory(lot_number='ITEM-LOT', serial_number='') next_item = ItemFactory(serial_number=None, lot_number='LOT') self.assertTrue(next_item.identifier.startswith('LOT-')) next_item.serial_number = 'SERIAL-NUMBER-2' next_item.lot_number = 'LOT-2' next_item.save() self.assertEqual(next_item.identifier, 'SERIAL-NUMBER-2')
def test_get_method_requires_purchase_price_aggregation(self): path = reverse('api:hospital:tracker:app:purchase_price', args=(self.client_1.id, self.category.id, 'advanced', 'unit_cost')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, {'min': None, 'max': 0, 'avg': 0}) path = reverse('api:hospital:tracker:app:purchase_price', args=(self.client_1.id, self.category.id, 'entry', 'system_cost')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, {'min': None, 'max': 0, 'avg': 0}) entry = ProductLevel.ENTRY.value item_1 = ItemFactory(cost_type=SYSTEM_COST, cost=100, is_used=True, device=DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=entry))) item_2 = ItemFactory(cost_type=SYSTEM_COST, cost=203, is_used=True, device=DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=entry))) item_3 = ItemFactory(device=DeviceFactory(client=self.client_1), cost_type=UNIT_COST, cost=100, is_used=True) RepCaseFactory(procedure_date=datetime.utcnow().date(), items=[item_1, item_2]) RepCaseFactory(procedure_date=datetime.utcnow().date(), items=[item_3]) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, { 'min': '100.00', 'max': '200.00', 'avg': '151.50' })
def setUp(self): product = ProductFactory() manufacturer = product.manufacturer client = ClientFactory() device = DeviceFactory(client=client, product=product) item_1 = ItemFactory(device=device, cost=100, purchased_date=date(2018, 4, 1), is_used=False) item_2 = ItemFactory(device=device, cost=120, purchased_date=date(2018, 4, 1), is_used=True) item_3 = ItemFactory(device=DeviceFactory( client=client, product=ProductFactory(manufacturer=manufacturer)), cost=500, purchased_date=date(2018, 12, 24), is_used=False) ItemFactory(device=device, cost=100, purchased_date=date(2017, 12, 23), is_used=True) self.rebate = RebateFactory(client=client, manufacturer=manufacturer, start_date=date(2018, 1, 1), end_date=date(2018, 12, 31)) self.tier = TierFactory(upper_bound=30, tier_type=MARKETSHARE, rebate=self.rebate) RebatableItemFactory(rebate=self.rebate, item_type=REBATED_ITEM, content_object=product) self.eligible_purchased_items = self.rebate.get_device_items( self.rebate.eligible_items) self.assertCountEqual(self.eligible_purchased_items, [item_1, item_2, item_3]) self.rebated_purchased_items = self.rebate.get_device_items( self.rebate.rebated_items) self.assertCountEqual(self.rebated_purchased_items, [item_1, item_2])
def setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory() self.product = ProductFactory() ClientPriceFactory(client=self.client, product=self.product) device = self.client.device_set.get(product=self.product) self.discounts = DiscountFactory.create_batch(2) self.item = ItemFactory(device=device, purchase_type=BULK_PURCHASE, is_used=False, discounts=self.discounts)
def setUp(self): super().setUp() self.client_1 = ClientFactory() physician = AccountFactory( client=self.client_1, user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) self.category_1, self.category_2, self.category_3 = CategoryFactory.create_batch( 3) device_1 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_1)) device_2 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_2)) device_3 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_3)) rep_case = RepCaseFactory(client=self.client_1, physician=physician) ItemFactory(device=device_1, rep_case=rep_case, is_used=True) ItemFactory(device=device_2, rep_case=rep_case, is_used=True) ItemFactory(device=device_3, rep_case=RepCaseFactory(), is_used=True) self.path = reverse('api:hospital:tracker:app:categories', args=(self.client_1.id, ))
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.product = ProductFactory() self.path = reverse('api:hospital:device:items', args=(self.client_1.id, self.product.id)) AccountFactory(client=self.client_1, user=self.user) ItemFactory.create_batch(2, device=DeviceFactory(product=self.product)) ItemFactory(device=DeviceFactory(client=self.client_1)) device = DeviceFactory(client=self.client_1, product=self.product) self.item_1, self.item_2 = ItemFactory.create_batch(2, device=device, is_used=False, purchase_type=BULK_PURCHASE) ItemFactory(device=device, purchase_type=CONSIGNMENT_PURCHASE, is_used=False) ItemFactory(device=device, purchase_type=BULK_PURCHASE, is_used=True)
def test_get_method_returns_physician_app_on_used_devices(self): manufacturer = ManufacturerFactory( image=ImageField(filename='medtronic.png'), short_name='MDT') entry_device_1 = DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=ProductLevel.ENTRY.value, manufacturer=manufacturer)) entry_device_2 = DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=ProductLevel.ENTRY.value)) advanced_device = DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=ProductLevel.ADVANCED.value)) today = datetime.utcnow().date() RepCaseFactory(physician=self.physician, client=self.client_1, procedure_date=today, items=[ ItemFactory(is_used=True, device=entry_device_1, cost_type=UNIT_COST, cost=100), ItemFactory(is_used=True, device=advanced_device, cost_type=UNIT_COST, cost=200), ItemFactory(is_used=True, device=entry_device_2, cost_type=UNIT_COST, cost=350), ItemFactory(is_used=True, device=advanced_device, cost_type=SYSTEM_COST, cost=470), ]) RepCaseFactory(client=self.client_1, procedure_date=today, items=[ ItemFactory(is_used=True, device=entry_device_1, cost_type=UNIT_COST, cost=90), ItemFactory(is_used=True, device=advanced_device, cost_type=SYSTEM_COST, cost=430), ]) response = self.authorized_client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual( response.data.pop('manufacturers'), [{ 'id': manufacturer.id, 'name': 'MDT', 'app': '100.00', 'image': 'manufacturers/medtronic.png' }, { 'id': entry_device_2.product.manufacturer.id, 'name': entry_device_2.product.manufacturer.display_name, 'app': '350.00', 'image': None }]) self.assertDictEqual( response.data, { 'client': { 'id': self.client_1.id, 'name': self.client_1.name, 'min': '90.00', 'max': '350.00', 'app': '180.00', }, 'physician': { 'id': self.physician.id, 'name': self.physician.user.name, 'app': '225.00', }, }) rmtree(settings.MEDIA_ROOT)
class RebateStatusTransitionTestCase(TestCase): def setUp(self): client = ClientFactory() product = ProductFactory() self.discount_1 = DiscountFactory(name='CCO', discount_type=PERCENT_DISCOUNT, percent=10, cost_type=UNIT_COST, order=1, apply_type=ON_DOCTOR_ORDER) self.discount_2 = DiscountFactory(name='Bulk', discount_type=VALUE_DISCOUNT, value=20, cost_type=SYSTEM_COST, order=1, apply_type=PRE_DOCTOR_ORDER) self.client_price = ClientPriceFactory( client=client, product=product, unit_cost=100, system_cost=120, discounts=[self.discount_1, self.discount_2]) device = client.device_set.get(product=product) today = datetime.utcnow().date() self.item_1 = ItemFactory( device=device, cost_type=UNIT_COST, rep_case=RepCaseFactory(procedure_date=today), is_used=True, discounts=[self.discount_1]) self.item_2, self.item_3 = ItemFactory.create_batch( 2, device=device, cost_type=SYSTEM_COST, is_used=False, discounts=[self.discount_2], purchased_date=today) self.rebate = RebateFactory(client=client, manufacturer=product.manufacturer) RebatableItemFactory(rebate=self.rebate, item_type=REBATED_ITEM, content_object=product) TierFactory(rebate=self.rebate, tier_type=SPEND, discount_type=PERCENT_DISCOUNT, percent=10, order=2) TierFactory(rebate=self.rebate, tier_type=PURCHASED_UNITS, discount_type=VALUE_DISCOUNT, value=20, lower_bound=2, upper_bound=10, order=2) TierFactory(rebate=self.rebate, tier_type=PURCHASED_UNITS, discount_type=VALUE_DISCOUNT, value=50, lower_bound=11, upper_bound=100, order=2) def test_transition_apply(self): self.assertEqual(self.rebate.status, NEW_REBATE) self.assertEqual(self.item_1.cost, 90) self.assertEqual(self.item_2.cost, 100) self.assertEqual(self.item_3.cost, 100) self.assertEqual(Discount.objects.count(), 2) self.rebate.apply() self.rebate.save() self.item_1.refresh_from_db() self.item_2.refresh_from_db() self.item_3.refresh_from_db() self.rebate.refresh_from_db() self.client_price.refresh_from_db() self.assertEqual(self.rebate.status, COMPLETE_REBATE) self.assertEqual(Discount.objects.count(), 6) unit_cost_discounts = Discount.objects.filter( apply_type=POST_DOCTOR_ORDER, cost_type=UNIT_COST) discount_3 = unit_cost_discounts.get(discount_type=PERCENT_DISCOUNT) discount_4 = unit_cost_discounts.get(discount_type=VALUE_DISCOUNT) system_cost_discounts = Discount.objects.filter( apply_type=POST_DOCTOR_ORDER, cost_type=SYSTEM_COST) discount_5 = system_cost_discounts.get(discount_type=PERCENT_DISCOUNT) discount_6 = system_cost_discounts.get(discount_type=VALUE_DISCOUNT) self.assertEqual(discount_3.percent, 10) self.assertEqual(discount_4.value, 20) self.assertEqual(discount_5.percent, 10) self.assertEqual(discount_6.value, 20) self.assertCountEqual(self.rebate.discount_set.all(), [discount_3, discount_4, discount_5, discount_6]) self.assertCountEqual(self.client_price.discounts(UNIT_COST), [self.discount_1, discount_3, discount_4]) self.assertCountEqual(self.client_price.discounts(SYSTEM_COST), [self.discount_2, discount_5, discount_6]) self.assertCountEqual(self.item_1.discounts.all(), [self.discount_1, discount_3, discount_4]) self.assertCountEqual(self.item_2.discounts.all(), [self.discount_2, discount_5, discount_6]) self.assertCountEqual(self.item_3.discounts.all(), [self.discount_2, discount_5, discount_6]) self.assertEqual(self.item_1.cost, 61) self.assertEqual(self.item_2.cost, 70) self.assertEqual(self.item_3.cost, 70) self.assertRaises(TransitionNotAllowed, self.rebate.apply) def test_transition_unapply(self): self.rebate.apply() self.rebate.unapply() self.rebate.save() self.item_1.refresh_from_db() self.item_2.refresh_from_db() self.item_3.refresh_from_db() self.rebate.refresh_from_db() self.client_price.refresh_from_db() self.assertEqual(self.rebate.status, NEW_REBATE) self.assertEqual(self.item_1.cost, 90) self.assertEqual(self.item_2.cost, 100) self.assertEqual(self.item_3.cost, 100) self.assertCountEqual(Discount.objects.all(), [self.discount_1, self.discount_2]) self.assertRaises(TransitionNotAllowed, self.rebate.unapply)
def test_update_cost(self): client = ClientFactory() product = ProductFactory() discount_1 = DiscountFactory(cost_type=UNIT_COST, value=10, discount_type=VALUE_DISCOUNT, apply_type=PRE_DOCTOR_ORDER) discount_2 = DiscountFactory(cost_type=SYSTEM_COST, percent=20, discount_type=PERCENT_DISCOUNT, apply_type=ON_DOCTOR_ORDER) client_price = ClientPriceFactory(product=product, client=client, unit_cost=100, system_cost=150, discounts=[discount_1, discount_2]) device = client.device_set.get(product=product) unit_item = ItemFactory(device=device, cost_type=UNIT_COST, purchased_date=date(2017, 9, 8)) system_item = ItemFactory(device=device, cost_type=SYSTEM_COST, is_used=True, rep_case=RepCaseFactory(procedure_date=date(2018, 7, 9))) item = ItemFactory(cost=1000) unit_item.update_cost(discounts=[]) system_item.update_cost(discounts=[]) item.update_cost(discounts=[]) self.assertEqual((unit_item.cost, unit_item.saving), (client_price.unit_cost, 0)) self.assertEqual((system_item.cost, system_item.saving), (client_price.system_cost, 0)) self.assertEqual((item.cost, item.saving), (item.cost, 0)) unit_item.update_cost(discounts=[discount_1, discount_2]) system_item.update_cost(discounts=[discount_1, discount_2]) item.update_cost(discounts=[discount_1, discount_2]) self.assertEqual((unit_item.cost, unit_item.saving), (Decimal('90.00'), 0)) self.assertEqual((system_item.cost, system_item.saving), (Decimal('120.00'), 30)) self.assertEqual((item.cost, item.saving), (Decimal('1000.00'), 0))
def test_save_method_errors(self): self.assertRaises(AttributeError, ItemFactory, serial_number=None, lot_number=None) item = ItemFactory() self.assertRaises(IntegrityError, Item.objects.create, serial_number=item.serial_number)
def setUp(self): client = ClientFactory() product = ProductFactory() self.discount_1 = DiscountFactory(name='CCO', discount_type=PERCENT_DISCOUNT, percent=10, cost_type=UNIT_COST, order=1, apply_type=ON_DOCTOR_ORDER) self.discount_2 = DiscountFactory(name='Bulk', discount_type=VALUE_DISCOUNT, value=20, cost_type=SYSTEM_COST, order=1, apply_type=PRE_DOCTOR_ORDER) self.client_price = ClientPriceFactory( client=client, product=product, unit_cost=100, system_cost=120, discounts=[self.discount_1, self.discount_2]) device = client.device_set.get(product=product) today = datetime.utcnow().date() self.item_1 = ItemFactory( device=device, cost_type=UNIT_COST, rep_case=RepCaseFactory(procedure_date=today), is_used=True, discounts=[self.discount_1]) self.item_2, self.item_3 = ItemFactory.create_batch( 2, device=device, cost_type=SYSTEM_COST, is_used=False, discounts=[self.discount_2], purchased_date=today) self.rebate = RebateFactory(client=client, manufacturer=product.manufacturer) RebatableItemFactory(rebate=self.rebate, item_type=REBATED_ITEM, content_object=product) TierFactory(rebate=self.rebate, tier_type=SPEND, discount_type=PERCENT_DISCOUNT, percent=10, order=2) TierFactory(rebate=self.rebate, tier_type=PURCHASED_UNITS, discount_type=VALUE_DISCOUNT, value=20, lower_bound=2, upper_bound=10, order=2) TierFactory(rebate=self.rebate, tier_type=PURCHASED_UNITS, discount_type=VALUE_DISCOUNT, value=50, lower_bound=11, upper_bound=100, order=2)
def test_item_to_string(self): expired_date = timezone.datetime.strptime('2018-12-01', '%Y-%m-%d').date() device = DeviceFactory(hospital_number='12345') item = ItemFactory(serial_number='SERIAL-ABCD', expired_date=expired_date, device=device) self.assertEqual(str(item), f'12345: SERIAL-ABCD expired on 2018-12-01')
def setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory(name='NSINC') self.product_1 = ProductFactory( name='Accolade VR', manufacturer=ManufacturerFactory(short_name='MDT')) self.product_2 = ProductFactory( name='Evera MRI XT', manufacturer=ManufacturerFactory(short_name='BIO')) ClientPriceFactory(client=self.client, product=self.product_1, system_cost=100, discounts=[ DiscountFactory(name='CCO', cost_type=SYSTEM_COST, discount_type=PERCENT_DISCOUNT, percent=20, order=2, apply_type=ON_DOCTOR_ORDER), DiscountFactory(name='Repless', cost_type=SYSTEM_COST, discount_type=VALUE_DISCOUNT, value=20, order=1, apply_type=ON_DOCTOR_ORDER), ]) bulk_discount = DiscountFactory(name='Bulk', cost_type=UNIT_COST, discount_type=VALUE_DISCOUNT, value=50, order=1, apply_type=PRE_DOCTOR_ORDER) ClientPriceFactory(client=self.client, product=self.product_2, unit_cost=200, discounts=[ DiscountFactory(name='Repless', cost_type=UNIT_COST, percent=10, order=1, apply_type=ON_DOCTOR_ORDER), bulk_discount ]) device = Device.objects.get(client=self.client, product=self.product_2) item = ItemFactory(device=device, is_used=False, serial_number='SER1234', discounts=[bulk_discount], cost_type=UNIT_COST, purchased_date=date(2018, 1, 1)) self.assertEqual(item.cost, 150) physician = AccountFactory( role=RoleFactory(priority=RolePriority.PHYSICIAN.value), client=self.client) self.rep_case = RepCaseFactory(client=self.client, owners=[physician], physician=physician, procedure_date=date(2018, 9, 10)) self.visit_reverse('admin:tracker_repcase_change', self.rep_case.id) self.wait_for_element_contains_text('#content h1', 'Change rep case')