Exemple #1
0
 def action(self, data):
     try:
         if data['messageType'] == 'Transaction':
             self.open_shift(data['language'].encode())
             self.actions.put({
                 'type': b'debit',
                 'amount': data['amount'],
                 'currency': data['currency'].encode(),
                 'id': data['cid'],
                 'owner': self.data['owner'],
             })
         elif data['messageType'] == 'Reversal' and self.check_reversal(
                 data['cid']):
             self.actions.put({
                 'type': b'reversal',
                 'amount': data['amount'],
                 'currency': data['currency'].encode(),
                 'id': data['cid'],
                 'owner': self.data['owner'],
             })
         elif data['messageType'] == 'OpenShift':
             self.open_shift(data['language'].encode())
         elif data['messageType'] == 'CloseShift':
             self.close_shift()
         elif data['messageType'] == 'Balance':
             self.actions.put({
                 'type': 'balance',
             })
         elif data['messageType'] == 'Cancel':
             self.call_eftapi('EFT_Abort')
         elif data['messageType'] == 'QueryStatus':
             # Resends the last status if case one update got lost
             event_manager.device_changed(self)
     except:
         pass
Exemple #2
0
 def action(self, data):
     try:
         """
         Check the max resolution for webcam.
         Take picture, output it on stdout and convert it in base 64.
         Release Event with picture in data.
         """
         v4l2 = subprocess.Popen(['v4l2-ctl', '--list-formats-ext'],
                                 stdout=subprocess.PIPE)
         all_sizes = subprocess.Popen(['grep', 'Size'],
                                      stdin=v4l2.stdout,
                                      stdout=subprocess.PIPE)
         all_resolutions = subprocess.Popen(['awk', '{print $3}'],
                                            stdin=all_sizes.stdout,
                                            stdout=subprocess.PIPE)
         sorted_resolutions = subprocess.Popen(['sort', '-rn'],
                                               stdin=all_resolutions.stdout,
                                               stdout=subprocess.PIPE)
         resolution = subprocess.check_output(
             ['awk', 'NR==1'],
             stdin=sorted_resolutions.stdout).decode('utf-8')
         self.data['image'] = base64.b64encode(
             subprocess.check_output([
                 "fswebcam", "-d", self.dev.interface, "-", "-r", resolution
             ]))
         self.data['message'] = 'Image captured'
     except subprocess.CalledProcessError as e:
         self.data['message'] = e.output
     event_manager.device_changed(self)
 def characteristic_value_updated(self, characteristic, value):
     total = value[0] + value[1] * 256 + value[2] * 256 * 256 + value[
         3] * 256 * 256 * 256
     if total > 256**4 / 2:
         total = total - 256**4
     self.btdriver.data['value'] = total / 1000000.0
     event_manager.device_changed(self.btdriver)
Exemple #4
0
    def _take_measure(self):
        """Reads the device's weight value, and pushes that value to the frontend."""

        with self._device_lock:
            self._read_weight()
            if self.data['value'] is not None or self._status[
                    'status'] == self.STATUS_ERROR:
                event_manager.device_changed(self)
Exemple #5
0
 def send_status(self):
     """ Sends the current status of the printer to the connected Odoo instance.
     """
     self.data = {
         'value': '',
         'state': self.state,
     }
     event_manager.device_changed(self)
 def take_control(self, new_owner, html=None):
     # ALLOW A CASHIER TO TAKE CONTROL OVER THE POSBOX, IN CASE OF MULTIPLE CASHIER PER DISPLAY
     self.owner = new_owner
     self.rendered_html = html
     self.data = {
         'value': '',
         'owner': self.owner,
     }
     event_manager.device_changed(self)
     self.event_data.set()
    def _keyboard_input(self, scancode):
        """Deal with a keyboard input. Send the character corresponding to the
        pressed key represented by its scancode to the connected Odoo instance.

        Args:
            scancode (int): The scancode of the pressed key.
        """
        self.data['value'] = self._scancode_to_char(scancode)
        if self.data['value']:
            event_manager.device_changed(self)
 def action(self, data):
     if data.get('action', False) == 'update_layout':
         layout = {
             'layout': data.get('layout'),
             'variant': data.get('variant'),
         }
         self._change_keyboard_layout(layout)
         self.save_layout(layout)
     else:
         self.data['value'] = ''
         event_manager.device_changed(self)
