示例#1
0
文件: admin.py 项目: romaia/stoq
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

    sparam = sysparam(store)
    sparam.BANKS_ACCOUNT = store.find(Account, description=_(u"Banks")).one().id
    sparam.TILLS_ACCOUNT = store.find(Account, description=_(u"Tills")).one().id
    sparam.IMBALANCE_ACCOUNT = store.find(Account,
                                          description=_(u"Imbalance")).one().id
示例#2
0
文件: admin.py 项目: 5l1v3r1/stoq-1
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())
示例#3
0
    def test_get_children_for(self):
        a1 = self.create_account()
        self.assertTrue(Account.get_children_for(self.store, a1).is_empty())

        a2 = self.create_account()
        a2.parent = a1
        self.assertEquals(Account.get_children_for(self.store, a1).one(), a2)

        a3 = self.create_account()
        self.assertEquals(Account.get_children_for(self.store, a1).one(), a2)
        a3.parent = a1
        self.assertEquals(set(Account.get_children_for(self.store, a1)),
                          set([a2, a3]))
示例#4
0
    def test_account_get_by_station(self):
        station = self.create_station()
        account = Account.get_by_station(self.store, station)
        self.failIf(account)
        account = self.create_account()
        account.station = station

        account = Account.get_by_station(self.store, station)
        self.failUnless(account)

        self.assertRaises(TypeError, Account.get_by_station, self.store, None)
        self.assertRaises(TypeError, Account.get_by_station, self.store,
                          object())
示例#5
0
    def test_get_children_for(self):
        a1 = self.create_account()
        self.assertTrue(Account.get_children_for(self.store, a1).is_empty())

        a2 = self.create_account()
        a2.parent = a1
        self.assertEqual(Account.get_children_for(self.store, a1).one(), a2)

        a3 = self.create_account()
        self.assertEqual(Account.get_children_for(self.store, a1).one(), a2)
        a3.parent = a1
        self.assertEqual(
            set(Account.get_children_for(self.store, a1)),
            set([a2, a3]))
示例#6
0
    def test_account_get_by_station(self):
        station = self.create_station()
        account = Account.get_by_station(self.store, station)
        self.assertFalse(account)
        account = self.create_account()
        account.station = station

        account = Account.get_by_station(self.store, station)
        self.assertTrue(account)

        self.assertRaises(TypeError, Account.get_by_station,
                          self.store, None)
        self.assertRaises(TypeError, Account.get_by_station,
                          self.store, object())
示例#7
0
    def testAccountGetByStation(self):
        station = self.create_station()
        account = Account.get_by_station(self.store, station)
        self.failIf(account)
        account = self.create_account()
        account.station = station

        account = Account.get_by_station(self.store, station)
        self.failUnless(account)

        self.assertRaises(TypeError, Account.get_by_station,
                          self.store, None)
        self.assertRaises(TypeError, Account.get_by_station,
                          self.store, object())
示例#8
0
    def test_get_children_for(self):
        a1 = self.create_account()
        self.assertTrue(Account.get_children_for(self.store, a1).is_empty())

        a2 = self.create_account()
        a2.parent = a1
        self.assertEquals(Account.get_children_for(self.store, a1).one(), a2)

        a3 = self.create_account()
        self.assertEquals(Account.get_children_for(self.store, a1).one(), a2)
        a3.parent = a1
        self.assertEquals(
            list(Account.get_children_for(self.store, a1).order_by(Account.id)),
            [a2, a3])
示例#9
0
 def before_start(self, store):
     account = store.find(Account, code=unicode(self.tp.account_id)).one()
     if account is None:
         account = Account(description=self.get_account_id(),
                           code=unicode(self.tp.account_id),
                           account_type=Account.TYPE_BANK,
                           parent=sysparam(store).BANKS_ACCOUNT,
                           store=store)
     self.account_id = account.id
     self.source_account_id = sysparam(store).IMBALANCE_ACCOUNT.id
     self.skipped = 0
 def _add_account(self):
     store = api.new_store()
     parent_account = store.fetch(self.account.get_selected())
     model = run_dialog(AccountEditor, self, store,
                        parent_account=parent_account)
     if store.confirm(model):
         account = Account.get(model.id, store=self.store)
         self._populate_accounts()
         self.account.select(account)
         self.emit('account-added')
     store.close()
示例#11
0
 def _add_account(self):
     store = api.new_store()
     parent_account = store.fetch(self.account.get_selected())
     model = run_dialog(AccountEditor,
                        self,
                        store,
                        parent_account=parent_account)
     if store.confirm(model):
         account = Account.get(model.id, store=self.store)
         self._populate_accounts()
         self.account.select(account)
         self.emit('account-added')
     store.close()
