Esempio n. 1
0
    def test_get_creditable_methods(self):
        # Incoming payments
        methods = PaymentMethod.get_creatable_methods(self.store,
                                                      Payment.TYPE_IN,
                                                      separate=False)
        self.assertTrue(methods)
        self.assertEqual(len(methods), 8)
        self.assertEqual(methods[0].method_name, u'bill')
        self.assertEqual(methods[1].method_name, u'card')
        self.assertEqual(methods[2].method_name, u'check')
        self.assertEqual(methods[3].method_name, u'credit')
        self.assertEqual(methods[4].method_name, u'deposit')
        self.assertEqual(methods[5].method_name, u'money')
        self.assertEqual(methods[6].method_name, u'multiple')
        self.assertEqual(methods[7].method_name, u'store_credit')

        methods = PaymentMethod.get_creatable_methods(self.store,
                                                      Payment.TYPE_OUT,
                                                      separate=False)
        self.assertTrue(methods)
        self.assertEqual(len(methods), 4)
        self.assertEqual(methods[0].method_name, u'bill')
        self.assertEqual(methods[1].method_name, u'check')
        self.assertEqual(methods[2].method_name, u'deposit')
        self.assertEqual(methods[3].method_name, u'money')
Esempio n. 2
0
    def _setup_comboboxentry_slave(self, data=None):
        widget = ProxyComboEntry()
        widget.props.sensitive = self.sensitive
        widget.model_attribute = "field_value"
        widget.data_type = unicode

        detail = sysparam.get_detail_by_name(self.model.field_name)
        is_mandatory = not detail.allow_none
        self._block_none_value = is_mandatory
        widget.set_property('mandatory', is_mandatory)

        if not data:
            field_type = detail.get_parameter_type()
            # FIXME: DEFAULT_PAYMENT_METHOD needs to filter information from
            # domain because it cannot be any non-creatable method.
            # Find a way to implement this in a generic on ParameterDetails
            if self.model.field_name == "DEFAULT_PAYMENT_METHOD":
                result = PaymentMethod.get_creatable_methods(
                    self.store, Payment.TYPE_IN, False)
            else:
                result = self.store.find(field_type)
            data = [(res.get_description(), unicode(res.id)) for res in result]
        widget.prefill(data)
        self.proxy.add_widget("field_value", widget)
        self.container.add(widget)
        widget.show()
        widget.connect('validation-changed',
                       self._on_entry__validation_changed)
Esempio n. 3
0
    def _setup_comboboxentry_slave(self, data=None):
        widget = ProxyComboEntry()
        widget.props.sensitive = self.sensitive
        widget.model_attribute = "field_value"
        widget.data_type = unicode

        detail = sysparam.get_detail_by_name(self.model.field_name)
        is_mandatory = not detail.allow_none
        self._block_none_value = is_mandatory
        widget.set_property('mandatory', is_mandatory)

        if not data:
            field_type = detail.get_parameter_type()
            # FIXME: DEFAULT_PAYMENT_METHOD needs to filter information from
            # domain because it cannot be any non-creatable method.
            # Find a way to implement this in a generic on ParameterDetails
            if self.model.field_name == "DEFAULT_PAYMENT_METHOD":
                result = PaymentMethod.get_creatable_methods(
                    self.store, Payment.TYPE_IN, False)
            else:
                result = self.store.find(field_type)
            data = [(res.get_description(), unicode(res.id)) for res in result]
        widget.prefill(data)
        self.proxy.add_widget("field_value", widget)
        self.container.add(widget)
        widget.show()
        widget.connect('validation-changed',
                       self._on_entry__validation_changed)
Esempio n. 4
0
    def _setup_payment_methods(self, payment_type):
        methods = PaymentMethod.get_creatable_methods(self.store, payment_type, separate=False)
        group = None
        for method in methods:
            method_name = method.method_name
            widget = gtk.RadioButton(group, N_(method.description))
            widget.connect("toggled", self._on_method__toggled)
            widget.set_data("method", method)
            if group is None:
                group = widget
            self.methods_box.pack_start(widget, False, False, 6)
            widget.show()

            self._methods[method_name] = method
            self._widgets[method_name] = widget
            self.method_set_sensitive(method_name, True)

        # Don't allow the user to change the kind of payment method if
        # there's only one
        if len(methods) == 1:
            self._widgets[methods[0].method_name].set_sensitive(False)
        else:
            # Money should be the first
            widget = self._widgets.get(u"money")
            if widget is not None:
                self.methods_box.reorder_child(widget, 0)

            # Multiple should be the last
            widget = self._widgets.get(u"multiple")
            if widget is not None:
                self.methods_box.reorder_child(widget, len(self.methods_box) - 1)
