Example #1
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Example #2
0
    def _get_parameter_value(self, obj):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        detail = sysparam.get_detail_by_name(obj.field_name)
        if detail.type == unicode:
            data = sysparam.get_string(obj.field_name)
        elif detail.type == bool:
            data = sysparam.get_bool(obj.field_name)
        elif detail.type == int:
            data = sysparam.get_int(obj.field_name)
        elif detail.type == decimal.Decimal:
            data = sysparam.get_decimal(obj.field_name)
        elif isinstance(detail.type, basestring):
            data = sysparam.get_object(self.store, obj.field_name)
        else:
            raise NotImplementedError(detail.type)

        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % obj.field_name)
            return data.get_description()
        elif detail.options:
            return detail.options[int(obj.field_value)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif obj.field_name == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)
        return unicode(data)
Example #3
0
    def _setup_widgets(self):
        # Salesperson combo
        salespersons = SalesPerson.get_active_salespersons(self.store)
        self.salesperson.prefill(salespersons)

        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError

        # CFOP combo
        if sysparam.get_bool('ASK_SALES_CFOP'):
            cfops = CfopData.get_for_sale(self.store)
            self.cfop.prefill(api.for_combo(cfops))
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        self._fill_clients_category_combo()
        self._setup_clients_widget()

        self._client_credit_set_visible(bool(self.client.read()))
Example #4
0
    def _setup_widgets(self):
        self._update_product_labels_visibility(False)
        cost_digits = sysparam.get_int('COST_PRECISION_DIGITS')
        self.quantity.set_sensitive(False)
        # 10 for the length of MAX_INT, 3 for the precision and 1 for comma
        self.quantity.set_max_length(14)
        self.cost.set_sensitive(False)
        # 10 for the length of MAX_INT and 1 for comma
        self.cost.set_max_length(10 + cost_digits + 1)
        self.add_sellable_button.set_sensitive(False)
        self.overlay.set_overlay_pass_through(self.box, True)
        self.unit_label.set_bold(True)

        for widget in [self.quantity, self.cost]:
            widget.set_adjustment(
                Gtk.Adjustment(lower=0, upper=MAX_INT, step_increment=1))

        self._reset_sellable()
        self._setup_summary()
        self.cost.set_digits(cost_digits)
        self.quantity.set_digits(3)

        self.barcode.grab_focus()
        self.item_table.set_focus_chain([
            self.barcode, self.quantity, self.cost, self.add_sellable_button,
            self.product_button
        ])
        self.register_validate_function(self.validate)
Example #5
0
    def _setup_widgets(self):
        # Salesperson combo
        salespersons = SalesPerson.get_active_salespersons(self.store)
        self.salesperson.prefill(api.for_person_combo(salespersons))

        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError

        # CFOP combo
        if sysparam.get_bool('ASK_SALES_CFOP'):
            cfops = CfopData.get_for_sale(self.store)
            self.cfop.prefill(api.for_combo(cfops))
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        self._fill_clients_category_combo()
        self._setup_clients_widget()

        self._client_credit_set_visible(bool(self.client.read()))
Example #6
0
    def _update_change(self):
        # XXX: The 'validate' signal was not emitted when there's no
        # proxy attaching widget/model. By calling the validate method
        # works as shortcut to emit the signal properly:
        value = self.received_value.validate(force=True)
        if value is ValueUnset:
            value = '0.0'

        sale_amount = (self.wizard.get_total_amount() -
                       self.wizard.get_total_paid())
        change_value = currency(value) - sale_amount
        self.change_value_lbl.set_text(get_formatted_price(change_value))

        # There is some change for the clientchange, but we cannot edit the
        # received value. This means that the client has already paid more than
        # the total sale amount.
        if change_value > 0 and not self.received_value.get_sensitive():
            self.credit_checkbutton.set_visible(True)
            policy = sysparam.get_int('RETURN_POLICY_ON_SALES')
            self.credit_checkbutton.set_sensitive(
                policy == ReturnPolicy.CLIENT_CHOICE)
            self.credit_checkbutton.set_active(
                policy == ReturnPolicy.RETURN_CREDIT)
        else:
            self.credit_checkbutton.set_visible(False)
