[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Multi-step ledger org-capture template

From: Stefan Huchler
Subject: Re: [O] Multi-step ledger org-capture template
Date: Sun, 26 Aug 2018 23:53:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

In case somebody wants something similar, I post my solution I came up
with here:

   (defun get-table-content (&optional start end)
     (let* ((start (or start (buffer-end -1)))
            (end (or end (buffer-end 1)))
             (s-split "\n" (buffer-substring-no-properties
                            start end))))
       (remove nil
                (lambda (line)
                   (lambda (elem)
                     (string-trim elem))
                   (remove "" (split-string
                               line "|"))))
   (with-current-buffer (org-capture-get :original-buffer)
     (call-interactively 'copy-region-as-kill))
   (let* (mapping)
       (insert-file-contents "capture-templates/products-mapping.org")
       (let* ((start (progn (goto-char (point-min))
                            (forward-line 1) (point))))
         (setq mapping (mapcar (lambda (x) (cons (nth 1 x) (car x)))            
                       (get-table-content start)))))
       (org-table-convert-region (buffer-end -1) (buffer-end 1) 2)    
       (let* ((data (get-table-content)))
          (concat "  " (org-read-date nil nil) " * Shop-name\n"
                   (lambda (line) (format "      %s \t\t%s St {=€%s}"
                             (assoc-default (nth 1 line) mapping)
                             (nth 0 line) (nth 4 line)))
                   data "\n")
                  "\n      assets:bank:chequing"))
         (let ((start (progn
                        (goto-char (point-min))
                        (forward-line 1) (point)))
               (end (progn
                      (goto-char (point-max))
                      (forward-line -1) (point))))
           (ledger-post-align-postings start end))       

products-mapping would like like that:

#+NAME: food
| expenses:food:spice:Basilikum | Basilikum bio Sonnentor, 15g |
| expenses:food:spice:Oregano   | Oregano bio Sonnentor, 20g   |

Of course it asumes that you have some html or email bill with a table
selected and you would have to change the (nth x line) depending where
in the bill the name, amount and price is listed, and maybe change the

reply via email to

[Prev in Thread] Current Thread [Next in Thread]