Example #1
0
 def test_get_scale_settings(self):
     device = DeviceSettings(store=self.store,
                             station=None,
                             type=DeviceSettings.SCALE_DEVICE)
     self.assertIsNone(
         device.get_scale_settings(store=self.store,
                                   station=self.current_station))
Example #2
0
 def test_get_description(self):
     device = DeviceSettings(store=self.store,
                             brand=u'Brand',
                             model=u'XX',
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     str = device.get_description()
     self.assertEquals(str, u'Brand XX')
Example #3
0
 def test_get_interface_virtual(self):
     device = DeviceSettings(store=self.store,
                             brand=u'virtual',
                             model=u'Simple',
                             device_name=u'/dev/null',
                             type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
     interface = device.get_interface()
     self.assertIsInstance(interface._port, VirtualPort)
Example #4
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)
Example #5
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)
Example #6
0
    def test_get_interface_usb(self, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'usb:0xa:0x1',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)

        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        NonFiscalPrinter.assert_called_with(brand=None, model=None, port=None,
                                            product_id=1, vendor_id=10,
                                            interface='usb')
Example #7
0
    def test_get_interface(self, Scale, ChequePrinter, SerialPort):
        port = SerialPort()
        SerialPort.return_value = port
        device = DeviceSettings(store=self.store,
                                device_name=u'/dev/ttyS0',
                                type=DeviceSettings.CHEQUE_PRINTER_DEVICE)

        obj = object()
        ChequePrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)

        obj = object()
        device.type = DeviceSettings.SCALE_DEVICE
        Scale.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)
        device.type = None
        with self.assertRaises(DatabaseInconsistency) as error:
            device.get_interface()
        expected = "The device type referred by this record" \
                   " (%r) is invalid, given None." % device
        self.assertEqual(str(error.exception), expected)
Example #8
0
 def create_model(self, store):
     return DeviceSettings(device_name=None,
                           station=api.get_current_station(store),
                           brand=None,
                           model=None,
                           type=None,
                           store=store)
Example #9
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()
Example #10
0
    def test_get_interface_ethernet(self, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'ethernet:127.0.0.1:9100',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)

        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        NonFiscalPrinter.assert_called_with(
            brand=None,
            model=None,
            port=None,
            product_id=None,
            vendor_id=None,
            interface='ethernet',
            device_name='ethernet:127.0.0.1:9100')
    def test_show(self, get_serial_devices, get_usb):
        get_serial_devices.return_value = [
            _Device('/dev/ttyS0'),
            _Device('/dev/ttyS1')
        ]
        get_usb.return_value = [
            # Without manufacturer and product
            Settable(idProduct=1234, idVendor=9999),
            # Without manufacturer
            Settable(idProduct=0x1234,
                     idVendor=0x9876,
                     manufacturer=None,
                     product='Printer'),
            # Complete
            Settable(idProduct=0x1234,
                     idVendor=0x9876,
                     manufacturer='USB',
                     product='Printer')
        ]

        station = self.create_station()
        settings = DeviceSettings(store=self.store,
                                  type=DeviceSettings.SCALE_DEVICE)
        editor = DeviceSettingsEditor(self.store,
                                      model=settings,
                                      station=station)
        self.check_editor(editor, 'editor-devicesetting-show')
Example #12
0
    def test_get_interface(self, Scale, ChequePrinter, SerialPort):
        port = SerialPort()
        SerialPort.return_value = port
        device = DeviceSettings(store=self.store,
                                type=DeviceSettings.CHEQUE_PRINTER_DEVICE)

        obj = object()
        ChequePrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)
        obj = object()
        device.type = DeviceSettings.SCALE_DEVICE
        Scale.return_value = obj
        self.assertIs(device.get_interface(), obj)
        ChequePrinter.assert_called_with(brand=device.brand,
                                         model=device.model,
                                         port=port)
        device.type = DeviceSettings._UNUSED
        with self.assertRaises(DatabaseInconsistency) as error:
            device.get_interface()
        expected = "The device type referred by this record" \
                   " (%r) is invalid, given 2." % device
        self.assertEquals(str(error.exception), expected)