Example #7
0
    def _setup_widgets(self):
        self._update_product_labels_visibility(False)
        cost_digits = sysparam.get_int("COST_PRECISION_DIGITS")
        self.quantity.set_sensitive(False)
        # 10 for the length of MAX_INT, 3 for the precision and 1 for comma
        self.quantity.set_max_length(14)
        self.cost.set_sensitive(False)
        # 10 for the length of MAX_INT and 1 for comma
        self.cost.set_max_length(10 + cost_digits + 1)
        self.add_sellable_button.set_sensitive(False)
        self.unit_label.set_bold(True)

        for widget in [self.quantity, self.cost]:
            widget.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))

        self._reset_sellable()
        self._setup_summary()
        self.cost.set_digits(cost_digits)
        self.quantity.set_digits(3)

        self.barcode.grab_focus()
        self.item_table.set_focus_chain(
            [self.barcode, self.quantity, self.cost, self.add_sellable_button, self.product_button]
        )
        self.register_validate_function(self.validate)
Example #8
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        marker('Finished filling sales persons')

        marker('Read parameter')
        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError
        marker('Finished reading parameter')
        self._setup_clients_widget()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam.get_bool('ASK_SALES_CFOP'):
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        # the maximum number allowed for an invoice is 999999999.
        self.invoice_number.set_adjustment(
            gtk.Adjustment(lower=1, upper=999999999, step_incr=1))

        if not self.model.invoice_number:
            new_invoice_number = Invoice.get_next_invoice_number(self.store)
            self.invoice_model.invoice_number = new_invoice_number
        else:
            new_invoice_number = self.model.invoice_number
            self.invoice_model.invoice_number = new_invoice_number
            self.invoice_number.set_sensitive(False)

        self.invoice_model.original_invoice = new_invoice_number
        marker('Finished setting up widgets')
Example #9
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = self.store.find(SalesPerson)
        self.salesperson.prefill(api.for_person_combo(salespersons))
        marker('Finished filling sales persons')

        marker('Read parameter')
        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError
        marker('Finished reading parameter')
        self._setup_clients_widget()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam.get_bool('ASK_SALES_CFOP'):
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        # the maximum number allowed for an invoice is 999999999.
        self.invoice_number.set_adjustment(
            gtk.Adjustment(lower=1, upper=999999999, step_incr=1))

        if not self.model.invoice_number:
            new_invoice_number = Invoice.get_next_invoice_number(self.store)
            self.invoice_model.invoice_number = new_invoice_number
        else:
            new_invoice_number = self.model.invoice_number
            self.invoice_model.invoice_number = new_invoice_number
            self.invoice_number.set_sensitive(False)

        self.invoice_model.original_invoice = new_invoice_number
        marker('Finished setting up widgets')
Example #10
0
 def get_component_cost(self):
     value = Decimal('0')
     for component in self.component_tree:
         if self.component_tree.get_parent(component):
             continue
         value += component.get_total_production_cost()
     value = value / self._product.yield_quantity
     return quantize(value, precision=sysparam.get_int('COST_PRECISION_DIGITS'))
Example #11
0
 def _maybe_schedule_idle_logout(self):
     # Verify if the user will use automatic logout.
     from stoqlib.lib.parameters import sysparam
     minutes = sysparam.get_int('AUTOMATIC_LOGOUT')
     # If user defined 0 minutes, ignore automatic logout.
     if minutes != 0:
         seconds = minutes * 60
         GLib.timeout_add_seconds(5, self._verify_idle_logout, seconds)
Example #12
0
 def get_component_cost(self):
     value = Decimal('0')
     for component in self.component_tree:
         if self.component_tree.get_parent(component):
             continue
         value += component.get_total_production_cost()
     value = value / self._product.yield_quantity
     return quantize(value, precision=sysparam.get_int('COST_PRECISION_DIGITS'))