示例#12
0
 def _import_account(self, store, node):
     account_id = self._get_text(node, _actns('id'))
     account_name = self._get_text(node, _actns('name'))
     account_type = self._get_text(node, _actns('type'))
     parent = self._get_text(node, _actns('parent'))
     parent_account = self._accounts.get(parent)
     if account_type == 'ROOT':
         account = None
     else:
         account = store.find(Account, description=account_name).one()
         if account is None:
             account = Account(account_type=_account_types.get(
                 account_type, Account.TYPE_CASH),
                               description=account_name,
                               code=self._get_text(node, _actns('code')),
                               parent=parent_account,
                               store=store)
     self._accounts[account_id] = account
示例#13
0
    def get_data(self):
        sheets = {}
        for account in Account.get_children_for(self.store, parent=None):
            if sysparam.compare_object('IMBALANCE_ACCOUNT', account):
                continue

            columns = []
            for start, end in get_month_intervals_for_year(self.year):
                column = []
                self._prepare_items(column, account, start, end)
                columns.append(column)

            # Skip empty sheets
            if sum(item[1] for c in columns for item in c) == 0:
                continue

            sheets[account.description] = columns

        return sheets
示例#14
0
    def process_one(self, data, fields, store):
        if data.parent_account:
            name = _(data.parent_account)
            parent = store.find(Account, description=name).one()
        else:
            parent = None
        account = Account(description=data.description,
                          parent=parent,
                          code=None,
                          station=api.get_current_station(store),
                          account_type=data.account_type,
                          store=store)

        if data.bank_number:
            BankAccount(account=account,
                        bank_account=data.bank_account,
                        bank_number=int(data.bank_number),
                        bank_branch=data.bank_branch,
                        store=store)
示例#15
0
 def setup_proxies(self):
     repeat_types = get_interval_type_items(with_multiples=True,
                                            adverb=True)
     repeat_types.insert(0, (_('Once'), _ONCE))
     self.repeat.prefill(repeat_types)
     is_paid = self.model.is_paid()
     # Show account information only after the payment is paid
     if is_paid:
         accounts = Account.get_accounts(self.store)
         self.account.prefill(api.for_combo(accounts, attr='long_description'))
         if self.payment_type == Payment.TYPE_OUT:
             account = self.model.transaction.source_account
         else:
             account = self.model.transaction.account
         self.account.select(account)
         self.account.set_property('sensitive', False)
     else:
         self.account.hide()
         self.account_lbl.hide()
     self.add_proxy(self.model, _PaymentEditor.proxy_widgets)
示例#16
0
文件: financial.py 项目: rg3915/stoq
    def get_data(self):
        sysparam_ = sysparam(self.store)

        sheets = {}
        for account in Account.get_children_for(self.store, parent=None):
            if account.id == sysparam_.IMBALANCE_ACCOUNT.id:
                continue

            columns = []
            for start, end in get_month_intervals_for_year(self.year):
                column = []
                self._prepare_items(column, account, start, end)
                columns.append(column)

            # Skip empty sheets
            if sum(item[1] for c in columns for item in c) == 0:
                continue

            sheets[account.description] = columns

        return sheets
示例#17
0
 def setup_proxies(self):
     repeat_types = get_interval_type_items(with_multiples=True,
                                            adverb=True)
     repeat_types.insert(0, (_('Once'), _ONCE))
     self.repeat.prefill(repeat_types)
     is_paid = self.model.is_paid()
     # Show account information only after the payment is paid
     if is_paid:
         accounts = Account.get_accounts(self.store)
         self.account.prefill(
             api.for_combo(accounts, attr='long_description'))
         if self.payment_type == Payment.TYPE_OUT:
             account = self.model.transaction.source_account
         else:
             account = self.model.transaction.account
         self.account.select(account)
         self.account.set_property('sensitive', False)
     else:
         self.account.hide()
         self.account_lbl.hide()
     self.add_proxy(self.model, _PaymentEditor.proxy_widgets)
 def _get_account_options(self):
     return [(ac.description, ac)
             for ac in Account.get_accounts(self.store)]
示例#19
0
文件: financial.py 项目: rg3915/stoq
    def _prepare_items(self, items, account, start, end):
        total = account.get_total_for_interval(start, end)
        items.append((account.description, total))

        for child in Account.get_children_for(self.store, parent=account):
            self._prepare_items(items, child, start, end)
示例#20
0
 def create_account(self):
     from stoqlib.domain.account import Account
     return Account(description=u"Test Account",
                    account_type=Account.TYPE_CASH,
                    store=self.store)
示例#21
0
    def _prepare_items(self, items, account, start, end):
        total = account.get_total_for_interval(start, end)
        items.append((account.description, total))

        for child in Account.get_children_for(self.store, parent=account):
            self._prepare_items(items, child, start, end)
示例#22
0
 def create_model(self, store):
     return Account(description=u"",
                    account_type=Account.TYPE_CASH,
                    store=store)
示例#23
0
def test_account_get_accounts(store, example_creator):
    account = example_creator.create_account()

    accounts = list(Account.get_accounts(store))
    assert account in accounts
    assert accounts == list(store.find(Account))