Esempio n. 1
0
    def test_remove_item(self):
        order = self.create_production_order()
        item = ProductionItem(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_item(item)

        item = self.create_production_item()
        order = item.order
        order.remove_item(item)
        self.assertEqual(order.get_items().count(), 0)

        with self.sysparam(SYNCHRONIZED_MODE=True):
            item = self.create_production_item()
            order = item.order

            before_remove = self.store.find(ProductionItem).count()
            order.remove_item(item)
            after_remove = self.store.find(ProductionItem).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(ProductionItem, order=order).count(), 0)
Esempio n. 2
0
    def testCanRemove(self):
        product = self.create_product()
        storable = Storable(product=product, store=self.store)
        self.assertTrue(product.can_remove())

        storable.increase_stock(1, get_current_branch(self.store), 0, 0)
        self.assertFalse(product.can_remove())

        # Product was sold.
        sale = self.create_sale()
        sale.add_sellable(product.sellable, quantity=1, price=10)

        method = PaymentMethod.get_by_name(self.store, u'money')
        method.create_payment(Payment.TYPE_IN, sale.group, sale.branch,
                              sale.get_sale_subtotal())

        sale.order()
        sale.confirm()

        self.assertFalse(product.can_remove())

        # Product is a component.
        from stoqlib.domain.product import ProductComponent
        product = self.create_product(10)
        component = self.create_product(5)
        Storable(product=component, store=self.store)
        self.assertTrue(component.can_remove())

        ProductComponent(product=product,
                         component=component,
                         store=self.store)

        self.assertFalse(component.can_remove())

        # Product is used in a production.
        from stoqlib.domain.production import ProductionItem
        product = self.create_product()
        Storable(product=product, store=self.store)
        self.assertTrue(product.can_remove())
        order = self.create_production_order()
        ProductionItem(product=product,
                       order=order,
                       quantity=1,
                       store=self.store)

        self.assertFalse(product.can_remove())
Esempio n. 3
0
    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()), [])
Esempio n. 4
0
    def create_production_item(self, quantity=1, order=None):
        from stoqlib.domain.product import ProductComponent, Storable
        from stoqlib.domain.production import (ProductionItem,
                                               ProductionMaterial)
        product = self.create_product(10)
        Storable(product=product, store=self.store)
        component = self.create_product(5)
        Storable(product=component, store=self.store)
        ProductComponent(product=product,
                         component=component,
                         store=self.store)

        if not order:
            order = self.create_production_order()
        component = list(product.get_components())[0]
        ProductionMaterial(product=component.component,
                           order=order,
                           needed=quantity,
                           store=self.store)

        return ProductionItem(product=product,
                              order=order,
                              quantity=quantity,
                              store=self.store)