Spaces:
Sleeping
Sleeping
File size: 6,420 Bytes
de77711 3ee3ddb aef5cd6 de77711 3ee3ddb aef5cd6 802b31f aef5cd6 802b31f de77711 aef5cd6 eee30e1 aef5cd6 2808a57 de77711 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | from voiceledger.parser.rules import parse_transaction
def test_parse_sale_with_quantity_and_unit_price() -> None:
transaction = parse_transaction("Sold 12 mangoes, 20 each")
assert transaction.transaction_type == "sale"
assert transaction.quantity == 12
assert transaction.item == "mangoes"
assert transaction.unit_price == 20
assert transaction.amount == 240
assert transaction.payment_status == "paid"
def test_parse_shorthand_sale() -> None:
transaction = parse_transaction("mango 12 x 20")
assert transaction.transaction_type == "sale"
assert transaction.item == "mango"
assert transaction.quantity == 12
assert transaction.unit_price == 20
assert transaction.amount == 240
def test_parse_quantity_first_sale() -> None:
transaction = parse_transaction("12 mango 20 each")
assert transaction.transaction_type == "sale"
assert transaction.item == "mango"
assert transaction.quantity == 12
assert transaction.unit_price == 20
assert transaction.amount == 240
def test_parse_expense() -> None:
transaction = parse_transaction("Paid 500 for supplies")
assert transaction.transaction_type == "expense"
assert transaction.amount == 500
assert transaction.item == "supplies"
assert transaction.payment_status == "paid"
def test_parse_shorthand_expense() -> None:
transaction = parse_transaction("rent 300")
assert transaction.transaction_type == "expense"
assert transaction.item == "rent"
assert transaction.amount == 300
def test_parse_hinglish_expense() -> None:
transaction = parse_transaction("rent 300 diya")
assert transaction.transaction_type == "expense"
assert transaction.item == "rent"
assert transaction.amount == 300
def test_parse_inventory_purchase() -> None:
transaction = parse_transaction("Bought 50 mangoes")
assert transaction.transaction_type == "inventory_purchase"
assert transaction.quantity == 50
assert transaction.item == "mangoes"
assert transaction.payment_status == "paid"
def test_parse_quantity_first_inventory_purchase() -> None:
transaction = parse_transaction("50 mango kharida")
assert transaction.transaction_type == "inventory_purchase"
assert transaction.quantity == 50
assert transaction.item == "mango"
def test_parse_gujarati_lite_inventory_purchase() -> None:
transaction = parse_transaction("50 mango lidha")
assert transaction.transaction_type == "inventory_purchase"
assert transaction.quantity == 50
assert transaction.item == "mango"
def test_parse_sale_without_unit_price_for_inventory() -> None:
transaction = parse_transaction("Sold 12 mangoes")
assert transaction.transaction_type == "sale"
assert transaction.quantity == 12
assert transaction.item == "mangoes"
assert transaction.unit_price is None
def test_parse_customer_credit() -> None:
transaction = parse_transaction("Amit owes 100")
assert transaction.transaction_type == "customer_credit"
assert transaction.customer == "Amit"
assert transaction.amount == 100
assert transaction.payment_status == "credit"
def test_parse_hinglish_customer_credit() -> None:
transaction = parse_transaction("Amit ne 100 dene hai")
assert transaction.transaction_type == "customer_credit"
assert transaction.customer == "Amit"
assert transaction.amount == 100
def test_parse_customer_payment() -> None:
transaction = parse_transaction("Amit paid 50")
assert transaction.transaction_type == "customer_payment"
assert transaction.customer == "Amit"
assert transaction.amount == 50
assert transaction.payment_status == "paid"
def test_parse_hinglish_customer_payment() -> None:
transaction = parse_transaction("Amit ne 50 diya")
assert transaction.transaction_type == "customer_payment"
assert transaction.customer == "Amit"
assert transaction.amount == 50
def test_parse_spanish_seller_phrases() -> None:
sale = parse_transaction("Vendí 12 mangos, 20 cada uno")
expense = parse_transaction("Pagué 500 por suministros")
credit = parse_transaction("Amit debe 100")
payment = parse_transaction("Amit pagó 50")
stock = parse_transaction("Compré 50 mangos")
assert sale.transaction_type == "sale"
assert sale.amount == 240
assert expense.transaction_type == "expense"
assert expense.amount == 500
assert credit.transaction_type == "customer_credit"
assert credit.amount == 100
assert payment.transaction_type == "customer_payment"
assert payment.amount == 50
assert stock.transaction_type == "inventory_purchase"
assert stock.quantity == 50
def test_parse_french_seller_phrases() -> None:
sale = parse_transaction("Vendu 12 mangues, 20 chacun")
expense = parse_transaction("Payé 500 pour fournitures")
credit = parse_transaction("Amit doit 100")
payment = parse_transaction("Amit a payé 50")
stock = parse_transaction("Acheté 50 mangues")
assert sale.transaction_type == "sale"
assert sale.amount == 240
assert expense.transaction_type == "expense"
assert expense.amount == 500
assert credit.transaction_type == "customer_credit"
assert credit.amount == 100
assert payment.transaction_type == "customer_payment"
assert payment.amount == 50
assert stock.transaction_type == "inventory_purchase"
assert stock.quantity == 50
def test_parse_portuguese_seller_phrases() -> None:
sale = parse_transaction("Vendi 12 mangas, 20 cada")
expense = parse_transaction("Paguei 500 por suprimentos")
credit = parse_transaction("Amit deve 100")
payment = parse_transaction("Amit pagou 50")
stock = parse_transaction("Comprei 50 mangas")
assert sale.transaction_type == "sale"
assert sale.amount == 240
assert expense.transaction_type == "expense"
assert expense.amount == 500
assert credit.transaction_type == "customer_credit"
assert credit.amount == 100
assert payment.transaction_type == "customer_payment"
assert payment.amount == 50
assert stock.transaction_type == "inventory_purchase"
assert stock.quantity == 50
def test_unknown_note_is_preserved() -> None:
transaction = parse_transaction("Need to check yesterday")
assert transaction.transaction_type == "unknown"
assert transaction.notes == "Need to check yesterday"
|