def test_can_remove(self): sellable = Sellable(store=self.store) self.assertTrue(sellable.can_remove()) sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) self.assertTrue(sellable.can_remove()) storable.increase_stock(1, self.current_branch, StockTransactionHistory.TYPE_INITIAL, None, self.current_user) sale = self.create_sale() sale.status = Sale.STATUS_QUOTE sale.branch = self.current_branch sale.add_sellable(sellable) self.assertFalse(sellable.can_remove()) # Can't remove the sellable if it's in a purchase. from stoqlib.domain.purchase import PurchaseItem sellable = self.create_sellable() Storable(product=sellable.product, store=self.store) self.assertTrue(sellable.can_remove()) PurchaseItem(store=self.store, quantity=8, quantity_received=0, cost=125, base_cost=125, sellable=sellable, order=self.create_purchase_order()) self.assertFalse(sellable.can_remove()) # The delivery service cannot be removed. sellable = sysparam.get_object(self.store, 'DELIVERY_SERVICE').sellable self.assertFalse(sellable.can_remove())
def testGetBalance(self): p = self.create_product() b1 = self.create_branch() b2 = self.create_branch() b3 = self.create_branch() storable = Storable(store=self.store, product=p) self.assertEqual(storable.get_balance_for_branch(b1), 0) self.assertEqual(storable.get_balance_for_branch(b2), 0) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 0) # Only b1 and b2 will increase stock storable.increase_stock(5, b1, 0, 0) storable.increase_stock(10, b2, 0, 0) self.assertEqual(storable.get_balance_for_branch(b1), 5) self.assertEqual(storable.get_balance_for_branch(b2), 10) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 15) # b1 will decrease *all* it's stock storable.decrease_stock(5, b1, 0, 0) self.assertEqual(storable.get_balance_for_branch(b1), 0) self.assertEqual(storable.get_balance_for_branch(b2), 10) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 10)
def testCanRemove(self): branch = get_current_branch(self.store) sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) self.failUnless(sellable.can_remove()) storable.increase_stock(1, branch, 0, 0) sale = self.create_sale() sale.status = Sale.STATUS_QUOTE sale.branch = branch sale.add_sellable(sellable) self.failIf(sellable.can_remove()) # Can't remove the sellable if it's in a purchase. from stoqlib.domain.purchase import PurchaseItem sellable = self.create_sellable() Storable(product=sellable.product, store=self.store) self.assertTrue(sellable.can_remove()) PurchaseItem(store=self.store, quantity=8, quantity_received=0, cost=125, base_cost=125, sellable=sellable, order=self.create_purchase_order()) self.assertFalse(sellable.can_remove()) # The delivery service cannot be removed. sellable = sysparam(self.store).DELIVERY_SERVICE.sellable self.failIf(sellable.can_remove())
def test_get_balance(self): p = self.create_product() b1 = self.create_branch() b2 = self.create_branch() b3 = self.create_branch() storable = Storable(store=self.store, product=p) self.assertEqual(storable.get_balance_for_branch(b1), 0) self.assertEqual(storable.get_balance_for_branch(b2), 0) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 0) # Only b1 and b2 will increase stock storable.increase_stock(5, b1, 0, None) storable.increase_stock(10, b2, 0, None) self.assertEqual(storable.get_balance_for_branch(b1), 5) self.assertEqual(storable.get_balance_for_branch(b2), 10) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 15) # b1 will decrease *all* it's stock storable.decrease_stock(5, b1, 0, None) self.assertEqual(storable.get_balance_for_branch(b1), 0) self.assertEqual(storable.get_balance_for_branch(b2), 10) self.assertEqual(storable.get_balance_for_branch(b3), 0) self.assertEqual(storable.get_total_balance(), 10)
def test_can_remove(self): branch = get_current_branch(self.store) sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) self.failUnless(sellable.can_remove()) storable.increase_stock(1, branch, 0, None) sale = self.create_sale() sale.status = Sale.STATUS_QUOTE sale.branch = branch sale.add_sellable(sellable) self.failIf(sellable.can_remove()) # Can't remove the sellable if it's in a purchase. from stoqlib.domain.purchase import PurchaseItem sellable = self.create_sellable() Storable(product=sellable.product, store=self.store) self.assertTrue(sellable.can_remove()) PurchaseItem(store=self.store, quantity=8, quantity_received=0, cost=125, base_cost=125, sellable=sellable, order=self.create_purchase_order()) self.assertFalse(sellable.can_remove()) # The delivery service cannot be removed. sellable = sysparam(self.store).DELIVERY_SERVICE.sellable self.failIf(sellable.can_remove())
def add_product(self, sale, price=None, quantity=1): from stoqlib.domain.product import Storable product = self.create_product(price=price) sellable = product.sellable sellable.tax_constant = self.create_sellable_tax_constant() sale.add_sellable(sellable, quantity=quantity) storable = Storable(product=product, store=self.store) storable.increase_stock(100, get_current_branch(self.store), 0, 0) return sellable
def create_loan_item(self, loan=None, quantity=1): from stoqlib.domain.loan import LoanItem from stoqlib.domain.product import Storable, StockTransactionHistory loan = loan or self.create_loan() sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(10, loan.branch, type=StockTransactionHistory.TYPE_INITIAL, object_id=None) return LoanItem(loan=loan, sellable=sellable, price=10, quantity=quantity, store=self.store)
def add_product(self, sale, price=None, quantity=1): from stoqlib.domain.product import Storable product = self.create_product(price=price) sellable = product.sellable sellable.tax_constant = self.create_sellable_tax_constant() sale.add_sellable(sellable, quantity=quantity) storable = Storable(product=product, store=self.store) storable.increase_stock(100, get_current_branch(self.store), 0, 0) return sellable
def _create_sale(self, invoice_number, due_date=None): sale = self.create_sale() sale.invoice.invoice_number = invoice_number sale.branch = get_current_branch(self.store) tax_types = cycle(['aliq', 'nt', 'outr']) # [0] - Description # [1] - Code # [2] - Price # [3] - Quantity # [4] - Base price for tax_type, data in zip( tax_types, [(u"Laranja", u"1", Decimal(1), Decimal(10), Decimal('1.5')), (u"Limão", u"2", Decimal('0.5'), Decimal(15), Decimal('0.3')), (u"Abacaxi", u"3", Decimal(3), Decimal(1), Decimal('3.3')), (u"Cenoura", u"4", Decimal('1.5'), Decimal(6), Decimal('1.9')), (u"Pêssego", u"5", Decimal('3.5'), Decimal(3), Decimal('3.0'))]): sellable = self._create_sellable(data[0], data[1], data[2]) storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(data[3], get_current_branch(self.store), StockTransactionHistory.TYPE_INITIAL, sale.id, self.current_user) sale_item = sale.add_sellable(sellable, data[3]) if tax_type == 'aliq': self._add_aliq(sale_item) elif tax_type == 'nt': self._add_nt(sale_item) elif tax_type == 'outr': self._add_outr(sale_item) # Set the base price to test the discount in NF-e. sale_item.base_price = data[4] icms_info = sale_item.icms_info icms_info.csosn = 201 icms_info.p_icms_st = 1 self._update_taxes(sale_item) sale.client = self.create_client() self._create_address(sale.client.person, street=u"Rua dos Tomates", streetnumber=2666, postal_code=u'87654-321') sale.order(self.current_user) method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(sale.branch, sale.station, Payment.TYPE_IN, sale.group, sale.get_sale_subtotal(), due_date=due_date) sale.confirm(self.current_user) return sale
def add_product(self, sale, price=None, quantity=1, code=u''): from stoqlib.domain.product import Storable, StockTransactionHistory product = self.create_product(price=price, code=code) sellable = product.sellable sellable.tax_constant = self.create_sellable_tax_constant() sale.add_sellable(sellable, quantity=quantity) storable = Storable(product=product, store=self.store) storable.increase_stock(100, get_current_branch(self.store), type=StockTransactionHistory.TYPE_INITIAL, object_id=None) return sellable
def _create_sale(self, invoice_number, due_date=None): sale = self.create_sale() sale.invoice_number = invoice_number sale.branch = get_current_branch(self.store) tax_types = cycle(['aliq', 'nt', 'outr']) # [0] - Description # [1] - Code # [2] - Price # [3] - Quantity # [4] - Base price for tax_type, data in zip(tax_types, [ (u"Laranja", u"1", Decimal(1), Decimal(10), Decimal('1.5')), (u"Limão", u"2", Decimal('0.5'), Decimal(15), Decimal('0.3')), (u"Abacaxi", u"3", Decimal(3), Decimal(1), Decimal('3.3')), (u"Cenoura", u"4", Decimal('1.5'), Decimal(6), Decimal('1.9')), (u"Pêssego", u"5", Decimal('3.5'), Decimal(3), Decimal('3.0'))]): sellable = self._create_sellable(data[0], data[1], data[2]) storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(data[3], get_current_branch(self.store), StockTransactionHistory.TYPE_INITIAL, sale.id) sale_item = sale.add_sellable(sellable, data[3]) if tax_type == 'aliq': self._add_aliq(sale_item) elif tax_type == 'nt': self._add_nt(sale_item) elif tax_type == 'outr': self._add_outr(sale_item) # Set the base price to test the discount in NF-e. sale_item.base_price = data[4] icms_info = sale_item.icms_info icms_info.csosn = 201 icms_info.p_icms_st = 1 self._update_taxes(sale_item) sale.client = self.create_client() self._create_address(sale.client.person, street=u"Rua dos Tomates", streetnumber=2666, postal_code=u'87654-321') sale.order() method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal(), due_date=due_date) sale.confirm() return sale
def create_storable(self, product=None, branch=None, stock=0, unit_cost=None, is_batch=False): from stoqlib.domain.product import Storable, StockTransactionHistory if not product: sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store, is_batch=is_batch) if branch and stock: storable.increase_stock( stock, branch, type=StockTransactionHistory.TYPE_INITIAL, object_id=None, unit_cost=unit_cost ) return storable
def create_storable(self, product=None, branch=None, stock=0, unit_cost=None, is_batch=False): from stoqlib.domain.product import Storable if not product: sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store, is_batch=is_batch) if branch and stock: if unit_cost: storable.increase_stock(stock, branch, 0, 0, unit_cost) else: storable.increase_stock(stock, branch, 0, 0) return storable
def create_transfer_order_item(self, order=None, quantity=5, sellable=None): from stoqlib.domain.product import Product, Storable, StockTransactionHistory if not order: order = self.create_transfer_order() if not sellable: sellable = self.create_sellable() product = self.store.find(Product, sellable=sellable).one() if not product.storable: storable = Storable(product=product, store=self.store) storable.increase_stock(quantity, order.source_branch, type=StockTransactionHistory.TYPE_TRANSFER_FROM, object_id=None) return order.add_sellable(sellable, batch=None, quantity=quantity)
def create_storable(self, product=None, branch=None, stock=0, unit_cost=None): from stoqlib.domain.product import Storable if not product: sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store) if branch and stock: if unit_cost: storable.increase_stock(stock, branch, 0, 0, unit_cost) else: storable.increase_stock(stock, branch, 0, 0) return storable
def create_loan_item(self, loan=None, product=None, quantity=1): from stoqlib.domain.loan import LoanItem from stoqlib.domain.product import Storable loan = loan or self.create_loan() if not product: sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(10, loan.branch, 0, 0) else: sellable = product.sellable storable = product.storable return LoanItem(loan=loan, sellable=sellable, price=10, quantity=quantity, store=self.store)
def create_inventory_item(self, inventory=None, quantity=5): from stoqlib.domain.inventory import InventoryItem from stoqlib.domain.product import Storable if not inventory: inventory = self.create_inventory() sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store) storable.increase_stock(quantity, inventory.branch, 0, 0) return InventoryItem(product=product, product_cost=product.sellable.cost, recorded_quantity=quantity, inventory=inventory, store=self.store)
def create_inventory_item(self, inventory=None, quantity=5): from stoqlib.domain.inventory import InventoryItem from stoqlib.domain.product import Storable if not inventory: inventory = self.create_inventory() sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store) storable.increase_stock(quantity, inventory.branch, 0, 0) return InventoryItem(product=product, product_cost=product.sellable.cost, recorded_quantity=quantity, inventory=inventory, store=self.store)
def testIncreaseDecreaseStock(self): branch = get_current_branch(self.store) product = self.create_product() storable = Storable(product=product, store=self.store) stock_item = storable.get_stock_item(branch, None) self.failIf(stock_item is not None) storable.increase_stock(1, branch, 0, 0) stock_item = storable.get_stock_item(branch, None) self.assertEquals(stock_item.stock_cost, 0) storable.increase_stock(1, branch, 0, 0, unit_cost=10) stock_item = storable.get_stock_item(branch, None) self.assertEquals(stock_item.stock_cost, 5) stock_item = storable.decrease_stock(1, branch, 0, 0) self.assertEquals(stock_item.stock_cost, 5) storable.increase_stock(1, branch, 0, 0) stock_item = storable.get_stock_item(branch, None) self.assertEquals(stock_item.stock_cost, 5) storable.increase_stock(2, branch, 0, 0, unit_cost=15) stock_item = storable.get_stock_item(branch, None) self.assertEquals(stock_item.stock_cost, 10)
def testIncreaseDecreaseStock(self): branch = get_current_branch(self.store) product = self.create_product() storable = Storable(product=product, store=self.store) stock_item = storable.get_stock_item(branch) self.failIf(stock_item is not None) storable.increase_stock(1, branch, 0, 0) stock_item = storable.get_stock_item(branch) self.assertEquals(stock_item.stock_cost, 0) storable.increase_stock(1, branch, 0, 0, unit_cost=10) stock_item = storable.get_stock_item(branch) self.assertEquals(stock_item.stock_cost, 5) stock_item = storable.decrease_stock(1, branch, 0, 0) self.assertEquals(stock_item.stock_cost, 5) storable.increase_stock(1, branch, 0, 0) stock_item = storable.get_stock_item(branch) self.assertEquals(stock_item.stock_cost, 5) storable.increase_stock(2, branch, 0, 0, unit_cost=15) stock_item = storable.get_stock_item(branch) self.assertEquals(stock_item.stock_cost, 10)
def create_loan_item(self, loan=None, product=None, quantity=1): from stoqlib.domain.loan import LoanItem from stoqlib.domain.product import Storable loan = loan or self.create_loan() if not product: sellable = self.create_sellable() storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(10, loan.branch, 0, 0) else: sellable = product.sellable storable = product.storable return LoanItem(loan=loan, sellable=sellable, price=10, quantity=quantity, store=self.store)
def create_transfer_order_item(self, order=None, quantity=5, sellable=None): from stoqlib.domain.product import Product, Storable from stoqlib.domain.transfer import TransferOrderItem if not order: order = self.create_transfer_order() if not sellable: sellable = self.create_sellable() product = self.store.find(Product, sellable=sellable).one() if not product.storable: storable = Storable(product=product, store=self.store) storable.increase_stock(quantity, order.source_branch, 0, 0) return TransferOrderItem(sellable=sellable, transfer_order=order, quantity=quantity, store=self.store)
def create_product(self, price=None, create_supplier=True, branch=None, stock=None): from stoqlib.domain.product import Storable sellable = self.create_sellable(price=price) if create_supplier: self.create_product_supplier_info(product=sellable.product) product = sellable.product if not branch: branch = get_current_branch(self.store) if stock: storable = Storable(product=product, store=self.store) storable.increase_stock(stock, branch, 0, 0, unit_cost=10) return product
def create_product(self, price=None, create_supplier=True, branch=None, stock=None): from stoqlib.domain.product import Storable sellable = self.create_sellable(price=price) if create_supplier: self.create_product_supplier_info(product=sellable.product) product = sellable.product if not branch: branch = get_current_branch(self.store) if stock: storable = Storable(product=product, store=self.store) storable.increase_stock(stock, branch, 0, 0, unit_cost=10) return product
def create_inventory_item(self, inventory=None, quantity=5): from stoqlib.domain.inventory import InventoryItem from stoqlib.domain.product import Storable, StockTransactionHistory if not inventory: inventory = self.create_inventory() sellable = self.create_sellable() product = sellable.product storable = Storable(product=product, store=self.store) storable.increase_stock(quantity, inventory.branch, type=StockTransactionHistory.TYPE_INITIAL, object_id=None) return InventoryItem(product=product, product_cost=product.sellable.cost, recorded_quantity=quantity, inventory=inventory, store=self.store)
def testCanRemove(self): product = self.create_product() storable = Storable(product=product, store=self.store) self.assertTrue(product.can_remove()) storable.increase_stock(1, get_current_branch(self.store), 0, 0) self.assertFalse(product.can_remove()) # Product was sold. sale = self.create_sale() sale.add_sellable(product.sellable, quantity=1, price=10) method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal()) sale.order() sale.confirm() self.assertFalse(product.can_remove()) # Product is a component. from stoqlib.domain.product import ProductComponent product = self.create_product(10) component = self.create_product(5) Storable(product=component, store=self.store) self.assertTrue(component.can_remove()) ProductComponent(product=product, component=component, store=self.store) self.assertFalse(component.can_remove()) # Product is used in a production. from stoqlib.domain.production import ProductionItem product = self.create_product() Storable(product=product, store=self.store) self.assertTrue(product.can_remove()) order = self.create_production_order() ProductionItem(product=product, order=order, quantity=1, store=self.store) self.assertFalse(product.can_remove())
def testCanRemove(self): product = self.create_product() storable = Storable(product=product, store=self.store) self.assertTrue(product.can_remove()) storable.increase_stock(1, get_current_branch(self.store), 0, 0) self.assertFalse(product.can_remove()) # Product was sold. sale = self.create_sale() sale.add_sellable(product.sellable, quantity=1, price=10) method = PaymentMethod.get_by_name(self.store, u'money') method.create_inpayment(sale.group, sale.branch, sale.get_sale_subtotal()) sale.order() sale.confirm() self.assertFalse(product.can_remove()) # Product is a component. from stoqlib.domain.product import ProductComponent product = self.create_product(10) component = self.create_product(5) Storable(product=component, store=self.store) self.assertTrue(component.can_remove()) ProductComponent(product=product, component=component, store=self.store) self.assertFalse(component.can_remove()) # Product is used in a production. from stoqlib.domain.production import ProductionItem product = self.create_product() Storable(product=product, store=self.store) self.assertTrue(product.can_remove()) order = self.create_production_order() ProductionItem(product=product, order=order, quantity=1, store=self.store) self.assertFalse(product.can_remove())
def create_product(self, price=None, with_supplier=True, branch=None, stock=None, storable=False, code=u""): from stoqlib.domain.product import Storable, StockTransactionHistory sellable = self.create_sellable(price=price, code=code) if with_supplier: self.create_product_supplier_info(product=sellable.product) product = sellable.product if not branch: branch = get_current_branch(self.store) if storable or stock: storable = Storable(product=product, store=self.store) if stock: storable.increase_stock( stock, branch, type=StockTransactionHistory.TYPE_INITIAL, object_id=None, unit_cost=10 ) return product
def _create_sale(self, invoice_number, due_date=None): sale = self.create_sale() sale.invoice_number = invoice_number sale.branch = get_current_branch(self.store) # [0] - Description # [1] - Code # [2] - Price # [3] - Quantity for data in [(u"Laranja", u"1", Decimal(1), Decimal(10)), (u"Limão", u"2", Decimal('0.5'), Decimal(15)), (u"Abacaxi", u"3", Decimal(3), Decimal(1)), (u"Cenoura", u"4", Decimal('1.5'), Decimal(6)), (u"Pêssego", u"5", Decimal('3.5'), Decimal(3))]: sellable = self._create_sellable(data[0], data[1], data[2]) storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(data[3], get_current_branch(self.store), StockTransactionHistory.TYPE_INITIAL, sale.id) sale.add_sellable(sellable, data[3]) sale.client = self.create_client() self._create_address(sale.client.person, street=u"Rua dos Tomates", streetnumber=2666, postal_code=u'87654-321') sale.order() method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal(), due_date=due_date) sale.confirm() return sale
def _create_sale(self, invoice_number, due_date=None): sale = self.create_sale() sale.invoice_number = invoice_number sale.branch = get_current_branch(self.store) # [0] - Description # [1] - Code # [2] - Price # [3] - Quantity for data in [(u"Laranja", u"1", Decimal(1), Decimal(10)), (u"Limão", u"2", Decimal('0.5'), Decimal(15)), (u"Abacaxi", u"3", Decimal(3), Decimal(1)), (u"Cenoura", u"4", Decimal('1.5'), Decimal(6)), (u"Pêssego", u"5", Decimal('3.5'), Decimal(3))]: sellable = self._create_sellable(data[0], data[1], data[2]) storable = Storable(product=sellable.product, store=self.store) storable.increase_stock(data[3], get_current_branch(self.store), 0, sale.id) sale.add_sellable(sellable, data[3]) sale.client = self.create_client() self._create_address(sale.client.person, street=u"Rua dos Tomates", streetnumber=2666, postal_code=u'87654-321') sale.order() method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal(), due_date=due_date) sale.confirm() return sale