コード例 #1
0
ファイル: engine.py プロジェクト: pawelniewie/5groszy.pl
    def map_and_commit(self, user_uid, account, transactions, additional):
        duplicates = 0
        start_date = None
        end_date = None

        try:
            for transaction in self.mapper.map_transactions(transactions):
                self.start_date = min(self.start_date or transaction.transaction_date, transaction.transaction_date) 
                self.end_date = max(self.end_date or transaction.transaction_date, transaction.transaction_date)

                if self.dbFacade.balances.changeDao.similar_exists(
                        balance_uid=self.account.uid,
                        amount=transaction.amount, bank_balance=transaction.bank_balance,
                        bank_settlement_date=transaction.bank_settlement_date, transaction_date=transaction.transaction_date):
                    duplicates += 1
                    log.info(_('Ignoring transaction %r because similar exists') % transaction)
                    continue

                transaction.user_uid = user_uid
                transaction.balance = account

                self.dbFacade.db.save(change)
                self.dbFacade.db.flush()

            self.dbFacade.db.commit()
        except:
            try: log.error(_('Failed to commit transactions because of an exception'), exc_info=1)
            except: pass

            try: self.dbFacade.db.rollback()
            except: pass

            raise

        return { 'duplicates': duplicates, 'start_date': start_date, 'end_date': end_date }
コード例 #2
0
ファイル: categories.py プロジェクト: pawelniewie/5groszy.pl
    def __init__(self):
        self.top = []
        self.by_name = {}
        self.by_key = {}
        
        for gk,group in categories.iteritems():
            if 'name' not in group:
                raise ValueError('No name in group %s' % gk)

            if len(group['name']):
                group_name = _(group['name'])
            else:
                group_name = ''

            if group['name'] in self.by_name:
                raise ValueError('Name in use %s' % group['name'])

            if gk in self.by_key:
                raise ValueError('Key in use %s' % ck)

            g = TransactionCategory(
                name=group_name,
                key=gk,
            )

            subcats = []
            for ck, subc in group['subcats'].iteritems():
                if 'name' not in subc:
                    raise ValueError('No name in category %s' % ck)
                
                if subc['name'] in self.by_name:
                    raise ValueError('Name in use %s' % subc['name'])

                if ck in self.by_key:
                    raise ValueError('Key in use %s' % ck)
                    
                tc = TransactionCategory(
                    name=_(subc['name']),
                    key=ck,
                    hardcoded=True,
                )

                subcats.append(tc)
                self.by_name[tc.name] = tc
                self.by_key[tc.key] = tc

            subcats.sort(lambda x, y: cmp(x.name, y.name))
            g.subcats = subcats 
        
            self.top.append(g)
            self.by_name[g.name] = g
            self.by_key[g.key] = g
        
        self.top.sort(lambda x, y: cmp(x.name, y.name))
コード例 #3
0
ファイル: mapper.py プロジェクト: pawelniewie/5groszy.pl
    def __init__(self, dbFacade):
        self.dbFacade = dbFacade

        self.cash_category = self.dbFacade.balances.categoryDao.find_by_key('cash').name
        self.exclude_category = self.dbFacade.balances.categoryDao.find_by_key('exclude').name

        self.card_transactions = []
        for key, patterns in card_transactions.iteritems():
            if self.dbFacade.balances.categoryDao.find_by_key(key) is None:
                raise ValueError(_('There\'s no category with %s key') % key)

            category = self.dbFacade.balances.categoryDao.find_by_key(key)

            self.card_transactions.extend(
                [(re.compile(pattern[0], re.L | re.I | re.U), category.name, pattern[1].decode('utf-8')) for pattern in patterns])
コード例 #4
0
ファイル: categories.py プロジェクト: pawelniewie/5groszy.pl
    def __init__(self, db = None, model = None, user_uid = None):
        self.top = []
        self.by_name = {}
        self.by_key = {}
        self.custom = None
        
        if db and model and user_uid:
            self.custom = db.query(model.TransactionCategory).filter_by(user_uid=user_uid)

        for gk,group in categories.iteritems():
            if 'name' not in group:
                raise ValueError('No name in group %s' % gk)

            if len(group['name']):
                group_name = _(group['name'])
            else:
                group_name = ''

            if group['name'] in self.by_name:
                raise ValueError('Name in use %s' % group['name'])

            if gk in self.by_key:
                raise ValueError('Key in use %s' % ck)

            g = TransactionCategory(
                name=group_name,
                key=gk,
            )

            subcats = []
            for ck, subc in group['subcats'].iteritems():
                if 'name' not in subc:
                    raise ValueError('No name in category %s' % ck)
                
                if subc['name'] in self.by_name:
                    raise ValueError('Name in use %s' % subc['name'])

                if ck in self.by_key:
                    raise ValueError('Key in use %s' % ck)
                    
                tc = TransactionCategory(
                    name=_(subc['name']),
                    key=ck,
                    hardcoded=True,
                )

                subcats.append(tc)
                self.by_name[tc.name] = tc
                self.by_key[tc.key] = tc

            # Append user's custom (from database) if any
            if self.custom:
                for custom_category in self.custom:
                    if custom_category.parent == g.key:
                        custom_category.key = custom_category.name
                        subcats.append(custom_category)
                        self.by_name[custom_category.name] = custom_category
                        self.by_key[custom_category.key] = custom_category            

            subcats.sort(lambda x, y: cmp(x.name, y.name))
            g.subcats = subcats 
        
            self.top.append(g)
            self.by_name[g.name] = g
            self.by_key[g.key] = g
        
        self.top.sort(lambda x, y: cmp(x.name, y.name))