Skip to content

Commit 08943c5

Browse files
duskybombManu
authored and
Manu
committed
Fix list behavior in invoice_template.py (fixes invoice-x#142)
1 parent f08305e commit 08943c5

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ target/
6060

6161
# PyCharm
6262
.idea/
63+
64+
# PyTest
65+
.pytest_cache/
66+

invoice2data/extract/invoice_template.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ def extract(self, optimized_str):
168168
if sum_field:
169169
res_find += res_val
170170
else:
171-
res_find = res_val
172-
break
171+
res_find.extend(res_val)
173172
else:
174173
res_find = re.findall(v, optimized_str)
175174
if res_find:
@@ -188,7 +187,11 @@ def extract(self, optimized_str):
188187
else:
189188
output[k] = self.parse_number(res_find[0])
190189
else:
191-
output[k] = res_find[0]
190+
res_find = list(set(res_find))
191+
if len(res_find) == 1:
192+
output[k] = res_find[0]
193+
else:
194+
output[k] = res_find
192195
else:
193196
logger.warning("regexp for field %s didn't match", k)
194197

invoice2data/extract/templates/com/com.oyo.invoice.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ fields:
33
amount: GrandTotalRs(\d+)
44
date: Date:(\d{1,2}\/\d{1,2}\/\d{1,4})
55
invoice_number: ([A-Z0-9]+)CashatHotel
6+
payment_method:
7+
- \d+(\S*)atHotel
68
keywords:
79
- OYO
810
- Oravel

invoice2data/test/compare/oyo.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"date": "31/12/2017",
66
"desc": "Invoice IBZY2087 from OYO",
77
"invoice_number": "IBZY2087",
8-
"issuer": "OYO"
8+
"issuer": "OYO",
9+
"payment_method": "Cash"
910
}
1011
]

0 commit comments

Comments
 (0)