示例#1
0
 def _get_interface(cls, iface):
     store = get_default_store()
     station = get_current_station(store)
     device = DeviceSettings.get_by_station_and_type(store, station, iface)
     if not device:
         return None
     return device.get_interface()
示例#2
0
 def test_get_by_station_and_type(self):
     station = self.create_station()
     type = DeviceSettings.SCALE_DEVICE
     device = DeviceSettings(store=self.store, station=station, type=type)
     results = device.get_by_station_and_type(store=self.store,
                                              station=station,
                                              type=type)
     self.assertEqual(results, device)
示例#3
0
 def test_get_by_station_and_type(self):
     station = self.create_station()
     type = DeviceSettings.SCALE_DEVICE
     device = DeviceSettings(store=self.store, station=station,
                             type=type)
     results = device.get_by_station_and_type(store=self.store,
                                              station=station,
                                              type=type)
     self.assertEquals(results.count(), 1)
示例#4
0
 def validate_confirm(self):
     if not self.edit_mode:
         settings = DeviceSettings.get_by_station_and_type(
             store=api.get_default_store(), station=self.model.station.id, type=self.model.type
         )
         if settings:
             self.station.set_invalid(
                 _(u'A %s already exists for station "%s"')
                 % (self.model.get_device_type_name(), self.model.station.name)
             )
             return False
     return True
示例#5
0
 def validate_confirm(self):
     if not self.edit_mode:
         settings = DeviceSettings.get_by_station_and_type(
             store=api.get_default_store(),
             station=self.model.station.id,
             type=self.model.type)
         if settings:
             self.station.set_invalid(
                 _(u"A %s already exists for station \"%s\"") %
                 (self.model.get_device_type_name(),
                  self.model.station.name))
             return False
     return True
示例#6
0
    def validate_confirm(self):
        settings = DeviceSettings.get_by_station_and_type(
            store=api.get_default_store(),
            station=self.model.station.id,
            type=self.model.type,
            exclude=self.model)
        if settings and self.is_active_button.get_active():
            warning(_(u"An active %s already exists for station \"%s\"") % (
                    self.model.device_type_name,
                    self.model.station_name))
            return False

        return True
示例#7
0
    def ensure_printer(cls, station, retries=20):
        # In multiclient mode there is no local printer
        if is_multiclient:
            return

        assert printer_lock.locked()

        store = api.get_default_store()
        device = DeviceSettings.get_by_station_and_type(
            store, station, DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
        if not device:
            # If we have no printer configured, there's nothing to ensure
            return

        # There is no need to lock the printer here, since it should already be locked by the
        # calling site of this method.
        # Test the printer to see if its working properly.
        printer = None
        try:
            printer = api.device_manager.printer
            return printer.is_drawer_open()
        except (SerialException, InvalidReplyException):
            if printer:
                printer._port.close()
            api.device_manager._printer = None
            for i in range(retries):
                log.info('Printer check failed. Reopening')
                try:
                    printer = api.device_manager.printer
                    printer.is_drawer_open()
                    break
                except SerialException:
                    gevent.sleep(1)
            else:
                # Reopening printer failed. re-raise the original exception
                raise

            # Invalidate the printer in the plugins so that it re-opens it
            manager = get_plugin_manager()

            # nfce does not need to reset the printer since it does not cache it.
            sat = get_plugin(manager, 'sat')
            if sat and sat.ui:
                sat.ui.printer = None

            nonfiscal = get_plugin(manager, 'nonfiscal')
            if nonfiscal and nonfiscal.ui:
                nonfiscal.ui.printer = printer

            return printer.is_drawer_open()