Exemplo n.º 1
0
    def create_fiscal_printer_constants(self):
        """
        Creates constants for a fiscal printer
        This can be called multiple times
        """
        # We only want to populate 'empty' objects.
        if not self.constants.find().is_empty():
            return

        store = self.store
        driver = self.get_fiscal_driver()
        constants = driver.get_constants()
        for constant in constants.get_items():
            constant_value = None
            if isinstance(constant, PaymentMethodType):
                constant_type = DeviceConstant.TYPE_PAYMENT
            elif isinstance(constant, UnitType):
                constant_type = DeviceConstant.TYPE_UNIT
            else:
                continue

            device_value = constants.get_value(constant, None)
            if isinstance(device_value, str):
                device_value = device_value.encode()

            DeviceConstant(constant_type=constant_type,
                           constant_name=str(describe_constant(constant)),
                           constant_value=constant_value,
                           constant_enum=int(constant),
                           device_value=constants.get_value(constant,
                                                            None).encode(),
                           printer=self,
                           store=store)

        for constant, device_value, value in driver.get_tax_constants():
            # FIXME: Looks like this is not used and/or is duplicating code from
            # ecfpriterdialog.py (_populate_constants)
            if constant == TaxType.CUSTOM:
                constant_name = '%0.2f %%' % value
            else:
                constant_name = describe_constant(constant)
            DeviceConstant(constant_type=DeviceConstant.TYPE_TAX,
                           constant_name=str(constant_name),
                           constant_value=value,
                           constant_enum=int(constant),
                           device_value=device_value.encode(),
                           printer=self,
                           store=store)
Exemplo n.º 2
0
    def create_fiscal_printer_constants(self):
        """
        Creates constants for a fiscal printer
        This can be called multiple times
        """
        # We only want to populate 'empty' objects.
        if not self.constants.find().is_empty():
            return

        store = self.store
        driver = self.get_fiscal_driver()
        constants = driver.get_constants()
        for constant in constants.get_items():
            constant_value = None
            if isinstance(constant, PaymentMethodType):
                constant_type = DeviceConstant.TYPE_PAYMENT
            elif isinstance(constant, UnitType):
                constant_type = DeviceConstant.TYPE_UNIT
            else:
                continue

            DeviceConstant(
                constant_type=constant_type,
                constant_name=unicode(describe_constant(constant)),
                constant_value=constant_value,
                constant_enum=int(constant),
                device_value=constants.get_value(constant, None),
                printer=self,
                store=store,
            )

        for constant, device_value, value in driver.get_tax_constants():
            # FIXME: Looks like this is not used and/or is duplicating code from
            # ecfpriterdialog.py (_populate_constants)
            if constant == TaxType.CUSTOM:
                constant_name = "%0.2f %%" % value
            else:
                constant_name = describe_constant(constant)
            DeviceConstant(
                constant_type=DeviceConstant.TYPE_TAX,
                constant_name=unicode(constant_name),
                constant_value=value,
                constant_enum=int(constant),
                device_value=device_value,
                printer=self,
                store=store,
            )
Exemplo n.º 3
0
Arquivo: admin.py Projeto: stoq/stoq
def ensure_sellable_constants(store):
    """ Create native sellable constants. """
    log.info("Creating sellable units")
    unit_list = [(u"Kg", UnitType.WEIGHT), (u"Lt", UnitType.LITERS), (u"m ", UnitType.METERS)]
    for desc, enum in unit_list:
        SellableUnit(description=desc, unit_index=int(enum), store=store)

    log.info("Creating sellable tax constants")
    for enum in [TaxType.SUBSTITUTION, TaxType.EXEMPTION, TaxType.NONE, TaxType.SERVICE]:
        desc = describe_constant(enum)
        SellableTaxConstant(description=desc, tax_type=int(enum), tax_value=None, store=store)
Exemplo n.º 4
0
def ensure_sellable_constants(store):
    """ Create native sellable constants. """
    log.info("Creating sellable units")
    unit_list = [(u"Kg", UnitType.WEIGHT), (u"Lt", UnitType.LITERS),
                 (u"m ", UnitType.METERS)]
    for desc, enum in unit_list:
        SellableUnit(description=desc, unit_index=int(enum), store=store)

    log.info("Creating sellable tax constants")
    for enum in [
            TaxType.SUBSTITUTION, TaxType.EXEMPTION, TaxType.NONE,
            TaxType.SERVICE
    ]:
        desc = describe_constant(enum)
        SellableTaxConstant(description=desc,
                            tax_type=int(enum),
                            tax_value=None,
                            store=store)