Exemplo n.º 1
0
    def test_sale_return_payment_step_partially_paid(self, info):
        sale = self.create_sale()
        sale.identifier = 1234
        self.add_product(sale, price=50, quantity=6)
        payments = self.add_payments(sale, method_type=u'check', installments=3,
                                     date=localdate(2012, 1, 1).date())
        sale.order()
        sale.confirm()
        payments[0].pay()
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.reason = u'reason'
        returned_sale.invoice.invoice_number = 1
        list(returned_sale.returned_items)[0].quantity = 1
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)
        self.click(wizard.next_button)
        step = wizard.get_current_step()

        info.assert_called_once_with(
            ("The client's debt has changed. "
             "Use this step to adjust the payments."),
            ("The debt before was $200.00 and now is $150.00. "
             "Cancel some unpaid installments and create new ones."))
        self.assertVisible(step.slave, ['remove_button'])
        self.assertEqual(step.slave.total_value.read(),
                         returned_sale.total_amount_abs +
                         returned_sale.paid_total)
        self.check_wizard(wizard,
                          'wizard-sale-return-payment-step-partially-paid')
Exemplo n.º 2
0
    def test_sale_return_payment_step_partially_paid(self, info):
        sale = self.create_sale()
        sale.identifier = 1234
        self.add_product(sale, price=50, quantity=6)
        payments = self.add_payments(sale, method_type=u'check', installments=3,
                                     date=localdate(2012, 1, 1).date())
        sale.order()
        sale.confirm()
        payments[0].pay()
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.reason = u'reason'
        returned_sale.invoice_number = 1
        list(returned_sale.returned_items)[0].quantity = 1
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)
        self.click(wizard.next_button)
        step = wizard.get_current_step()

        info.assert_called_once_with(
            ("The client's debt has changed. "
             "Use this step to adjust the payments."),
            ("The debt before was $200.00 and now is $150.00. "
             "Cancel some unpaid installments and create new ones."))
        self.assertVisible(step.slave, ['remove_button'])
        self.assertEqual(step.slave.total_value.read(),
                         returned_sale.total_amount_abs +
                         returned_sale.paid_total)
        self.check_wizard(wizard,
                          'wizard-sale-return-payment-step-partially-paid')
Exemplo n.º 3
0
    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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])
Exemplo n.º 4
0
    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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])
Exemplo n.º 5
0
    def test_sale_return_items_step(self, info):
        sale = self.create_sale()
        package = self.create_product(description=u'Package', is_package=True)
        component = self.create_product(description=u'Component', stock=3)
        self.create_product_component(product=package, component=component)

        self.add_product(sale, code=u'1234')
        self.add_product(sale, quantity=2, code=u'5678')
        package_item = sale.add_sellable(package.sellable)
        sale.add_sellable(component.sellable, parent=package_item, price=0)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()

        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)
Exemplo n.º 6
0
    def testSaleReturnItemsStep(self, info):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        wizard = SaleReturnWizard(self.store, returned_sale)
        step = wizard.get_current_step()
        objectlist = step.slave.klist

        def _reset_objectlist(objectlist):
            for item in objectlist:
                item.quantity = item.max_quantity
                item.will_return = bool(item.quantity)
                objectlist.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 objectlist:
            item.will_return = False
            objectlist.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

        _reset_objectlist(objectlist)
        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 objectlist:
            item.quantity = 0
            objectlist.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

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

        for item in objectlist:
            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(objectlist)
Exemplo n.º 7
0
    def testSaleReturnItemsStep(self, info):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        wizard = SaleReturnWizard(self.store, returned_sale)
        step = wizard.get_current_step()
        objectlist = step.slave.klist

        def _reset_objectlist(objectlist):
            for item in objectlist:
                item.quantity = item.max_quantity
                item.will_return = bool(item.quantity)
                objectlist.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 objectlist:
            item.will_return = False
            objectlist.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

        _reset_objectlist(objectlist)
        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 objectlist:
            item.quantity = 0
            objectlist.update(item)
        step.force_validation()
        self.assertNotSensitive(wizard, ['next_button'])

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

        for item in objectlist:
            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(objectlist)
Exemplo n.º 8
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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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')
Exemplo n.º 9
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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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')
Exemplo n.º 10
0
    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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])

        # XXX: changed because invoice_number is no longer mandatory
        self.assertSensitive(wizard, ['next_button'])

        step.invoice_number.update(0)
        self.assertInvalid(step, ['invoice_number'])
        step.invoice_number.update(1000000000)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        # Check if the invoice number already exists in Invoice table
        invoice = Invoice(invoice_type=Invoice.TYPE_OUT, branch=main_branch)
        invoice.invoice_number = 123
        step.invoice_number.update(123)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        step.invoice_number.update(1)
        self.assertValid(step, ['invoice_number'])
        invoice.branch = self.create_branch()
        step.invoice_number.update(123)
        self.assertValid(step, ['invoice_number'])
        self.assertSensitive(wizard, ['next_button'])
