Exemplo n.º 1
0
    def process_one(self, data, fields, store):
        tax = store.fetch(self.tax_constant)
        sellable = Sellable(store=store,
                            description=data.description,
                            price=int(data.price),
                            cost=int(data.cost))
        sellable.tax_constant = tax
        sellable.code = data.barcode
        sellable.barcode = data.barcode

        Service(sellable=sellable, store=store)
Exemplo n.º 2
0
    def process_one(self, data, fields, store):
        tax = store.fetch(self.tax_constant)
        sellable = Sellable(store=store,
                            description=data.description,
                            price=int(data.price),
                            cost=int(data.cost))
        sellable.tax_constant = tax
        sellable.code = data.barcode
        sellable.barcode = data.barcode

        Service(sellable=sellable,
                store=store)
Exemplo n.º 3
0
    def process_one(self, data, fields, store):
        base_category = self._get_or_create(
            SellableCategory,
            store,
            suggested_markup=Decimal(data.markup),
            salesperson_commission=Decimal(data.commission),
            category=None,
            description=data.base_category)

        # create a commission source
        self._get_or_create(CommissionSource,
                            store,
                            direct_value=Decimal(data.commission),
                            installments_value=Decimal(data.commission2),
                            category=base_category)

        category = self._get_or_create(SellableCategory,
                                       store,
                                       description=data.category,
                                       suggested_markup=Decimal(data.markup2),
                                       category=base_category)

        sellable = Sellable(store=store,
                            cost=Decimal(data.cost),
                            category=category,
                            description=data.description,
                            price=Decimal(data.price))
        sellable.barcode = data.barcode
        sellable.code = u'%02d' % self._code
        self._code += 1
        if u'unit' in fields:
            if not data.unit in self.units:
                raise ValueError(u"invalid unit: %s" % data.unit)
            sellable.unit = store.fetch(self.units[data.unit])
        sellable.tax_constant_id = self.tax_constant_id

        product = Product(store=store, sellable=sellable, ncm=data.ncm)

        taxes = self._maybe_create_taxes(store)
        product.set_icms_template(taxes['icms'])
        product.set_pis_template(taxes['pis'])
        product.set_cofins_template(taxes['cofins'])

        supplier = store.fetch(self.supplier)
        ProductSupplierInfo(store=store,
                            supplier=supplier,
                            is_main_supplier=True,
                            base_cost=Decimal(data.cost),
                            product=product)
        Storable(product=product, store=store)
Exemplo n.º 4
0
    def process_one(self, data, fields, store):
        base_category = self._get_or_create(
            SellableCategory,
            store,
            suggested_markup=Decimal(data.markup),
            salesperson_commission=Decimal(data.commission),
            category=None,
            description=data.base_category,
        )

        # create a commission source
        self._get_or_create(
            CommissionSource,
            store,
            direct_value=Decimal(data.commission),
            installments_value=Decimal(data.commission2),
            category=base_category,
        )

        category = self._get_or_create(
            SellableCategory,
            store,
            description=data.category,
            suggested_markup=Decimal(data.markup2),
            category=base_category,
        )

        sellable = Sellable(
            store=store,
            cost=Decimal(data.cost),
            category=category,
            description=data.description,
            price=Decimal(data.price),
        )
        sellable.barcode = data.barcode
        sellable.code = u"%02d" % self._code
        self._code += 1
        if u"unit" in fields:
            if not data.unit in self.units:
                raise ValueError(u"invalid unit: %s" % data.unit)
            sellable.unit = store.fetch(self.units[data.unit])
        sellable.tax_constant_id = self.tax_constant_id

        product = Product(sellable=sellable, store=store)

        supplier = store.fetch(self.supplier)
        ProductSupplierInfo(
            store=store, supplier=supplier, is_main_supplier=True, base_cost=Decimal(data.cost), product=product
        )
        Storable(product=product, store=store)
Exemplo n.º 5
0
    def create_sellable(self, price=None, product=True, description=u"Description", code=u""):
        from stoqlib.domain.product import Product
        from stoqlib.domain.service import Service
        from stoqlib.domain.sellable import Sellable

        tax_constant = sysparam(self.store).DEFAULT_PRODUCT_TAX_CONSTANT
        if price is None:
            price = 10
        sellable = Sellable(cost=125, price=price, description=description, store=self.store)
        sellable.code = code
        sellable.tax_constant = tax_constant
        if product:
            Product(sellable=sellable, store=self.store)
        else:
            Service(sellable=sellable, store=self.store)
        return sellable
Exemplo n.º 6
0
 def create_sellable(self, price=None, product=True,
                     description=u'Description', code=u''):
     from stoqlib.domain.product import Product
     from stoqlib.domain.service import Service
     from stoqlib.domain.sellable import Sellable
     tax_constant_id = sysparam.get_object_id('DEFAULT_PRODUCT_TAX_CONSTANT')
     if price is None:
         price = 10
     sellable = Sellable(cost=125,
                         price=price,
                         description=description,
                         store=self.store)
     sellable.code = code
     sellable.tax_constant_id = tax_constant_id
     if product:
         Product(sellable=sellable, store=self.store)
     else:
         Service(sellable=sellable, store=self.store)
     return sellable