Example #13
0
 def _setup_widgets(self):
     self.order.set_text(unicode(self.model.order.identifier))
     for widget in [self.quantity, self.cost, self.quantity_sold,
                    self.quantity_returned]:
         widget.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT,
                                              step_incr=1))
     self.description.set_text(self.model.sellable.get_description())
     self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
Example #14
0
    def setup_widgets(self):
        self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
        self.consignment_yes_button.set_active(self.model.consignment)
        self.consignment_yes_button.set_sensitive(self._model_created)
        self.consignment_no_button.set_sensitive(self._model_created)
        self.manage_stock.set_sensitive(self._model_created)

        self.description.grab_focus()
Example #15
0
 def _setup_widgets(self):
     unit = self.model.product.sellable.unit
     if unit is None:
         description = _(u"Unit(s)")
     else:
         description = unit.description
     self.unit_label.set_text(description)
     self.base_cost.set_digits(sysparam.get_int("COST_PRECISION_DIGITS"))
     self.base_cost.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))
     self.minimum_purchase.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))
Example #16
0
    def setup_proxies(self):
        self._setup_widgets()
        self.proxy = self.add_proxy(self.model,
                                    StartSaleQuoteStep.proxy_widgets)
        if sysparam.get_bool('ASK_SALES_CFOP'):
            self.add_proxy(self.model, StartSaleQuoteStep.cfop_widgets)

        expire_delta = sysparam.get_int('EXPIRATION_SALE_QUOTE_DATE')
        if expire_delta > 0:
            self.expire_date.update(localtoday() +
                                    relativedelta(days=expire_delta))
Example #17
0
    def setup_proxies(self):
        self._setup_widgets()
        self.proxy = self.add_proxy(self.model,
                                    StartSaleQuoteStep.proxy_widgets)
        if sysparam.get_bool('ASK_SALES_CFOP'):
            self.add_proxy(self.model, StartSaleQuoteStep.cfop_widgets)

        expire_delta = sysparam.get_int('EXPIRATION_SALE_QUOTE_DATE')
        if expire_delta > 0 and not self.model.expire_date:
            # Only set the expire date if id doesn't already have one.
            self.expire_date.update(localtoday() +
                                    relativedelta(days=expire_delta))
Example #18
0
    def setup_proxies(self):
        self._setup_widgets()
        self.proxy = self.add_proxy(self.model,
                                    StartSaleQuoteStep.proxy_widgets)
        if sysparam.get_bool('ASK_SALES_CFOP'):
            self.add_proxy(self.model, StartSaleQuoteStep.cfop_widgets)

        expire_delta = sysparam.get_int('EXPIRATION_SALE_QUOTE_DATE')
        if expire_delta > 0 and not self.model.expire_date:
            # Only set the expire date if id doesn't already have one.
            self.expire_date.update(localtoday() +
                                    relativedelta(days=expire_delta))
Example #19
0
 def _setup_widgets(self):
     unit = self.model.product.sellable.unit
     if unit is None:
         description = _(u'Unit(s)')
     else:
         description = unit.description
     self.unit_label.set_text(description)
     self.base_cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
     self.base_cost.set_adjustment(
         gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))
     self.minimum_purchase.set_adjustment(
         gtk.Adjustment(lower=0, upper=MAX_INT, step_incr=1))
Example #20
0
    def on_barcode__validate(self, widget, value):
        if not value:
            return

        max_barcode = sysparam.get_int('BARCODE_MAX_SIZE')
        if value and len(value) > max_barcode:
            return ValidationError(_(u'Barcode must have %s digits or less.') %
                                   max_barcode)
        if self.model.sellable.check_barcode_exists(value):
            return ValidationError(_('The barcode %s already exists') % value)
        if self._demo_mode and value not in _DEMO_BAR_CODES:
            return ValidationError(_("Cannot create new barcodes in "
                                     "demonstration mode"))
Example #21
0
    def on_barcode__validate(self, widget, value):
        if not value:
            return

        max_barcode = sysparam.get_int('BARCODE_MAX_SIZE')
        if value and len(value) > max_barcode:
            return ValidationError(_(u'Barcode must have %s digits or less.') %
                                   max_barcode)
        if self.model.sellable.check_barcode_exists(value):
            return ValidationError(_('The barcode %s already exists') % value)
        if self._demo_mode and value not in _DEMO_BAR_CODES:
            return ValidationError(_("Cannot create new barcodes in "
                                     "demonstration mode"))
