Exemplo n.º 1
0
 def _setup_slaves(self):
     self.slave = MultipleMethodSlave(self.wizard,
                                      self,
                                      self.store,
                                      self.store.fetch(self._consignment),
                                      None,
                                      self._outstanding_value,
                                      finish_on_total=False)
     self.attach_slave('place_holder', self.slave)
Exemplo n.º 2
0
 def setup_slaves(self):
     register_payment_slaves()
     self.slave = MultipleMethodSlave(self,
                                      self,
                                      self.store,
                                      order=self.model,
                                      outstanding_value=currency(0),
                                      finish_on_total=False)
     self.slave.enable_remove()
     self.attach_slave('place_holder', self.slave)
Exemplo n.º 3
0
class _PaymentsEditor(BaseEditor):
    """Editor that offers a generic entry to input a string value."""
    gladefile = "HolderTemplate"
    title = _('Payments Editor')
    model_type = object
    size = (-1, 400)

    def __init__(self, store, model):
        BaseEditor.__init__(self, store, model)
        self.update_fully_paid(self._slave_valid)

    def update_fully_paid(self, fully_paid):  # pragma no cover
        """This gets called every time the user creates or removes a payment

        Subclasses can override this method if the model requires aditional
        decision if the model is fully paid or not
        """
        pass

    def setup_slaves(self):
        register_payment_slaves()
        self.slave = MultipleMethodSlave(self,
                                         self,
                                         self.store,
                                         order=self.model,
                                         outstanding_value=currency(0),
                                         finish_on_total=False)
        self.slave.enable_remove()
        self.attach_slave('place_holder', self.slave)

    def on_confirm(self):
        for payment in self.slave.payments:
            if payment.is_preview():
                payment.set_pending()
            # Set the payment status to paid for credit method.
            # This avoid the credit to be used on another sale.
            if payment.is_pending(
            ) and payment.method.method_name == u'credit':
                payment.pay()

    # Mimic a Wizard, so that we can use the payment slaves
    def refresh_next(self, valid):
        # setup_slaves gets called before BaseEditor is finished constructing
        # itself. If this is the case, save the valid state so we can refresh
        # later
        if not hasattr(self, 'main_dialog'):
            self._slave_valid = valid
            return

        self.update_fully_paid(valid)

    def disable_back(self):
        pass
Exemplo n.º 4
0
 def setup_slaves(self):
     register_payment_slaves()
     self.slave = MultipleMethodSlave(wizard=self.wizard,
                                      parent=self,
                                      store=self.store,
                                      order=self.model,
                                      payment_method=None,
                                      finish_on_total=False,
                                      allow_remove_paid=False,
                                      require_total_value=False)
     self.slave.enable_remove()
     self.attach_slave('place_holder', self.slave)
Exemplo n.º 5
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')
Exemplo n.º 6
0
class SaleQuotePaymentStep(WizardEditorStep):
    """A step for creating payments for a |sale|

    All this step does is to attach
    :class:`stoq.lib.gui.slaves.paymentslave.MultipleMethodSlave`, so
    see it for more information
    """

    gladefile = 'HolderTemplate'
    model_type = Sale

    #
    #  WizardEditorStep
    #

    def post_init(self):
        self.register_validate_function(self._validation_func)
        self.force_validation()
        missing_value = self.slave.get_missing_change_value()
        if missing_value < 0:
            info(_(u"Your payments total is greater than the sale total. Maybe"
                   " you want to correct them."))

    def setup_slaves(self):
        register_payment_slaves()
        self.slave = MultipleMethodSlave(
            wizard=self.wizard,
            parent=self,
            store=self.store,
            order=self.model,
            payment_method=None,
            finish_on_total=False,
            allow_remove_paid=False,
            require_total_value=False)
        self.slave.enable_remove()
        self.attach_slave('place_holder', self.slave)

    def has_next_step(self):
        return False

    #
    #  Callbacks
    #

    def _validation_func(self, value):
        can_finish = value and self.slave.can_confirm()
        self.wizard.refresh_next(can_finish)
Exemplo n.º 7
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.assertEqual(slave.value.read(), 10)
        self.assertEqual(str(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.assertEqual(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.assertEqual(slave.value.read(), 10)
        self.assertSensitive(slave, ['add_button'])
        self.assertEqual(
            str(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.assertEqual(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.assertEqual(slave.value.read(), 5)
        self.assertSensitive(slave, ['add_button'])
Exemplo n.º 8
0
class CloseConsignmentPaymentStep(BaseWizardStep):
    gladefile = 'HolderTemplate'
    slave_holder = 'place_holder'

    def __init__(self,
                 wizard,
                 previous,
                 store,
                 consignment,
                 outstanding_value=Decimal(0)):
        self._method = PaymentMethod.get_by_name(store, u'money')
        BaseWizardStep.__init__(self, store, wizard, previous=None)
        self._consignment = consignment
        self._outstanding_value = outstanding_value
        self._setup_slaves()

    def _setup_slaves(self):
        self.slave = MultipleMethodSlave(self.wizard,
                                         self,
                                         self.store,
                                         self.store.fetch(self._consignment),
                                         None,
                                         self._outstanding_value,
                                         finish_on_total=False)
        self.attach_slave('place_holder', self.slave)

    def _validate_step(self, value):
        can_finish = value and self.slave.can_confirm()
        self.wizard.refresh_next(can_finish)

    def validate_step(self):
        return True

    def post_init(self):
        self.register_validate_function(self._validate_step)
        self.force_validation()
        self._validate_step(False)
        self.wizard.enable_finish()

    def has_next_step(self):
        return False