def test_get_value(self): constant = SellableTaxConstant(store=self.store, tax_type=TaxType.NONE) self.assertEqual(constant.get_value(), 'TAX_NONE') constant = SellableTaxConstant(store=self.store, tax_type=TaxType.EXEMPTION) self.assertEqual(constant.get_value(), 'TAX_EXEMPTION') constant = SellableTaxConstant(store=self.store, tax_type=TaxType.SUBSTITUTION) self.assertEqual(constant.get_value(), 'TAX_SUBSTITUTION') constant = SellableTaxConstant(store=self.store, tax_type=TaxType.SERVICE) self.assertEqual(constant.get_value(), 'TAX_SERVICE')
def create_sellable_tax_constant(self): from stoqdrivers.enum import TaxType from stoqlib.domain.sellable import SellableTaxConstant return SellableTaxConstant(description=u"18", tax_type=int(TaxType.CUSTOM), tax_value=18, store=self.store)
def test_get_tax_constant_for_device_invalid_tax_value(self): sellable = self.create_sellable() sellable.tax_constant = SellableTaxConstant( store=self.store, description=u'', tax_value=decimal.Decimal('3.1415'), tax_type=int(TaxType.CUSTOM)) self.assertRaises( DeviceError, self.ecf_printer.get_tax_constant_for_device, sellable)
def _add_product(self, sale, tax=None, price=None, code=None): product = self.create_product(price=price) sellable = product.sellable if code: sellable.code = code sellable.tax_constant = SellableTaxConstant( description=unicode(tax), tax_type=int(TaxType.CUSTOM), tax_value=tax, store=self.store) sale.add_sellable(sellable, quantity=1) self.create_storable(product, get_current_branch(self.store), stock=100) return sellable
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)
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 create_model(self, store): return SellableTaxConstant(tax_type=int(TaxType.CUSTOM), tax_value=None, description=u'', store=store)
def test_registers(self): order = self.create_receiving_order() receiving_invoice = order.receiving_invoice order.receival_date = localdate(2007, 6, 1) receiving_invoice.discount_value = 10 # order.purchase.discount_value = 5 # order.purchase.surcharge_value = 8 # order.surcharge_value = 15 receiving_invoice.ipi_total = 10 receiving_invoice.freight_total = 6 receiving_invoice.secure_value = 6 receiving_invoice.expense_value = 12 supplier = self.create_supplier() company = supplier.person.has_individual_or_company_facets() company.state_registry = u'103238426117' receiving_invoice.supplier = supplier employee = self.create_employee() branch = get_current_branch(self.store) branch.manager = employee purchase = order.purchase_orders.find()[0] purchase.status = purchase.ORDER_PENDING sellable = self.create_sellable() sellable.tax_constant = SellableTaxConstant(description=u"18", tax_type=int( TaxType.CUSTOM), tax_value=18, store=self.store) self.create_receiving_order_item(order, sellable=sellable) sellable2 = self.create_sellable() sellable2.tax_constant = SellableTaxConstant(description=u"6", tax_type=int( TaxType.CUSTOM), tax_value=6, store=self.store) self.create_receiving_order_item(order, sellable=sellable2) purchase.confirm() order.confirm() sellable.code = u'9999' sellable2.code = u'10000' sale = self.create_sale() sale.open_date = localdate(2007, 6, 10) sellable3 = self.create_sellable() product = sellable3.product sellable.tax_constant = SellableTaxConstant(description=u"18", tax_type=int( TaxType.CUSTOM), tax_value=18, store=self.store) sale.add_sellable(sellable3, quantity=1) self.create_storable(product, get_current_branch(self.store), stock=100) sale.order() method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal()) sale.confirm() sale.group.pay() sale.close_date = localdate(2007, 6, 10) sale.confirm_date = localdate(2007, 6, 10) sellable3.code = u'09999' inventory = self.create_inventory(branch=branch) inventory.open_date = localdate(2007, 6, 15) # product came from sellable3 inventory_item = InventoryItem(product=product, product_cost=product.sellable.cost, inventory=inventory, recorded_quantity=99, store=self.store) inventory_item.cfop_data = self.store.find(CfopData).order_by( CfopData.code).first() inventory_item.reason = u'Test' inventory_item.actual_quantity = 99 inventory_item.counted_quantity = 99 inventory_item.adjust(invoice_number=999) inventory.close() inventory.close_date = localdate(2007, 6, 15) generator = StoqlibSintegraGenerator(self.store, localdate(2007, 6, 1), localdate(2007, 6, 30)) try: compare_sintegra_file(generator.sintegra, 'sintegra-receival') except AssertionError as e: self.fail(e)
def test_get_description(self): constant = SellableTaxConstant(store=self.store, description=u'foo') self.assertEqual(constant.get_description(), u'foo')