Example #22
0
    def get_query_executer(self):
        """
        Fetchs the QueryExecuter for the SearchContainer

        :returns: a querty executer
        :rtype: a :class:`QueryExecuter` subclass
        """
        if self._query_executer is None:
            executer = QueryExecuter(self.store)
            if not self._lazy_search:
                executer.set_limit(sysparam.get_int('MAX_SEARCH_RESULTS'))
            if self._search_spec is not None:
                executer.set_search_spec(self._search_spec)
            self._query_executer = executer
        return self._query_executer
Example #23
0
    def get_query_executer(self):
        """
        Fetchs the QueryExecuter for the SearchContainer

        :returns: a querty executer
        :rtype: a :class:`QueryExecuter` subclass
        """
        if self._query_executer is None:
            executer = QueryExecuter(self.store)
            if not self._lazy_search:
                executer.set_limit(sysparam.get_int('MAX_SEARCH_RESULTS'))
            if self._search_spec is not None:
                executer.set_search_spec(self._search_spec)
            self._query_executer = executer
        return self._query_executer
Example #24
0
    def needs_closing(self):
        """Checks if there's an open till that needs to be closed before
        we can do any further fiscal operations.
        :returns: True if it needs to be closed, otherwise false
        """
        if self.status != Till.STATUS_OPEN:
            return False

        # Verify that the till wasn't opened today
        if self.opening_date.date() == localtoday().date():
            return False

        if localnow().hour < sysparam.get_int('TILL_TOLERANCE_FOR_CLOSING'):
            return False

        return True
Example #25
0
    def _setup_widgets(self):
        self.order.set_text(str(self.model.order.identifier))
        for widget in [self.quantity, self.cost, self.quantity_sold,
                       self.quantity_returned]:
            widget.set_adjustment(Gtk.Adjustment(lower=0, upper=MAX_INT,
                                                 step_increment=1))

        unit = self.model.sellable.unit
        digits = QUANTITY_PRECISION if unit and unit.allow_fraction else 0
        for widget in [self.quantity,
                       self.quantity_sold,
                       self.quantity_returned]:
            widget.set_digits(digits)

        self.description.set_text(self.model.sellable.get_description())
        self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
Example #26
0
    def needs_closing(self):
        """Checks if there's an open till that needs to be closed before
        we can do any further fiscal operations.
        :returns: True if it needs to be closed, otherwise false
        """
        if self.status != Till.STATUS_OPEN:
            return False

        # Verify that the till wasn't opened today
        if self.opening_date.date() == localtoday().date():
            return False

        if localnow().hour < sysparam.get_int('TILL_TOLERANCE_FOR_CLOSING'):
            return False

        return True
Example #27
0
    def _setup_widgets(self):
        self.order.set_text(unicode(self.model.order.identifier))
        for widget in [self.quantity, self.cost, self.quantity_sold,
                       self.quantity_returned]:
            widget.set_adjustment(gtk.Adjustment(lower=0, upper=MAX_INT,
                                                 step_incr=1))

        unit = self.model.sellable.unit
        digits = QUANTITY_PRECISION if unit and unit.allow_fraction else 0
        for widget in [self.quantity,
                       self.quantity_sold,
                       self.quantity_returned]:
            widget.set_digits(digits)

        self.description.set_text(self.model.sellable.get_description())
        self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
