28 lines
866 B
Python
28 lines
866 B
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (c) 2020, Studio Infinity and contributors
|
|
# For license information, please see license.txt
|
|
|
|
from __future__ import unicode_literals
|
|
import frappe
|
|
from frappe.model.document import Document
|
|
from frappe.utils.csvutils import read_csv_content
|
|
from frappe.utils.dateutils import parse_date
|
|
import re
|
|
|
|
class JWImport(Document):
|
|
def process_invoice_file(self):
|
|
fcontent = frappe.get_doc('File',
|
|
dict(file_url=self.load_from_file)).get_content()
|
|
rows = read_csv_content(fcontent)
|
|
header = [frappe.scrub(h) for h in rows.pop(0)]
|
|
self.set('lines', [])
|
|
for row in rows:
|
|
rec = self.append('lines', {})
|
|
for fieldname, val in zip(header, row):
|
|
if val:
|
|
if fieldname[-4:] == 'date':
|
|
val = parse_date(val)
|
|
elif fieldname == 'amount':
|
|
val = re.sub('^[^.,\d]*', '', val)
|
|
rec.set(fieldname, val)
|