Exemple #1
0
    def _get_sellable(self):
        barcode = self.barcode.get_text()
        if not barcode:
            raise StoqlibError("_get_sellable needs a barcode")
        barcode = unicode(barcode)

        fmt = api.sysparam(self.store).SCALE_BARCODE_FORMAT

        # Check if this barcode is from a scale
        info = parse_barcode(barcode, fmt)
        if info:
            barcode = info.code
            weight = info.weight

        sellable = self.store.find(Sellable,
                                   barcode=barcode,
                                   status=Sellable.STATUS_AVAILABLE).one()

        # If the barcode didnt match, maybe the user typed the product code
        if not sellable:
            sellable = self.store.find(Sellable,
                                       code=barcode,
                                       status=Sellable.STATUS_AVAILABLE).one()

        # If the barcode has the price information, we need to calculate the
        # corresponding weight.
        if info and sellable and info.mode == BarcodeInfo.MODE_PRICE:
            weight = info.price / sellable.price

        if info and sellable:
            self.quantity.set_value(weight)

        return sellable
Exemple #2
0
def test_barcode_parse_barcode_weight():
    info = parse_barcode('2123456005279', BarcodeInfo.OPTION_6_DIGITS_WEIGHT)

    assert info.code == '123456'
    assert info.price is None
    assert info.weight == Decimal('0.527')
    assert info.mode == BarcodeInfo.MODE_WEIGHT
Exemple #3
0
def test_barcode_parse_barcode_price():
    info = parse_barcode('2000100005279', BarcodeInfo.OPTION_4_DIGITS_PRICE)

    assert info.code == '0001'
    assert info.price == Decimal('5.27')
    assert info.weight is None
    assert info.mode == BarcodeInfo.MODE_PRICE
Exemple #4
0
    def _get_sellable(self):
        barcode = self.barcode.get_text()
        if not barcode:
            raise StoqlibError("_get_sellable needs a barcode")
        barcode = unicode(barcode)

        fmt = api.sysparam(self.store).SCALE_BARCODE_FORMAT

        # Check if this barcode is from a scale
        info = parse_barcode(barcode, fmt)
        if info:
            barcode = info.code
            weight = info.weight

        sellable = self.store.find(Sellable, barcode=barcode,
                                   status=Sellable.STATUS_AVAILABLE).one()

        # If the barcode didnt match, maybe the user typed the product code
        if not sellable:
            sellable = self.store.find(Sellable, code=barcode,
                                       status=Sellable.STATUS_AVAILABLE).one()

        # If the barcode has the price information, we need to calculate the
        # corresponding weight.
        if info and sellable and info.mode == BarcodeInfo.MODE_PRICE:
            weight = info.price / sellable.price

        if info and sellable:
            self.quantity.set_value(weight)

        return sellable
Exemple #5
0
    def _get_sellable_and_batch(self):
        text = self.barcode.get_text()
        if not text:
            raise StoqlibError("_get_sellable_and_batch needs a barcode")
        text = unicode(text)

        fmt = api.sysparam.get_int('SCALE_BARCODE_FORMAT')

        # Check if this barcode is from a scale
        barinfo = parse_barcode(text, fmt)
        if barinfo:
            text = barinfo.code
            weight = barinfo.weight

        batch = None
        query = Sellable.status == Sellable.STATUS_AVAILABLE

        # FIXME: Put this logic for getting the sellable based on
        # barcode/code/batch_number on domain. Note that something very
        # simular is done on abstractwizard.py

        sellable = self.store.find(
            Sellable, And(query,
                          Lower(Sellable.barcode) == text.lower())).one()

        # If the barcode didnt match, maybe the user typed the product code
        if not sellable:
            sellable = self.store.find(
                Sellable, And(query,
                              Lower(Sellable.code) == text.lower())).one()

        # If none of the above found, try to get the batch number
        if not sellable:
            query = Lower(StorableBatch.batch_number) == text.lower()
            batch = self.store.find(StorableBatch, query).one()
            if batch:
                sellable = batch.storable.product.sellable
                if not sellable.is_available:
                    # If the sellable is not available, reset both
                    sellable = None
                    batch = None

        # If the barcode has the price information, we need to calculate the
        # corresponding weight.
        if barinfo and sellable and barinfo.mode == BarcodeInfo.MODE_PRICE:
            weight = info.price / sellable.price

        if barinfo and sellable:
            self.quantity.set_value(weight)

        return sellable, batch