Example #28
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = SalesPerson.get_active_salespersons(
            self.store, api.get_current_branch(self.store))
        self.salesperson.prefill(salespersons)
        marker('Finished filling sales persons')

        marker('Read parameter')
        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError
        marker('Finished reading parameter')
        self._setup_clients_widget()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam.get_bool('ASK_SALES_CFOP'):
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        marker('Finished setting up widgets')
Example #29
0
    def setup_widgets(self):
        marker('Setting up widgets')
        # Only quotes have expire date.
        self.expire_date.hide()
        self.expire_label.hide()

        # Hide client category widgets
        self.client_category_lbl.hide()
        self.client_category.hide()

        # if the NF-e plugin is active, the client is mandantory in this
        # wizard (in this situation, we have only quote sales).
        if self.model.status == Sale.STATUS_QUOTE:
            manager = get_plugin_manager()
            mandatory_client = manager.is_active('nfe')
            self.client.set_property('mandatory', mandatory_client)

        marker('Filling sales persons')
        salespersons = SalesPerson.get_active_salespersons(self.store)
        self.salesperson.prefill(salespersons)
        marker('Finished filling sales persons')

        marker('Read parameter')
        change_salesperson = sysparam.get_int('ACCEPT_CHANGE_SALESPERSON')
        if change_salesperson == ChangeSalespersonPolicy.ALLOW:
            self.salesperson.grab_focus()
        elif change_salesperson == ChangeSalespersonPolicy.DISALLOW:
            self.salesperson.set_sensitive(False)
        elif change_salesperson == ChangeSalespersonPolicy.FORCE_CHOOSE:
            self.model.salesperson = None
            self.salesperson.grab_focus()
        else:
            raise AssertionError
        marker('Finished reading parameter')
        self._setup_clients_widget()
        self._fill_transporter_combo()
        self._fill_cost_center_combo()

        if sysparam.get_bool('ASK_SALES_CFOP'):
            self._fill_cfop_combo()
        else:
            self.cfop_lbl.hide()
            self.cfop.hide()
            self.create_cfop.hide()

        marker('Finished setting up widgets')
Example #30
0
    def has_late_payments(cls, store, person):
        """Checks if the provided person has unpaid payments that are overdue

        :param person: A :class:`person <stoqlib.domain.person.Person>` to
          check if has late payments
        :returns: True if the person has overdue payments. False otherwise
        """
        tolerance = sysparam.get_int('TOLERANCE_FOR_LATE_PAYMENTS')

        query = And(
            cls.person_id == person.id, cls.status == Payment.STATUS_PENDING,
            cls.due_date < localtoday() - relativedelta(days=tolerance))

        late_payments = store.find(cls, query)
        if late_payments.any():
            return True

        return False
Example #31
0
    def has_late_payments(cls, store, person):
        """Checks if the provided person has unpaid payments that are overdue

        :param person: A :class:`person <stoqlib.domain.person.Person>` to
          check if has late payments
        :returns: True if the person has overdue payments. False otherwise
        """
        tolerance = sysparam.get_int('TOLERANCE_FOR_LATE_PAYMENTS')

        query = And(
            cls.person_id == person.id,
            cls.status == Payment.STATUS_PENDING,
            cls.due_date < localtoday() - relativedelta(days=tolerance))

        late_payments = store.find(cls, query)
        if late_payments.any():
            return True

        return False
Example #32
0
 def sysparam(self, **kwargs):
     """
     Updates a set of system parameters within a context.
     The values will be reverted when leaving the scope.
     kwargs contains a dictionary of parameter name->value
     """
     from stoqlib.lib.parameters import sysparam
     old_values = {}
     for param, value in kwargs.items():
         if isinstance(value, bool):
             old_values[param] = sysparam.get_bool(param)
             sysparam.set_bool(self.store, param, value)
         elif isinstance(value, int):
             old_values[param] = sysparam.get_int(param)
             sysparam.set_int(self.store, param, value)
         elif isinstance(value, Domain) or value is None:
             old_values[param] = sysparam.get_object(self.store, param)
             sysparam.set_object(self.store, param, value)
         elif isinstance(value, str):
             old_values[param] = sysparam.get_string(param)
             sysparam.set_string(self.store, param, value)
         elif isinstance(value, Decimal):
             old_values[param] = sysparam.get_decimal(param)
             sysparam.set_decimal(self.store, param, value)
         else:
             raise NotImplementedError(type(value))
     try:
         yield
     finally:
         for param, value in old_values.items():
             if isinstance(value, bool):
                 sysparam.set_bool(self.store, param, value)
             elif isinstance(value, int):
                 sysparam.set_int(self.store, param, value)
             elif isinstance(value, Domain) or value is None:
                 sysparam.set_object(self.store, param, value)
             elif isinstance(value, str):
                 sysparam.set_string(self.store, param, value)
             elif isinstance(value, Decimal):
                 sysparam.set_decimal(self.store, param, value)
             else:
                 raise NotImplementedError(type(value))
