def add_defaults(self): items = [ (_("Branches"), "branches", gtk.STOCK_HOME), (_("C.F.O.P."), "cfop", STOQ_CALC), (_("Client Categories"), "client_categories", STOQ_CLIENTS), (_("Clients"), "clients", STOQ_CLIENTS), (_("Computers"), "stations", STOQ_SYSTEM), (_("Devices"), "devices", STOQ_DEVICES), (_("Employees"), "employees", STOQ_ADMIN_APP), (_("Events"), "events", gtk.STOCK_DIALOG_WARNING), (_("Fiscal Books"), "fiscal_books", STOQ_EDIT), (_("Forms"), "forms", STOQ_FORMS), (_("Invoice Printers"), "invoice_printers", gtk.STOCK_PRINT), (_("Parameters"), "parameters", gtk.STOCK_PREFERENCES), (_("Payment Categories"), "payment_categories", STOQ_PAYABLE_APP), (_("Payment Methods"), "payment_methods", STOQ_MONEY), (_("Plugins"), "plugins", STOQ_PLUGIN), (_("Roles"), "employee_roles", STOQ_USERS), (_("Taxes"), "taxes", STOQ_TAXES), (_("Suppliers"), "suppliers", STOQ_SUPPLIERS), (_("Tax Classes"), "tax_templates", STOQ_DOCUMENTS), (_("Transporters"), "transporters", STOQ_DELIVERY), (_("User Profiles"), "user_profiles", STOQ_USER_PROFILES), (_("Users"), "users", STOQ_HR), ] for label, name, pixbuf in locale_sorted(items, key=operator.itemgetter(0)): self.add_item(label, name, pixbuf)
def add_defaults(self): items = [ (_('Branches'), 'branches', STOQ_BRANCHES), (_('C.F.O.P.'), 'cfop', STOQ_MOVEMENT_PRODUCT), (_('Client Categories'), 'client_categories', STOQ_CLIENTS), (_('Clients'), 'clients', STOQ_CLIENTS), (_('Computers'), 'stations', STOQ_SYSTEM), (_('Devices'), 'devices', STOQ_DEVICES), (_('Employees'), 'employees', STOQ_EMPLOYEE), (_('Events'), 'events', STOQ_STATUS_WARNING), (_('Fiscal Books'), 'fiscal_books', STOQ_BOOK), (_('Forms'), 'forms', STOQ_FORMS), (_('Invoice Printers'), 'invoice_printers', STOQ_PRINTER), (_('Parameters'), 'parameters', STOQ_PARAMETERS), (_('Payment Categories'), 'payment_categories', STOQ_PAYMENT_CATEGORY), (_('Payment Methods'), 'payment_methods', STOQ_PAYMENT_TYPE), (_('Plugins'), 'plugins', STOQ_PLUGIN), (_('Products'), 'products', STOQ_PRODUCTS), (_('Roles'), 'employee_roles', STOQ_EMPLOYEE_CARD), (_('Services'), 'services', STOQ_SERVICES), (_('Taxes'), 'taxes', STOQ_DOCUMENTS), (_('Suppliers'), 'suppliers', STOQ_SUPPLIERS), (_('Tax Classes'), 'tax_templates', STOQ_TAX_TYPE), (_('Transporters'), 'transporters', STOQ_TRANSPORTER), (_('User Profiles'), 'user_profiles', STOQ_USER_PROFILES), (_('Users'), 'users', STOQ_HR), (_('Connect to Stoq.Link'), 'stoq_link_connect', STOQ_CONNECT), ] for label, name, pixbuf in locale_sorted(items, key=operator.itemgetter(0)): self.add_item(label, name, pixbuf)
def for_person_combo(self, resultset): """ This is similar to :py:func:`~stoqlib.api.StoqAPI.for_combo` but takes a class that references a :py:class:`~stoqlib.domain.person.Person`, such as a :py:class:`~stoqlib.domain.person.Client`, :py:class:`~stoqlib.domain.person.Company`, :py:class:`~stoqlib.domain.person.Supplier` etc. :param resultset: a resultset Example:: suppliers = Supplier.get_active_suppliers(self.store) self.supplier.prefill(api.for_person_combo(suppliers)) """ from stoqlib.domain.person import Person from storm import Undef store = resultset._store facet = resultset._find_spec.default_cls where = resultset._where # This is fetching all persons to cache the objects and avoid extra # queries when constructing the combo strings. resultset = store.find((Person, facet), Person.id == facet.person_id) if where is not Undef: resultset = resultset.find(where) items = [(obj[1].get_description(), obj[1]) for obj in resultset] # FIXME: A combo only changes to data mode (the one that it # returns an object insted of the label) when prefilled with # objects. Prefilling with this fake data will prevent the problem # from happening. We should fix this on kiwi later if not items: return [('', None)] return locale_sorted(items, key=operator.itemgetter(0))
def get_serial_devices(cls): """Get a list of serial devices available on the system :returns: a list of :class:`SerialDevice` """ from serial.tools.list_ports import comports ports = [SerialDevice(p.device) for p in comports()] return locale_sorted(ports, key=operator.attrgetter('device_name'))
def for_combo(self, resultset, attr=None, empty=None, sorted=True): """ Prepares the result of a table for inserting into a combo. Formats the item and sorts them according to the current locale :param resultset: a resultset :param attr: attribute to use instead of :py:class:`~stoqlib.domain.interfaces.IDescribable` :param empty: if set, add an initial None item with this parameter as a label Example:: categories = self.store.find(SellableCategory) self.category_combo.prefill(api.for_combo(categories, attr='full_description')) """ if attr is not None: items = [(getattr(obj, attr), obj) for obj in resultset] else: # If attr is not specified, the objects in the resultset must # implement IDescribable items = [(obj.get_description(), obj) for obj in resultset] if sorted: items = locale_sorted(items, key=operator.itemgetter(0)) if empty is not None: items.insert(0, (empty, None)) return items
def add_defaults(self): items = [ (_('Branches'), 'branches', gtk.STOCK_HOME), (_('C.F.O.P.'), 'cfop', STOQ_CALC), (_('Client Categories'), 'client_categories', STOQ_CLIENTS), (_('Clients'), 'clients', STOQ_CLIENTS), (_('Computers'), 'stations', STOQ_SYSTEM), (_('Devices'), 'devices', STOQ_DEVICES), (_('Employees'), 'employees', STOQ_ADMIN_APP), (_('Events'), 'events', gtk.STOCK_DIALOG_WARNING), (_('Fiscal Books'), 'fiscal_books', STOQ_EDIT), (_('Forms'), 'forms', STOQ_FORMS), (_('Invoice Printers'), 'invoice_printers', gtk.STOCK_PRINT), (_('Parameters'), 'parameters', gtk.STOCK_PREFERENCES), (_('Payment Categories'), 'payment_categories', STOQ_PAYABLE_APP), (_('Payment Methods'), 'payment_methods', STOQ_MONEY), (_('Plugins'), 'plugins', STOQ_PLUGIN), (_('Products'), 'products', STOQ_PRODUCTS), (_('Roles'), 'employee_roles', STOQ_USERS), (_('Services'), 'services', STOQ_SERVICES), (_('Taxes'), 'taxes', STOQ_TAXES), (_('Suppliers'), 'suppliers', STOQ_SUPPLIERS), (_('Tax Classes'), 'tax_templates', STOQ_DOCUMENTS), (_('Transporters'), 'transporters', STOQ_DELIVERY), (_('User Profiles'), 'user_profiles', STOQ_USER_PROFILES), (_('Users'), 'users', STOQ_HR), (_('Connect to Stoq.Link'), 'stoq_link_connect', STOQ_CONNECT), ] for label, name, pixbuf in locale_sorted( items, key=operator.itemgetter(0)): self.add_item(label, name, pixbuf)
def add_defaults(self): items = [ (_('Branches'), 'branches', gtk.STOCK_HOME), (_('C.F.O.P.'), 'cfop', STOQ_CALC), (_('Client Categories'), 'client_categories', STOQ_CLIENTS), (_('Clients'), 'clients', STOQ_CLIENTS), (_('Computers'), 'stations', STOQ_SYSTEM), (_('Devices'), 'devices', STOQ_DEVICES), (_('Employees'), 'employees', STOQ_ADMIN_APP), (_('Events'), 'events', gtk.STOCK_DIALOG_WARNING), (_('Fiscal Books'), 'fiscal_books', STOQ_EDIT), (_('Forms'), 'forms', STOQ_FORMS), (_('Invoice Printers'), 'invoice_printers', gtk.STOCK_PRINT), (_('Parameters'), 'parameters', gtk.STOCK_PREFERENCES), (_('Payment Categories'), 'payment_categories', STOQ_PAYABLE_APP), (_('Payment Methods'), 'payment_methods', STOQ_MONEY), (_('Plugins'), 'plugins', STOQ_PLUGIN), (_('Roles'), 'employee_roles', STOQ_USERS), (_('Taxes'), 'taxes', STOQ_TAXES), (_('Suppliers'), 'suppliers', STOQ_SUPPLIERS), (_('Tax Classes'), 'tax_templates', STOQ_DOCUMENTS), (_('Transporters'), 'transporters', STOQ_DELIVERY), (_('User Profiles'), 'user_profiles', STOQ_USER_PROFILES), (_('Users'), 'users', STOQ_HR), ] for label, name, pixbuf in locale_sorted(items, key=operator.itemgetter(0)): self.add_item(label, name, pixbuf)
def get_serial_devices(self): """Get a list of serial devices available on the system :returns: a list of :class:`SerialDevice` """ if gudev: devices = self._get_gudev_devices() elif self._hal_manager: devices = self._get_hal_devices() else: devices = self._get_default_devices() return locale_sorted(devices, key=operator.attrgetter('device_name'))
def get_editable_methods(cls, store): """Gets a list of methods that are editable Eg, you can change the details such as maximum installments etc. :returns: a list of :class:`payment methods <PaymentMethod>` """ # FIXME: Dont let users see online payments for now, to avoid # confusions with active state. online is an exception to that # logic. 'trade' for the same reason clause = And(cls.method_name != u"online", cls.method_name != u"trade") methods = store.find(cls, clause) return locale_sorted(methods, key=operator.attrgetter("description"))
def get_editable_methods(cls, store): """Gets a list of methods that are editable Eg, you can change the details such as maximum installments etc. :returns: a list of :class:`payment methods <PaymentMethod>` """ # FIXME: Dont let users see online payments for now, to avoid # confusions with active state. online is an exception to that # logic. 'trade' for the same reason clause = And(cls.method_name != u'online', cls.method_name != u'trade') methods = store.find(cls, clause) return locale_sorted(methods, key=operator.attrgetter('description'))
def _setup_widgets(self): items = [(b.person.name, b) for b in self.store.find(Branch) if b is not self.branch] self.destination_branch.prefill(locale_sorted( items, key=operator.itemgetter(0))) self.source_branch.set_text(self.branch.person.name) employees = self.store.find(Employee) self.source_responsible.prefill(api.for_combo(employees)) self.destination_responsible.prefill(api.for_combo(employees)) self.transfer_order.source_branch = self.branch self.transfer_order.destination_branch = items[0][1]
def _populate_printers(self): supported_ifaces = get_supported_printers_by_iface(ICouponPrinter).items() printers = [] for brand, printer_classes in supported_ifaces: for printer_class in printer_classes: printer = _PrinterModel(brand, printer_class) printers.append((printer.get_description(), printer)) if sysparam(self.store).DEMO_MODE: from stoqdrivers.printers.virtual.Simple import Simple printer = _PrinterModel('virtual', Simple) printers.append((printer.get_description(), printer)) self.printer.prefill(locale_sorted( printers, key=operator.itemgetter(0)))
def get_available_applications(self): user = api.get_current_user(self.store) permissions = user.profile.get_permissions() descriptions = get_utility(IApplicationDescriptions).get_descriptions() available_applications = [] # sorting by app_full_name for name, full, icon, descr in locale_sorted( descriptions, key=operator.itemgetter(1)): if permissions.get(name): available_applications.append( Application(name, full, icon, descr)) return available_applications
def _fill_wo_categories_combo(self): wo_categories = list(self.store.find(WorkOrderCategory)) self.wo_categories.color_attribute = 'color' if len(wo_categories) > 0: items = [(category.get_description(), category) for category in wo_categories] items = locale_sorted(items, key=operator.itemgetter(0)) items.insert(0, ('No category', None)) self.wo_categories.prefill(items) self.wo_categories.set_sensitive(True) # We can use any work order, since all workorders in the same sale are # sharing the same category. workorder = WorkOrder.find_by_sale(self.store, self.model).any() if workorder and workorder.category: self.wo_categories.select(workorder.category)
def _fill_clients_combo(self): # FIXME: This should not be using a normal ProxyComboEntry, # we need a specialized widget that does the searching # on demand. # This is to keep the clients in cache clients_cache = list(Client.get_active_clients(self.store)) clients_cache # pyflakes # We are using ClientView here to show the fancy name as well clients = ClientView.get_active_clients(self.store) items = [(c.get_description(), c.client) for c in clients] items = locale_sorted(items, key=operator.itemgetter(0)) self.client.prefill(items) # TODO: Implement a has_items() in kiwi self.client.set_sensitive(len(self.client.get_model()))
def _fill_wo_categories_combo(self): wo_categories = list(self.store.find(WorkOrderCategory)) self.wo_categories.color_attribute = 'color' if len(wo_categories) > 0: items = [(category.get_description(), category) for category in wo_categories] items = locale_sorted(items, key=operator.itemgetter(0)) items.insert(0, ('No category', None)) self.wo_categories.prefill(items) self.wo_categories.set_sensitive(True) workorders = WorkOrder.find_by_sale(self.store, self.model) if workorders: # We only need the first workorder, because all workorders in the # same sale are sharing the same category. self.wo_categories.select(workorders[0].category)
def _populate_printers(self): supported_ifaces = get_supported_printers_by_iface(ICouponPrinter).items() printers = [] for brand, printer_classes in supported_ifaces: for printer_class in printer_classes: printer = _PrinterModel(brand, printer_class) printers.append((printer.get_description(), printer)) # Allow to use virtual printer for both demo mode and developer mode # so it's easier for testers and developers to test ecf functionality if sysparam.get_bool('DEMO_MODE') or is_developer_mode(): from stoqdrivers.printers.virtual.Simple import Simple printer = _PrinterModel('virtual', Simple) printers.append((printer.get_description(), printer)) self.printer.prefill(locale_sorted( printers, key=operator.itemgetter(0)))
def _populate_printers(self): supported_ifaces = get_supported_printers_by_iface(ICouponPrinter).items() printers = [] for brand, printer_classes in supported_ifaces: for printer_class in printer_classes: printer = _PrinterModel(brand, printer_class) printers.append((printer.get_description(), printer)) # Allow to use virtual printer for both demo mode and developer mode # so it's easier for testers and developers to test ecf functionality if sysparam(self.store).DEMO_MODE or is_developer_mode(): from stoqdrivers.printers.virtual.Simple import Simple printer = _PrinterModel('virtual', Simple) printers.append((printer.get_description(), printer)) self.printer.prefill(locale_sorted( printers, key=operator.itemgetter(0)))
def get_countries(): """Fetch a list of translated/untranslated countries suitable for usage within combo.prefill():: [(translated label, label), ...] :returns: a list of tuples """ # FIXME: Get this lazely from /usr/share/xml/iso-codes/iso_3166.xml # as pointed out on bug 5100. def cmp_func(a, b): return locale.strcoll(a[0], b[0]) # We store translated country names in a set to ensure # there are no dupes because the combo expects that. items = set() for country in countries: items.add((dgettext("iso_3166", country), country)) return locale_sorted(items, key=operator.itemgetter(0))
def get_available_applications(self): user = api.get_current_user(self.store) permissions = user.profile.get_permissions() descriptions = get_utility(IApplicationDescriptions).get_descriptions() available_applications = [] # sorting by app_full_name for name, full, icon, descr in locale_sorted( descriptions, key=operator.itemgetter(1)): # FIXME: The delivery app is still experimental. Remove this # once it is considered stable enough for our users if name == 'delivery' and not api.is_developer_mode(): continue if permissions.get(name): available_applications.append( Application(name, full, icon, descr)) return available_applications
def get_available_applications(self): user = api.get_current_user(self.store) permissions = {} for settings in user.profile.profile_settings: permissions[settings.app_dir_name] = settings.has_permission descriptions = get_utility(IApplicationDescriptions).get_descriptions() available_applications = [] # sorting by app_full_name for name, full, icon, descr in locale_sorted( descriptions, key=operator.itemgetter(1)): # FIXME: # if name in self._hidden_apps: # continue # and name not in self._blocked_apps: if permissions.get(name): available_applications.append( Application(name, full, icon, descr)) return available_applications
def get_active_methods(cls, store): """Returns a list of active payment methods """ methods = store.find(PaymentMethod, is_active=True) return locale_sorted(methods, key=operator.attrgetter('description'))