コード例 #1
0
ファイル: FS345.py プロジェクト: echeverrifm/stoqdrivers
 def handle_error(self, error_value, raw):
     error = int(error_value[2:])
     # Page 61-62
     if error == 39:
         raise DriverError('Bad parameters: %r' % raw, error)
     elif error == 10:
         raise CouponOpenError(_("Document is already open"), error)
     elif error == 11:
         raise CouponNotOpenError(_("Coupon is not open"), error)
     elif error == 12:
         raise CouponNotOpenError(_("There's no open document to cancel"),
                                  error)
     elif error == 15:
         raise CancelItemError(_("There is no such item in "
                                 "the coupon"), error)
     elif error == 16:
         raise DriverError("Bad discount/markup parameter", error)
     elif error == 21:
         log.warning(_('Printer error %s: No paper'), error)
     elif error == 22:
         raise DriverError(
             "Reduce Z was already sent today, try again tomorrow", error)
     elif error == 23:
         raise PendingReduceZ
     elif error == 24:
         raise DriverError("Bad unit specified: %r" % raw, error)
     elif error == 42:
         raise DriverError("Read X has not been sent yet", error)
     elif error == 45:
         raise DriverError(_("Required field is blank"), error)
     else:
         raise DriverError("Unhandled error: %d" % error, error)
コード例 #2
0
    def coupon_add_item(self,
                        code,
                        description,
                        price,
                        taxcode,
                        quantity=Decimal("1.0"),
                        unit=UnitType.EMPTY,
                        discount=Decimal("0.0"),
                        markup=Decimal("0.0"),
                        unit_desc=""):
        coupon_status = self._get_coupon_status()
        if coupon_status != OPENED_FISCAL_COUPON:
            raise CouponNotOpenError(_("Coupon is not open"))

        if unit == UnitType.CUSTOM:
            unit = unit_desc
        else:
            unit = self._consts.get_value(unit)
        qtd = int(quantity * self._decimals_quantity)
        value = int(price * self._decimals_price)
        st = taxcode
        # Register the sale item
        reply = self._send_command('0A02', '0000', code, description, str(qtd),
                                   unit, str(value), st)
        id = reply.fields[0]
        if discount:
            self.apply_discount(id, discount)
        elif markup:
            self.apply_markup(id, markup)
        return int(id)
コード例 #3
0
ファイル: EP375.py プロジェクト: Lobo-RJ/stoqdrivers
    def coupon_add_item(self, code, description, price, taxcode,
                        quantity=Decimal("1.0"), unit=UnitType.EMPTY,
                        discount=Decimal("0.0"),
                        surcharge=Decimal("0.0"), unit_desc=""):
        if not self._is_coupon_open:
            raise CouponNotOpenError("There is no coupon opened")
        if unit == UnitType.CUSTOM:
            unit = UnitType.EMPTY
        if surcharge:
            cmd = self.CMD_ADD_ITEM_WITH_SURCHARGE
        else:
            cmd = self.CMD_ADD_ITEM_WITH_DISCOUNT

        #
        # FIXME: The product code can only contain alphanumeric characters if
        # the taxcode is between 90-99, i.e, if the product isn't tied to ICMS,
        # otherwise the printer will not recognizes the command. Sooooo, what
        # can I do? Right now, if the product code has not only numbers, i'll
        # prefix with 0s to avoid more problems to the callsite, but my warning
        # remains *HERE*
        #
        code_num = 0
        try:
            code_num = int(code[:7])
        except ValueError:
            code = "%06d%s" % (code_num, code[7:])
        unit = self._consts.get_value(unit)
        item = CouponItem(code, description, taxcode, quantity, price,
                          discount, surcharge, unit)
        item_id = self._get_next_coupon_item_id()
        self.items_dict[item_id] = item

        self._send_command(cmd, item.get_packaged())
        return item_id
コード例 #4
0
ファイル: EP375.py プロジェクト: leandrodax/stoqdrivers
 def coupon_cancel(self):
     status = self._get_status()
     if status.has_opened_sale():
         self.coupon_add_payment(PaymentMethodType.MONEY,
                                 self._get_coupon_remaining_value())
     elif status.has_opened_report():
         self._send_command('K')
     # We can have the "coupon state flag" set to True, but no coupon really
     # opened; and we *must* to manage this case too...
     elif self._is_coupon_open:
         return
     else:
         raise CouponNotOpenError("There is no coupon opened")
     self._send_command(self.CMD_CANCEL_COUPON)
     self._is_coupon_open = False