Example #33
0
 def sysparam(self, **kwargs):
     """
     Updates a set of system parameters within a context.
     The values will be reverted when leaving the scope.
     kwargs contains a dictionary of parameter name->value
     """
     from stoqlib.lib.parameters import sysparam
     old_values = {}
     for param, value in kwargs.items():
         if isinstance(value, bool):
             old_values[param] = sysparam.get_bool(param)
             sysparam.set_bool(self.store, param, value)
         elif isinstance(value, int):
             old_values[param] = sysparam.get_int(param)
             sysparam.set_int(self.store, param, value)
         elif isinstance(value, Domain) or value is None:
             old_values[param] = sysparam.get_object(self.store, param)
             sysparam.set_object(self.store, param, value)
         elif isinstance(value, str):
             old_values[param] = sysparam.get_string(param)
             sysparam.set_string(self.store, param, value)
         elif isinstance(value, Decimal):
             old_values[param] = sysparam.get_decimal(param)
             sysparam.set_decimal(self.store, param, value)
         else:
             raise NotImplementedError(type(value))
     try:
         yield
     finally:
         for param, value in old_values.items():
             if isinstance(value, bool):
                 sysparam.set_bool(self.store, param, value)
             elif isinstance(value, int):
                 sysparam.set_int(self.store, param, value)
             elif isinstance(value, Domain) or value is None:
                 sysparam.set_object(self.store, param, value)
             elif isinstance(value, str):
                 sysparam.set_string(self.store, param, value)
             elif isinstance(value, Decimal):
                 sysparam.set_decimal(self.store, param, value)
             else:
                 raise NotImplementedError(type(value))
Example #34
0
    def _update_widgets(self):
        if (isinstance(self.wizard, SaleTradeWizard)
                or not self.wizard.model.sale.client):
            self.box1.hide()
            # Just a precaution
            self.message.hide()

        msg = _("A reversal payment to the client will be created. "
                "You can see it on the Payable Application.")
        self.message.set_text(msg)
        policy = sysparam.get_int('RETURN_POLICY_ON_SALES')
        if policy == ReturnPolicy.RETURN_MONEY:
            self.refund.set_active(True)
        elif policy == ReturnPolicy.RETURN_CREDIT:
            self.credit.set_active(True)
        for widget in self.credit.get_group():
            widget.set_sensitive(policy == ReturnPolicy.CLIENT_CHOICE)

        self.wizard.credit = self.credit.get_active()

        self.wizard.update_view()
        self.force_validation()
Example #35
0
    def _update_widgets(self):
        self.proxy.update('total_amount_abs')

        if self.model.total_amount < 0:
            self.total_amount_lbl.set_text(_("Overpaid:"))
        elif self.model.total_amount > 0:
            self.total_amount_lbl.set_text(_("Missing:"))
        else:
            self.total_amount_lbl.set_text(_("Difference:"))

        if (isinstance(self.wizard, SaleTradeWizard) or
                not self.wizard.model.sale.client):
            self.credit_checkbutton.hide()

        policy = sysparam.get_int('RETURN_POLICY_ON_SALES')
        self.credit_checkbutton.set_sensitive(policy == ReturnPolicy.CLIENT_CHOICE)
        self.credit_checkbutton.set_active(policy == ReturnPolicy.RETURN_CREDIT)

        self.wizard.credit = self.credit_checkbutton.read()

        self.wizard.update_view()
        self.force_validation()
