Browse Source

[enh] Convert iso to utf8 csv file

ljf 7 years ago
parent
commit
3d36136d63
1 changed files with 4 additions and 3 deletions
  1. 4 3
      coin/billing/management/commands/import_payments_from_csv.py

+ 4 - 3
coin/billing/management/commands/import_payments_from_csv.py

@@ -47,7 +47,7 @@ DATE_FORMAT="%d/%m/%Y"
 ID_REGEX=r"(?i)(\b|_)ID[\s\-\_\/]*(\d+)(\b|_)"
 # If the label of the payment contains one of these, the payment won't be
 # matched to a member when importing it.
-KEYWORDS_TO_NOTMATCH=[ "DON", "MECENAT", "REM CHQ" ]
+KEYWORDS_TO_NOTMATCH=[ "REM CHQ" ]
 
 class Command(BaseCommand):
 
@@ -78,9 +78,10 @@ class Command(BaseCommand):
     def handle(self, *args, **options):
 
         assert options["filename"] != ""
-
         if not os.path.isfile(options["filename"]):
             raise CommandError("This file does not exists.")
+        os.system("iconv -f ISO-8859-1 -t UTF-8 %s > %s.utf8.csv" % (options["filename"], options["filename"]))
+        options["filename"] = options["filename"] + '.utf8.csv'
 
         payments = self.convert_csv_to_dicts(self.clean_csv(self.load_csv(options["filename"])))
 
@@ -266,7 +267,7 @@ class Command(BaseCommand):
                     break
 
                 familynamematch = member_last_name
-                usernamematch = str(member.username)
+                usernamematch = member.username
 
             if familynamematch != None:
                 payment["member_matched"] = usernamematch