Exemplo n.º 1
0
    def open(self, filename, lineno, date, account, currencies, booking_str, kvlist):
        """Process an open directive.

        Args:
          filename: The current filename.
          lineno: The current line number.
          date: A datetime object.
          account: A string, the name of the account.
          currencies: A list of constraint currencies.
          booking_str: A string, the booking method, or None if none was specified.
          kvlist: a list of KeyValue instances.
        Returns:
          A new Open object.
        """
        meta = new_metadata(filename, lineno, kvlist)
        error = False
        if booking_str:
            try:
                # Note: Somehow the 'in' membership operator is not defined on Enum.
                booking = Booking[booking_str]
            except KeyError:
                # If the per-account method is invalid, set it to the global
                # default method and continue.
                booking = self.options['booking_method']
                error = True
        else:
            booking = None

        entry = Open(meta, date, account, currencies, booking)
        if error:
            self.errors.append(ParserError(meta,
                                           "Invalid booking method: {}".format(booking_str),
                                           entry))
        return entry
Exemplo n.º 2
0
def share(entries: Entries,
          unused_options_map,
          config_string="{}") -> Tuple[Entries, List[NamedTuple]]:
    new_entries: Entries = []
    errors: List[NamedTuple] = []

    # 1. Parse config
    with plugin_error_handler(entries, new_entries, errors, "share",
                              PluginShareError):
        config = load_config(config_string)

        new_entries[:], errors[:] = marked.on_marked_transactions(
            per_marked_transaction,
            entries,
            config,
            config.mark_name,
            ("Income", "Expenses"),
            PluginShareError,
        )

        if config.open_date != None:
            for account in sorted(new_accounts):
                new_meta = new_metadata(entries[0].meta["filename"], 0)
                open_entry = Open(new_meta, config.open_date, account, None,
                                  None)
                new_entries.append(open_entry)

    return new_entries, errors
Exemplo n.º 3
0
    def addEntry(self, account, entry):

        date = data.EXP_OPEN_DATE
        opendir = Open(None, date, account, None, None)

        self.ledger += [opendir]

        self.refresh()
Exemplo n.º 4
0
def stage_missing_accounts(stage, entry_file_selector, account_map=None):
    """Stages Open directives for any missing accounts referenced in new entries."""
    for account, date, currencies in stage.get_missing_accounts(
            account_map=account_map):
        open_entry = Open(date=date,
                          account=account,
                          currencies=sorted(list(currencies)),
                          meta=None,
                          booking=None)
        stage.add_entry(open_entry, entry_file_selector(open_entry))
Exemplo n.º 5
0
    def __call__(self, entry, ledger):
        opens = []

        self.ledger = ledger

        if isinstance(entry, Transaction):
            matchedSomeRule = False
            for rule in self.rules:
                if rule.test(entry):
                    entry = rule.apply(entry)
                    matchedSomeRule = True
            if not matchedSomeRule:
                entry, rule = self.userInputFn(entry)
                if rule:
                    self.add_rule(rule)

            for p in entry.postings:
                if self.is_not_open(p.account, entry.date):
                    opens.append(
                        Open(None, data.EXP_OPEN_DATE, p.account, None, None))
        return entry, opens
Exemplo n.º 6
0
    def open(self, filename, lineno, date, account, currencies, booking,
             kvlist):
        """Process an open directive.

        Args:
          filename: The current filename.
          lineno: The current line number.
          date: A datetime object.
          account: A string, the name of the account.
          currencies: A list of constraint currencies.
          booking: A string, the booking method, or None if none was specified.
          kvlist: a list of KeyValue instances.
        Returns:
          A new Open object.
        """
        meta = new_metadata(filename, lineno, kvlist)
        entry = Open(meta, date, account, currencies, booking)
        if booking and booking not in BOOKING_METHODS:
            self.errors.append(
                ParserError(meta, "Invalid booking method: {}".format(booking),
                            entry))
        return entry