Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
    def _register_station(self):
        # Register the current computer as a branch station
        from stoqlib.database.runtime import new_store
        from stoqlib.domain.person import Branch
        from stoqlib.domain.station import BranchStation
        from stoqlib.exceptions import StoqlibError
        from stoqlib.net.socketutils import get_hostname
        store = new_store()

        branches = store.find(Branch)
        if branches:
            branch = branches[0]
        else:
            branch = None

        try:
            BranchStation(store=store,
                          is_active=True,
                          branch=branch,
                          name=get_hostname())
        except StoqlibError as e:
            raise SystemExit("ERROR: %s" % e)

        store.commit()
        store.close()
Exemple #5
0
def _set_person_utilities():
    store = new_store()
    branch = sysparam.get_object(store, 'MAIN_COMPANY')
    provide_utility(ICurrentBranch, branch)

    station = BranchStation(name=u"Stoqlib station", branch=branch,
                            store=store, is_active=True)
    provide_utility(ICurrentBranchStation, station)
    store.commit(close=True)
Exemple #6
0
    def setup_station_combo(self):
        if self._branch_station:
            self.station.prefill([(self._branch_station.name,
                                   self._branch_station)])
            self.model.station = self._branch_station
            return

        self.station.prefill(
            [(station.name, station)
             for station in BranchStation.get_active_stations(self.store)])
Exemple #7
0
    def setup_station_combo(self):
        if self._branch_station:
            self.station.prefill([(self._branch_station.name,
                                   self._branch_station)])
            self.model.station = self._branch_station
            return

        self.station.prefill(
            [(station.name, station)
             for station in BranchStation.get_active_stations(self.store)])
Exemple #8
0
    def setup_proxies(self):
        stations = BranchStation.get_active_stations(self.store)
        self.station.prefill([(station.name, station)
                              for station in stations])

        layouts = self.store.find(InvoiceLayout)
        self.layout.prefill([(layout.get_description(), layout)
                             for layout in layouts.order_by(InvoiceLayout.description)])

        self.proxy = self.add_proxy(self.model,
                                    InvoicePrinterEditor.proxy_widgets)
Exemple #9
0
    def setup_proxies(self):
        stations = BranchStation.get_active_stations(self.store)
        self.station.prefill([(station.name, station)
                              for station in stations])

        layouts = self.store.find(InvoiceLayout)
        self.layout.prefill([(layout.get_description(), layout)
                             for layout in layouts.order_by(InvoiceLayout.description)])

        self.proxy = self.add_proxy(self.model,
                                    InvoicePrinterEditor.proxy_widgets)
Exemple #10
0
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()
Exemple #11
0
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()
Exemple #12
0
    def _create_station(self, store):
        # FIXME: This is fishy, we can probably simplify this significantly by
        #        allowing users to connect to the initial database without
        #        having a branch station nor branch registered.
        #        The whole BranchStation/Branch creation is weird, it should
        #        be done at the same place.
        logger.info('_create_station')
        if self.create_examples:
            branch = api.sysparam.get_object(store, 'MAIN_COMPANY')
            assert branch
            provide_utility(ICurrentBranch, branch)
        else:
            branch = None

        station_name = get_hostname()
        if store.find(BranchStation, branch=branch, name=station_name).one():
            return
        station = BranchStation(store=store,
                                is_active=True,
                                branch=branch,
                                name=station_name)
        provide_utility(ICurrentBranchStation, station)
Exemple #13
0
 def test_get_station(self):
     with self.assertRaisesRegexp(
         TypeError, ur"BranchStation.get_station\(\) requires a Branch"):
         BranchStation.get_station(self.store, None, None)
Exemple #14
0
 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')
Exemple #15
0
 def test_get_active_stations(self):
     active = self.store.find(BranchStation, is_active=True).order_by(
         BranchStation.name)
     self.assertEquals(set(BranchStation.get_active_stations(self.store)),
                       set(active))
Exemple #16
0
 def test_get_station(self):
     with self.assertRaisesRegex(
             TypeError, r"BranchStation.get_station\(\) requires a Branch"):
         BranchStation.get_station(self.store, None, None)
Exemple #17
0
 def test_get_active_stations(self):
     active = self.store.find(BranchStation,
                              is_active=True).order_by(BranchStation.name)
     self.assertEqual(set(BranchStation.get_active_stations(self.store)),
                      set(active))
Exemple #18
0
    def test_check_station_exists(self):
        station = self.create_station()
        self.assertFalse(station.check_station_exists(u'foo'))

        BranchStation(name=u'foo', store=self.store)
        self.assertTrue(station.check_station_exists(u'foo'))
Exemple #19
0
 def create_station(self):
     from stoqlib.domain.station import BranchStation
     return BranchStation(name=u"station",
                          branch=get_current_branch(self.store),
                          store=self.store)
Exemple #20
0
    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
Exemple #21
0
 def create_model(self, store):
     return BranchStation(name=u"",
                          branch=None,
                          is_active=True,
                          store=store)