Hi
I am writing a plugin to flag transactions that have specified accounts 
('cash') with a 'CASH' tag.
I can't work out how to amend a tag - I have copied code from an example 
plugin but it doesn't do anything - the print shows both tags as the same.
The code is below - but I also tried doing a *entry._replace(tags={'CASH'})* 
doesn't work, or *entry.tags={'CASH'}*. or *entry.tags=fixedset({'CASH'})*
I can't see any way to manipulate tags in beancount.core.data.
Any help please?
Regards
Paul


    new_entries = []
    for entry in entries:
        if isinstance(entry, data.Transaction):
            orig_entry = entry
            for posting in entry.postings:
                 if (posting.account in accounts):
*                     entry._replace(tags=(entry.tags or set()) | 
set(('CASH',)))*
                     print (orig_entry.tags, entry.tags)
        new_entries.append(entry)
#        print (entry)
    return new_entries, []

==========================



"""
For example, a possible configuration could be:
  plugin "flagcash" "{
 'accounts': {
              'Assets:Cash:Bank',
       'Assets:Cash:Float' }
  }"

"""
__author__ = 'Paul Hamshere'
#from beancount.core.number import MISSING
from beancount.core import data
from beancount.core import account_types
#from beancount.core import amount
#from beancount.parser import printer

__plugins__ = ['flagcash']

DEBUG = 0

def flagcash(entries, options_map, config):
    """
    Args:
      entries: a list of entry instances
      options_map: a dict of options parsed from the file
      config: A configuration string, which is intended to be a Python dict
    Returns:
      A tuple of entries and errors.
    """
    # Parse and extract configuration values.
    config_obj = eval(config, {}, {})
    if not isinstance(config_obj, dict):
        raise RuntimeError("Invalid plugin configuration: should be a 
single dict.")

    accounts = config_obj.pop('accounts', {})
    new_entries = []
    for entry in entries:
        if isinstance(entry, data.Transaction):
            orig_entry = entry
            for posting in entry.postings:
                 if (posting.account in accounts):
*                     entry._replace(tags=(entry.tags or set()) | 
set(('CASH',)))*
                     print (orig_entry.tags, entry.tags)
        new_entries.append(entry)
#        print (entry)
    return new_entries, []

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/d0f35a56-698f-4835-a3a6-8578eced9409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to