@@ -65,30 +65,30 @@ def test_path(s):
if not s.is_absolute():
s = TESTS_DIR / s
return s
def Amount(number, currency='USD'):
return bc_amount.Amount(Decimal(number), currency)
def Cost(number, currency='USD', date=FY_MID_DATE, label=None):
return bc_data.Cost(Decimal(number), currency, date, label)
def Posting(account, number,
currency='USD', cost=None, price=None, flag=None,
**meta):
type_=bc_data.Posting, **meta):
if cost is not None:
cost = Cost(*cost)
if meta is None:
if not meta:
meta = None
return bc_data.Posting(
return type_(
account,
Amount(number, currency),
cost,
price,
flag,
meta,
)
LINK_METADATA_STRINGS = {
'Invoices/304321.pdf',
'rt:123/456',
'rt://ticket/234',
@@ -123,26 +123,27 @@ class Transaction:
self.date = date
self.flag = flag
self.payee = payee
self.narration = narration
self.tags = set(tags or '')
self.links = set(links or '')
self.postings = []
self.meta = {
'filename': '<test>',
'lineno': 0,
}
self.meta.update(meta)
for posting in postings:
self.add_posting(*posting)
if postings is not None:
def add_posting(self, arg, *args, **kwargs):
"""Add a posting to this transaction. Use any of these forms:
txn.add_posting(account, number, …, kwarg=value, …)
txn.add_posting(account, number, …, posting_kwargs_dict)
txn.add_posting(posting_object)
"""
if kwargs:
posting = Posting(arg, *args, **kwargs)
elif args:
if isinstance(args[-1], dict):