Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Text based Doctype import #26

Merged
merged 70 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2230f25
:construction: Text based Doctype import
madmath03 Nov 26, 2019
cd4d834
Merge branch 'develop' into feat/mapping
AminovE99 Jan 22, 2020
4f6b938
:lipstick: Beautify appear of fields
AminovE99 Jan 22, 2020
5dc92dc
Merge branch 'develop' into feat/mapping
madmath03 Jan 22, 2020
f26c2c9
:construction: Add generate_doctype function
AminovE99 Jan 23, 2020
e3b2f4e
Merge branch 'feat/mapping' of github.com:Monogramm/erpnext_ocr into …
AminovE99 Jan 23, 2020
fd5e0a0
:lipstick: Beauty code
AminovE99 Jan 23, 2020
fdcfb00
:sparkles: Add generating doctype function
AminovE99 Jan 24, 2020
9dd6de6
:ok_hand: Change architecture of code
AminovE99 Jan 26, 2020
dc8821f
:art: Add missing space
madmath03 Jan 27, 2020
1a02e68
:construction: test in progress
AminovE99 Jan 28, 2020
06516ea
:white_check_mark: Add test
AminovE99 Jan 28, 2020
ff1956a
:construction: Update test and add ability to generate tables
AminovE99 Jan 30, 2020
8238167
::sparkles:: Add new fields and feature
AminovE99 Feb 3, 2020
e4236a3
:sparkles: Add new fields
AminovE99 Feb 3, 2020
d63c61d
:sparkles: Add new version of OCR Import
AminovE99 Feb 6, 2020
aa3c1de
:construction: Workable ocr without tests
AminovE99 Feb 7, 2020
6826ba4
:construction: Add test for sales invoices
AminovE99 Feb 10, 2020
27500c5
Merge branch 'develop' into feat/mapping
AminovE99 Feb 10, 2020
0fc5c92
:construction: Remove library json
AminovE99 Feb 10, 2020
17f41d5
:bug: Resolve bug
AminovE99 Feb 11, 2020
b82b94e
:bug: Fix import data
AminovE99 Feb 11, 2020
4c59883
:bug: Fix bug with testing
AminovE99 Feb 11, 2020
a4c3161
:lipstick: Beauty code
AminovE99 Feb 11, 2020
e553dbb
:lipstick: Beauty code
AminovE99 Feb 11, 2020
bb03063
:bug: Remove library
AminovE99 Feb 11, 2020
4dd806c
:lipstick: Devide some lines
AminovE99 Feb 11, 2020
bda08b9
:bug: Add future imports
AminovE99 Feb 12, 2020
9597f63
:bug: Fix data.json
AminovE99 Feb 12, 2020
49eb627
:bug: Add utf-8 encoding
AminovE99 Feb 12, 2020
709dc9b
:bug: Remove unnecesary file
AminovE99 Feb 12, 2020
b484b3f
:bug: Remove double Item
AminovE99 Feb 12, 2020
bcac109
:art: Add empty lines
madmath03 Feb 12, 2020
c7618cd
:ok_hand: Add item doc in test_recors.json
AminovE99 Feb 12, 2020
1e8b3d4
:lipstick: Remove datetime library
AminovE99 Feb 12, 2020
92aaf9f
:sparkles: Automatically first run wizard for tests
AminovE99 Feb 13, 2020
85ff567
:sparkles: add before test function
AminovE99 Feb 14, 2020
cd325c2
:sparkles: Add new install
AminovE99 Feb 14, 2020
2c6e1b1
:construction: Create company and all item group
AminovE99 Feb 14, 2020
12e6072
:construction: Add all info for tests
AminovE99 Feb 15, 2020
55b5c09
:construction: Add more info
AminovE99 Feb 15, 2020
fe77acf
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
6162bca
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
c1b2f7a
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
2cc72d0
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
36e4a5f
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
7c48429
Merge branch 'develop' into feat/mapping
madmath03 Feb 15, 2020
1acb6ad
:white_check_mark: Add allow_multiple_items in before tests
AminovE99 Feb 16, 2020
478bdfe
Merge branch 'feat/mapping' of github.com:Monogramm/erpnext_ocr into …
AminovE99 Feb 16, 2020
e8f19db
:bug: Remove unnecessary library
AminovE99 Feb 16, 2020
2ed4ddf
:bug: Remove some unnecesary doctypes from test_records.json
AminovE99 Feb 17, 2020
491fabc
:rewind: Add previous docker configuration
AminovE99 Feb 17, 2020
498ba02
:poop: Add compatability with hard code
AminovE99 Feb 18, 2020
222052c
:bug: Condition for version 10
AminovE99 Feb 18, 2020
ad5e18b
:lipstick: Beauty code
AminovE99 Feb 19, 2020
1863339
:lipstick: Add libraries
AminovE99 Feb 19, 2020
359f6c0
:lipstick: Remove unusable libraries
AminovE99 Feb 19, 2020
a863ac5
:bulb: Update test comment
madmath03 Feb 27, 2020
253fa5f
:wrench: EXPORT LC_ALL in debian
AminovE99 Mar 6, 2020
cf88c50
Merge branch 'develop' into feat/mapping
AminovE99 Mar 6, 2020
2b138c8
:wrench: Fix bug with 12 version
AminovE99 Mar 6, 2020
dcd65c1
:fire: Remove unnecessary test and function
AminovE99 Mar 6, 2020
87364be
📄 Update copyright year
madmath03 Mar 9, 2020
6441c5c
:art: Add EOL dots in method docs
madmath03 Mar 9, 2020
26a0bba
:white_check_mark: Add library
AminovE99 Mar 11, 2020
ae0557d
:green_hear: Increase sleeping time for tests
AminovE99 Mar 11, 2020
37101c6
:bulb: Update the wait time in comment
madmath03 Mar 11, 2020
7fa76e3
:speech_balloon: Edit exception message
madmath03 Mar 11, 2020
b101566
:white_check_mark: Remove item creation
AminovE99 Mar 12, 2020
06a46c5
:white_check_mark: Change test_records.json
AminovE99 Mar 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ script:
- docker-compose -f docker-compose.${DATABASE}.yml ps "erpnext_app" | grep "Up"
- docker-compose -f docker-compose.${DATABASE}.yml logs "erpnext_web"
- docker-compose -f docker-compose.${DATABASE}.yml ps "erpnext_web" | grep "Up"
- echo 'Wait until test finished (3 minutes)' && sleep 180
- echo 'Wait until test finished (5 minutes)' && sleep 300
- docker-compose -f docker-compose.${DATABASE}.yml logs "sut"
- docker-compose -f docker-compose.${DATABASE}.yml ps "sut" | grep "Exit 0"
# Test container restart
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ You can report bugs or request new features by creating an [issue](https://githu

Here are a few rules to follow in order to ease code reviews and discussions before maintainers accept and merge your work.

You MUST follow the [The Best of the Best Practices (BOBP) Guide for Python](https://gist.github.com/sloria/7001839). If you don't know about any of them, you should really read the recommendations.
You MUST follow the [Best of the Best Practices (BOBP) Guide for Python](https://gist.github.com/sloria/7001839). If you don't know about any of them, you should really read the recommendations.

You SHOULD write tests.

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ADD .travis/docker_test.sh /docker_test.sh
RUN set -ex; \
sudo chmod 755 /docker_test.sh; \
sudo pip install coverage==4.5.4; \
sudo pip install python-coveralls
sudo pip install python-coveralls;

EXPOSE 4444

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Monogramm
Copyright (c) 2020 Monogramm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions erpnext_ocr/erpnext_ocr/doctype/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import unicode_literals
1 change: 1 addition & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import unicode_literals
9 changes: 9 additions & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

TEST_RESULT_FOR_SI = '''
\n\nD. Brawn Manufacture\n\nInvoice no. DVT-AX-345678\n\nPayment date: 03/12/2006\n\n \n\n
\n\n \n\n \n\nReference Designation ty Unit price “Total CHF Sales\nWork\nSERVICE D COMPLETE OVERHAUL 1 5500.00 500,00 220\nSERVICE D REFRESHING COMPLETE CASE 1 380,00 380.00 220\nAND RHODIUM BATH\nExterior parts:\nJO.297.085.FP FLAT GASKET. 1 3.00 3.00 220\nJO.197.075.FP FLAT GASKET 1 4.00 4.00 220\nJO.199.059.08 FLAT ROUND GASKET 1 6.00 600 220\nVi.261.036.8C W.G.FIXATION SCREWS 10 4.00 40.00 220\nAL465.085.BC WHITE GOLD "FOIL" 1 70.00 70.00 220\nPAIR OF HAND\nLENGTH: 10/13.50MM\nCALIBRE 2868\nSPECIAL DISCOUNT -3003.00 — -3003.00\nDiscount “500.00 “800.00\nTotal CHF 2100.00\nRETURN AFTER REPAIR\n\nNO COMMERCIAL VALUE\n'''

TEST_RESULT_FOR_ITEM = '''
Series STO-ITEM-.YYYY.-\n\nItem Code fdsa\n\nItem Name fdsa\n\nItem Group Consumable\nDefault Unit of Measure Nos\n\nfdsa\n\nShelf Life In Days\n\nEnd of Life 31-12-2099\nDefault Material Request Purchase\nType\n\nSr UOM\n\n1 Nos\n\nMax Sample Quantity\n\nVariant Based On\n\nSr Company\n\n1 fdsa\n\nIs Purchase Item\nMinimum Order Qty\n\nSafety Stock\nCountry of Origin Russian Federation\n\nIs Sales Item\n\nWeightage\n\nMaintain Stock\n\nInclude Item In Manufacturing\n\nOpening Stock\n\nValuation Rate\nStandard Selling Rate\n\nAllow over delivery or receipt\nupto this percent\n\n0 Weight Per Unit\n\nItem Attribute\n\nDefault Warehouse\n\nStores - F\n\nv Lead Time in days\n\n0 Last Purchase Rate\n\nv Max Discount (%)\nNo of Months\n\nNo of Months\n\nv\n\n0\nRUB 0,00\n\nRUB 123,00\n\n0\n\nConversion Factor\n\n‘l\n
'''
8 changes: 8 additions & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/ocr_import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2020, Monogramm and contributors
// For license information, please see license.txt

frappe.ui.form.on('OCR Import', {
refresh: function(frm) {

}
});
152 changes: 152 additions & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/ocr_import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:doctype_link",
"beta": 0,
"creation": "2019-11-25 16:37:26.611197",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "doctype_link",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Doctype",
"length": 0,
"no_copy": 0,
"options": "DocType",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "mappings",
"fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Mappings",
"length": 0,
"no_copy": 0,
"options": "OCR Import Mapping",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2020-01-24 06:38:56.285558",
"modified_by": "Administrator",
"module": "ERPNext OCR",
"name": "OCR Import",
"name_case": "",
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "ERPNext OCR Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"write": 1
}
],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "doctype_link",
"track_changes": 1,
"track_seen": 0,
"track_views": 0
}
72 changes: 72 additions & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/ocr_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Monogramm and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