コード例 #5
0
class MP25Status(object):
    PENDING_REDUCE_Z = 66

    st1_codes = {
        128: (OutofPaperError(_("Printer is out of paper"))),
        # 64: (AlmostOutofPaper(_("Printer almost out of paper"))),
        32: (PrinterError(_("Printer clock error"))),
        16: (PrinterError(_("Printer in error state"))),
        8: (CommandError(_("First data value in CMD is not ESC (1BH)"))),
        4: (CommandError(_("Nonexistent command"))),
        # 2: (CouponOpenError(_("Printer has a coupon currently open"))),
        1: (CommandError(_("Invalid number of parameters")))}

    st2_codes = {
        128: (CommandError(_("Invalid CMD parameter"))),
        64: (HardwareFailure(_("Fiscal memory is full"))),
        32: (HardwareFailure(_("Error in CMOS memory"))),
        16: (PrinterError(_("Given tax is not programmed on the printer"))),
        8: (DriverError(_("No available tax slot"))),
        4: (CancelItemError(_("The item wasn't added in the coupon or can't "
                              "be cancelled"))),

        # 2: (PrinterError(_("Owner data (CGC/IE) not programmed on the printer"))),
        # FIXME: This shouldn't be commented. But it will break the tests.
        # Need to update the tests for all bematech printers
        #1: (CommandError(_("Command not executed")))
    }

    st3_codes = {
        # 7: (CouponOpenError(_("Coupon already Open"))),
        # 8: (CouponNotOpenError(_("Coupon is closed"))),
        13: (PrinterOfflineError(_("Printer is offline"))),
        16: (DriverError(_("Surcharge or discount greater than coupon total"
                           "value"))),
        17: (DriverError(_("Coupon with no items"))),
        20: (PaymentAdditionError(_("Payment method not recognized"))),
        22: (PaymentAdditionError(_("Isn't possible add more payments since"
                                    "the coupon total value already was "
                                    "reached"))),
        23: (DriverError(_("Coupon isn't totalized yet"))),
        43: (CouponNotOpenError(_("Printer not initialized"))),
        45: (PrinterError(_("Printer without serial number"))),
        52: (DriverError(_("Invalid start date"))),
        53: (DriverError(_("Invalid final date"))),
        85: (DriverError(_("Sale with null value"))),
        91: (ItemAdditionError(_("Surcharge or discount greater than item"
                                 "value"))),
        100: (DriverError(_("Invalid date"))),
        115: (CancelItemError(_("Item doesn't exists or already was cancelled"))),
        118: (DriverError(_("Surcharge greater than item value"))),
        119: (DriverError(_("Discount greater than item value"))),
        129: (CouponOpenError(_("Invalid month"))),
        169: (CouponTotalizeError(_("Coupon already totalized"))),
        170: (PaymentAdditionError(_("Coupon not totalized yet"))),
        171: (DriverError(_("Surcharge on subtotal already effected"))),
        172: (DriverError(_("Discount on subtotal already effected"))),
        176: (DriverError(_("Invalid date")))}

    def __init__(self, reply):
        self.st1, self.st2, self.st3 = reply[-3:]

    @property
    def open(self):
        return self.st1 & 2

    def _check_error_in_dict(self, error_codes, value):
        for key in error_codes:
            if key & value:
                raise error_codes[key]

    def check_error(self):
        log.debug("status: st1=%s st2=%s st3=%s" %
                  (self.st1, self.st2, self.st3))

        if self.st1 != 0:
            self._check_error_in_dict(self.st1_codes, self.st1)

        if self.st2 != 0:
            self._check_error_in_dict(self.st2_codes, self.st2)

            # first bit means not executed, look in st3 for more
            if self.st2 & 1 and self.st3:
                if self.st3 in self.st3_codes:
                    raise self.st3_codes[self.st3]
コード例 #6
0
ファイル: FS345.py プロジェクト: echeverrifm/stoqdrivers
 def _verify_coupon_open(self):
     if not self.status_check(self._get_status(), 4, 2):
         raise CouponNotOpenError(_("Coupon is not open"))