コード例 #1
0
    def _check_branch(self):
        from stoqlib.database.runtime import (get_default_store, new_store,
                                              get_current_station,
                                              set_current_branch_station)
        from stoqlib.domain.person import Company
        from stoqlib.lib.parameters import sysparam
        from stoqlib.lib.message import info

        default_store = get_default_store()

        compaines = default_store.find(Company)
        if (compaines.count() == 0 or
                not sysparam.has_object('MAIN_COMPANY')):
            from stoqlib.gui.base.dialogs import run_dialog
            from stoqlib.gui.dialogs.branchdialog import BranchDialog
            if self._ran_wizard:
                info(_("You need to register a company before start using Stoq"))
            else:
                info(_("Could not find a company. You'll need to register one "
                       "before start using Stoq"))
            store = new_store()
            person = run_dialog(BranchDialog, None, store)
            if not person:
                raise SystemExit
            branch = person.branch
            sysparam.set_object(store, 'MAIN_COMPANY', branch)
            current_station = get_current_station(store)
            if current_station is not None:
                current_station.branch = branch
            store.commit()
            store.close()

        set_current_branch_station(default_store, station_name=None)
コード例 #2
0
ファイル: nfe.py プロジェクト: pauloscarin1972/stoq
    def create_purchase_order(self,
                              responsible,
                              create_payments=False,
                              station_name=u'StoqLinkServer'):
        payment_group = self._create_payment_group()
        identifier = PurchaseOrder.get_temporary_identifier(self.store)
        notes = _(u"Invoice number: %s") % self.invoice_number
        station = set_current_branch_station(self.store,
                                             station_name,
                                             confirm=False)
        self._create_and_confirm_purchase_order(identifier, payment_group,
                                                notes, station, responsible)
        if create_payments:
            self._create_payments(station)

        self.create_receiving_order(station)
        self.store.commit()

        return self.purchase_order
コード例 #3
0
ファイル: startup.py プロジェクト: Guillon88/stoq
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    if register_station:
        try:
            default_store = get_default_store()
        except DatabaseError as e:
            error(e.short, str(e.msg))

        config.get_settings().check_version(default_store)

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        default_store = get_default_store()
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()
コード例 #4
0
ファイル: startup.py プロジェクト: 5l1v3r1/stoq-1
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    db_settings = config.get_settings()
    try:
        default_store = get_default_store()
    except DatabaseError as e:
        # Only raise an error if a database is actually required
        if register_station or load_plugins or check_schema:
            error(e.short, str(e.msg))
        else:
            default_store = None

    if register_station:
        db_settings.check_version(default_store)
        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()