Example #36
0
    def has_late_payments(cls, store, person):
        """Checks if the provided person has unpaid payments that are overdue

        :param person: A :class:`person <stoqlib.domain.person.Person>` to
          check if has late payments
        :returns: True if the person has overdue payments. False otherwise
        """
        tolerance = sysparam.get_int('TOLERANCE_FOR_LATE_PAYMENTS')

        query = And(
            cls.person_id == person.id, cls.status == Payment.STATUS_PENDING,
            cls.due_date < localtoday() - relativedelta(days=tolerance))

        for late_payments in store.find(cls, query):
            sale = late_payments.sale
            # Exclude payments for external sales as they are handled by an
            # external entity (e.g. a payment gateway) meaning that they be
            # out of sync with the Stoq database.
            if not sale or not sale.is_external():
                return True

        return False
Example #37
0
    def _update_widgets(self):
        self.proxy.update('total_amount_abs')

        if self.model.total_amount < 0:
            self.total_amount_lbl.set_text(_("Overpaid:"))
        elif self.model.total_amount > 0:
            self.total_amount_lbl.set_text(_("Missing:"))
        else:
            self.total_amount_lbl.set_text(_("Difference:"))

        if (isinstance(self.wizard, SaleTradeWizard) or
                not self.wizard.model.sale.client):
            self.credit_checkbutton.hide()

        policy = sysparam.get_int('RETURN_POLICY_ON_SALES')
        self.credit_checkbutton.set_sensitive(policy == ReturnPolicy.CLIENT_CHOICE)
        self.credit_checkbutton.set_active(policy == ReturnPolicy.RETURN_CREDIT)

        self.wizard.credit = self.credit_checkbutton.read()

        self.wizard.update_view()
        self.force_validation()
Example #38
0
    def _update_change(self):
        # XXX: The 'validate' signal was not emitted when there's no
        # proxy attaching widget/model. By calling the validate method
        # works as shortcut to emit the signal properly:
        value = self.received_value.validate(force=True)
        if value is ValueUnset:
            value = '0.0'

        sale_amount = (self.wizard.get_total_amount() -
                       self.wizard.get_total_paid())
        change_value = currency(value) - sale_amount
        self.change_value_lbl.set_text(get_formatted_price(change_value))

        # There is some change for the clientchange, but we cannot edit the
        # received value. This means that the client has already paid more than
        # the total sale amount.
        if change_value > 0 and not self.received_value.get_sensitive():
            self.credit_checkbutton.set_visible(True)
            policy = sysparam.get_int('RETURN_POLICY_ON_SALES')
            self.credit_checkbutton.set_sensitive(policy == ReturnPolicy.CLIENT_CHOICE)
            self.credit_checkbutton.set_active(policy == ReturnPolicy.RETURN_CREDIT)
        else:
            self.credit_checkbutton.set_visible(False)
Example #39
0
    def has_late_payments(cls, store, person):
        """Checks if the provided person has unpaid payments that are overdue

        :param person: A :class:`person <stoqlib.domain.person.Person>` to
          check if has late payments
        :returns: True if the person has overdue payments. False otherwise
        """
        tolerance = sysparam.get_int('TOLERANCE_FOR_LATE_PAYMENTS')

        query = And(
            cls.person_id == person.id,
            cls.status == Payment.STATUS_PENDING,
            cls.due_date < localtoday() - relativedelta(days=tolerance))

        for late_payments in store.find(cls, query):
            sale = late_payments.sale
            # Exclude payments for external sales as they are handled by an
            # external entity (e.g. a payment gateway) meaning that they be
            # out of sync with the Stoq database.
            if not sale or not sale.is_external():
                return True

        return False
Example #40
0
def get_formatted_cost(float_value, symbol=True):
    from stoqlib.lib.parameters import sysparam
    precision = sysparam.get_int('COST_PRECISION_DIGITS')
    return get_formatted_price(float_value, symbol=symbol, precision=precision)
Example #41
0
def get_formatted_cost(float_value, symbol=True):
    from stoqlib.lib.parameters import sysparam
    precision = sysparam.get_int('COST_PRECISION_DIGITS')
    return get_formatted_price(float_value, symbol=symbol,
                               precision=precision)
Example #42
0
 def setup_widgets(self):
     self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
     self.description.grab_focus()
Example #43
0
 def setup_widgets(self):
     self.cost.set_digits(sysparam.get_int('COST_PRECISION_DIGITS'))
     self.description.grab_focus()