def test_show(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)
        sellable = product.sellable
        storable = product.storable

        item = workorder.add_sellable(sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-show')

        self.assertValid(editor, ['price'])
        editor.price.update(0)
        self.assertInvalid(editor, ['price'])
        editor.price.update(-1)
        self.assertInvalid(editor, ['price'])
        with mock.patch.object(sellable, 'is_valid_price') as ivp:
            ivp.return_value = {
                'is_valid': False,
                'min_price': decimal.Decimal('10.00'),
                'max_discount': decimal.Decimal('0.00'),
            }
            editor.price.update(1)
            ivp.assert_called_once_with(1, workorder.client.category,
                                        api.get_current_user(self.store))
            self.assertInvalid(editor, ['price'])

        self.assertValid(editor, ['quantity'])
        with mock.patch.object(storable, 'get_balance_for_branch') as gbfb:
            gbfb.return_value = 0
            editor.quantity.update(20)
            gbfb.assert_called_once_with(workorder.branch)
            self.assertInvalid(editor, ['quantity'])
    def test_on_confirm(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        # Nothing made
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=1)
        item.reserve(1)
        editor = _WorkOrderItemEditor(self.store, model=item)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            self.assertEqual(reserve.call_count, 0)
            self.assertEqual(return_to_stock.call_count, 0)

        # Reserving more quantity
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=10)
        item.reserve(2)
        editor = _WorkOrderItemEditor(self.store, model=item)
        editor.quantity.update(8)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            reserve.assert_called_once_with(6)
            self.assertEqual(return_to_stock.call_count, 0)

        # Returning some quantity to stock
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=10)
        item.reserve(6)
        editor = _WorkOrderItemEditor(self.store, model=item)
        editor.quantity.update(4)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            self.assertEqual(reserve.call_count, 0)
            return_to_stock.assert_called_once_with(2)
Beispiel #3
0
    def test_on_confirm(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        # Nothing made
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=1)
        item.reserve(1)
        editor = _WorkOrderItemEditor(self.store, model=item)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            self.assertEqual(reserve.call_count, 0)
            self.assertEqual(return_to_stock.call_count, 0)

        # Reserving more quantity
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=10)
        item.reserve(2)
        editor = _WorkOrderItemEditor(self.store, model=item)
        editor.quantity.update(8)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            reserve.assert_called_once_with(6)
            self.assertEqual(return_to_stock.call_count, 0)

        # Returning some quantity to stock
        product = self.create_product(stock=10)
        item = workorder.add_sellable(product.sellable, quantity=10)
        item.reserve(6)
        editor = _WorkOrderItemEditor(self.store, model=item)
        editor.quantity.update(4)
        with contextlib.nested(
                mock.patch.object(item, 'return_to_stock'),
                mock.patch.object(item, 'reserve')) as (return_to_stock,
                                                        reserve):
            editor.on_confirm()
            self.assertEqual(reserve.call_count, 0)
            return_to_stock.assert_called_once_with(2)