import re

import frappe
from erpnext_ocr.erpnext_ocr.doctype.ocr_import_mapping.ocr_import_mapping import find_field, generate_child_doctype
from frappe.model.document import Document


class OCRImport(Document):
pass


@frappe.whitelist()
def generate_doctype(doctype_import_link, read_result, ignore_mandatory=False, ignore_validate=False):
"""
Generate doctype from raw text.
:param ignore_validate: Ignore validation
:param ignore_mandatory: Ignore mandatory fields
:param doctype_import_link:
:param read_result: text from document
:return: generated doctype
"""

doctype_import_doc = frappe.get_doc("OCR Import", doctype_import_link)
generated_doc = frappe.new_doc(doctype_import_link)

if ignore_mandatory:
generated_doc.company = "_Test Company"
generated_doc.price_list = "_Test Price List"
generated_doc.flags.ignore_mandatory = ignore_mandatory
generated_doc.flags.ignore_validate = ignore_validate

list_with_errors = []
list_with_table_values = []

for field in doctype_import_doc.mappings:
try:
found_field = find_field(field, read_result)
if found_field is None:
frappe.throw(
frappe._("Cannot find field {0} in text").format(field.field))
if field.value_type == "Table":
iter_of_str = re.finditer(field.regexp, read_result)
for item_match in iter_of_str:
raw_table_doc = generated_doc.append(field.field)
raw_table_doc.flags.ignore_mandatory = ignore_mandatory
item_str = item_match.group()
table_doc = generate_child_doctype(field.link_to_child_doc,
item_str,
raw_table_doc)
list_with_table_values.append(table_doc)
generated_doc.__dict__[field.field] = list_with_table_values
elif field.value_type == "Date":
generated_doc.__dict__[field.field] = frappe.utils.get_datetime(found_field)
else:
generated_doc.__dict__[field.field] = found_field
except KeyError:
list_with_errors.append("Field {} doesn't exist in doctype".
format(doctype_import_doc))
if list_with_errors:
frappe.throw(list_with_errors)
try:
generated_doc.set_new_name()
generated_doc.insert()
except frappe.exceptions.DuplicateEntryError:
frappe.throw("Generated doc already exists")
return generated_doc
23 changes: 23 additions & 0 deletions erpnext_ocr/erpnext_ocr/doctype/ocr_import/test_ocr_import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
// rename this file from _test_[name] to test_[name] to activate
// and remove above this line

QUnit.test("test: OCR Import", function (assert) {
let done = assert.async();

// number of asserts
assert.expect(1);

frappe.run_serially([
// insert a new OCR Import
() => frappe.tests.make('OCR Import', [
// values to be set
{key: 'value'}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
},
() => done()
]);

});
Loading