Esempio n. 5
0
    def _setup_widgets(self):
        self.remove_button.hide()
        if isinstance(self.model, (PaymentRenegotiation, Sale, ReturnedSale,
                                   StockDecrease)):
            payment_type = Payment.TYPE_IN
        elif isinstance(self.model, PurchaseOrder):
            payment_type = Payment.TYPE_OUT
        else:
            raise AssertionError

        money_method = PaymentMethod.get_by_name(self.store, u'money')
        self._add_method(money_method)
        for method in PaymentMethod.get_creatable_methods(
            self.store, payment_type, separate=False):
            if method.method_name in [u'multiple', u'money']:
                continue
            self._add_method(method)

        self.payments.set_columns(self._get_columns())
        self.payments.add_list(self.model.group.payments)

        self.total_value.set_bold(True)
        self.received_value.set_bold(True)
        self.missing_value.set_bold(True)
        self.total_value.update(self._total_value)
        self.remove_button.set_sensitive(False)
        self._update_values()
Esempio n. 6
0
    def _setup_payment_methods(self, payment_type):
        methods = PaymentMethod.get_creatable_methods(self.store,
                                                      payment_type,
                                                      separate=False)
        group = None
        for method in methods:
            method_name = method.method_name
            widget = gtk.RadioButton(group, N_(method.description))
            widget.connect('toggled', self._on_method__toggled)
            widget.set_data('method', method)
            if group is None:
                group = widget
            self.methods_box.pack_start(widget, False, False, 6)
            widget.show()

            self._methods[method_name] = method
            self._widgets[method_name] = widget
            self.method_set_sensitive(method_name, True)

        # Don't allow the user to change the kind of payment method if
        # there's only one
        if len(methods) == 1:
            self._widgets[methods[0].method_name].set_sensitive(False)
        else:
            # Money should be the first
            widget = self._widgets.get(u'money')
            if widget is not None:
                self.methods_box.reorder_child(widget, 0)

            # Multiple should be the last
            widget = self._widgets.get(u'multiple')
            if widget is not None:
                self.methods_box.reorder_child(widget,
                                               len(self.methods_box) - 1)
Esempio n. 7
0
    def testGetCreditableMethodsSeparate(self):
        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_IN, separate=True)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 6)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'card')
        self.assertEquals(methods[2].method_name, u'check')
        self.assertEquals(methods[3].method_name, u'deposit')
        self.assertEquals(methods[4].method_name, u'money')
        self.assertEquals(methods[5].method_name, u'store_credit')

        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_OUT, separate=True)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 4)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'check')
        self.assertEquals(methods[2].method_name, u'deposit')
        self.assertEquals(methods[3].method_name, u'money')
Esempio n. 8
0
 def populate(self, value):
     from stoqlib.domain.payment.method import PaymentMethod
     assert self.payment_type is not None
     store = get_store_for_field(self)
     methods = set(PaymentMethod.get_creatable_methods(
         store, self.payment_type, separate=self.separate))
     # Add the current value, just in case the payment method is not
     # currently creatable
     methods.add(value)
     self.widget.prefill(api.for_combo(methods))
     if value is not None:
         self.widget.select(value)
Esempio n. 9
0
 def populate(self, value):
     from stoqlib.domain.payment.method import PaymentMethod
     assert self.payment_type is not None
     store = get_store_for_field(self)
     methods = set(PaymentMethod.get_creatable_methods(
         store, self.payment_type, separate=self.separate))
     # Add the current value, just in case the payment method is not
     # currently creatable
     methods.add(value)
     self.widget.prefill(api.for_combo(methods))
     if value is not None:
         self.widget.select(value)
Esempio n. 10
0
    def test_get_creditable_methods_separate(self):
        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_IN, separate=True)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 7)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'card')
        self.assertEquals(methods[2].method_name, u'check')
        self.assertEquals(methods[3].method_name, u'credit')
        self.assertEquals(methods[4].method_name, u'deposit')
        self.assertEquals(methods[5].method_name, u'money')
        self.assertEquals(methods[6].method_name, u'store_credit')

        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_OUT, separate=True)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 4)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'check')
        self.assertEquals(methods[2].method_name, u'deposit')
        self.assertEquals(methods[3].method_name, u'money')
