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)
def sysparam(self, **kwargs): """ Updates a set of system parameters within a context. The values will be reverted when leaving the scope. kwargs contains a dictionary of parameter name->value """ from stoqlib.lib.parameters import sysparam old_values = {} for param, value in kwargs.items(): if type(value) is bool: old_values[param] = sysparam.get_bool(param) sysparam.set_bool(self.store, param, value) elif isinstance(value, Domain) or value is None: old_values[param] = sysparam.get_object(self.store, param) sysparam.set_object(self.store, param, value) else: raise NotImplementedError(type(value)) try: yield finally: for param, value in old_values.items(): if type(value) is bool: sysparam.set_bool(self.store, param, value) elif isinstance(value, Domain) or value is None: sysparam.set_object(self.store, param, value) else: raise NotImplementedError(type(value))
def when_done(self, store): if sysparam.has_object('SUGGESTED_SUPPLIER'): return if not self.suppliers: return sysparam.set_object(store, 'SUGGESTED_SUPPLIER', self.suppliers[0])
def when_done(self, store): if sysparam.has_object('MAIN_COMPANY'): return if not self.branches: return sysparam.set_object(store, 'MAIN_COMPANY', self.branches[0]) assert sysparam.has_object('MAIN_COMPANY')
def test_can_close(self): service = self.create_service() self.assertTrue(service.can_close()) old = sysparam.get_object(self.store, 'DELIVERY_SERVICE') try: sysparam.set_object(self.store, 'DELIVERY_SERVICE', service) self.assertFalse(service.can_close()) finally: sysparam.set_object(self.store, 'DELIVERY_SERVICE', old)
def create_main_branch(store, name): """Creates a new branch and sets it as the main branch for the system :param store: a store :param name: name of the new branch """ person = Person(name=name, store=store) Company(person=person, store=store) branch = Branch(person=person, store=store) sysparam.set_object(store, 'MAIN_COMPANY', branch) provide_utility(ICurrentBranch, branch) admin = get_admin_user(store) admin.add_access_to(branch) return branch
def sysparam(self, **kwargs): """ Updates a set of system parameters within a context. The values will be reverted when leaving the scope. kwargs contains a dictionary of parameter name->value """ from stoqlib.lib.parameters import sysparam old_values = {} for param, value in kwargs.items(): if isinstance(value, bool): old_values[param] = sysparam.get_bool(param) sysparam.set_bool(self.store, param, value) elif isinstance(value, int): old_values[param] = sysparam.get_int(param) sysparam.set_int(self.store, param, value) elif isinstance(value, Domain) or value is None: old_values[param] = sysparam.get_object(self.store, param) sysparam.set_object(self.store, param, value) elif isinstance(value, str): old_values[param] = sysparam.get_string(param) sysparam.set_string(self.store, param, value) elif isinstance(value, Decimal): old_values[param] = sysparam.get_decimal(param) sysparam.set_decimal(self.store, param, value) else: raise NotImplementedError(type(value)) try: yield finally: for param, value in old_values.items(): if isinstance(value, bool): sysparam.set_bool(self.store, param, value) elif isinstance(value, int): sysparam.set_int(self.store, param, value) elif isinstance(value, Domain) or value is None: sysparam.set_object(self.store, param, value) elif isinstance(value, str): sysparam.set_string(self.store, param, value) elif isinstance(value, Decimal): sysparam.set_decimal(self.store, param, value) else: raise NotImplementedError(type(value))
def register_accounts(store): # FIXME: If you need to run this in a patch, you need to # make sure that .find().one() is fixed bellow, as accounts # with the same names are allowed. # It's for now okay to run this when creating a new # database. from stoqlib.domain.account import Account log.info("Creating Accounts") for name, atype in [ (_(u"Assets"), Account.TYPE_ASSET), (_(u"Banks"), Account.TYPE_BANK), (_(u"Equity"), Account.TYPE_EQUITY), (_(u"Expenses"), Account.TYPE_EXPENSE), (_(u"Imbalance"), Account.TYPE_BANK), (_(u"Income"), Account.TYPE_INCOME), (_(u"Tills"), Account.TYPE_CASH), ]: # FIXME: This needs to rewritten to not use .find().one(), # see comment above. account = store.find(Account, description=name).one() if not account: account = Account(store=store, description=name) account.account_type = atype sysparam.set_object(store, "BANKS_ACCOUNT", store.find(Account, description=_(u"Banks")).one()) sysparam.set_object(store, "TILLS_ACCOUNT", store.find(Account, description=_(u"Tills")).one()) sysparam.set_object(store, "IMBALANCE_ACCOUNT", store.find(Account, description=_(u"Imbalance")).one())
def register_accounts(store): # FIXME: If you need to run this in a patch, you need to # make sure that .find().one() is fixed bellow, as accounts # with the same names are allowed. # It's for now okay to run this when creating a new # database. from stoqlib.domain.account import Account log.info("Creating Accounts") for name, atype in [ (_(u"Assets"), Account.TYPE_ASSET), (_(u"Banks"), Account.TYPE_BANK), (_(u"Equity"), Account.TYPE_EQUITY), (_(u"Expenses"), Account.TYPE_EXPENSE), (_(u"Imbalance"), Account.TYPE_BANK), (_(u"Income"), Account.TYPE_INCOME), (_(u"Tills"), Account.TYPE_CASH), ]: # FIXME: This needs to rewritten to not use .find().one(), # see comment above. account = store.find(Account, description=name).one() if not account: account = Account(store=store, description=name) account.account_type = atype sysparam.set_object(store, 'BANKS_ACCOUNT', store.find(Account, description=_(u"Banks")).one()) sysparam.set_object(store, 'TILLS_ACCOUNT', store.find(Account, description=_(u"Tills")).one()) sysparam.set_object(store, 'IMBALANCE_ACCOUNT', store.find(Account, description=_(u"Imbalance")).one())
def test_can_remove(self): service = self.create_service() old = sysparam.get_object(self.store, 'DELIVERY_SERVICE') try: sysparam.set_object(self.store, 'DELIVERY_SERVICE', service) self.assertFalse(service.can_remove()) finally: sysparam.set_object(self.store, 'DELIVERY_SERVICE', old) # Service already used. sale = self.create_sale() sale.add_sellable(service.sellable, quantity=1, price=10) self.assertFalse(service.sellable.can_remove()) # Service is used in a production. from stoqlib.domain.production import ProductionService service = self.create_service() self.assertTrue(service.can_remove()) ProductionService(service=service, order=self.create_production_order(), store=self.store) self.assertFalse(service.can_remove())
def test_get_logo_data(self): image = self.create_image() image.image = b'foobar' sysparam.set_object(self.store, 'CUSTOM_LOGO_FOR_REPORTS', image) data = get_logo_data(self.store) self.assertEquals(data, 'data:image/png;base64,Zm9vYmFy')
def test_get_logo_data(self): image = self.create_image() image.image = "foobar" sysparam.set_object(self.store, "CUSTOM_LOGO_FOR_REPORTS", image) data = get_logo_data(self.store) self.assertEquals(data, "data:image/png;base64,Zm9vYmFy")
def test_get_logo_data(self): image = self.create_image() image.image = b'foobar' sysparam.set_object(self.store, 'CUSTOM_LOGO_FOR_REPORTS', image) data = get_logo_data(self.store) self.assertEqual(data, 'data:image/png;base64,Zm9vYmFy')
def on_confirm(self): if (isinstance(self.model, Supplier) and not sysparam.has_object('SUGGESTED_SUPPLIER')): sysparam.set_object(self.store, 'SUGGESTED_SUPPLIER', self.model)