Beispiel #1
0
    def create_model(self, store):
        self._model_created = True
        sellable = Sellable(store=store)
        model = Product(store=store, sellable=sellable)
        no_storable = [Product.TYPE_WITHOUT_STOCK, Product.TYPE_PACKAGE]
        if not self._product_type in no_storable:
            storable = Storable(product=model, store=store)

        if self._product_type == Product.TYPE_BATCH:
            storable.is_batch = True
        elif self._product_type == Product.TYPE_WITHOUT_STOCK:
            model.manage_stock = False
        elif self._product_type == Product.TYPE_CONSIGNED:
            model.consignment = True
        elif self._product_type == Product.TYPE_GRID:
            model.is_grid = True
            # Configurable products should not manage stock
            model.manage_stock = False
        elif self._product_type == Product.TYPE_PACKAGE:
            model.is_package = True
            # Package products should not manage stock
            model.manage_stock = False

        if self._template is not None:
            sellable.tax_constant = self._template.sellable.tax_constant
            sellable.unit = self._template.sellable.unit
            sellable.category = self._template.sellable.category
            sellable.base_price = self._template.sellable.base_price
            sellable.cost = self._template.sellable.cost
            sellable.default_sale_cfop = self._template.sellable.default_sale_cfop

            model.manufacturer = self._template.manufacturer
            model.brand = self._template.brand
            model.model = self._template.model
            model.family = self._template.family
            model.ncm = self._template.ncm
            model.set_icms_template(self._template._icms_template)
            model.set_ipi_template(self._template._ipi_template)
            model.set_pis_template(self._template._pis_template)
            model.set_cofins_template(self._template._cofins_template)

            for product_attr in self._template.attributes:
                ProductAttribute(store=self.store,
                                 product_id=model.id,
                                 attribute_id=product_attr.attribute.id)
            for supplier_info in self._template.suppliers:
                ProductSupplierInfo(store=self.store,
                                    product=model,
                                    supplier=supplier_info.supplier)
        else:
            sellable.tax_constant = sysparam.get_object(
                self.store, 'DEFAULT_PRODUCT_TAX_CONSTANT')
            sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT')

        return model
Beispiel #2
0
 def create_model(self, store):
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store)
     sellable = Sellable(description=u"", price=currency(0), store=store)
     sellable.tax_constant = tax_constant
     sellable.unit_id = sysparam.get_object_id("SUGGESTED_UNIT")
     model = Service(sellable=sellable, store=store)
     return model
Beispiel #3
0
 def create_model(self, store):
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE,
                                                    self.store)
     sellable = Sellable(description=u'', price=currency(0), store=store)
     sellable.tax_constant = tax_constant
     sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT')
     model = Service(sellable=sellable, store=store)
     return model
Beispiel #4
0
    def create_service(self, description=u"Description", price=10):
        from stoqlib.domain.sellable import Sellable, SellableTaxConstant
        from stoqlib.domain.service import Service

        tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store)
        sellable = Sellable(price=price, description=description, store=self.store)
        sellable.tax_constant = tax_constant
        service = Service(sellable=sellable, store=self.store)
        return service
Beispiel #5
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     Storable(product=model, store=store)
     return model
Beispiel #6
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     Storable(product=model, store=store)
     return model
Beispiel #7
0
 def _set_delivery_default(self, store):
     if self.has_object("DELIVERY_SERVICE"):
         return
     from stoqlib.domain.sellable import (Sellable, SellableTaxConstant)
     from stoqlib.domain.service import Service
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, store)
     sellable = Sellable(store=store, description=_(u'Delivery'))
     sellable.tax_constant = tax_constant
     service = Service(sellable=sellable, store=store)
     self.set_object(store, "DELIVERY_SERVICE", service)
Beispiel #8
0
 def create_model(self, store):
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, self.store)
     sellable = Sellable(description=u'',
                         price=currency(0),
                         store=store)
     sellable.status = Sellable.STATUS_AVAILABLE
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Service(sellable=sellable, store=store)
     return model
Beispiel #9
0
    def _set_delivery_default(self, store):
        if self.has_object("DELIVERY_SERVICE"):
            return
        from stoqlib.domain.sellable import Sellable, SellableTaxConstant
        from stoqlib.domain.service import Service

        tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, store)
        sellable = Sellable(store=store, description=_(u"Delivery"))
        sellable.tax_constant = tax_constant
        service = Service(sellable=sellable, store=store)
        self.set_object(store, "DELIVERY_SERVICE", service)
Beispiel #10
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)
Beispiel #11
0
 def create_service(self, description=u'Description', price=10):
     from stoqlib.domain.sellable import Sellable, SellableTaxConstant
     from stoqlib.domain.service import Service
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE,
                                                    self.store)
     sellable = Sellable(price=price,
                         description=description,
                         store=self.store)
     sellable.tax_constant = tax_constant
     service = Service(sellable=sellable, store=self.store)
     return service