Exemplo n.º 7
0
    def post(self, store):
        data = self.get_json()

        if 'product' not in data:
            abort(400, 'There is no product data on payload')

        sellable_id = data.get('sellable_id')
        barcode = data.get('barcode')
        description = data.get('description')
        base_price = self._price_validation(data)

        if sellable_id and store.get(Sellable, sellable_id):
            abort(400, 'Product with this id already exists')

        if barcode and store.find(Sellable, barcode=barcode):
            abort(400, 'Product with this barcode already exists')

        sellable = Sellable(store=store)
        if sellable_id:
            sellable.id = sellable_id
        sellable.code = barcode
        sellable.barcode = barcode
        sellable.description = description
        # FIXME The sellable is created with STATUS_CLOSED because we need the taxes info
        # to start selling so this is just a temporary sellable just to save it on the
        # database so the override can be created
        sellable.status = Sellable.STATUS_CLOSED
        sellable.base_price = base_price

        product_data = data.get('product')
        product = Product(store=store, sellable=sellable)
        product.manage_stock = product_data.get('manage_stock', False)

        return make_response(
            jsonify({
                'message': 'Product created',
                'data': {
                    'id': sellable.id,
                    'barcode': sellable.barcode,
                    'description': sellable.description,
                    'status': sellable.status,
                }
            }), 201)
Exemplo n.º 8
0
    def create_sellable(self, product_info, responsible):
        if product_info.get('is_package') != 'true':
            raise SellableError(
                """A criação de produtos somente é permitida para produtos do tipo pacote.
                Verifique o cache do seu navegador.""")

        sellable = None
        if product_info["code"]:
            sellable = self.store.find(Sellable,
                                       Sellable.code == product_info["code"])
        if sellable:
            return

        sellable = Sellable(store=self.store,
                            description=product_info["description"],
                            cost=Decimal(product_info["cost"]),
                            price=Decimal(product_info["price"]))

        sellable.code = product_info["code"]
        sellable.barcode = product_info["barcode"]
        sellable.notes = "Created via API" + product_info["notes"]
        sellable.unit_id = product_info["unit_id"] or None
        sellable.tax_constant_id = product_info["tax_constant"] or None
        sellable.default_sale_cfop_id = product_info[
            "default_sale_cfop_id"] or None
        sellable.category_id = product_info["category_id"] or None
        # FIXME Need to get more info from NFe to fill both Product and Storable
        product = Product(store=self.store, sellable=sellable)
        product.manage_stock = product_info.get('manage_stock') == 'true'
        product.is_package = product_info.get('is_package') == 'true'
        package_quantity = product_info.get('package_quantity')
        item_ean = product_info.get('item_ean')
        item = self.store.find(Sellable, barcode=item_ean).one()
        ProductComponent(product=product,
                         component=item.product,
                         price=sellable.get_price(),
                         quantity=Decimal(package_quantity))
        return sellable
Exemplo n.º 9
0
    def post(self, store):
        data = self.get_json()

        log.debug("POST /sellable station: %s payload: %s",
                  self.get_current_station(store), data)

        if 'product' not in data:
            abort(400, 'There is no product data on payload')

        sellable_id = data.get('sellable_id')
        barcode = data.get('barcode')
        description = data.get('description')
        base_price = self._price_validation(data)
        sellable = store.get(Sellable, sellable_id)
        sellable_created_via_sale = sellable and Sellable.NOTES_CREATED_VIA_SALE in sellable.notes

        if sellable and not sellable_created_via_sale:
            message = 'Product with id {} already exists'.format(sellable_id)
            log.warning(message)
            return make_response(jsonify({
                'message': message,
            }), 200)

        if barcode and store.find(Sellable, barcode=barcode):
            message = 'Product with barcode {} already exists'.format(barcode)
            log.warning(message)
            return make_response(jsonify({
                'message': message,
            }), 200)

        if not sellable:
            sellable = Sellable(store=store)
            if sellable_id:
                sellable.id = sellable_id
        sellable.code = barcode
        sellable.barcode = barcode
        sellable.description = description
        # FIXME The sellable is created with STATUS_CLOSED because we need the taxes info
        # to start selling so this is just a temporary sellable just to save it on the
        # database so the override can be created
        sellable.status = Sellable.STATUS_CLOSED
        sellable.base_price = base_price
        # If the sellable was pre-created on a sale it has a notes informing it and to
        # proceed this note is removed
        sellable.notes = sellable.notes.replace(
            Sellable.NOTES_CREATED_VIA_SALE, "")

        product = sellable.product if sellable_created_via_sale else (Product(
            store=store, sellable=sellable))

        product_data = data.get('product')
        product.manage_stock = product_data.get('manage_stock', False)

        # For clients that will control their inventory, we have to create a Storable
        if product.manage_stock and not store.get(Storable, product.id):
            storable = Storable(store=store, product=product)
            storable.maximum_quantity = 1000

        return make_response(
            jsonify({
                'message': 'Product created',
                'data': {
                    'id': sellable.id,
                    'barcode': sellable.barcode,
                    'description': sellable.description,
                    'status': sellable.status,
                }
            }), 201)