コード例 #1
0
ファイル: test_sale_wizard.py プロジェクト: Sts0mrg0/stoq
    def test_queries(self):
        sale = self.create_sale()
        sale.identifier = 12345
        self.add_product(sale, price=10)

        self.sale = sale
        total = sale.get_total_sale_amount()

        with self.count_tracer() as tracer:
            self.wizard = ConfirmSaleWizard(self.store,
                                            sale,
                                            subtotal=total,
                                            total_paid=0)

        # NOTE: Document increases/decreases
        # 3: select user/branch/station (normally cached)
        # 1: select sales_person
        # 1: select transporter
        # 1: select cost cebnter
        # 1: select payment method
        # 4: select sale_item
        #  - one is need_adjust_batches
        # 1: select payment status
        # 1: select the branch acronym for sale repr()
        self.assertEqual(tracer.count, 13)
コード例 #2
0
ファイル: test_sale_wizard.py プロジェクト: tmaxter/stoq
    def testQueries(self):
        sale = self.create_sale()
        sale.identifier = 12345
        self.add_product(sale, price=10)

        self.sale = sale
        total = sale.get_total_sale_amount()

        with self.count_tracer() as tracer:
            self.wizard = ConfirmSaleWizard(self.store, sale,
                                            subtotal=total,
                                            total_paid=0)

        # NOTE: Document increases/decreases
        # 3: select user/branch/station (normally cached)
        # 1: select sales_person
        # 4: select parameters
        # 1: select client
        # 1: select transporter
        # 1: select cost cebnter
        # 2: select invoice number
        # 1: select payment method
        # 2: select sale_item
        # 1: select payment status
        self.assertEquals(tracer.count, 17)
コード例 #3
0
ファイル: test_sale_wizard.py プロジェクト: Sts0mrg0/stoq
    def test_update_widgets(self):
        client1 = self.create_client(name=u'Client01')
        client2 = self.create_client(name=u'Client02')
        client1.credit_limit = 1000
        sale_item = self.create_sale_item()
        subtotal = sale_item.sale.get_sale_subtotal()
        wizard = ConfirmSaleWizard(store=self.store,
                                   model=sale_item.sale,
                                   subtotal=subtotal,
                                   total_paid=0)
        salespersonstep = wizard._first_step

        # Right now, there should be no client selected and the methods store
        # credit and credit should be disabled
        self.check_wizard(wizard=wizard,
                          ui_test_name='wizard-sales-person-step')

        # After selecting the client1, the option store credit should be available
        salespersonstep.client_gadget.set_value(client1)
        self.check_wizard(
            wizard=wizard,
            ui_test_name='wizard-sales-person-step-with-store-credit-radio')

        # selecting the client2 should disable the store credit again.
        salespersonstep.client_gadget.set_value(client2)
        self.check_wizard(
            wizard=wizard,
            ui_test_name='wizard-sales-person-step-without-store-credit-radio')

        # De-selecting the client should not break, and also disable the methods
        # IE, they should be just like when the dialog was opened
        salespersonstep.client_gadget.set_value(None)
        self.check_wizard(wizard=wizard,
                          ui_test_name='wizard-sales-person-step-client-none')
コード例 #4
0
    def test_create(self):
        sale = self._create_sale()
        subtotal = sale.get_sale_subtotal()

        wizard = ConfirmSaleWizard(self.store, sale, subtotal)
        slave = MultipleMethodSlave(wizard, None, self.store, sale)
        self.check_slave(slave, 'slave-multiple-method')