Beispiel #12
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)
Beispiel #13
0
    def create_model(self, store):
        self._model_created = True
        sellable = Sellable(store=store)
        model = Product(store=store, sellable=sellable)
        no_storable = [Product.TYPE_WITHOUT_STOCK, Product.TYPE_PACKAGE]
        if not self._product_type in no_storable:
            storable = Storable(product=model, store=store)

        if self._product_type == Product.TYPE_BATCH:
            storable.is_batch = True
        elif self._product_type == Product.TYPE_WITHOUT_STOCK:
            model.manage_stock = False
        elif self._product_type == Product.TYPE_CONSIGNED:
            model.consignment = True
        elif self._product_type == Product.TYPE_GRID:
            model.is_grid = True
            # Configurable products should not manage stock
            model.manage_stock = False
        elif self._product_type == Product.TYPE_PACKAGE:
            model.is_package = True
            # Package products should not manage stock
            model.manage_stock = False

        if self._template is not None:
            sellable.tax_constant = self._template.sellable.tax_constant
            sellable.unit = self._template.sellable.unit
            sellable.category = self._template.sellable.category
            sellable.base_price = self._template.sellable.base_price
            sellable.cost = self._template.sellable.cost

            model.manufacturer = self._template.manufacturer
            model.brand = self._template.brand
            model.family = self._template.family
            model.ncm = self._template.ncm
            model.icms_template = self._template.icms_template
            model.ipi_template = self._template.ipi_template

            for product_attr in self._template.attributes:
                ProductAttribute(store=self.store,
                                 product_id=model.id,
                                 attribute_id=product_attr.attribute.id)
            for supplier_info in self._template.suppliers:
                ProductSupplierInfo(
                    store=self.store,
                    product=model,
                    supplier=supplier_info.supplier)
        else:
            sellable.tax_constant_id = sysparam.get_object_id(
                'DEFAULT_PRODUCT_TAX_CONSTANT')
            sellable.unit_id = sysparam.get_object_id('SUGGESTED_UNIT')

        return model
Beispiel #14
0
 def create_delivery_service(self):
     from stoqlib.domain.sellable import (Sellable,
                                          SellableTaxConstant)
     from stoqlib.domain.service import Service
     key = u"DELIVERY_SERVICE"
     store = new_store()
     tax_constant = SellableTaxConstant.get_by_type(TaxType.SERVICE, store)
     sellable = Sellable(description=_(u'Delivery'),
                         store=store)
     sellable.tax_constant = tax_constant
     service = Service(sellable=sellable, store=store)
     self._set_schema(key, service.id)
     store.commit(close=True)
Beispiel #15
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     # FIXME: Instead of creating and then removing, we should only create
     # the Storable if the user chooses to do so, but due to the way the
     # editor is implemented, it is not that easy. Change this once we write
     # the new product editor.
     Storable(product=model, store=store)
     return model
Beispiel #16
0
 def create_model(self, store):
     self._model_created = True
     tax_constant = sysparam(store).DEFAULT_PRODUCT_TAX_CONSTANT
     sellable = Sellable(store=store)
     sellable.tax_constant = tax_constant
     sellable.unit = sysparam(self.store).SUGGESTED_UNIT
     model = Product(store=store, sellable=sellable)
     # FIXME: Instead of creating and then removing, we should only create
     # the Storable if the user chooses to do so, but due to the way the
     # editor is implemented, it is not that easy. Change this once we write
     # the new product editor.
     Storable(product=model, store=store)
     return model
Beispiel #17
0
    def create_sellable(self, price=None, product=True, description=u"Description"):
        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.tax_constant = tax_constant
        if product:
            Product(sellable=sellable, store=self.store)
        else:
            Service(sellable=sellable, store=self.store)
        return sellable
Beispiel #18
0
    def process_one(self, data, fields, store):
        base_category = self._get_or_create(SellableCategory,
                                            store,
                                            suggested_markup=int(data.markup),
                                            salesperson_commission=int(
                                                data.commission),
                                            category=None,
                                            description=data.base_category)

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

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

        sellable = Sellable(store=store,
                            cost=Decimal(data.cost),
                            category=category,
                            description=data.description,
                            price=int(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 = store.fetch(self.tax_constant)

        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)
Beispiel #19
0
 def create_sellable(self, price=None, product=True,
                     description=u'Description'):
     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.tax_constant = tax_constant
     if product:
         Product(sellable=sellable, store=self.store)
     else:
         Service(sellable=sellable, store=self.store)
     return sellable
Beispiel #20
0
    def process_one(self, data, fields, store):
        base_category = self._get_or_create(
            SellableCategory, store,
            suggested_markup=int(data.markup),
            salesperson_commission=int(data.commission),
            category=None,
            description=data.base_category)

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

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

        sellable = Sellable(store=store,
                            cost=Decimal(data.cost),
                            category=category,
                            description=data.description,
                            price=int(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 = store.fetch(self.tax_constant)

        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)