Beispiel #1
0
    def test_get_custom_tax_constant(self):
        constant = DeviceConstant.get_custom_tax_constant(
            self.ecf_printer, 0, self.store)
        self.assertEquals(constant, None)

        constant = DeviceConstant.get_custom_tax_constant(
            self.ecf_printer, 18, self.store)
        self.assertNotEquals(constant, None)
        self.assertEquals(constant.constant_type, DeviceConstant.TYPE_TAX)
        self.assertEquals(constant.constant_enum, TaxType.CUSTOM)
        self.assertEquals(constant.constant_value, 18)
        self.assertEquals(constant.device_value, u'T1')
Beispiel #2
0
    def test_get_tax_constant(self):
        constant = DeviceConstant.get_tax_constant(self.ecf_printer, -1,
                                                   self.store)
        self.assertEquals(constant, None)

        constant = DeviceConstant.get_tax_constant(self.ecf_printer,
                                                   TaxType.NONE, self.store)
        self.assertNotEquals(constant, None)
        self.assertEquals(constant.constant_type, DeviceConstant.TYPE_TAX)
        self.assertEquals(constant.constant_enum, TaxType.NONE)
        self.assertEquals(constant.constant_value, None)
        self.assertEquals(constant.device_value, u'TN')
Beispiel #3
0
    def testGetTaxConstant(self):
        constant = DeviceConstant.get_tax_constant(
            self.ecf_printer, -1, self.store)
        self.assertEquals(constant, None)

        constant = DeviceConstant.get_tax_constant(
            self.ecf_printer, TaxType.NONE, self.store)
        self.assertNotEquals(constant, None)
        self.assertEquals(constant.constant_type, DeviceConstant.TYPE_TAX)
        self.assertEquals(constant.constant_enum, TaxType.NONE)
        self.assertEquals(constant.constant_value, None)
        self.assertEquals(constant.device_value, u'TN')
Beispiel #4
0
    def testGetCustomTaxConstant(self):
        constant = DeviceConstant.get_custom_tax_constant(
            self.ecf_printer, 0, self.store)
        self.assertEquals(constant, None)

        constant = DeviceConstant.get_custom_tax_constant(
            self.ecf_printer, 18, self.store)
        self.assertNotEquals(constant, None)
        self.assertEquals(constant.constant_type, DeviceConstant.TYPE_TAX)
        self.assertEquals(constant.constant_enum, TaxType.CUSTOM)
        self.assertEquals(constant.constant_value, 18)
        self.assertEquals(constant.device_value, u'T1')
Beispiel #5
0
 def create_model(self, store):
     return DeviceConstant(store=store,
                           printer=self.printer,
                           constant_type=self.constant_type,
                           constant_value=None,
                           constant_name=u"Unnamed",
                           constant_enum=int(TaxType.CUSTOM),
                           device_value=None)
Beispiel #6
0
    def _populate_constants(self, model, status):
        driver = status.get_driver()
        for tax_enum, device_value, value in driver.get_tax_constants():
            if tax_enum == TaxType.CUSTOM:
                constant = self.store.find(SellableTaxConstant,
                                           tax_value=value).one()
                # If the constant is not defined in the system, create it
                if not constant:
                    constant = SellableTaxConstant(
                        tax_value=value,
                        tax_type=int(TaxType.CUSTOM),
                        description=u'%0.2f %%' % value,
                        store=self.store)
            elif tax_enum == TaxType.SERVICE:
                constant = self.store.find(DeviceConstant,
                                           constant_enum=int(tax_enum),
                                           printer=model).one()
                # Skip, If we have a service tax defined for this printer
                # This needs to be improved when we support more than one
                # service tax
                if constant is not None:
                    continue
            else:
                constant = self.store.find(SellableTaxConstant,
                                           tax_type=int(tax_enum)).one()
                # Ignore if its unkown tax
                if not constant:
                    continue

            if value:
                constant_name = u'%0.2f %%' % (value, )
            elif constant:
                constant_name = constant.description
            else:
                constant_name = None
            DeviceConstant(constant_enum=int(tax_enum),
                           constant_name=constant_name,
                           constant_type=DeviceConstant.TYPE_TAX,
                           constant_value=value,
                           device_value=device_value,
                           printer=model,
                           store=self.store)

        # This is going to be ugly, most printers don't support
        # a real constant for the payment methods, so we have to look
        # at the description and guess
        payment_enums = {
            'dinheiro': PaymentMethodType.MONEY,
            'cheque': PaymentMethodType.CHECK,
            'boleto': PaymentMethodType.BILL,
            'cartao credito': PaymentMethodType.CREDIT_CARD,
            'cartao debito': PaymentMethodType.DEBIT_CARD,
            'financeira': PaymentMethodType.FINANCIAL,
            'vale compra': PaymentMethodType.GIFT_CERTIFICATE
        }

        payment_methods = []
        for device_value, constant_name in driver.get_payment_constants():
            lower = constant_name.lower()
            lower = lower.replace('é', 'e')  # Workaround method names with
            lower = lower.replace('ã', 'a')  # accents
            payment_enum = payment_enums.get(lower)
            if payment_enum is None:
                continue

            # Avoid register the same method twice for the same device
            if payment_enum in payment_methods:
                continue
            DeviceConstant(constant_enum=int(payment_enum),
                           constant_name=unicode(constant_name),
                           constant_type=DeviceConstant.TYPE_PAYMENT,
                           constant_value=None,
                           device_value=device_value,
                           printer=model,
                           store=self.store)
            payment_methods.append(payment_enum)
 def _on_list_slave__before_delete_items(self, slave, items):
     for item in items:
         DeviceConstant.delete(item.id, store=self.store)
Beispiel #8
0
 def _on_list_slave__before_delete_items(self, slave, items):
     for item in items:
         DeviceConstant.delete(item.id, store=self.store)