def test_prices_and_markups(self): self._category.markup = 0 sellable = Sellable(category=self._category, cost=50, description=u"Test", price=currency(100), store=self.store) self.failUnless(sellable.price == 100, u"Expected price: %r, got %r" % (100, sellable.price)) self.failUnless(sellable.markup == 100, u"Expected markup: %r, got %r" % (100, sellable.markup)) sellable.markup = 10 self.failUnless(sellable.price == 55, u"Expected price: %r, got %r" % (55, sellable.price)) sellable.price = 50 self.failUnless(sellable.markup == 0, u"Expected markup %r, got %r" % (0, sellable.markup)) # When the price specified isn't equivalent to the markup specified. # In this case the price don't must be updated based on the markup. sellable = Sellable(cost=50, description=u"Test", price=currency(100), store=self.store) self.failUnless(sellable.price == 100) # A simple test: product without cost and price, markup must be 0 sellable.cost = currency(0) sellable.price = currency(0) self.failUnless(sellable.markup == 0, u"Expected markup %r, got %r" % (0, sellable.markup))
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
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
def test_markup(self): sellable = Sellable(category=None, cost=0, store=self.store) cat = self.create_client_category(u'Cat 1') cat_price = ClientCategoryPrice(sellable=sellable, category=cat, price=150, max_discount=0, store=self.store) self.assertEqual(cat_price.markup, 0) sellable.cost = 10 self.assertEqual(cat_price.markup, 1400) cat_price.markup = 10
def test_price_based_on_specified_markup(self): # When the price isn't defined, but the category, markup and the cost. # In this case the category's markup must be ignored and the price # calculated applying the markup specified in the sellable's cost. sellable = Sellable(description=u"FY123", category=self._category, cost=100, store=self.store) sellable.markup = 5 self.assertEquals(sellable.markup, 5) self.assertEquals(sellable.price, 105) sellable.cost = Decimal('100.33') sellable.markup = 7 self.assertEquals(sellable.price, currency('107.35')) sellable.markup = 8 self.assertEquals(sellable.price, currency('108.36'))