You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
866 B
27 lines
866 B
# -*- 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)
|
|
|