Can't import csv with two positive rows #19

Closed
opened 2025-12-28 23:24:09 +01:00 by adam · 6 comments
Owner

Originally created by @eitchtee on GitHub (Jan 31, 2025).

Yes, I like it pretty much, just still figuring out the data for importing

  type:
    source: amount
    target: type
    detection_method: sign

  type:
    source: "Valor"
    target: "type"
    detection_method: sign

what are these for ?

Image

I am in the middle of setup for my data import, just a bit confused about the part for own transfer , it would be something like transfer from acc A to acc B, and I have separate credit with debit table, both positive balance, so merge format not seems work

settings:
  file_type: csv
  delimiter: ","
  encoding: utf-8
  skip_lines: 0
  importing: transactions
  trigger_transaction_rules: true
  skip_errors: true

mapping:
  account:
    target: account
    default: "MYR Wallet"
    type: name

  date:
    target: date
    source: Date
    format: "%d/%m/%Y"

  amount:
    target: amount
    source: Valor

  description:
    target: description
    source: Description

  type:
    source: "Valor"
    target: "type"
    detection_method: sign

  notes:
    target: notes
    source: Notes

  is_paid:
    target: is_paid
    detection_method: always_paid

deduplicate:
  - type: compare
    fields:
      - internal_id
    match_type: strict

Originally posted by @lucius100 in #41