コード例 #5
0
    def test_on_method_toggled(self):
        sale = self._create_sale()
        subtotal = sale.get_sale_subtotal()

        wizard = ConfirmSaleWizard(self.store, sale, subtotal)
        slave = MultipleMethodSlave(wizard, None, self.store, sale)

        self.assertEquals(slave.value.read(), 10)
        self.assertEquals(unicode(slave.value.emit("validate", 0)),
                          u"You must provide a payment value.")
        self.assertNotSensitive(slave, ['add_button'])

        # Test with an invalid value.
        slave.value.set_text("Test")
        self.assertNotSensitive(slave, ['add_button'])
        for radio in slave.methods_box.get_children():
            if radio.get_label() == 'Check':
                radio.set_active(True)
                break
        # Check if value was updated.
        self.assertEquals(slave.value.read(), 10)
        self.assertSensitive(slave, ['add_button'])

        # Test with store credit.
        for radio in slave.methods_box.get_children():
            if radio.get_label() == 'Store Credit':
                radio.set_active(True)
                break
        self.assertEquals(slave.value.read(), 10)
        self.assertSensitive(slave, ['add_button'])
        self.assertEquals(
            unicode(slave.value.emit("validate", 30)),
            u"Client does not have enough credit. Client store credit: 20.0.")
        self.assertNotSensitive(slave, ['add_button'])
        slave.value.update(10)
        self.assertSensitive(slave, ['add_button'])

        # Change the payment method.
        for radio in slave.methods_box.get_children():
            if radio.get_label() == 'Bill':
                radio.set_active(True)
                break
        self.assertEquals(slave.value.read(), 10)
        self.assertSensitive(slave, ['add_button'])

        # Change to money.
        slave.value.update(5)
        self.assertSensitive(slave, ['add_button'])
        for radio in slave.methods_box.get_children():
            if radio.get_label() == 'Money':
                radio.set_active(True)
                break
        # Check if the value typed was kept.
        self.assertEquals(slave.value.read(), 5)
        self.assertSensitive(slave, ['add_button'])
コード例 #6
0
ファイル: test_sale_wizard.py プロジェクト: tmaxter/stoq
    def _create_wizard(self, sale=None, total_paid=0):
        if not sale:
            # Create a sale and the wizard that will be used in where
            sale = self.create_sale()
            sale.identifier = 12345
            self.add_product(sale, price=10)

        self.sale = sale
        self.wizard = ConfirmSaleWizard(self.store, sale,
                                        subtotal=sale.get_total_sale_amount(),
                                        total_paid=total_paid)
        self.step = self.wizard.get_current_step()
コード例 #7
0
 def test_on_auth_number_validate(self):
     sellable = self.create_sellable(price=100)
     sale = self.create_sale()
     sale.add_sellable(sellable)
     subtotal = sale.get_sale_subtotal()
     wizard = ConfirmSaleWizard(self.store, sale, subtotal)
     method = PaymentMethod.get_by_name(self.store, u'card')
     slave = CardMethodSlave(wizard, None, self.store, sale, method)
     slave.auth_number.update(1234567)
     self.assertEquals(str(slave.auth_number.emit("validate", 1234567)),
                       "Authorization number must have 6 digits or less.")
     self.assertNotSensitive(wizard, ['next_button'])
     slave.auth_number.update(123456)
     self.assertSensitive(wizard, ['next_button'])
コード例 #8
0
ファイル: test_sale_wizard.py プロジェクト: 5l1v3r1/stoq-1
    def test_finish_with_unaivable_items(self, warning):
        sale = self.create_sale()
        sale.identifier = 1234
        sellable = self.create_sellable()
        self.create_sale_item(sale, sellable=sellable)
        sellable.status = Sellable.STATUS_CLOSED

        self.wizard = ConfirmSaleWizard(self.store, sale,
                                        subtotal=sale.get_total_sale_amount(),
                                        total_paid=0)
        self.step = self.wizard.get_current_step()
        self.assertEqual(sale.status, Sale.STATUS_ORDERED)
        with contextlib.nested(mock.patch.object(self.store, 'commit'),
                               mock.patch.object(self.wizard, 'close')) as (commit, close):
            self._go_to_next()
            self.assertEqual(close.call_count, 1)
            message = ("Description is not available for sale. Try making it "
                       "available first or change it on sale and then try again.")
            warning.assert_called_once_with(message)
            self.assertEqual(sale.status, Sale.STATUS_ORDERED)
