parser logic added
This commit is contained in:
@@ -44,17 +44,59 @@ BROODSTICKS OLIJF
|
||||
expect(items.single.quantity, 4);
|
||||
});
|
||||
|
||||
test('drops discount rows and Dutch totals', () {
|
||||
final items = ReceiptParser.parse('''
|
||||
test('folds a discount into the previous item', () {
|
||||
final result = ReceiptParser.parseReceipt('''
|
||||
AARDBEIEN 7,98
|
||||
ACTIE AARDBEIEN -2,00
|
||||
Totaal 82,99
|
||||
VISA 82,99
|
||||
Totaal korting: -2,21
|
||||
Totaal 5,98
|
||||
VISA 5,98
|
||||
Totaal korting: -2,00
|
||||
''');
|
||||
|
||||
expect(items.map((item) => item.name), ['AARDBEIEN']);
|
||||
expect(items.single.price, 7.98);
|
||||
expect(result.items.map((item) => item.name), ['AARDBEIEN']);
|
||||
expect(result.items.single.price, 5.98);
|
||||
expect(result.items.single.discount, -2.00);
|
||||
expect(result.validationPassed, isTrue);
|
||||
});
|
||||
|
||||
test('parses Kruidvat-style inline quantity', () {
|
||||
final items = ReceiptParser.parse('''
|
||||
ZEEPTABLET NEUTRAL 2 X 3,99 PER STUK 7,98
|
||||
KORTING NEUTRAL ZE.HP -1,00
|
||||
Totaal 6,98
|
||||
''');
|
||||
|
||||
expect(items, hasLength(1));
|
||||
expect(items.single.name, 'ZEEPTABLET NEUTRAL');
|
||||
expect(items.single.quantity, 2);
|
||||
expect(items.single.unitPrice, 3.99);
|
||||
expect(items.single.price, 6.98);
|
||||
});
|
||||
|
||||
test('parses Lidl-style price-reduction lines', () {
|
||||
final items = ReceiptParser.parse('''
|
||||
MELK 1,09 B
|
||||
In prijs verlaagd -0,50
|
||||
Totaal 0,59
|
||||
''');
|
||||
|
||||
expect(items, hasLength(1));
|
||||
expect(items.single.name, 'MELK');
|
||||
expect(items.single.price, 0.59);
|
||||
});
|
||||
|
||||
test('ignores BTW breakdown rows', () {
|
||||
final items = ReceiptParser.parse('''
|
||||
MELK 2,09
|
||||
Totaal 2,09
|
||||
BTW
|
||||
B 9% 0,17
|
||||
C 21% 0,00
|
||||
Bedr.Excl 1,92
|
||||
Bedr.Incl 2,09
|
||||
''');
|
||||
|
||||
expect(items.map((item) => item.name), ['MELK']);
|
||||
});
|
||||
|
||||
test('pairs a name column with a price column from OCR', () {
|
||||
@@ -66,10 +108,16 @@ Totaal korting: -2,21
|
||||
expect(items.first.name, 'JUMBO BIO VOLLE MELK');
|
||||
expect(items.first.price, 2.09);
|
||||
|
||||
final eggs = items.firstWhere((item) => item.name.startsWith('BIOLOGISCH EI'));
|
||||
final eggs = items.firstWhere(
|
||||
(item) => item.name.startsWith('BIOLOGISCH EI'),
|
||||
);
|
||||
expect(eggs.quantity, 2);
|
||||
expect(eggs.price, 5.58);
|
||||
|
||||
final berries = items.firstWhere((item) => item.name == 'AARDBEIEN');
|
||||
expect(berries.quantity, 2);
|
||||
expect(berries.price, 5.98);
|
||||
|
||||
expect(items.last.name, 'JUMBO PREM LUIER M4');
|
||||
expect(items.last.price, 6.20);
|
||||
expect(items, hasLength(26));
|
||||
|
||||
Reference in New Issue
Block a user