Originally created by @eitchtee on GitHub (Jan 31, 2025). > Yes, I like it pretty much, just still figuring out the data for importing > > ``` > type: > source: amount > target: type > detection_method: sign > > type: > source: "Valor" > target: "type" > detection_method: sign > ``` > > what are these for ? > > <img width="503" alt="Image" src="https://github.com/user-attachments/assets/faaeb476-20fc-49b8-af76-fc8eabf42a32" /> > > I am in the middle of setup for my data import, just a bit confused about the part for own transfer , it would be something like transfer from acc A to acc B, and I have separate credit with debit table, both positive balance, so merge format not seems work > > ``` > settings: > file_type: csv > delimiter: "," > encoding: utf-8 > skip_lines: 0 > importing: transactions > trigger_transaction_rules: true > skip_errors: true > > mapping: > account: > target: account > default: "MYR Wallet" > type: name > > date: > target: date > source: Date > format: "%d/%m/%Y" > > amount: > target: amount > source: Valor > > description: > target: description > source: Description > > type: > source: "Valor" > target: "type" > detection_method: sign > > notes: > target: notes > source: Notes > > is_paid: > target: is_paid > detection_method: always_paid > > deduplicate: > - type: compare > fields: > - internal_id > match_type: strict > ``` _Originally posted by @lucius100 in [#41](https://github.com/eitchtee/WYGIWYH/issues/41#issuecomment-2628057599)_
adam added the bug label 2025-12-28 23:24:09 +01:00
adam closed this issue 2025-12-28 23:24:09 +01:00
Author
Owner

@eitchtee commented on GitHub (Jan 31, 2025):

@lucius100 I've opened this issue to track this as it's looking like you won't be able to import this with the available options. Let me have a look and get back to you.

@eitchtee commented on GitHub (Jan 31, 2025): @lucius100 I've opened this issue to track this as it's looking like you won't be able to import this with the available options. Let me have a look and get back to you.
Author
Owner

@eitchtee commented on GitHub (Jan 31, 2025):

@lucius100 please upgrade to v0.8.4

You might want to have two different accounts one for Dompet and another one for TNG, so the Own Transfers make sense

Then you can use the following template:

settings:
  file_type: csv
  delimiter: ","
  encoding: utf-8
  skip_lines: 0
  importing: transactions
  trigger_transaction_rules: true
  skip_errors: true

mapping:
  account:
    target: account
    source: "Wallet"
    type: name

  date:
    target: date
    source: Date
    format: "%d/%m/%Y"

  amount:
    target: amount
    source: ["Credits", "Debits"]
    transformations:
        - type: "replace"
          pattern: "MYR "
          replacement: ""
        - type: "replace"
          pattern: ","
          replacement: ""
          
  description:
    target: description
    source: Description
    
  category:
    target: category
    source: Category

  type:
    source: Credits
    target: "type"
    required: false
    detection_method: always_income
   
  type2:
    source: Debits
    target: "type"
    required: false
    detection_method: always_expense

  is_paid:
    target: is_paid
    detection_method: always_paid
    
  internal_id:
    target: internal_id
    transformations:
        - type: hash
          fields: ["Date", "Description", "Category", "Wallet"]

deduplication:
  - type: compare
    fields:
      - internal_id
    match_type: strict

If you don't want to have different accounts, you can use your original account definition, just make sure MYR Wallet is a created account on the app.

account:
    target: account
    default: "MYR Wallet"
    type: name

Explanation:

We use two different type mappings, one for each table column, the first to have a valid value is used. If Credits is empty, Debits is used and always validates to an expense; if Credits has a value, it is used and always validates to an Income.

Also, since your file doesn't have some sort of unique identifier we create one by hashing Date, Description, Category and Wallet together, this should be enough to not duplicate entries if you re-import a file with the same values.

And finally, we use some replaces to remove "MYR " and commas from your values.


Let me know how this goes. If you have any more questions feel free to ask them.

@eitchtee commented on GitHub (Jan 31, 2025): @lucius100 please upgrade to v0.8.4 You might want to have two different accounts one for `Dompet` and another one for `TNG`, so the `Own Transfers` make sense Then you can use the following template: ```yaml settings: file_type: csv delimiter: "," encoding: utf-8 skip_lines: 0 importing: transactions trigger_transaction_rules: true skip_errors: true mapping: account: target: account source: "Wallet" type: name date: target: date source: Date format: "%d/%m/%Y" amount: target: amount source: ["Credits", "Debits"] transformations: - type: "replace" pattern: "MYR " replacement: "" - type: "replace" pattern: "," replacement: "" description: target: description source: Description category: target: category source: Category type: source: Credits target: "type" required: false detection_method: always_income type2: source: Debits target: "type" required: false detection_method: always_expense is_paid: target: is_paid detection_method: always_paid internal_id: target: internal_id transformations: - type: hash fields: ["Date", "Description", "Category", "Wallet"] deduplication: - type: compare fields: - internal_id match_type: strict ``` If you don't want to have different accounts, you can use your original account definition, just make sure `MYR Wallet` is a created account on the app. ```yaml account: target: account default: "MYR Wallet" type: name ``` --- Explanation: We use two different `type` mappings, one for each table column, the first to have a valid value is used. If Credits is empty, Debits is used and always validates to an expense; if Credits has a value, it is used and always validates to an Income. Also, since your file doesn't have some sort of unique identifier we create one by hashing Date, Description, Category and Wallet together, this should be enough to not duplicate entries if you re-import a file with the same values. And finally, we use some replaces to remove "MYR " and commas from your values. --- Let me know how this goes. If you have any more questions feel free to ask them.
Author
Owner

@lucius100 commented on GitHub (Jan 31, 2025):

Image

I make some changes to the data, so I have few errors while importing, have error on replace MYR and comma, so I removed them.

[2025-01-31 20:27:02] WARNING: Error processing row 1: 'NoneType' object has no attribute 'replace'
[2025-01-31 20:27:02] WARNING: Error processing row 2: 'NoneType' object has no attribute 'replace'
[2025-01-31 20:27:02] WARNING: Error processing row 3: 'NoneType' object has no attribute 'replace'

now have error on amount, can't figured out

[2025-01-31 20:28:18] WARNING: Error processing row 1: Required field amount is missing
[2025-01-31 20:28:18] WARNING: Error processing row 2: Required field amount is missing

here is the latest yaml code.

settings:
  file_type: csv
  delimiter: ","
  encoding: utf-8
  skip_lines: 0
  importing: transactions
  trigger_transaction_rules: true
  skip_errors: true

mapping:
  account:
    target: account
    source: "Wallet"
    type: name

  date:
    target: date
    source: Date
    format: "%d/%m/%Y"

  amount:
    target: amount
    source: ["Credits", "Debits"]
          
  description:
    target: description
    source: Description
    
  category:
    target: category
    source: Category

  type:
    source: Credits
    target: "type"
    required: false
    detection_method: always_income
   
  type2:
    source: Debits
    target: "type"
    required: false
    detection_method: always_expense

  is_paid:
    target: is_paid
    detection_method: always_paid
    
  internal_id:
    target: internal_id
    transformations:
        - type: hash
          fields: ["Date", "Description", "Category", "Wallet"]

deduplication:
  - type: compare
    fields:
      - internal_id
    match_type: strict
@lucius100 commented on GitHub (Jan 31, 2025): <img width="449" alt="Image" src="https://github.com/user-attachments/assets/d7dac14a-2afb-48f0-9a6b-33c3c874b42b" /> I make some changes to the data, so I have few errors while importing, have error on replace MYR and comma, so I removed them. ``` [2025-01-31 20:27:02] WARNING: Error processing row 1: 'NoneType' object has no attribute 'replace' [2025-01-31 20:27:02] WARNING: Error processing row 2: 'NoneType' object has no attribute 'replace' [2025-01-31 20:27:02] WARNING: Error processing row 3: 'NoneType' object has no attribute 'replace' ``` now have error on amount, can't figured out ``` [2025-01-31 20:28:18] WARNING: Error processing row 1: Required field amount is missing [2025-01-31 20:28:18] WARNING: Error processing row 2: Required field amount is missing ``` here is the latest yaml code. ``` settings: file_type: csv delimiter: "," encoding: utf-8 skip_lines: 0 importing: transactions trigger_transaction_rules: true skip_errors: true mapping: account: target: account source: "Wallet" type: name date: target: date source: Date format: "%d/%m/%Y" amount: target: amount source: ["Credits", "Debits"] description: target: description source: Description category: target: category source: Category type: source: Credits target: "type" required: false detection_method: always_income type2: source: Debits target: "type" required: false detection_method: always_expense is_paid: target: is_paid detection_method: always_paid internal_id: target: internal_id transformations: - type: hash fields: ["Date", "Description", "Category", "Wallet"] deduplication: - type: compare fields: - internal_id match_type: strict ```
Author
Owner

@eitchtee commented on GitHub (Jan 31, 2025):

[2025-01-31 20:27:02] WARNING: Error processing row 1: 'NoneType' object has no attribute 'replace'

This error is probably because you had some empty rows, in the first screenshot you had Initial balance without a Credit or Debits value. It's ok to error in this case.

[2025-01-31 20:28:18] WARNING: Error processing row 1: Required field amount is missing

This is probably due to the same thing, a row with empty values for Credits and Debits.


I tried importing the data you shared just now, with your configuration and got no errors.

If you really want to import everything, you can add default: "0" to your amount mapping:

amount:
    target: amount
    source: ["Credits", "Debits"]
    default: "0"

Any transaction without a value will be imported with the 0 as the amount, just for reference sake. This way you won't even need to remove the commas and "MYR "

@eitchtee commented on GitHub (Jan 31, 2025): > [2025-01-31 20:27:02] WARNING: Error processing row 1: 'NoneType' object has no attribute 'replace' This error is probably because you had some empty rows, in the first screenshot you had `Initial balance` without a Credit or Debits value. It's ok to error in this case. > [2025-01-31 20:28:18] WARNING: Error processing row 1: Required field amount is missing This is probably due to the same thing, a row with empty values for Credits and Debits. --- I tried importing the data you shared just now, with your configuration and got no errors. If you really want to import everything, you can add `default: "0"` to your amount mapping: ``` amount: target: amount source: ["Credits", "Debits"] default: "0" ``` Any transaction without a value will be imported with the 0 as the amount, just for reference sake. This way you won't even need to remove the commas and "MYR "
Author
Owner

@lucius100 commented on GitHub (Feb 1, 2025):

Edit: Finally found the issue, I just copy the header and found out instead of "Credits" "Debits" , it was " Credits " , " Debits "
After fixing the space, now it can import smoothly, haha

@lucius100 commented on GitHub (Feb 1, 2025): Edit: Finally found the issue, I just copy the header and found out instead of "Credits" "Debits" , it was " Credits " , " Debits " After fixing the space, now it can import smoothly, haha
Author
Owner

@eitchtee commented on GitHub (Feb 1, 2025):

Oh man haha. It's always the last thing you expect.

Good it worked. Let me know if you have any other issue.

@eitchtee commented on GitHub (Feb 1, 2025): Oh man haha. It's always the last thing you expect. Good it worked. Let me know if you have any other issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#19