Exemplo n.º 1
0
    def test_merchandise_table_with_minimum_subset(self):
        offer = Offer()
        offer.merchandise_list = MerchandiseListModel(offer)
        offer.merchandise_list.add_item(create_merch())

        merchandise_table = offer.merchanidse_table(
            PrintOptions(False, True, False, False, False, False, False, True))

        expected_merchandise_table = """
    <table cellspacing=0>
        <thead><tr class="header">
            <td width=655 align=left><b>Towar</b></td>
            <td width=90 align=right><b>Wartość</b></td>
        </tr></thead>

        <tr class="row1">
            <td>CODE</td>
            <td align=right>8.99 zł</td>
        </tr>

        <tr style="font-weight:bold;">
            <td align=right colspan=1>Razem:</td>
            <td align=right>8.99 zł</td>
        </tr>
    </table>
"""
        assert_that(
            merchandise_table,
            is_(equal_to_ignoring_whitespace(expected_merchandise_table)))
Exemplo n.º 2
0
    def test_remove_row(self, qtbot, active_window, rows, expected):
        m1 = create_merch(1)
        m2 = create_merch(2)
        active_window.offer.merchandise_list.change_item_count(m1)
        active_window.offer.merchandise_list.change_item_count(m2)

        for row in rows:
            x = active_window.ui.tableView.columnViewportPosition(1) + 5
            y = active_window.ui.tableView.rowViewportPosition(row) + 5
            qtbot.mouseClick(active_window.ui.tableView.viewport(),
                             Qt.LeftButton, Qt.NoModifier, QPoint(x, y))
            qtbot.mouseClick(active_window.ui.push_button_remove_row,
                             Qt.LeftButton)

        merch_list = {
            "none": [],
            "first": [m1],
            "second": [m2],
            "both": [m1, m2],
        }
        expected_merch_list = merch_list[expected]
        if expected_merch_list:
            assert_that(active_window.offer.merchandise_list.list,
                        contains_exactly(*expected_merch_list))
        else:
            assert_that(active_window.offer.merchandise_list.list,
                        is_(empty()))

        expected_item_count = len(expected_merch_list)
        assert_that(active_window.ui.tableView.model().rowCount(),
                    is_(expected_item_count + 1))

        total = {
            "none": "0.00",
            "first": "8.99",
            "second": "8.99",
            "both": "17.98",
        }
        expected_grand_total = total[expected]
        x = active_window.ui.tableView.columnViewportPosition(7) + 5
        y = active_window.ui.tableView.rowViewportPosition(
            expected_item_count) + 5
        grand_total = active_window.ui.tableView.indexAt(QPoint(x, y)).data(
            Qt.DisplayRole)
        assert_that(grand_total, is_(expected_grand_total))
Exemplo n.º 3
0
    def test_select_2_merchandise(self, mocker, active_window):
        m1 = create_merch(1)
        m2 = create_merch(2)

        dialog = mocker.patch("src.main_window.MerchandiseSelectionDialog",
                              autospec=True)
        dialog.make.return_value = dialog
        dialog.exec_.return_value = QDialog.Accepted
        dialog.selected = {m1.id: m1, m2.id: m2}

        active_window.select_merchandise()

        dialog.make.assert_called_once_with(active_window)
        dialog.exec_.assert_called_once()
        active_window.offer.merchandise_list.change_item_count.assert_any_call(
            m1)
        active_window.offer.merchandise_list.change_item_count.assert_any_call(
            m2)
        assert_that(
            active_window.offer.merchandise_list.change_item_count.call_count,
            is_(2))
Exemplo n.º 4
0
    def test_merchandise_table_with_all_columns(self):
        offer = Offer()
        offer.merchandise_list = MerchandiseListModel(offer)
        offer.merchandise_list.add_item(create_merch())

        merchandise_table = offer.merchanidse_table()

        expected_merchandise_table = """
    <table cellspacing=0>
        <thead><tr class="header">
            <td width=40 align=left><b>Lp.</b></td>
            <td width=285 align=left><b>Towar</b></td>
            <td width=90 align=right><b>Cena kat.</b></td>
            <td width=75 align=right><b>Rabat</b></td>
            <td width=90 align=right><b>Cena</b></td>
            <td width=75 align=right><b>Ilość</b></td>
            <td width=90 align=right><b>Wartość</b></td>
        </tr></thead>

        <tr class="row1">
            <td align=right style="padding-right: 5">1</td>
            <td>CODE</td>
            <td align=right>9.99 zł</td>
            <td align=right>10.0%</td>
            <td align=right>8.99 zł</td>
            <td align=right>1 szt.</td>
            <td align=right>8.99 zł</td>
        </tr>
        <tr class="row1 spec">
            <td></td>
            <td colspan=6>DESCR</td>
        </tr>

        <tr style="font-weight:bold;">
            <td align=right colspan=6>Razem:</td>
            <td align=right>8.99 zł</td>
        </tr>
    </table>
"""
        assert_that(
            merchandise_table,
            is_(equal_to_ignoring_whitespace(expected_merchandise_table)))