Exemple #9
0
    def _take_measure(self):
        """Reads the device's weight value, and pushes that value to the frontend."""

        if self._is_reading:
            with self._device_lock:
                self._read_weight()
                self._check_last_weight_time()
                if self.data['value'] is not None or self._status[
                        'status'] == self.STATUS_ERROR:
                    event_manager.device_changed(self)
        else:
            time.sleep(0.5)
 def action(self, data):
     if data.get('action') == "update_url":
         self.update_url(data.get('url'))
     elif data.get('action') == "display_refresh":
         self.call_xdotools('F5')
     elif data.get('action') == "take_control":
         self.take_control(self.data['owner'], data.get('html'))
     elif data.get('action') == "customer_facing_display":
         self.update_customer_facing_display(self.data['owner'], data.get('html'))
     elif data.get('action') == "get_owner":
         self.data = {
             'value': '',
             'owner': self.owner,
         }
         event_manager.device_changed(self)
Exemple #11
0
    def send_status(self,
                    response=False,
                    stage=False,
                    ticket=False,
                    ticket_merchant=False,
                    error=False,
                    owner=False,
                    cid=False,
                    card=False,
                    payment_transaction_id=False):
        """Triggers a device_changed to notify all listeners of the new status.

        :param response: The result of a transaction
        :type response: String
        :param stage: The status of the transaction
        :type stage: String
        :param ticket: The transaction receipt destined to the merchant, if any
        :type ticket: String
        :param ticket_merchant: The transaction receipt destined to the merchant, if any
        :type ticket_merchant: String
        :param error: The error that happened, if any
        :type error: String
        :param owner: The session id of the POS that should process the update
        :type owner: String
        :param cid: The cid of payment line that is being processed
        :type cid: String
        :param card: The type of card that was used
        :type card: String
        :param payment_transaction_id: The transaction ID given by the terminal
        :type payment_transaction_id: Integer
        """

        self.data = {
            'value': '',
            'Stage': stage,
            'Response': response,
            'Ticket': ticket,
            'TicketMerchant': ticket_merchant,
            'Card': card,
            'PaymentTransactionID': payment_transaction_id,
            'Error': error,
            'Reversal': True,  # The payments can be reversed
            'owner': owner or self.data['owner'],
            'cid': cid or self.cid,
            'processing': self.processing,
        }
        event_manager.device_changed(self)
Exemple #12
0
    def _barcode_scanner_input(self, scancode):
        """Deal with a barcode scanner input. Add the new character scanned to
        the current barcode or complete the barcode if "Return" is pressed.
        When a barcode is completed, two tasks are performed:
            - Send a device_changed update to the event manager to notify the
            listeners that the value has changed (used in Enterprise).
            - Add the barcode to the list barcodes that are being queried in
            Community.

        Args:
            scancode (int): The scancode of the pressed key.
        """
        if scancode == 28:  # Return
            self.data['value'] = self._current_barcode
            event_manager.device_changed(self)
            self._barcodes.put((time.time(), self._current_barcode))
            self._current_barcode = ''
        else:
            self._current_barcode += self._scancode_to_char(scancode)
Exemple #13
0
    def _read_once_action(self, data):
        """Reads the scale current weight value and pushes it to the frontend."""

        self._read_weight()
        event_manager.device_changed(self)
Exemple #14
0
    def _push_status(self):
        """Updates the current status and pushes it to the frontend."""

        self.data['status'] = self._status
        event_manager.device_changed(self)