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 _cancel_group(self): msg = _("This will cancel the group and related quotes. " "Are you sure?") if not yesno(msg, gtk.RESPONSE_NO, _("Cancel group"), _("Don't Cancel")): return store = api.new_store() group = store.fetch(self._group) group.cancel() QuoteGroup.delete(group.id, store=store) store.confirm(True) store.close() self.wizard.finish()
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 _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 _remove_quote(self): q = self.search.results.get_selected().quotation msg = _('Are you sure you want to remove "%s" ?') % q.get_description() if not yesno(msg, gtk.RESPONSE_NO, _("Remove quote"), _("Don't remove")): return store = api.new_store() group = store.fetch(q.group) quote = store.fetch(q) group.remove_item(quote) # there is no reason to keep the group if there's no more quotes if group.get_items().count() == 0: QuoteGroup.delete(group.id, store=store) store.confirm(True) store.close() self.search.refresh()
def testGroupQuotationPurchase(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 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 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 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, 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, 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)