def test_cancel(self):
        rsale = self.create_pending_returned_sale()
        rsale.status = ReturnedSale.STATUS_CONFIRMED
        dialog = ReturnedSaleUndoDialog(self.store, rsale)

        self.assertFalse(rsale.is_undone())
        self.click(dialog.main_dialog.cancel_button)
        self.assertFalse(rsale.is_undone())
    def test_show(self):
        rsale = self.create_pending_returned_sale()
        rsale.sale.identifier = 336
        rsale.identifier = 60
        rsale.status = ReturnedSale.STATUS_CONFIRMED
        rsale.reason = u'Teste'

        dialog = ReturnedSaleUndoDialog(self.store, rsale)
        self.check_dialog(dialog, 'dialog-returned-sale-undo')
    def test_undo(self):
        rsale = self.create_pending_returned_sale()
        rsale.status = ReturnedSale.STATUS_CONFIRMED
        dialog = ReturnedSaleUndoDialog(self.store, rsale)

        self.assertNotSensitive(dialog.main_dialog, ['ok_button'])
        dialog.undo_reason.update('foo')
        self.assertSensitive(dialog.main_dialog, ['ok_button'])

        self.assertFalse(rsale.is_undone())
        self.click(dialog.main_dialog.ok_button)
        self.assertTrue(rsale.is_undone())
    def test_undo_without_stock(self, warning):
        product = self.create_product(storable=True)

        rsale = self.create_pending_returned_sale(product=product)
        rsale.status = ReturnedSale.STATUS_CONFIRMED

        dialog = ReturnedSaleUndoDialog(self.store, rsale)

        self.assertNotSensitive(dialog.main_dialog, ['ok_button'])
        dialog.undo_reason.update('foo')
        self.assertSensitive(dialog.main_dialog, ['ok_button'])

        self.assertFalse(rsale.is_undone())
        self.click(dialog.main_dialog.ok_button)
        self.assertFalse(rsale.is_undone())

        warning.assert_called_once_with(
            'It was not possible to undo this returned sale. Some of the '
            'returned products are out of stock.')