Exemplo n.º 11
0
    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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])

        # XXX: changed because invoice_number is no longer mandatory
        self.assertSensitive(wizard, ['next_button'])

        step.invoice_number.update(0)
        self.assertInvalid(step, ['invoice_number'])
        step.invoice_number.update(1000000000)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        # Check if the invoice number already exists in Invoice table
        invoice = Invoice(invoice_type=Invoice.TYPE_OUT, branch=main_branch)
        invoice.invoice_number = 123
        step.invoice_number.update(123)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        step.invoice_number.update(1)
        self.assertValid(step, ['invoice_number'])
        invoice.branch = self.create_branch()
        step.invoice_number.update(123)
        self.assertValid(step, ['invoice_number'])
        self.assertSensitive(wizard, ['next_button'])
Exemplo n.º 12
0
    def testSaleReturnInvoiceStep(self):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])
        self.assertNotSensitive(wizard, ['next_button'])

        self.assertInvalid(step, ['invoice_number'])
        step.invoice_number.update(0)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])
        step.invoice_number.update(1000000000)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        module = 'stoqlib.domain.base.Domain.check_unique_value_exists'
        with mock.patch(module) as check_unique_value_exists:
            check_unique_value_exists.return_value = True
            step.invoice_number.update(2)
            self.assertInvalid(step, ['invoice_number'])
            self.assertNotSensitive(wizard, ['next_button'])

        step.invoice_number.update(1)
        self.assertValid(step, ['invoice_number'])
        self.assertSensitive(wizard, ['next_button'])
Exemplo n.º 13
0
    def testSaleReturnInvoiceStep(self):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        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'])
        self.assertNotSensitive(wizard, ['next_button'])

        self.assertInvalid(step, ['invoice_number'])
        step.invoice_number.update(0)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])
        step.invoice_number.update(1000000000)
        self.assertInvalid(step, ['invoice_number'])
        self.assertNotSensitive(wizard, ['next_button'])

        module = 'stoqlib.domain.base.Domain.check_unique_value_exists'
        with mock.patch(module) as check_unique_value_exists:
            check_unique_value_exists.return_value = True
            step.invoice_number.update(2)
            self.assertInvalid(step, ['invoice_number'])
            self.assertNotSensitive(wizard, ['next_button'])

        step.invoice_number.update(1)
        self.assertValid(step, ['invoice_number'])
        self.assertSensitive(wizard, ['next_button'])
Exemplo n.º 14
0
    def test_create(self):
        sale = self.create_sale()
        self.add_product(sale)
        self.add_product(sale, quantity=2)
        self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        SaleReturnWizard(self.store, returned_sale)

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

        module = 'stoqlib.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)
Exemplo n.º 16
0
    def test_finish(self, print_report, yesno):
        sale = self.create_sale()
        self.add_product(sale)
        payment, = self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.reason = u"Reason"
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)
        step = wizard.get_current_step()

        module = 'stoqlib.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)
Exemplo n.º 17
0
    def testFinishWithReversalPayment(self, info):
        sale = self.create_sale()
        self.add_product(sale)
        payment, = self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.invoice_number = 123456
        returned_sale.reason = u"Reason"
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)

        module = 'stoqlib.gui.events.SaleReturnWizardFinishEvent.emit'
        with mock.patch(module) as emit:
            self.click(wizard.next_button)
            info.assert_called_once_with(
                "A reversal payment to the client will be created. "
                "You can see it on the Payable Application.")
            emit.assert_called_once_with(returned_sale)
Exemplo n.º 18
0
    def testFinishWithGroupCancelling(self, info):
        sale = self.create_sale()
        self.add_product(sale)
        payment, = self.add_payments(sale)
        sale.order()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()
        returned_sale.invoice_number = 123456
        returned_sale.reason = u"Reason"
        wizard = SaleReturnWizard(self.store, returned_sale)
        self.click(wizard.next_button)

        module = 'stoqlib.gui.events.SaleReturnWizardFinishEvent.emit'
        with mock.patch(module) as emit:
            # Cancel the payment, so returned_sale.total_amount will be 0
            payment.cancel()
            self.click(wizard.next_button)
            info.assert_called_once_with(
                "The client does not have a debt to this sale anymore. "
                "Any existing unpaid installment will be cancelled.")
            emit.assert_called_once_with(returned_sale)
Exemplo n.º 19
0
    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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()

        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)
Exemplo n.º 20
0
    def test_sale_return_items_step(self, info):
        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()
        sale.confirm()
        returned_sale = sale.create_sale_return_adapter()

        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)

        _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')
                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')
                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')
                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')
                self.assertFalse(item.parent_item.will_return)