def test_with_unblocked_sellables_query(self): p1 = self.create_product() supplier = self.create_supplier() # Product should appear when querying without a supplier query = Sellable.get_unblocked_sellables_query(self.store) results = self.store.find(ProductFullStockView, query) self.assertTrue(p1.id in [p.product_id for p in results]) # But should not appear when querying with a supplier # When querying using the supplier, we should use the # ProductFullStockSupplierView instead. query = Sellable.get_unblocked_sellables_query(self.store, supplier=supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertFalse(p1.id in [p.id for p in results]) # Now relate the two ProductSupplierInfo(store=self.store, supplier=supplier, product=p1, is_main_supplier=True) # And it should appear now query = Sellable.get_unblocked_sellables_query(self.store, supplier=supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertTrue(p1.id in [s.product_id for s in results]) # But should not appear for a different supplier other_supplier = self.create_supplier() query = Sellable.get_unblocked_sellables_query(self.store, supplier=other_supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertFalse(p1.id in [s.product_id for s in results])
def test_with_unblocked_sellables_query(self): # This is used in the purchase wizard and breaks storm from stoqlib.domain.sellable import Sellable p1 = self.create_product() supplier = self.create_supplier() # Product should appear when querying without a supplier query = Sellable.get_unblocked_sellables_query(self.store) results = self.store.find(ProductFullStockView, query) self.assertTrue(p1.id in [p.product_id for p in results]) # But should not appear when querying with a supplier # When querying using the supplier, we should use the # ProductFullStockSupplierView instead. query = Sellable.get_unblocked_sellables_query(self.store, supplier=supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertFalse(p1.id in [p.id for p in results]) # Now relate the two ProductSupplierInfo(store=self.store, supplier=supplier, product=p1, is_main_supplier=True) # And it should appear now query = Sellable.get_unblocked_sellables_query(self.store, supplier=supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertTrue(p1.id in [s.product_id for s in results]) # But should not appear for a different supplier other_supplier = self.create_supplier() query = Sellable.get_unblocked_sellables_query(self.store, supplier=other_supplier) results = self.store.find(ProductFullStockItemSupplierView, query) self.assertFalse(p1.id in [s.product_id for s in results])
def get_sellable_view_query(self): """This method should return a tuple containing the viewable that should be used and a query that should filter the sellables that can and cannot be added to this step. """ return (self.sellable_view, Sellable.get_unblocked_sellables_query(self.store))
def get_sellable_view_query(self): branch = api.get_current_branch(self.store) branch_query = self.sellable_view.branch_id == branch.id sellable_query = Sellable.get_unblocked_sellables_query(self.store, storable=True) query = And(branch_query, sellable_query) return self.sellable_view, query
def test_run_wizard(self, run_dialog, new_store): run_dialog.return_value = None new_store.return_value = self.store query = Sellable.get_unblocked_sellables_query(self.store) dialog = PurchaseSellableSearch(store=self.store, search_spec=ProductFullStockView, search_query=query) with mock.patch.object(self.store, "commit"): with mock.patch.object(self.store, "close"): self.click(dialog._toolbar.new_button) run_dialog.assert_called_once_with(ProductCreateWizard, dialog, self.store)
def test_run_wizard(self, run_dialog, new_store): run_dialog.return_value = None new_store.return_value = self.store query = Sellable.get_unblocked_sellables_query(self.store) dialog = PurchaseSellableSearch(store=self.store, search_spec=ProductFullStockView, search_query=query) with mock.patch.object(self.store, 'commit'): with mock.patch.object(self.store, 'close'): self.click(dialog._toolbar.new_button) run_dialog.assert_called_once_with(ProductCreateWizard, dialog, self.store)
def test_run_editor(self, run_dialog, new_store): run_dialog.return_value = None new_store.return_value = self.store query = Sellable.get_unblocked_sellables_query(self.store) dialog = PurchaseSellableSearch(store=self.store, search_spec=ProductFullStockView, search_query=query) dialog.search.refresh() dialog.results.select(dialog.results[0]) product = dialog.results[0].product with mock.patch.object(self.store, "commit"): with mock.patch.object(self.store, "close"): self.click(dialog._toolbar.edit_button) run_dialog.assert_called_once_with(ProductEditor, dialog, self.store, product, visual_mode=False)
def get_sellable_view_query(self): supplier = self.model.supplier if self.wizard.all_products: supplier = None # If we our query includes the supplier, we must use another viewable, # that actually joins with that table if supplier: viewable = ProductFullStockItemSupplierView else: viewable = self.sellable_view query = Sellable.get_unblocked_sellables_query(self.store, supplier=supplier, consigned=self.model.consigned) return viewable, query
def test_run_editor(self, run_dialog, new_store): run_dialog.return_value = None new_store.return_value = self.store query = Sellable.get_unblocked_sellables_query(self.store) dialog = AdvancedSellableSearch(store=self.store, table=ProductFullStockView, query=query) dialog.search.refresh() dialog.results.select(dialog.results[0]) product = dialog.results[0].product with mock.patch.object(self.store, 'commit'): with mock.patch.object(self.store, 'close'): self.click(dialog._toolbar.edit_button) run_dialog.assert_called_once_with(ProductEditor, dialog, self.store, product, visual_mode=False)
def get_sellable_view_query(self): sellable_query = And( Sellable.get_unblocked_sellables_query(self.store, storable=False), self.sellable_view.branch_id == self.model.source_branch_id) return self.sellable_view, sellable_query
def get_sellable_view_query(self): branch_query = self.sellable_view.branch_id == self.model.branch.id sellable_query = Sellable.get_unblocked_sellables_query(self.store, storable=True) query = And(branch_query, sellable_query) return self.sellable_view, query
def get_sellable_view_query(self): query = Sellable.get_unblocked_sellables_query(self.store) return self.sellable_view, query
def get_sellable_view_query(self): sellable_query = Sellable.get_unblocked_sellables_query(self.store, storable=False) return self.sellable_view, sellable_query