コード例 #9
0
ファイル: test_sale_wizard.py プロジェクト: tmaxter/stoq
    def testSaleToClientWithLatePayments(self, yesno, print_report):
        #: this parameter allows a client to buy even if he has late payments
        sysparam(self.store).update_parameter(u'LATE_PAYMENTS_POLICY',
                                              unicode(int(LatePaymentPolicy.ALLOW_SALES)))

        sale = self.create_sale()
        sale.identifier = 12345
        self.add_product(sale)
        sale.client = self.create_client()
        wizard = ConfirmSaleWizard(self.store, sale, sale.get_total_sale_amount())
        step = wizard.get_current_step()

        money_method = PaymentMethod.get_by_name(self.store, u'money')
        today = localtoday().date()

        sale.client.credit_limit = currency('90000000000')
        step.pm_slave.select_method(u'money')

        # checks if a client can buy normally
        self.assertTrue(wizard.next_button.props.sensitive)

        # checks if a client with late payments can buy
        payment = self.create_payment(Payment.TYPE_IN,
                                      today - relativedelta(days=1),
                                      method=money_method)
        payment.status = Payment.STATUS_PENDING
        payment.group = self.create_payment_group()
        payment.group.payer = sale.client.person

        step.pm_slave.select_method('bill')
        self.assertTrue(wizard.next_button.props.sensitive)

        step.pm_slave.select_method(u'store_credit')
        self.assertTrue(wizard.next_button.props.sensitive)

        #: this parameter disallows a client with late payments to buy with
        #: store credit
        sysparam(self.store).update_parameter(
            u'LATE_PAYMENTS_POLICY',
            unicode(int(LatePaymentPolicy.DISALLOW_STORE_CREDIT)))

        # checks if a client can buy normally
        payment.due_date = today
        self.assertEquals(step.client.emit('validate', sale.client), None)
        self.assertTrue(wizard.next_button.props.sensitive)

        # checks if a client with late payments can buy with money method
        step.pm_slave.select_method(u'money')
        payment.due_date = today - relativedelta(days=3)
        self.assertEquals(step.client.emit('validate', sale.client), None)
        self.assertTrue(wizard.next_button.props.sensitive)

        # checks if a client with late payments can buy with store credit
        step.pm_slave.select_method(u'store_credit')
        self.assertEquals(
            unicode(step.client.emit('validate', sale.client)),
            u'It is not possible to sell with store credit for clients with '
            'late payments.')
        # self.assertFalse(wizard.next_button.props.sensitive)
        step.client.validate(force=True)
        # FIXME: This is not updating correcly
        # self.assertNotSensitive(wizard, ['next_button'])

        #: this parameter disallows a client with late payments to buy with
        #: store credit
        sysparam(self.store).update_parameter(
            u'LATE_PAYMENTS_POLICY',
            unicode(int(LatePaymentPolicy.DISALLOW_SALES)))

        # checks if a client can buy normally
        payment.due_date = today
        self.assertEquals(step.client.emit('validate', sale.client), None)

        # checks if a client with late payments can buy
        payment.due_date = today - relativedelta(days=3)

        step.pm_slave.select_method(u'store_credit')
        self.assertEquals(
            unicode(step.client.emit('validate', sale.client)),
            u'It is not possible to sell for clients with late payments.')

        step.pm_slave.select_method('check')
        self.assertEquals(
            unicode(step.client.emit('validate', sale.client)),
            u'It is not possible to sell for clients with late payments.')

        step.pm_slave.select_method(u'store_credit')
        sysparam(self.store).update_parameter(
            u'LATE_PAYMENTS_POLICY',
            unicode(int(LatePaymentPolicy.ALLOW_SALES)))

        sale.client.credit_limit = currency("9000")
        # Force validation since we changed the credit limit.
        step.client.validate(force=True)

        self.click(wizard.next_button)

        # finish wizard
        self.click(wizard.next_button)

        self.assertEquals(sale.payments[0].method.method_name, u'store_credit')

        yesno.assert_called_once_with(
            'Do you want to print the booklets for this sale?',
            gtk.RESPONSE_YES, 'Print booklets', "Don't print")

        print_report.assert_called_once_with(BookletReport,
                                             list(sale.group.get_payments_by_method_name(u'store_credit')))