Example #13
0
    def test_properties(self):
        station = self.create_station()
        device = DeviceSettings(store=self.store, brand=u'Brand', model=u'XX',
                                type=DeviceSettings.CHEQUE_PRINTER_DEVICE,
                                station=station)

        self.assertEqual(device.description, u'Brand XX')
        self.assertEqual(device.station_name, u'station')
        self.assertEqual(device.device_type_name, u'Cheque Printer')
Example #14
0
    def test_get_interface_serial(self, SerialPort, NonFiscalPrinter):
        device = DeviceSettings(store=self.store,
                                device_name=u'/dev/ttyUSB0',
                                type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
        port0 = SerialPort(device=device.device_name)
        port1 = SerialPort(device=u'/dev/ttyUSB1')
        SerialPort.side_effect = [port0, SerialException, port1]
        obj = object()
        NonFiscalPrinter.return_value = obj
        self.assertIs(device.get_interface(), obj)
        SerialPort.assert_called_with(baudrate=9600, device=device.device_name)
        NonFiscalPrinter.assert_called_with(brand=None,
                                            model=None,
                                            port=port0,
                                            product_id=None,
                                            vendor_id=None,
                                            interface='serial',
                                            device_name='/dev/ttyUSB0')
        with mock.patch('os.path.exists') as mock_os:
            # Raising the SerialException because the device port has changed names.
            mock_os.side_effect = [False, True]
            SerialPort.assert_called_with(baudrate=9600,
                                          device=u'/dev/ttyUSB0')
            device.device_name = u'/dev/ttyUSB1'
            self.assertIs(device.get_interface(), obj)
            NonFiscalPrinter.assert_called_with(brand=None,
                                                model=None,
                                                port=port1,
                                                product_id=None,
                                                vendor_id=None,
                                                interface='serial',
                                                device_name='/dev/ttyUSB1')

        with mock.patch('os.path.exists') as mock_os:
            with self.assertRaises(SerialException):
                # SerialException, but the port is correct or OS is not Linux.
                mock_os.return_value = True
                SerialPort.side_effect = SerialException
                device.get_interface()

        with mock.patch('os.path.exists') as mock_os:
            with self.assertRaises(SerialException):
                # Device not in any ports we search.
                mock_os.return_value = False
                SerialPort.side_effect = SerialException
                device.get_interface()
Example #15
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
 def test_show(self, get_serial_devices):
     get_serial_devices.return_value = [
         _Device('/dev/ttyS0'),
         _Device('/dev/ttyS1')
     ]
     station = self.create_station()
     settings = DeviceSettings(store=self.store,
                               type=DeviceSettings.SCALE_DEVICE)
     editor = DeviceSettingsEditor(self.store,
                                   model=settings,
                                   station=station)
     self.check_editor(editor, 'editor-devicesetting-show')
Example #17
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
Example #18
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
Example #19
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()
Example #20
0
File: pos.py Project: pkaislan/stoq
    def __init__(self, window, store=None):
        self._suggested_client = None
        self._current_store = None
        self._trade = None
        self._trade_infobar = None

        ShellApp.__init__(self, window, store=store)

        self._delivery = None
        self._coupon = None
        # Cant use self._coupon to verify if there is a sale, since
        # CONFIRM_SALES_ON_TILL doesnt create a coupon
        self._sale_started = False
        self._scale_settings = DeviceSettings.get_scale_settings(self.store)
Example #21
0
File: pos.py Project: tmaxter/stoq
    def __init__(self, window, store=None):
        self._suggested_client = None
        self._current_store = None
        self._trade = None
        self._trade_infobar = None

        ShellApp.__init__(self, window, store=store)

        self._delivery = None
        self.param = api.sysparam(self.store)
        self._coupon = None
        # Cant use self._coupon to verify if there is a sale, since
        # CONFIRM_SALES_ON_TILL doesnt create a coupon
        self._sale_started = False
        self._scale_settings = DeviceSettings.get_scale_settings(self.store)
Example #22
0
File: pos.py Project: romaia/stoq
    def __init__(self, app, store=None):
        self._suggested_client = None
        self._current_store = None
        self._trade = None
        self._trade_infobar = None
        self._trade_total_paid = 0

        AppWindow.__init__(self, app, store=store)

        self._delivery = None
        self.param = api.sysparam(self.store)
        self._coupon = None
        # Cant use self._coupon to verify if there is a sale, since
        # CONFIRM_SALES_ON_TILL doesnt create a coupon
        self._sale_started = False
        self._scale_settings = DeviceSettings.get_scale_settings(self.store)
Example #23
0
def test_device_settings_is_valid(store, current_station):
    device = DeviceSettings(store=store,
                            device_name=u'usb:0xa:0x1',
                            type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE,
                            station=current_station)

    assert device.is_valid() is False

    device.model = "foo"
    device.brand = "bar"

    assert device.is_valid() is True
Example #24
0
def _get_scale(store):
    """ Returns a Scale instance pre-configured for the current
    workstation.
    """
    global _scale
    if _scale:
        return _scale
    settings = DeviceSettings.get_scale_settings(store)
    if settings and settings.is_active:
        _scale = Scale(brand=settings.brand,
                       model=settings.model,
                       device=settings.device_name)
    else:
        warning(_(u"There is no scale configured"),
                _(u"There is no scale configured for this station "
                  "(\"%s\") or the scale is not enabled currently"
                  % get_current_station(store).name))
    return _scale
Example #25
0
 def test_get_scale_settings(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.SCALE_DEVICE)
     self.assertIsNone(device.get_scale_settings(store=self.store))
Example #26
0
 def test_get_scale_settings(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.SCALE_DEVICE)
     self.assertIsNone(device.get_scale_settings(store=self.store))
Example #27
0
 def test_get_description(self):
     device = DeviceSettings(store=self.store, brand=u'Brand', model=u'XX',
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     str = device.get_description()
     self.assertEquals(str, u'Brand XX')
Example #28
0
 def test_get_status_string(self):
     device = DeviceSettings(store=self.store)
     self.assertEqual(device.get_status_string(), _(u'Active'))
     device.inactivate()
     self.assertEqual(device.get_status_string(), _(u'Inactive'))
Example #29
0
 def test_is_a_printer(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     self.assertEquals(device.is_a_printer(), True)
     device.type = DeviceSettings.SCALE_DEVICE
     self.assertEquals(device.is_a_printer(), False)
Example #30
0
 def test_activate(self):
     device = DeviceSettings(store=self.store, is_active=False)
     self.assertFalse(device.is_active)
     device.activate()
     self.assertTrue(device.is_active)
Example #31
0
 def test_get_interface_virtual(self):
     device = DeviceSettings(store=self.store, brand=u'virtual',
                             model=u'Simple', device_name=u'/dev/null',
                             type=DeviceSettings.NON_FISCAL_PRINTER_DEVICE)
     interface = device.get_interface()
     self.assertIsInstance(interface._port, VirtualPort)
Example #32
0
 def test_is_a_printer(self):
     device = DeviceSettings(store=self.store,
                             type=DeviceSettings.CHEQUE_PRINTER_DEVICE)
     self.assertEquals(device.is_a_printer(), True)
     device.type = DeviceSettings.SCALE_DEVICE
     self.assertEquals(device.is_a_printer(), False)
Example #33
0
 def test_activate(self):
     device = DeviceSettings(store=self.store, is_active=False)
     self.assertFalse(device.is_active)
     device.activate()
     self.assertTrue(device.is_active)
Example #34
0
 def test_get_status_string(self):
     device = DeviceSettings(store=self.store)
     self.assertEquals(device.get_status_string(), _(u'Active'))
     device.inactivate()
     self.assertEquals(device.get_status_string(), _(u'Inactive'))