예제 #1
0
    def test_complete(self):
        station = self.create_station()
        today = localdate(2007, 1, 1)
        reduction_date = localdatetime(2007, 1, 1, 23, 59)
        day = FiscalDayHistory(store=self.store,
                               emission_date=today,
                               station=station,
                               serial=u'Stoqlib test serial',
                               serial_id=1,
                               coupon_start=1,
                               coupon_end=23,
                               crz=18,
                               cro=25,
                               period_total=Decimal("456.00"),
                               total=Decimal("123141.00"),
                               reduction_date=reduction_date)
        for code, value, type in [(u'2500', Decimal("123.00"), u'ICMS'),
                                  (u'F', Decimal("789.00"), u'ICMS')]:
            FiscalDayTax(fiscal_day_history=day,
                         code=code,
                         value=value,
                         type=type,
                         store=self.store)

        branch = get_current_branch(self.store)
        user = self.create_employee()
        branch.manager = user
        manager = branch.manager.person
        company = branch.person.company
        address = branch.person.get_main_address()

        start = today + relativedelta(day=1)
        end = today + relativedelta(day=31)

        s = SintegraFile()
        s.add_header(company.get_cnpj_number(), u'110042490114',
                     branch.get_description(), address.get_city(),
                     address.get_state(),
                     branch.person.get_fax_number_number(), start, end)
        # if we don't a street number, use zero for sintegra
        s.add_complement_header(address.street, address.streetnumber or 0,
                                address.complement, address.district,
                                address.get_postal_code_number(), manager.name,
                                branch.person.get_phone_number_number())

        for item in self.store.find(FiscalDayHistory):
            s.add_fiscal_coupon(item.emission_date, item.serial,
                                item.serial_id, item.coupon_start,
                                item.coupon_end, item.cro, item.crz,
                                item.period_total, item.total)
            for tax in item.taxes:
                s.add_fiscal_tax(item.emission_date, item.serial, tax.code,
                                 tax.value)
        s.close()

        try:
            compare_sintegra_file(s, 'sintegra')
        except AssertionError as e:
            self.fail(e)
예제 #2
0
    def _update_sintegra_data(self):
        data = self._driver.get_sintegra()
        if data is None:
            return

        store = new_store()
        # coupon_start and coupon_end are actually, start coo, and current coo.
        coupon_start = data.coupon_start
        coupon_end = data.coupon_end
        # 0 means that the start coo isn't known, fetch
        # the current coo from the the database and add 1
        # TODO: try to avoid this hack
        if coupon_start == 0:
            results = store.find(FiscalDayHistory,
                                 station=self._printer.station).order_by(
                                     Desc(FiscalDayHistory.emission_date))
            if results.count():
                coupon_start = results[0].coupon_end + 1
            else:
                coupon_start = 1

        # Something went wrong or no coupons opened during the day
        if coupon_end <= coupon_start:
            store.commit(close=True)
            return

        station = store.fetch(self._printer.station)
        day = FiscalDayHistory(
            store=store,
            emission_date=data.opening_date,
            station=station,
            serial=unicode(data.serial),
            # 1 -> 001, FIXME: should fix stoqdrivers
            serial_id=int(data.serial_id),
            coupon_start=coupon_start,
            coupon_end=coupon_end,
            crz=data.crz,
            cro=data.cro,
            reduction_date=TransactionTimestamp(),
            period_total=data.period_total,
            total=data.total)

        for code, value, type in data.taxes:
            FiscalDayTax(fiscal_day_history=day,
                         code=unicode(code),
                         value=value,
                         type=unicode(type),
                         store=store)
        store.commit(close=True)
예제 #3
0
    def test_complete(self):
        station = self.create_station()
        today = datetime.date(2007, 1, 1)
        reduction_date = datetime.datetime(2007, 1, 1, 23, 59)
        day = FiscalDayHistory(store=self.store,
                               emission_date=today,
                               station=station,
                               serial=u'serial',
                               serial_id=1,
                               coupon_start=1,
                               coupon_end=23,
                               crz=18,
                               cro=25,
                               period_total=Decimal("456.00"),
                               total=Decimal("123141.00"),
                               reduction_date=reduction_date)
        for code, value, type in [(u'2500', Decimal("123.00"), u'ICMS'),
                                  (u'F', Decimal("789.00"), u'ICMS')]:
            FiscalDayTax(fiscal_day_history=day, code=code,
                         value=value, type=type,
                         store=self.store)

        printer = ECFPrinter(
            store=self.store,
            model=u'FS345',
            brand=u'daruma',
            device_name=u'test',
            device_serial=u'serial',
            baudrate=9600,
            station=station,
            user_number=1,
            register_date=today,
            register_cro=1,
        )

        f = CATFile(printer)
        f.software_version = '6.6.6'  # kiko sends <3

        appinfo = get_utility(IAppInfo)
        f.add_software_house(company, appinfo.get('name'),
                             appinfo.get('version'))
        # Cant call add_ecf_identification, since it depends on a
        # conected printer
        # f.add_ecf_identification()

        for item in self.store.find(FiscalDayHistory):
            f.add_z_reduction(item)
            for i, tax in enumerate(item.taxes):
                f.add_z_reduction_details(item, tax, i + 1)

        sale = self.create_sale()
        sale.client = self.create_client()
        sale.confirm_date = today
        sellable = self.add_product(sale, price=100)
        sellable.code = u'09999'

        self.add_payments(sale)
        history = FiscalSaleHistory(store=self.store,
                                    sale=sale)

        f.add_fiscal_coupon(sale, sale.client, history)
        for i, item in enumerate(sale.get_items()):
            f.add_fiscal_coupon_details(sale, sale.client, history,
                                        item, 800, i + 1)

        for payment in sale.payments:
            f.add_payment_method(sale, history, payment)

        diff = compare_files(f, 'cat52')
        self.assertFalse(diff, '%s\n%s' % ("Files differ, output:", diff))