Exemplo n.º 5
0
    def test_merchandise_table_without_list_price_and_discount(self):
        offer = Offer()
        offer.merchandise_list = MerchandiseListModel(offer)
        offer.merchandise_list.add_item(create_merch())

        merchandise_table = offer.merchanidse_table(
            PrintOptions(print_list_price=False, print_discount=False))

        expected_merchandise_table = """
    <table cellspacing=0>
        <thead><tr class="header">
            <td width=40 align=left><b>Lp.</b></td>
            <td width=450 align=left><b>Towar</b></td>
            <td width=90 align=right><b>Cena</b></td>
            <td width=75 align=right><b>Ilość</b></td>
            <td width=90 align=right><b>Wartość</b></td>
        </tr></thead>

        <tr class="row1">
            <td align=right style="padding-right: 5">1</td>
            <td>CODE</td>
            <td align=right>8.99 zł</td>
            <td align=right>1 szt.</td>
            <td align=right>8.99 zł</td>
        </tr>
        <tr class="row1 spec">
            <td></td>
            <td colspan=4>DESCR</td>
        </tr>

        <tr style="font-weight:bold;">
            <td align=right colspan=4>Razem:</td>
            <td align=right>8.99 zł</td>
        </tr>
    </table>
"""
        assert_that(
            merchandise_table,
            is_(equal_to_ignoring_whitespace(expected_merchandise_table)))
Exemplo n.º 6
0
    def test_whole_printout(self, mocker):
        expected_date = date(2020, 12, 15)
        mock_date = mocker.patch("src.offer.date", autospec=True)
        mock_date.today.return_value = expected_date

        vars = {"order email": "*****@*****.**", "HQ": "lorem<br />ipsum"}
        mocker.patch("src.offer.get_var",
                     autospce=True,
                     side_effect=lambda key: vars[key])

        expected_symbol = "X2012N08"
        user = mocker.create_autospec(User(), spec_set=True)
        user.new_offer_symbol.return_value = expected_symbol
        user.name = "Author Name"
        user.mail = "*****@*****.**"
        user.gender_suffix = "a"
        user.phone = "123 456 789"

        offer = Offer.create_empty(user)

        customer = mocker.create_autospec(Customer(), spec_set=True)
        customer.id = 1
        customer.company_name = "Full business name"
        customer.concated_name = "Mr John Doe"
        customer.html_address = "255 Some street<br />\nIn some town"
        offer.customer = customer

        offer.merchandise_list.add_item(create_merch())
        offer.remarks = "Some remarks"

        expected_document = """<html>
<head>
<title>Oferta</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<style>
    .spec { font-size: 6pt; }
    .row0 { background: #efefef; }
    .row1 { background: #dadada; }
</style>
</head>
<body>
<table>
<thead>
<tr><td>
    <table>
    <tr>
        <td valign=top width=315>
            Oferta nr: <b>X2012N08</b><br />
            Z dnia: 15.12.2020<br />
            Dla:<br />
            <b>Full business name</b><br />
            255 Some street<br />
In some town<br />
            Mr John Doe
        </td>
        <td width=315>
            lorem<br />ipsum<br />
            <b>Author Name</b><br />
            [email protected]<br />
            Tel.: 123 456 789
        </td>
        <td width=115 align=right>
            <img src=:/logos width=114 valign=top>
        </td>
    </tr>
    <tr>
        <td colspan=3>
            <hr width=100%>
        </td>
    </tr>
    </table>
</td></tr>
</thead>
<tbody>
<tr><td>
    W odpowiedzi na zapytanie, przedstawiamy ofertę na dostawę następujących produktów:
</td></tr>
<tr><td>
    
    <table cellspacing=0>
        <thead><tr class="header">
            <td width=40 align=left><b>Lp.</b></td>
            <td width=285 align=left><b>Towar</b></td>
            <td width=90 align=right><b>Cena kat.</b></td>
            <td width=75 align=right><b>Rabat</b></td>
            <td width=90 align=right><b>Cena</b></td>
            <td width=75 align=right><b>Ilość</b></td>
            <td width=90 align=right><b>Wartość</b></td>
        </tr></thead>

        <tr class="row1">
            <td align=right style="padding-right: 5">1</td>
            <td>CODE</td>
            <td align=right>9.99 zł</td>
            <td align=right>10.0%</td>
            <td align=right>8.99 zł</td>
            <td align=right>1 szt.</td>
            <td align=right>8.99 zł</td>
        </tr>
        <tr class="row1 spec">
            <td></td>
            <td colspan=6>DESCR</td>
        </tr>

        <tr style="font-weight:bold;">
            <td align=right colspan=6>Razem:</td>
            <td align=right>8.99 zł</td>
        </tr>
    </table>

</td></tr>
<tr><td>
    Podane ceny nie zawierają podatku VAT<br />
</td></tr>
<tr><td>
<table cellspacing=3>
    <tr>
        <td width=140>Uwagi:</td>
        <td width=602>Some remarks</td>
    </tr>
</table>

</td></tr>
<tr><td>
    <p>
    <b>Zamówienia prosimy kierować na adres:</b> [email protected] z kopią do autora oferty.<br />
    <br />
    Łączymy pozdrowienia.
    </p>
    <p align=center style="margin-left: 500">
        Ofertę przygotowała<br /><br /><br />
        Author Name
    </p>
</td></tr>
</tbody>
</table>
</body>
</html>
"""

        document = offer.printout()
        assert_that(document,
                    is_(equal_to_ignoring_whitespace(expected_document)))