示例#1
0
 def make_split(self, dbs):
     return dm.Split(
             account_id=dbs.account_id,
             number=dbs.number,
             description=dbs.description,
             amount=dbs.amount,
             status=dbs.status,
         )
示例#2
0
 def mod_split(self, split):
     return dm.Split(
             account_id=split['account_id'],
             number=split['number'] + 'm',
             description='x' + split['description'],
             amount=split['amount'] * 2,
             status='r',
         )
示例#3
0
 def test_update_transaction(self, xdata):
     self.assert_transaction_exists(xdata)
     updated = dm.Transaction(
                     date=xdata['date'] + timedelta(1),
                     description='updated description',
                     transaction_id=xdata['transaction_id'],
                     splits=[dm.Split(s) for s in xdata['splits']],
                 )
     db_o = self.query_obj.save(updated)
     assert db_o.transaction_id == updated.transaction_id
     assert db_o.split_set.count() == 2
     self.assert_transaction_exists(updated)
示例#4
0
 def domain_obj(self):
     return dm.Transaction(
         transaction_id=248,
         date=date(2015, 7, 16),
         description='Birthday card',
         splits=[
             dm.Split(
                 split_id=613,
                 number=365,
                 account_id=10,
                 status='c',
                 amount=-25,
             ),
             dm.Split(
                 split_id=614,
                 description='Moked',
                 account_id=18,
                 amount=25,
             ),
         ],
     )
示例#5
0
 def test_create_transaction(self):
     sa = {
             'number': '101',
             'account_id': self.salary.account_id,
             'status': 'n',
             'amount': -8000,
             'description': '',
         }
     sb = {
             'number': '1432',
             'account_id': self.citibank.account_id,
             'status': 'n',
             'amount': 8000,
             'description': '',
         }
     xact = {
             'date': date(2015, 7, 26),
             'description': 'Payday',
         }
     splits = [dm.Split(sa), dm.Split(sb)]
     xact_obj = dm.Transaction(xact, splits=splits)
     self.assert_transaction_not_exists(xact, [sa, sb])
     self.query_obj.save(xact_obj)
     self.assert_transaction_exists(xact, [sa, sb])
示例#6
0
 def test_domain_to_orm(self):
     obj = domain.Split(
         split_id=613,
         number='365',
         description='Split Desc',
         account_id=12,
         status='n',
         amount='18',
     )
     instance = orm.domain_to_orm(obj)
     assert isinstance(instance, db.Split)
     assert instance.split_id == 613
     assert instance.number == '365'
     assert instance.description == 'Split Desc'
     assert instance.account_id == 12
     assert instance.status == 'n'
     assert instance.amount == '18'
示例#7
0
 def test_dm_to_pd(self):
     obj = dm.Split(
         split_id=53,
         number='100',
         description='Paycheck',
         account_id=3,
         status='c',
         amount=-8000,
     )
     ser = self.serializer_class(obj)
     data = ser.data
     assert 'split_id' not in data
     assert data['number'] == '100'
     assert data['description'] == 'Paycheck'
     assert data['account_id'] == 3
     assert data['status'] == 'c'
     assert data['amount'] == '-8000.00'
示例#8
0
 def update(self, instance, validated_data):
     data = validated_data.copy()
     # this won't support partial split updates
     data['splits'] = [dm.Split(**sdata) for sdata in data['splits']]
     return super(TransactionSerializer, self).update(instance, data)
示例#9
0
 def create(self, validated_data):
     data = validated_data.copy()
     data['splits'] = [dm.Split(**sdata) for sdata in data['splits']]
     return super(TransactionSerializer, self).create(data)