def test_create(self): branch = self.create_branch() BranchStation.create(self.store, branch, u'foo') with self.assertRaisesRegex( StoqlibError, u"There is already a station registered as `foo'."): BranchStation.create(self.store, branch, u'foo')
def _register_branch_station(caller_store, station_name, confirm=True): from gi.repository import Gtk from stoqlib.lib.parameters import sysparam if not sysparam.get_bool('DEMO_MODE'): fmt = _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") if confirm and not yesno(fmt % (station_name, db_settings.address), Gtk.ResponseType.YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.utils.login import LoginHelper h = LoginHelper() try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.station import BranchStation with new_store() as store: branch = sysparam.get_object(store, 'MAIN_COMPANY') station = BranchStation.create(store, branch=branch, name=station_name) return caller_store.fetch(station)
def _register_branch_station(caller_store, station_name): import gtk from stoqlib.lib.parameters import sysparam if not sysparam.get_bool('DEMO_MODE'): fmt = _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") if not yesno(fmt % (station_name, db_settings.address), gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.utils.login import LoginHelper h = LoginHelper(username="******") try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.station import BranchStation with new_store() as store: branch = sysparam.get_object(store, 'MAIN_COMPANY') station = BranchStation.create(store, branch=branch, name=station_name) return caller_store.fetch(station)
def _provide_current_station(station_name=None, branch_name=None): if not station_name: station_name = get_hostname() store = new_store() if branch_name: branch = store.find( Person, And(Person.name == branch_name, Branch.person_id == Person.id)).one() else: branches = store.find(Branch) if branches.count() == 0: person = Person(name=u"test", store=store) branch = Branch(person=person, store=store) else: branch = branches[0] provide_utility(ICurrentBranch, branch) station = BranchStation.get_station(store, branch, station_name) if not station: station = BranchStation.create(store, branch, station_name) assert station assert station.is_active provide_utility(ICurrentBranchStation, station) store.commit(close=True)
def _provide_current_station(station_name=None, branch_name=None): if not station_name: station_name = get_hostname() store = new_store() if branch_name: branch = store.find(Person, And(Person.name == branch_name, Branch.person_id == Person.id)).one() else: branches = store.find(Branch) if branches.count() == 0: person = Person(name=u"test", store=store) branch = Branch(person=person, store=store) else: branch = branches[0] provide_utility(ICurrentBranch, branch) station = BranchStation.get_station(store, branch, station_name) if not station: station = BranchStation.create(store, branch, station_name) assert station assert station.is_active provide_utility(ICurrentBranchStation, station) store.commit(close=True)
def _register_branch(caller_store, station_name): import gtk from stoqlib.lib.parameters import sysparam if not sysparam(caller_store).DEMO_MODE: fmt = _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") if not yesno(fmt % (station_name, db_settings.address), gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.utils.login import LoginHelper h = LoginHelper(username="******") try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.person import Branch from stoqlib.domain.station import BranchStation branches = caller_store.find(Branch) if branches.is_empty(): error(_("Schema error, no branches found")) # TODO # Always select the first branch as the main branch, until we # support multiple branches properly. And then, provide a way to the # user choose which one will be the main branch. branch = branches[0] store = new_store() try: station = BranchStation.create(store, branch=store.fetch(branch), name=station_name) except StoqlibError as e: error(_("ERROR: %s") % e) station_id = station.id store.commit(close=True) return caller_store.find(BranchStation, id=station_id).one()
def _register_branch(caller_store, station_name): import gtk from stoqlib.lib.parameters import sysparam if not sysparam(caller_store).DEMO_MODE: if not yesno( _(u"The computer '%s' is not registered to the Stoq " u"server at %s.\n\n" u"Do you want to register it " u"(requires administrator access) ?") % (station_name, db_settings.address), gtk.RESPONSE_YES, _(u"Register computer"), _(u"Quit")): raise SystemExit from stoqlib.gui.login import LoginHelper h = LoginHelper(username="******") try: user = h.validate_user() except LoginError as e: error(str(e)) if not user: error(_("Must login as 'admin'")) from stoqlib.domain.person import Branch from stoqlib.domain.station import BranchStation branches = caller_store.find(Branch) if branches.is_empty(): error(_("Schema error, no branches found")) # TODO # Always select the first branch as the main branch, until we # support multiple branches properly. And then, provide a way to the # user choose which one will be the main branch. branch = branches[0] store = new_store() try: station = BranchStation.create(store, branch=store.fetch(branch), name=station_name) except StoqlibError as e: error(_("ERROR: %s") % e) station_id = station.id store.commit(close=True) return caller_store.find(BranchStation, id=station_id).one()
def test_create(self): branch = self.create_branch() BranchStation.create(self.store, branch, u'foo') with self.assertRaisesRegexp( StoqlibError, u"There is already a station registered as `foo'."): BranchStation.create(self.store, branch, u'foo')
from stoqlib.domain.station import BranchStation branches = caller_store.find(Branch) if branches.is_empty(): error(_("Schema error, no branches found")) # TODO # Always select the first branch as the main branch, until we # support multiple branches properly. And then, provide a way to the # user choose which one will be the main branch. branch = branches[0] store = new_store() try: station = BranchStation.create(store, branch=store.fetch(branch), name=station_name) except StoqlibError, e: error(_("ERROR: %s") % e) station_id = station.id store.commit(close=True) return caller_store.find(BranchStation, id=station_id).one() def set_current_branch_station(store, station_name): """Registers the current station and the branch of the station as the current branch for the system :param store: a store :param station_name: name of the station to register