def test_remove_service_item(self): order = self.create_production_order() item = ProductionService(store=self.store) with self.assertRaisesRegexp( ValueError, (u'Argument item must have an order attribute ' u'associated with the current production ' u'order instance.')): order.remove_service_item(item) item.order = order order.remove_service_item(item)
def test_remove_service_item(self): order = self.create_production_order() item = ProductionService(store=self.store) with self.assertRaisesRegex( ValueError, (u'Argument item must have an order attribute ' u'associated with the current production ' u'order instance.')): order.remove_service_item(item) item = self.create_production_service() order = item.order order.remove_service_item(item) self.assertEqual(order.get_service_items().count(), 0) with self.sysparam(SYNCHRONIZED_MODE=True): item = self.create_production_service() order = item.order before_remove = self.store.find(ProductionService).count() order.remove_service_item(item) after_remove = self.store.find(ProductionService).count() # The item should still be on the database self.assertEqual(before_remove, after_remove) # But not related to the loan self.assertEqual( self.store.find(ProductionService, order=order).count(), 0)
def get_order_item(self, sellable, cost, quantity): item = self._get_production_service_by_sellable(sellable) if item is None: return ProductionService(service=sellable.service, quantity=quantity, order=self.model, store=self.store) item.quantity += quantity return item
def test_can_remove(self): service = self.create_service() self.assertTrue(service.can_remove()) # Service already used. sale = self.create_sale() sale.add_sellable(service.sellable, quantity=1, price=10) self.assertFalse(service.sellable.can_remove()) # Service is used in a production. from stoqlib.domain.production import ProductionService service = self.create_service() self.assertTrue(service.can_remove()) ProductionService(service=service, order=self.create_production_order(), store=self.store) self.assertFalse(service.can_remove())
def test_items(self): order = self.create_production_order() item = ProductionItem(product=self.create_product(), order=order, quantity=1, store=self.store) service = ProductionService(service=self.create_service(), order=order, store=self.store) self.assertTrue(item in order.get_items()) self.assertTrue(service in order.get_service_items()) self.assertRaises(AssertionError, order.remove_item, service) self.assertRaises(AssertionError, order.remove_service_item, item) order.remove_item(item) self.assertEqual(list(order.get_items()), []) order.remove_service_item(service) self.assertEqual(list(order.get_service_items()), [])
def test_can_remove(self): service = self.create_service() old = sysparam.get_object(self.store, 'DELIVERY_SERVICE') try: sysparam.set_object(self.store, 'DELIVERY_SERVICE', service) self.assertFalse(service.can_remove()) finally: sysparam.set_object(self.store, 'DELIVERY_SERVICE', old) # Service already used. sale = self.create_sale() sale.add_sellable(service.sellable, quantity=1, price=10) self.assertFalse(service.sellable.can_remove()) # Service is used in a production. from stoqlib.domain.production import ProductionService service = self.create_service() self.assertTrue(service.can_remove()) ProductionService(service=service, order=self.create_production_order(), store=self.store) self.assertFalse(service.can_remove())
def test_unit_description(self): item = ProductionService(store=self.store) item.service = self.create_service() item.service.sellable.unit = self.create_sellable_unit(description=u'un') self.assertEqual(item.unit_description, u'un')
def test_get_description(self): item = ProductionService(store=self.store) item.service = self.create_service() item.service.sellable.description = u'service' self.assertEqual(item.get_description(), u'service')
def test_unit_description(self): item = ProductionService(store=self.store) item.service = self.create_service() item.service.sellable.unit = self.create_sellable_unit( description=u'un') self.assertEqual(item.unit_description, u'un')
def create_production_service(self): from stoqlib.domain.production import ProductionService service = self.create_service() return ProductionService(service=service, order=self.create_production_order(), store=self.store)