def _get_or_create_quote_group(self, order, store): if order is not None: quotation = store.find(Quotation, purchase=order).one() return quotation.group else: return QuoteGroup(branch=api.get_current_branch(store), store=store)
def test_cancel(self): order = self.create_purchase_order() quote = QuoteGroup(store=self.store, branch=order.branch) order.status = PurchaseOrder.ORDER_QUOTING quote.add_item(order) self.assertEqual(order.status, PurchaseOrder.ORDER_QUOTING) order.cancel() self.assertEqual(order.status, PurchaseOrder.ORDER_CANCELLED)
def test_remove_item(self): order = self.create_purchase_order() quote = QuoteGroup(store=self.store, branch=order.branch) order.status = PurchaseOrder.ORDER_QUOTING quote.add_item(order) items = quote.get_items() item = items.one() self.assertEquals(item.purchase, order) quote.remove_item(item) items = quote.get_items() self.assertFalse(items)
def test_close(self): order = self.create_purchase_order() quote = QuoteGroup(store=self.store, branch=order.branch) order.status = PurchaseOrder.ORDER_QUOTING quote.add_item(order) self.assertEqual(order.status, PurchaseOrder.ORDER_QUOTING) quotations = quote.get_items() self.assertEqual(quotations.count(), 1) self.assertFalse(quotations[0].is_closed()) quotations[0].close() self.assertTrue(quotations[0].is_closed()) self.assertEqual(order.status, PurchaseOrder.ORDER_CANCELLED)
def test_group_quotation_purchase(self): order = self.create_purchase_order() quote = QuoteGroup(store=self.store, branch=order.branch) order.status = PurchaseOrder.ORDER_QUOTING quote.add_item(order) self.assertEqual(order.status, PurchaseOrder.ORDER_QUOTING) quotations = quote.get_items() self.assertEqual(quotations.count(), 1) self.assertFalse(quotations[0].is_closed()) quotations[0].close() results = self.store.find(QuotationView, id=quotations[0].id) self.failUnless(list(results)) self.assertEquals(results.count(), 1) self.assertEquals(results[0].group, quote) self.assertEquals(results[0].quotation, quotations[0]) self.assertEquals(results[0].purchase, order)
def create_quote_group(self, productions, store): quote_data = {} to_quote_items = {} # For each select production, we get all materials that need to be # purchased. for production in productions: for material in production.get_material_items(): if material.to_purchase <= 0: continue sellable = material.product.sellable quantity = material.to_purchase if sellable in to_quote_items: to_quote_items[sellable] += quantity else: to_quote_items[sellable] = quantity # For each material we need to buy, we build a dictionary relating # them to the suppliers. for sellable, quantity in to_quote_items.items(): product = sellable.product for supplier_info in product.suppliers: supplier = supplier_info.supplier quote_data.setdefault(supplier, []).append( (sellable, quantity)) group = QuoteGroup(store=store, station=api.get_current_station(store), branch=api.get_current_branch(store)) # For each supplier that offer a material we need, we create a quote # with all the materials he offers and add it to the group. for supplier, items in quote_data.items(): order = self._create_purchase_order(store, supplier, items) group.add_item(order) return group
def create_quote_group(self, branch=None): from stoqlib.domain.purchase import QuoteGroup if not branch: branch = get_current_branch(self.store) return QuoteGroup(store=self.store, branch=branch)