Esempio n. 11
0
    def test_get_creditable_methods(self):
        # Incoming payments
        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_IN, separate=False)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 8)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'card')
        self.assertEquals(methods[2].method_name, u'check')
        self.assertEquals(methods[3].method_name, u'credit')
        self.assertEquals(methods[4].method_name, u'deposit')
        self.assertEquals(methods[5].method_name, u'money')
        self.assertEquals(methods[6].method_name, u'multiple')
        self.assertEquals(methods[7].method_name, u'store_credit')

        methods = PaymentMethod.get_creatable_methods(
            self.store, Payment.TYPE_OUT, separate=False)
        self.assertTrue(methods)
        self.assertEquals(len(methods), 4)
        self.assertEquals(methods[0].method_name, u'bill')
        self.assertEquals(methods[1].method_name, u'check')
        self.assertEquals(methods[2].method_name, u'deposit')
        self.assertEquals(methods[3].method_name, u'money')
Esempio n. 12
0
    def _setup_payment_methods(self, payment_type):
        methods = PaymentMethod.get_creatable_methods(
            self.store, payment_type, separate=False)
        group = None
        for method in methods:
            method_name = method.method_name
            widget = gtk.RadioButton(group, N_(method.description))
            widget.connect('toggled', self._on_method__toggled)
            widget.set_data('method', method)
            if group is None:
                group = widget
            self.methods_box.pack_start(widget, False, False, 6)
            widget.show()

            self._methods[method_name] = method
            self._widgets[method_name] = widget
            self.method_set_visible(method_name, True)

        if len(methods) == 1:
            self._default_method = methods[0].method_name
        else:
            # Money should be the first
            widget = self._widgets.get(u'money')
            if widget is not None:
                self.methods_box.reorder_child(widget, 0)

            # Multiple should be the last
            widget = self._widgets.get(u'multiple')
            if widget is not None:
                self.methods_box.reorder_child(
                    widget, len(self.methods_box) - 1)

        # The default method could not have been passed to the constructor,
        # or if it was, it could not be active. Fallback to the parameters'
        # one or money in case it's not active too
        if (self._default_method is None or
            self._default_method not in self._widgets):
            default = api.sysparam.get_object(self.store,
                                              "DEFAULT_PAYMENT_METHOD")
            if default.method_name in self._widgets:
                self._default_method = default.method_name
            else:
                self._default_method = u'money'

        self._select_default_method()
Esempio n. 13
0
    def _setup_payment_methods(self, payment_type):
        methods = PaymentMethod.get_creatable_methods(self.store,
                                                      payment_type,
                                                      separate=False)
        group = None
        for method in methods:
            widget = self._add_method(method, group)
            if group is None:
                group = widget

        if self._no_payments:
            self._add_method(None, group)

        if len(methods) == 1:
            self._default_method = methods[0].method_name
        else:
            # Money should be the first
            widget = self._widgets.get(u'money')
            if widget is not None:
                self.methods_box.reorder_child(widget, 0)

            # Multiple should be the last
            widget = self._widgets.get(u'multiple')
            if widget is not None:
                self.methods_box.reorder_child(widget,
                                               len(self.methods_box) - 1)

        # The default method could not have been passed to the constructor,
        # or if it was, it could not be active. Fallback to the parameters'
        # one or money in case it's not active too
        if (self._default_method is None
                or self._default_method not in self._widgets):
            default = api.sysparam.get_object(self.store,
                                              "DEFAULT_PAYMENT_METHOD")
            if default.method_name in self._widgets:
                self._default_method = default.method_name
            else:
                self._default_method = u'money'

        self._select_default_method()
Esempio n. 14
0
    def _setup_payment_methods(self, payment_type):
        methods = PaymentMethod.get_creatable_methods(
            self.store, payment_type, separate=False)
        group = None
        for method in methods:
            widget = self._add_method(method, group)
            if group is None:
                group = widget

        if self._no_payments:
            self._add_method(None, group)

        if len(methods) == 1:
            self._default_method = methods[0].method_name
        else:
            # Money should be the first
            widget = self._widgets.get(u'money')
            if widget is not None:
                self.methods_box.reorder_child(widget, 0)

            # Multiple should be the last
            widget = self._widgets.get(u'multiple')
            if widget is not None:
                self.methods_box.reorder_child(
                    widget, len(self.methods_box) - 1)

        # The default method could not have been passed to the constructor,
        # or if it was, it could not be active. Fallback to the parameters'
        # one or money in case it's not active too
        if (self._default_method is None or
            self._default_method not in self._widgets):
            default = api.sysparam.get_object(self.store,
                                              "DEFAULT_PAYMENT_METHOD")
            if default.method_name in self._widgets:
                self._default_method = default.method_name
            else:
                self._default_method = u'money'

        self._select_default_method()