Beispiel #4
0
    def test_show(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)
        sellable = product.sellable
        storable = product.storable

        item = workorder.add_sellable(sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-show')

        self.assertValid(editor, ['price'])
        editor.price.update(0)
        self.assertInvalid(editor, ['price'])
        editor.price.update(-1)
        self.assertInvalid(editor, ['price'])
        with mock.patch.object(sellable, 'is_valid_price') as ivp:
            ivp.return_value = {
                'is_valid': False,
                'min_price': decimal.Decimal('10.00'),
                'max_discount': decimal.Decimal('0.00'),
            }
            editor.price.update(1)
            ivp.assert_called_once_with(1, workorder.client.category,
                                        api.get_current_user(self.store))
            self.assertInvalid(editor, ['price'])

        self.assertValid(editor, ['quantity'])
        with mock.patch.object(storable, 'get_balance_for_branch') as gbfb:
            gbfb.return_value = 0
            editor.quantity.update(20)
            # Called 2 times:
            # on_quantity__content_changed() - Is necessary check if the quantity
            # is valid to avoid update the quantity_reserved widget.
            # on_quantity__validate()
            self.assertEqual(gbfb.call_count, 2)
            self.assertInvalid(editor, ['quantity'])

        # Item without stock control.
        product2 = self.create_product()
        item2 = workorder.add_sellable(product2.sellable, quantity=2)
        editor = _WorkOrderItemEditor(self.store, model=item2)
        self.check_editor(editor, 'editor-workorderitem-without-storable-show')
    def test_show_with_sale(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.sale = self.create_sale()
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)

        item = workorder.add_sellable(product.sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-with-sale-show')
Beispiel #6
0
    def test_show_with_sale(self):
        workorder = self.create_workorder(description=u'Test equipment')
        workorder.sale = self.create_sale()
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)

        item = workorder.add_sellable(product.sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-with-sale-show')
Beispiel #7
0
    def test_show(self):
        workorder = self.create_workorder(equipment=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)
        sellable = product.sellable
        storable = product.storable

        item = workorder.add_sellable(sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-show')

        self.assertValid(editor, ['price'])
        editor.price.update(0)
        self.assertInvalid(editor, ['price'])
        editor.price.update(-1)
        self.assertInvalid(editor, ['price'])
        with mock.patch.object(sellable, 'is_valid_price') as ivp:
            ivp.return_value = {
                'is_valid': False,
                'min_price': decimal.Decimal('10.00'),
                'max_discount': decimal.Decimal('0.00'),
            }
            editor.price.update(1)
            ivp.assert_called_once_with(1, workorder.client.category,
                                        api.get_current_user(self.store))
            self.assertInvalid(editor, ['price'])

        self.assertValid(editor, ['quantity'])
        editor.quantity.update(0)
        self.assertInvalid(editor, ['quantity'])
        with mock.patch.object(storable, 'get_balance_for_branch') as gbfb:
            gbfb.return_value = False
            editor.quantity.update(20)
            gbfb.assert_called_once_with(workorder.branch)
            self.assertInvalid(editor, ['quantity'])
        with mock.patch.object(sellable, 'is_valid_quantity') as ivq:
            ivq.return_value = False
            editor.quantity.update(5)
            ivq.assert_called_once_with(5)
            self.assertInvalid(editor, ['quantity'])
Beispiel #8
0
    def testShow(self):
        workorder = self.create_workorder(equipment=u'Test equipment')
        workorder.client = self.create_client()
        workorder.client.category = self.create_client_category()

        product = self.create_product(stock=10)
        sellable = product.sellable
        storable = product.storable

        item = workorder.add_sellable(sellable)
        editor = _WorkOrderItemEditor(self.store, model=item)
        self.check_editor(editor, 'editor-workorderitem-show')

        self.assertValid(editor, ['price'])
        editor.price.update(0)
        self.assertInvalid(editor, ['price'])
        editor.price.update(-1)
        self.assertInvalid(editor, ['price'])
        with mock.patch.object(sellable, 'is_valid_price') as ivp:
            ivp.return_value = False
            editor.price.update(1)
            ivp.assert_called_once_with(1, workorder.client.category)
            self.assertInvalid(editor, ['price'])

        self.assertValid(editor, ['quantity'])
        editor.quantity.update(0)
        self.assertInvalid(editor, ['quantity'])
        with mock.patch.object(storable, 'get_balance_for_branch') as gbfb:
            gbfb.return_value = False
            editor.quantity.update(20)
            gbfb.assert_called_once_with(workorder.branch)
            self.assertInvalid(editor, ['quantity'])
        with mock.patch.object(sellable, 'is_valid_quantity') as ivq:
            ivq.return_value = False
            editor.quantity.update(5)
            ivq.assert_called_once_with(5)
            self.assertInvalid(editor, ['quantity'])