def test_sale_return_invoice_step(self):
        main_branch = get_current_branch(self.store)
        sale = self.create_sale(branch=main_branch)
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order(self.current_user)
        sale.confirm(self.current_user)
        returned_sale = sale.create_sale_return_adapter(
            self.current_branch, self.current_user, self.current_station)
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)
        step = wizard.get_current_step()

        self.check_wizard(wizard, 'wizard-sale-return-invoice-step')
        self.assertNotSensitive(wizard, ['next_button'])

        self.assertInvalid(step, ['reason'])
        step.reason.update(
            "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
            "do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
        self.assertValid(step, ['reason'])
        msg = ('A reversal payment to the client will be created. '
               'You can see it on the Payable Application.')
        self.assertEqual(step.message.get_text(), msg)

        # XXX: changed because invoice_number is no longer mandatory
        self.assertSensitive(wizard, ['next_button'])
Beispiel #2
0
    def test_sale_return_invoice_step_with_credit(self):
        sale = self.create_sale()
        self.add_product(sale)
        payment, = self.add_payments(sale)
        sale.order(self.current_user)
        sale.confirm(self.current_user)
        returned_sale = sale.create_sale_return_adapter(self.current_branch, self.current_user,
                                                        self.current_station)
        returned_sale.reason = u"Reason"
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)

        invoice_step = wizard.get_current_step()
        invoice_step.credit.set_active(True)
        self.check_wizard(wizard, 'wizard-sale-return-invoice-step-with-credit')
    def test_create(self):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order(self.current_user)
        sale.confirm(self.current_user)
        returned_sale = sale.create_sale_return_adapter(
            self.current_branch, self.current_user, self.current_station)
        SaleReturnWizard(self.store, returned_sale)

        for item in returned_sale.returned_items:
            self.assertTrue(item.will_return)
            self.assertEqual(item.quantity, item.max_quantity)
Beispiel #4
0
    def test_finish(self, print_report, yesno):
        sale = self.create_sale()
        self.add_product(sale)
        payment, = self.add_payments(sale)
        sale.order(self.current_user)
        sale.confirm(self.current_user)
        returned_sale = sale.create_sale_return_adapter(self.current_branch, self.current_user,
                                                        self.current_station)
        returned_sale.reason = u"Reason"
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)
        step = wizard.get_current_step()

        module = 'stoq.lib.gui.events.SaleReturnWizardFinishEvent.emit'
        with mock.patch(module):
            step.reason = "123"
            step.credit.set_active(True)
            with mock.patch.object(self.store, 'commit'):
                self.click(wizard.next_button)
            yesno.assert_called_once_with('Would you like to print the credit letter?',
                                          Gtk.ResponseType.YES,
                                          'Print Letter', "Don't print")
            print_report.assert_called_once_with(ClientCreditReport, sale.client)
    def test_sale_return_items_step(self):
        sale = self.create_sale()
        package = self.create_product(description=u'Package', is_package=True)
        component = self.create_product(description=u'Component',
                                        stock=5,
                                        storable=True)
        p_comp = self.create_product_component(product=package,
                                               component=component,
                                               component_quantity=5,
                                               price=2)

        self.add_product(sale, code=u'1234')
        self.add_product(sale, quantity=2, code=u'5678')
        package_item = sale.add_sellable(package.sellable)
        package_qty = package_item.quantity
        sale.add_sellable(component.sellable,
                          quantity=package_qty * p_comp.quantity,
                          price=package_qty * p_comp.price,
                          parent=package_item)
        self.add_payments(sale)
        sale.order(self.current_user)
        sale.confirm(self.current_user)
        returned_sale = sale.create_sale_return_adapter(
            self.current_branch, self.current_user, self.current_station)

        wizard = SaleReturnWizard(self.store, returned_sale)
        step = wizard.get_current_step()
        objecttree = step.slave.klist

        def _reset_objectlist(objecttree):
            for item in objecttree:
                item.quantity = item.max_quantity
                item.will_return = bool(item.quantity)
                objecttree.update(item)

        self.check_wizard(wizard, 'wizard-sale-return-items-step')
        self.assertSensitive(wizard, ['next_button'])

        # If we don't have anything marked as will_return, wizard's
        # next_button should not be sensiive.
        for item in objecttree:
            item.will_return = False
            objecttree.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

        _reset_objectlist(objecttree)
        step.force_validation()
        self.assertSensitive(wizard, ['next_button'])

        # If we don't have a quantity to return of anything, wizard's
        # next_button should not be sensiive.
        for item in objecttree:
            item.quantity = 0
            objecttree.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

        _reset_objectlist(objecttree)
        step.force_validation()
        self.assertSensitive(wizard, ['next_button'])

        for item in objecttree:
            item.quantity = item.max_quantity + 1
            # If anything is marked to return with more than max_quantity
            # wizard's next_button should not be sensitive
            step.force_validation()
            self.assertNotSensitive(wizard, ['next_button'])
            _reset_objectlist(objecttree)

        quantity_col = objecttree.get_column_by_name('quantity')
        will_return_col = objecttree.get_column_by_name('will_return')
        _reset_objectlist(objecttree)
        # None of the siblings are being returned, so the parent will be
        # unchecked
        for item in objecttree:
            if item.parent_item:
                item.quantity = 0
                objecttree.emit('cell-edited', item, quantity_col)
                self.assertFalse(item.parent_item.will_return)

        _reset_objectlist(objecttree)
        # Return all siblings, so return its parent as well
        for item in objecttree:
            if item.parent_item:
                item.quantity = 5
                objecttree.emit('cell-edited', item, quantity_col)
                self.assertTrue(item.parent_item.will_return)

        _reset_objectlist(objecttree)
        for item in objecttree:
            if item.parent_item:
                item.will_return = True
                objecttree.emit('cell-edited', item, will_return_col)
                self.assertTrue(item.parent_item.will_return)

        _reset_objectlist(objecttree)
        for item in objecttree:
            if item.parent_item:
                item.will_return = False
                objecttree.emit('cell-edited', item, will_return_col)
                self.assertFalse(item.parent_item.will_return)