Add acct under point to reconcile prompt. Fix reconcile balance display of empty accounts
This commit is contained in:
parent
4810da9398
commit
efce6c8936
4 changed files with 44 additions and 34 deletions
|
|
@ -33,28 +33,30 @@
|
|||
|
||||
(defun ledger-split-commodity-string (str)
|
||||
"Split a commoditized amount into two parts"
|
||||
(let (val
|
||||
comm)
|
||||
(with-temp-buffer
|
||||
(insert str)
|
||||
(goto-char (point-min))
|
||||
(cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t)
|
||||
;; found a decimal number
|
||||
(setq val
|
||||
(string-to-number
|
||||
(ledger-commodity-string-number-decimalize
|
||||
(delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)))
|
||||
(goto-char (point-min))
|
||||
(re-search-forward "[^[:space:]]" nil t)
|
||||
(setq comm
|
||||
(delete-and-extract-region (match-beginning 0) (match-end 0)))
|
||||
(list val comm))
|
||||
((re-search-forward "0" nil t)
|
||||
;; couldn't find a decimal number, look for a single 0,
|
||||
;; indicating account with zero balance
|
||||
(list 0 ledger-reconcile-default-commodity))
|
||||
(t
|
||||
(error "split-commodity-string: cannot parse commodity string: %S" str))))))
|
||||
(if (> (length str) 0)
|
||||
(let (val
|
||||
comm)
|
||||
(with-temp-buffer
|
||||
(insert str)
|
||||
(goto-char (point-min))
|
||||
(cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t)
|
||||
;; found a decimal number
|
||||
(setq val
|
||||
(string-to-number
|
||||
(ledger-commodity-string-number-decimalize
|
||||
(delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)))
|
||||
(goto-char (point-min))
|
||||
(re-search-forward "[^[:space:]]" nil t)
|
||||
(setq comm
|
||||
(delete-and-extract-region (match-beginning 0) (match-end 0)))
|
||||
(list val comm))
|
||||
((re-search-forward "0" nil t)
|
||||
;; couldn't find a decimal number, look for a single 0,
|
||||
;; indicating account with zero balance
|
||||
(list 0 ledger-reconcile-default-commodity))
|
||||
(t
|
||||
(error "split-commodity-string: cannot parse commodity string: %S" str)))))
|
||||
(list 0 ledger-reconcile-default-commodity)))
|
||||
|
||||
|
||||
(defun ledger-string-balance-to-commoditized-amount (str)
|
||||
|
|
|
|||
|
|
@ -229,6 +229,18 @@ BEG, END, and LEN control how far it can align."
|
|||
(add-hook 'after-change-functions 'ledger-post-maybe-align t t))
|
||||
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil))))
|
||||
|
||||
|
||||
(defun ledger-post-read-account-with-prompt (prompt)
|
||||
(let* ((context (ledger-context-at-point))
|
||||
(default
|
||||
(if (eq (ledger-context-line-type context) 'acct-transaction)
|
||||
(regexp-quote (ledger-context-field-value context 'account))
|
||||
nil)))
|
||||
(ledger-read-string-with-default prompt default)))
|
||||
|
||||
|
||||
(provide 'ldg-post)
|
||||
|
||||
|
||||
|
||||
;;; ldg-post.el ends here
|
||||
|
|
|
|||
|
|
@ -351,10 +351,11 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
|
|||
(set-window-buffer (split-window (get-buffer-window buf) nil nil) rbuf)
|
||||
(pop-to-buffer rbuf)))
|
||||
|
||||
(defun ledger-reconcile (account)
|
||||
"Start reconciling ACCOUNT."
|
||||
(interactive "sAccount to reconcile: ")
|
||||
(let ((buf (current-buffer))
|
||||
(defun ledger-reconcile ()
|
||||
"Start reconciling, prompt for account."
|
||||
(interactive)
|
||||
(let ((account (ledger-post-read-account-with-prompt "Account to reconcile"))
|
||||
(buf (current-buffer))
|
||||
(rbuf (get-buffer ledger-recon-buffer-name))) ;; this means
|
||||
;; only one
|
||||
;; *Reconcile*
|
||||
|
|
|
|||
|
|
@ -258,12 +258,7 @@ used to generate the buffer, navigating the buffer, etc."
|
|||
the default."
|
||||
;; It is intended completion should be available on existing account
|
||||
;; names, but it remains to be implemented.
|
||||
(let* ((context (ledger-context-at-point))
|
||||
(default
|
||||
(if (eq (ledger-context-line-type context) 'acct-transaction)
|
||||
(regexp-quote (ledger-context-field-value context 'account))
|
||||
nil)))
|
||||
(ledger-read-string-with-default "Account" default)))
|
||||
(ledger-post-read-account-with-prompt "Account"))
|
||||
|
||||
(defun ledger-report-expand-format-specifiers (report-cmd)
|
||||
"Expand %(account) and %(payee) appearing in REPORT-CMD with thing under point."
|
||||
|
|
@ -437,9 +432,9 @@ Optional EDIT the command."
|
|||
("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$"
|
||||
(date nil status nil nil code payee))))
|
||||
(acct-transaction
|
||||
(("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$"
|
||||
(("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$"
|
||||
(indent account commodity amount nil comment))
|
||||
("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$"
|
||||
("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$€£]\\s-?\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$"
|
||||
(indent account commodity amount nil))
|
||||
("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\(-?[0-9]+\\(\\.[0-9]*\\)?\\)[ \t]+\\(.*?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$"
|
||||
(indent account amount nil commodity comment))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue