Changed the sample data format from JSON to CSV for the test site live demonstration.

This commit is contained in:
依瑪貓 2023-04-12 21:32:21 +08:00
parent 621020b0f0
commit 165e28441a
6 changed files with 2429 additions and 64 deletions

View File

@ -18,7 +18,10 @@
"""The sample data generation.
"""
import csv
import typing as t
from datetime import date, timedelta
from pathlib import Path
import click
@ -28,12 +31,12 @@ from testlib import Accounts, create_test_app, JournalEntryLineItemData, \
@click.command()
@click.argument("file")
def main(file) -> None:
def main() -> None:
"""Creates the sample data and output to a file."""
data: SampleData = SampleData(create_test_app(), "editor")
with open(file, "wt") as fp:
fp.write(data.json())
data_dir: Path = Path(__file__).parent / "test_site" / "data"
data.write_journal_entries(data_dir / "sample-journal_entries.csv")
data.write_line_items(data_dir / "sample-journal_entry_line_items.csv")
class SampleData(BaseTestData):
@ -301,6 +304,65 @@ class SampleData(BaseTestData):
[JournalEntryLineItemData(
credit_account, credit_description, amount)])]))
def write_journal_entries(self, file: Path) -> None:
"""Writes the journal entries to the CSV file.
:param file: The CSV file.
:return: None.
"""
today: date = date.today()
def filter_data(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry data for JSON encoding.
:param data: The journal entry data.
:return: The journal entry data for JSON encoding.
"""
data = data.copy()
data["date"] = (today - data["date"]).days
del data["created_by_id"]
del data["updated_by_id"]
return data
with open(file, "wt") as fp:
writer: csv.DictWriter = csv.DictWriter(
fp, fieldnames=["id", "date", "no", "note"])
writer.writeheader()
writer.writerows([filter_data(x) for x in self._journal_entries])
def write_line_items(self, file: Path) -> None:
"""Writes the journal entries to the CSV file.
:param file: The CSV file.
:return: None.
"""
from accounting import db
from accounting.models import Account
def filter_data(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry line item data for JSON encoding.
:param data: The journal entry line item data.
:return: The journal entry line item data for JSON encoding.
"""
data = data.copy()
with self._app.app_context():
data["account_id"] \
= db.session.get(Account, data["account_id"]).code
if "original_line_item_id" not in data:
data["original_line_item_id"] = None
data["is_debit"] = "1" if data["is_debit"] else ""
return data
with open(file, "wt") as fp:
writer: csv.DictWriter = csv.DictWriter(
fp, fieldnames=["id", "journal_entry_id",
"original_line_item_id", "is_debit", "no",
"account_id", "currency_code", "description",
"amount"])
writer.writeheader()
writer.writerows([filter_data(x) for x in self._line_items])
if __name__ == "__main__":
main()

View File

@ -0,0 +1,762 @@
id,date,no,note
920595794,1825,1,
167719688,1824,1,
924719319,1811,1,
323507578,1810,1,
262621044,1797,1,
653817937,1796,1,
816967804,1783,1,
856488549,1782,1,
974220139,1769,1,
564198001,1768,1,
534029375,1755,1,
409536685,1754,1,
696925565,1741,1,
311111882,1740,1,
330777832,1727,1,
113025054,1726,1,
487817808,1713,1,
241456952,1712,1,
364065422,1699,1,
167733813,1698,1,
866421596,1685,1,
763529473,1684,1,
833713134,1671,1,
168537646,1670,1,
680934663,1657,1,
608321515,1656,1,
590554378,1643,1,
822636649,1642,1,
502438349,1629,1,
916479257,1628,1,
759312362,1615,1,
777388379,1614,1,
128533828,1601,1,
880256320,1600,1,
300937285,1587,1,
663824372,1586,1,
328847075,1573,1,
340162514,1572,1,
594742129,1559,1,
127751868,1558,1,
975252333,1545,1,
164653789,1544,1,
913321677,1531,1,
644327573,1530,1,
646511092,1517,1,
542576751,1516,1,
721300970,1503,1,
119119879,1502,1,
778655945,1489,1,
954739598,1488,1,
160677124,1475,1,
650444891,1474,1,
275286747,1461,1,
586298065,1460,1,
483231167,1447,1,
677238826,1446,1,
987666214,1433,1,
615122154,1432,1,
192638198,1419,1,
522150224,1418,1,
157970376,1405,1,
672859325,1404,1,
766319138,1391,1,
202527913,1390,1,
544153063,1377,1,
776427441,1376,1,
201385617,1363,1,
836692365,1362,1,
635455165,1349,1,
601199000,1348,1,
223698225,1335,1,
292479913,1334,1,
151098400,1321,1,
239171360,1320,1,
897871634,1307,1,
715964039,1306,1,
721522332,1293,1,
862264784,1292,1,
839281301,1279,1,
623085076,1278,1,
359772314,1265,1,
789931149,1264,1,
294683943,1251,1,
719606226,1250,1,
636698875,1237,1,
300098192,1236,1,
158995071,1223,1,
119944658,1222,1,
609243413,1209,1,
937075952,1208,1,
982505748,1195,1,
597742281,1194,1,
432728297,1181,1,
294593180,1180,1,
366178386,1167,1,
363145239,1166,1,
404215195,1153,1,
734768107,1152,1,
718837714,1139,1,
676223847,1138,1,
527324347,1125,1,
127545563,1124,1,
285970855,1111,1,
494617980,1110,1,
618075266,1097,1,
886514998,1096,1,
669449408,1083,1,
905732390,1082,1,
120868897,1069,1,
968895440,1068,1,
594126056,1055,1,
983321611,1054,1,
217258196,1041,1,
748044362,1040,1,
550938659,1027,1,
499350285,1026,1,
474800323,1013,1,
941375983,1012,1,
672583721,999,1,
235397028,998,1,
471789584,985,1,
767845926,984,1,
196974640,971,1,
407699876,970,1,
584761419,957,1,
645818558,956,1,
844178241,943,1,
963904656,942,1,
329751044,929,1,
616057487,928,1,
677792701,915,1,
229571999,914,1,
770629438,901,1,
974300311,900,1,
622448143,887,1,
775027570,886,1,
977691200,873,1,
315594452,872,1,
758899307,859,1,
978022319,858,1,
228533193,845,1,
557094954,844,1,
934274659,831,1,
767710804,830,1,
991004642,817,1,
800201824,816,1,
863909652,803,1,
425568442,802,1,
410006227,789,1,
423235300,788,1,
671001264,775,1,
393949116,774,1,
647460045,761,1,
345027852,760,1,
389485218,747,1,
562198875,746,1,
721297709,733,1,
684907870,732,1,
490439441,719,1,
749713268,718,1,
381786692,705,1,
894638770,704,1,
358593852,691,1,
215132977,690,1,
308109683,677,1,
957835487,676,1,
806684705,663,1,
426159370,662,1,
121182405,649,1,
957960762,648,1,
141944057,635,1,
241049223,634,1,
348998240,621,1,
320606991,620,1,
686655353,607,1,
961773909,606,1,
404465691,593,1,
611214094,592,1,
560924807,579,1,
580060734,578,1,
156733729,565,1,
621737486,564,1,
416009158,551,1,
385647761,550,1,
949563508,537,1,
275121057,536,1,
812541441,523,1,
852720162,522,1,
924747979,509,1,
985292129,508,1,
923148238,495,1,
362041242,494,1,
811169848,481,1,
871493096,480,1,
213966403,467,1,
943205571,466,1,
866531476,453,1,
845270003,452,1,
968566807,439,1,
691976185,438,1,
785453444,425,1,
282506457,424,1,
617017554,411,1,
780203660,410,1,
571247306,397,1,
920518434,396,1,
414175655,383,1,
549085154,382,1,
838137695,369,1,
518589128,368,1,
210878113,355,1,
946224829,354,1,
157303099,341,1,
887584486,340,1,
544035334,327,1,
417741323,326,1,
424475535,313,1,
636455373,312,1,
946803193,299,1,
623495077,298,1,
704429996,285,1,
129822874,284,1,
274101370,271,1,
169507838,270,1,
227085275,257,1,
809230420,256,1,
489045353,243,1,
850581440,242,1,
415297271,229,1,
423539815,228,1,
653210790,215,1,
737777742,214,1,
788141156,201,1,
975326987,200,1,
496699465,187,1,
117816559,186,1,
158496631,173,1,
564646901,172,1,
795983274,159,1,
274728220,158,1,
581586933,145,1,
649099645,144,1,
243513393,131,1,
402999178,130,1,
823867439,117,1,
271370438,116,1,
146329215,103,1,
707167506,102,1,
490971858,89,1,
803145319,88,1,
141610606,75,1,
573278167,74,1,
926268699,61,1,
259559611,60,1,
653092670,47,1,
173180273,46,1,
399973243,33,1,
950572866,32,1,
431937430,19,1,
889697632,18,1,
688217608,5,1,
205619160,4,1,
441864102,1807,1,
912340574,1776,1,
209734890,1746,1,
243847232,1715,1,
545178022,1684,2,
757644914,1654,1,
709824777,1623,1,
702866006,1593,1,
677273983,1562,1,
241001022,1531,2,
578066267,1503,2,
598819130,1472,1,
815746861,1442,1,
893881104,1411,1,
874097643,1381,1,
928946469,1350,1,
739916751,1319,1,
628915518,1289,1,
158355796,1258,1,
977635103,1228,1,
403376322,1197,1,
401612265,1166,2,
533623827,1137,1,
670798503,1106,1,
270312680,1076,1,
184537410,1045,1,
160595264,1015,1,
599914415,984,2,
969597247,953,1,
836450793,923,1,
556074668,892,1,
774322200,862,1,
383523937,831,2,
823934445,800,1,
119545102,772,1,
679121510,741,1,
509206305,711,1,
588269753,680,1,
364261289,650,1,
297729584,619,1,
924371653,588,1,
512378982,558,1,
182081687,527,1,
844596552,497,1,
242512891,466,2,
708522969,435,1,
993303180,407,1,
315847857,376,1,
299835785,346,1,
543632811,315,1,
102186083,285,2,
160769407,254,1,
655405209,223,1,
833962437,193,1,
167207427,162,1,
943978137,132,1,
302101265,101,1,
278323943,70,1,
175211372,42,1,
608345857,11,1,
514771804,1833,1,
593369716,1832,1,
705767689,1828,1,
593372990,1803,1,
184537754,1802,1,
995622116,1798,1,
749424364,1772,1,
121488238,1771,1,
640079073,1767,1,
824601810,1742,1,
542282982,1741,2,
994649755,1737,1,
983539118,1711,1,
367416911,1710,1,
532597030,1706,1,
572446528,1680,1,
340236287,1679,1,
759591805,1675,1,
886317404,1650,1,
351767548,1649,1,
646170267,1645,1,
343093301,1619,1,
705817069,1618,1,
912206806,1614,2,
244039693,1589,1,
623877530,1588,1,
193626244,1584,1,
864752440,1558,2,
698269931,1557,1,
723712694,1553,1,
574930230,1527,1,
544819126,1526,1,
384766666,1522,1,
651851628,1499,1,
952119252,1498,1,
674668054,1494,1,
547522619,1468,1,
173186830,1467,1,
865012414,1463,1,
206856704,1438,1,
801403464,1437,1,
111325157,1433,2,
262372074,1407,1,
784935817,1406,1,
340522160,1402,1,
835792937,1377,2,
638617129,1376,2,
730208680,1372,1,
156194429,1346,1,
699671683,1345,1,
497947013,1341,1,
786969266,1315,1,
965456430,1314,1,
741480080,1310,1,
996594000,1285,1,
759434327,1284,1,
248929835,1280,1,
100188306,1254,1,
397143707,1253,1,
997071662,1249,1,
799963514,1224,1,
586462685,1223,2,
840211917,1219,1,
280297680,1193,1,
622664327,1192,1,
337423599,1188,1,
744409889,1162,1,
324290549,1161,1,
399978290,1157,1,
976614162,1133,1,
733411608,1132,1,
779502252,1128,1,
694642910,1102,1,
589967992,1101,1,
812154532,1097,2,
446336381,1072,1,
997465638,1071,1,
695463728,1067,1,
437461833,1041,2,
363848061,1040,2,
832431988,1036,1,
150221940,1011,1,
928316021,1010,1,
614264138,1006,1,
844037652,980,1,
847052057,979,1,
244380507,975,1,
664173677,949,1,
910360755,948,1,
449187964,944,1,
655278726,919,1,
749024286,918,1,
588856997,914,2,
698675186,888,1,
235049763,887,2,
190317946,883,1,
394258185,858,2,
683058769,857,1,
569480987,853,1,
794010803,827,1,
517616540,826,1,
126618363,822,1,
165804887,796,1,
712868700,795,1,
448615093,791,1,
292392546,768,1,
176399757,767,1,
941309949,763,1,
917170432,737,1,
393779218,736,1,
229114748,732,2,
796830345,707,1,
361375142,706,1,
636984952,702,1,
183871802,676,2,
726573750,675,1,
104003572,671,1,
207516690,646,1,
886960586,645,1,
796556194,641,1,
280072790,615,1,
376646507,614,1,
670013900,610,1,
710911370,584,1,
692062709,583,1,
945120601,579,2,
238099067,554,1,
141946232,553,1,
363924657,549,1,
200423540,523,2,
450386730,522,2,
501201103,518,1,
722592147,493,1,
111175359,492,1,
695275339,488,1,
770948173,462,1,
125366752,461,1,
495203796,457,1,
436996037,431,1,
537753065,430,1,
870522427,426,1,
150461691,403,1,
213932656,402,1,
141488648,398,1,
658991952,372,1,
787118332,371,1,
453823736,367,1,
164470486,342,1,
541106783,341,2,
922957464,337,1,
311051490,311,1,
655629665,310,1,
547633846,306,1,
466122789,281,1,
748946528,280,1,
432001491,276,1,
229423752,250,1,
481974272,249,1,
117595916,245,1,
964413002,219,1,
107966394,218,1,
351737718,214,2,
101282939,189,1,
400238568,188,1,
179085420,184,1,
159931628,158,2,
115738557,157,1,
291513790,153,1,
713892472,128,1,
620731758,127,1,
856667031,123,1,
927266285,97,1,
978689593,96,1,
381169193,92,1,
599832757,66,1,
142513296,65,1,
921491954,61,2,
839977040,38,1,
805264458,37,1,
423929180,33,2,
228098407,7,1,
911305213,6,1,
116464373,2,1,
108355497,40,1,
218698859,5,2,
638428066,30,1,
116571429,60,2,
824441170,35,1,
934539456,10,1,
271350601,45,1,
870787195,6,2,
284648942,25,1,
438677999,55,1,
501435816,27,1,
180500081,8,1,
468159641,60,3,
722956493,60,4,
560303779,60,5,
238549424,60,6,
768396487,59,1,
517470102,59,2,
965190270,59,3,
215903999,59,4,
478029651,58,1,
874038847,58,2,
849913651,58,3,
761054191,58,4,
400796832,57,1,
970704514,57,2,
556356224,57,3,
741253588,57,4,
355733835,56,1,
323736502,56,2,
451515758,56,3,
225990920,56,4,
992232778,55,2,
647459911,55,3,
789334321,55,4,
717150023,55,5,
845627271,54,1,
487627248,54,2,
839234085,54,3,
113633678,54,4,
971665356,53,1,
934382703,53,2,
760076948,53,3,
809509517,53,4,
596847052,52,1,
745457603,52,2,
503874758,52,3,
646819576,52,4,
836672490,51,1,
452049971,51,2,
147242491,51,3,
906978237,51,4,
329394419,50,1,
797892803,50,2,
613999829,50,3,
696139462,50,4,
887080294,49,1,
388730039,49,2,
890037830,49,3,
581863261,49,4,
579390300,48,1,
333715152,48,2,
523632671,48,3,
366230483,48,4,
857547265,47,2,
109733956,47,3,
114838736,47,4,
913691134,47,5,
531295049,46,2,
421868682,46,3,
427214791,46,4,
221316724,46,5,
191024248,45,2,
213602801,45,3,
614533920,45,4,
493931718,45,5,
238314782,44,1,
710782153,44,2,
462494012,44,3,
358897897,44,4,
210206997,43,1,
486781355,43,2,
872028540,43,3,
972765259,43,4,
265930733,42,2,
671569090,42,3,
579480125,42,4,
463751608,42,5,
709403395,41,1,
173246446,41,2,
663555479,41,3,
999954005,41,4,
608615196,40,2,
838019513,40,3,
592119748,40,4,
126852606,40,5,
113264316,39,1,
988673782,39,2,
331146869,39,3,
628774637,39,4,
667988387,38,2,
853384636,38,3,
925053987,38,4,
245176667,38,5,
126299195,37,2,
736982561,37,3,
722196792,37,4,
591364013,37,5,
724565500,36,1,
259676294,36,2,
907087078,36,3,
457074841,36,4,
276057268,35,2,
792870181,35,3,
291259938,35,4,
696660280,35,5,
375748406,34,1,
958051707,34,2,
777603420,34,3,
235964104,34,4,
249855189,33,3,
264355079,33,4,
565768229,33,5,
940942156,33,6,
334860946,32,2,
974029840,32,3,
885953975,32,4,
121142827,32,5,
439417290,31,1,
915459717,31,2,
532456051,31,3,
961300250,31,4,
106171276,30,2,
341023837,30,3,
655719662,30,4,
239701820,30,5,
669321248,29,1,
380569098,29,2,
405140021,29,3,
359640438,29,4,
509795327,28,1,
487999378,28,2,
828335342,28,3,
418476186,28,4,
372067537,27,2,
416154021,27,3,
504319878,27,4,
148303022,27,5,
755070679,26,1,
718789501,26,2,
722521549,26,3,
510505515,26,4,
189764314,25,2,
283953036,25,3,
941354935,25,4,
722404083,25,5,
844973537,24,1,
936745933,24,2,
659022926,24,3,
185376101,24,4,
725191286,23,1,
321637118,23,2,
788778448,23,3,
585477956,23,4,
605054808,22,1,
780188639,22,2,
780018244,22,3,
857065036,22,4,
199089854,21,1,
348192086,21,2,
289518063,21,3,
831333771,21,4,
510792845,20,1,
234156394,20,2,
187419584,20,3,
935322395,20,4,
348520531,19,2,
417969553,19,3,
692795304,19,4,
213131066,19,5,
558144531,18,2,
680562985,18,3,
370027571,18,4,
420457647,18,5,
177953996,17,1,
211565294,17,2,
594340749,17,3,
543836150,17,4,
520536761,16,1,
437394817,16,2,
606478888,16,3,
507521652,16,4,
208657583,15,1,
312837142,15,2,
236775257,15,3,
292716353,15,4,
489753786,14,1,
932441865,14,2,
335340858,14,3,
203222754,14,4,
735247201,13,1,
508845275,13,2,
902053604,13,3,
810554908,13,4,
451882915,12,1,
818503006,12,2,
760753816,12,3,
207784823,12,4,
658437082,11,2,
687949009,11,3,
775562720,11,4,
668017098,11,5,
434298402,10,2,
721116817,10,3,
597672211,10,4,
113135722,10,5,
732353307,9,1,
724984925,9,2,
952090946,9,3,
653723454,9,4,
520076751,8,2,
785925776,8,3,
286426950,8,4,
581197173,8,5,
778924243,7,2,
791851102,7,3,
370405076,7,4,
417757829,7,5,
635656498,6,3,
762929401,6,4,
856084599,6,5,
853906992,6,6,
642991787,5,3,
929081937,5,4,
298801582,5,5,
983831266,5,6,
153538209,4,2,
706440996,4,3,
557497187,4,4,
966432524,4,5,
322782940,3,1,
483498184,3,2,
741476687,3,3,
515764137,3,4,
213705166,2,2,
405160550,2,3,
473671974,2,4,
619813884,2,5,
197013244,1,1,
674079750,1,2,
631878930,1,3,
457552543,1,4,
477152158,0,1,
603928836,0,2,
225159020,0,3,
542040855,0,4,
1 id date no note
2 920595794 1825 1
3 167719688 1824 1
4 924719319 1811 1
5 323507578 1810 1
6 262621044 1797 1
7 653817937 1796 1
8 816967804 1783 1
9 856488549 1782 1
10 974220139 1769 1
11 564198001 1768 1
12 534029375 1755 1
13 409536685 1754 1
14 696925565 1741 1
15 311111882 1740 1
16 330777832 1727 1
17 113025054 1726 1
18 487817808 1713 1
19 241456952 1712 1
20 364065422 1699 1
21 167733813 1698 1
22 866421596 1685 1
23 763529473 1684 1
24 833713134 1671 1
25 168537646 1670 1
26 680934663 1657 1
27 608321515 1656 1
28 590554378 1643 1
29 822636649 1642 1
30 502438349 1629 1
31 916479257 1628 1
32 759312362 1615 1
33 777388379 1614 1
34 128533828 1601 1
35 880256320 1600 1
36 300937285 1587 1
37 663824372 1586 1
38 328847075 1573 1
39 340162514 1572 1
40 594742129 1559 1
41 127751868 1558 1
42 975252333 1545 1
43 164653789 1544 1
44 913321677 1531 1
45 644327573 1530 1
46 646511092 1517 1
47 542576751 1516 1
48 721300970 1503 1
49 119119879 1502 1
50 778655945 1489 1
51 954739598 1488 1
52 160677124 1475 1
53 650444891 1474 1
54 275286747 1461 1
55 586298065 1460 1
56 483231167 1447 1
57 677238826 1446 1
58 987666214 1433 1
59 615122154 1432 1
60 192638198 1419 1
61 522150224 1418 1
62 157970376 1405 1
63 672859325 1404 1
64 766319138 1391 1
65 202527913 1390 1
66 544153063 1377 1
67 776427441 1376 1
68 201385617 1363 1
69 836692365 1362 1
70 635455165 1349 1
71 601199000 1348 1
72 223698225 1335 1
73 292479913 1334 1
74 151098400 1321 1
75 239171360 1320 1
76 897871634 1307 1
77 715964039 1306 1
78 721522332 1293 1
79 862264784 1292 1
80 839281301 1279 1
81 623085076 1278 1
82 359772314 1265 1
83 789931149 1264 1
84 294683943 1251 1
85 719606226 1250 1
86 636698875 1237 1
87 300098192 1236 1
88 158995071 1223 1
89 119944658 1222 1
90 609243413 1209 1
91 937075952 1208 1
92 982505748 1195 1
93 597742281 1194 1
94 432728297 1181 1
95 294593180 1180 1
96 366178386 1167 1
97 363145239 1166 1
98 404215195 1153 1
99 734768107 1152 1
100 718837714 1139 1
101 676223847 1138 1
102 527324347 1125 1
103 127545563 1124 1
104 285970855 1111 1
105 494617980 1110 1
106 618075266 1097 1
107 886514998 1096 1
108 669449408 1083 1
109 905732390 1082 1
110 120868897 1069 1
111 968895440 1068 1
112 594126056 1055 1
113 983321611 1054 1
114 217258196 1041 1
115 748044362 1040 1
116 550938659 1027 1
117 499350285 1026 1
118 474800323 1013 1
119 941375983 1012 1
120 672583721 999 1
121 235397028 998 1
122 471789584 985 1
123 767845926 984 1
124 196974640 971 1
125 407699876 970 1
126 584761419 957 1
127 645818558 956 1
128 844178241 943 1
129 963904656 942 1
130 329751044 929 1
131 616057487 928 1
132 677792701 915 1
133 229571999 914 1
134 770629438 901 1
135 974300311 900 1
136 622448143 887 1
137 775027570 886 1
138 977691200 873 1
139 315594452 872 1
140 758899307 859 1
141 978022319 858 1
142 228533193 845 1
143 557094954 844 1
144 934274659 831 1
145 767710804 830 1
146 991004642 817 1
147 800201824 816 1
148 863909652 803 1
149 425568442 802 1
150 410006227 789 1
151 423235300 788 1
152 671001264 775 1
153 393949116 774 1
154 647460045 761 1
155 345027852 760 1
156 389485218 747 1
157 562198875 746 1
158 721297709 733 1
159 684907870 732 1
160 490439441 719 1
161 749713268 718 1
162 381786692 705 1
163 894638770 704 1
164 358593852 691 1
165 215132977 690 1
166 308109683 677 1
167 957835487 676 1
168 806684705 663 1
169 426159370 662 1
170 121182405 649 1
171 957960762 648 1
172 141944057 635 1
173 241049223 634 1
174 348998240 621 1
175 320606991 620 1
176 686655353 607 1
177 961773909 606 1
178 404465691 593 1
179 611214094 592 1
180 560924807 579 1
181 580060734 578 1
182 156733729 565 1
183 621737486 564 1
184 416009158 551 1
185 385647761 550 1
186 949563508 537 1
187 275121057 536 1
188 812541441 523 1
189 852720162 522 1
190 924747979 509 1
191 985292129 508 1
192 923148238 495 1
193 362041242 494 1
194 811169848 481 1
195 871493096 480 1
196 213966403 467 1
197 943205571 466 1
198 866531476 453 1
199 845270003 452 1
200 968566807 439 1
201 691976185 438 1
202 785453444 425 1
203 282506457 424 1
204 617017554 411 1
205 780203660 410 1
206 571247306 397 1
207 920518434 396 1
208 414175655 383 1
209 549085154 382 1
210 838137695 369 1
211 518589128 368 1
212 210878113 355 1
213 946224829 354 1
214 157303099 341 1
215 887584486 340 1
216 544035334 327 1
217 417741323 326 1
218 424475535 313 1
219 636455373 312 1
220 946803193 299 1
221 623495077 298 1
222 704429996 285 1
223 129822874 284 1
224 274101370 271 1
225 169507838 270 1
226 227085275 257 1
227 809230420 256 1
228 489045353 243 1
229 850581440 242 1
230 415297271 229 1
231 423539815 228 1
232 653210790 215 1
233 737777742 214 1
234 788141156 201 1
235 975326987 200 1
236 496699465 187 1
237 117816559 186 1
238 158496631 173 1
239 564646901 172 1
240 795983274 159 1
241 274728220 158 1
242 581586933 145 1
243 649099645 144 1
244 243513393 131 1
245 402999178 130 1
246 823867439 117 1
247 271370438 116 1
248 146329215 103 1
249 707167506 102 1
250 490971858 89 1
251 803145319 88 1
252 141610606 75 1
253 573278167 74 1
254 926268699 61 1
255 259559611 60 1
256 653092670 47 1
257 173180273 46 1
258 399973243 33 1
259 950572866 32 1
260 431937430 19 1
261 889697632 18 1
262 688217608 5 1
263 205619160 4 1
264 441864102 1807 1
265 912340574 1776 1
266 209734890 1746 1
267 243847232 1715 1
268 545178022 1684 2
269 757644914 1654 1
270 709824777 1623 1
271 702866006 1593 1
272 677273983 1562 1
273 241001022 1531 2
274 578066267 1503 2
275 598819130 1472 1
276 815746861 1442 1
277 893881104 1411 1
278 874097643 1381 1
279 928946469 1350 1
280 739916751 1319 1
281 628915518 1289 1
282 158355796 1258 1
283 977635103 1228 1
284 403376322 1197 1
285 401612265 1166 2
286 533623827 1137 1
287 670798503 1106 1
288 270312680 1076 1
289 184537410 1045 1
290 160595264 1015 1
291 599914415 984 2
292 969597247 953 1
293 836450793 923 1
294 556074668 892 1
295 774322200 862 1
296 383523937 831 2
297 823934445 800 1
298 119545102 772 1
299 679121510 741 1
300 509206305 711 1
301 588269753 680 1
302 364261289 650 1
303 297729584 619 1
304 924371653 588 1
305 512378982 558 1
306 182081687 527 1
307 844596552 497 1
308 242512891 466 2
309 708522969 435 1
310 993303180 407 1
311 315847857 376 1
312 299835785 346 1
313 543632811 315 1
314 102186083 285 2
315 160769407 254 1
316 655405209 223 1
317 833962437 193 1
318 167207427 162 1
319 943978137 132 1
320 302101265 101 1
321 278323943 70 1
322 175211372 42 1
323 608345857 11 1
324 514771804 1833 1
325 593369716 1832 1
326 705767689 1828 1
327 593372990 1803 1
328 184537754 1802 1
329 995622116 1798 1
330 749424364 1772 1
331 121488238 1771 1
332 640079073 1767 1
333 824601810 1742 1
334 542282982 1741 2
335 994649755 1737 1
336 983539118 1711 1
337 367416911 1710 1
338 532597030 1706 1
339 572446528 1680 1
340 340236287 1679 1
341 759591805 1675 1
342 886317404 1650 1
343 351767548 1649 1
344 646170267 1645 1
345 343093301 1619 1
346 705817069 1618 1
347 912206806 1614 2
348 244039693 1589 1
349 623877530 1588 1
350 193626244 1584 1
351 864752440 1558 2
352 698269931 1557 1
353 723712694 1553 1
354 574930230 1527 1
355 544819126 1526 1
356 384766666 1522 1
357 651851628 1499 1
358 952119252 1498 1
359 674668054 1494 1
360 547522619 1468 1
361 173186830 1467 1
362 865012414 1463 1
363 206856704 1438 1
364 801403464 1437 1
365 111325157 1433 2
366 262372074 1407 1
367 784935817 1406 1
368 340522160 1402 1
369 835792937 1377 2
370 638617129 1376 2
371 730208680 1372 1
372 156194429 1346 1
373 699671683 1345 1
374 497947013 1341 1
375 786969266 1315 1
376 965456430 1314 1
377 741480080 1310 1
378 996594000 1285 1
379 759434327 1284 1
380 248929835 1280 1
381 100188306 1254 1
382 397143707 1253 1
383 997071662 1249 1
384 799963514 1224 1
385 586462685 1223 2
386 840211917 1219 1
387 280297680 1193 1
388 622664327 1192 1
389 337423599 1188 1
390 744409889 1162 1
391 324290549 1161 1
392 399978290 1157 1
393 976614162 1133 1
394 733411608 1132 1
395 779502252 1128 1
396 694642910 1102 1
397 589967992 1101 1
398 812154532 1097 2
399 446336381 1072 1
400 997465638 1071 1
401 695463728 1067 1
402 437461833 1041 2
403 363848061 1040 2
404 832431988 1036 1
405 150221940 1011 1
406 928316021 1010 1
407 614264138 1006 1
408 844037652 980 1
409 847052057 979 1
410 244380507 975 1
411 664173677 949 1
412 910360755 948 1
413 449187964 944 1
414 655278726 919 1
415 749024286 918 1
416 588856997 914 2
417 698675186 888 1
418 235049763 887 2
419 190317946 883 1
420 394258185 858 2
421 683058769 857 1
422 569480987 853 1
423 794010803 827 1
424 517616540 826 1
425 126618363 822 1
426 165804887 796 1
427 712868700 795 1
428 448615093 791 1
429 292392546 768 1
430 176399757 767 1
431 941309949 763 1
432 917170432 737 1
433 393779218 736 1
434 229114748 732 2
435 796830345 707 1
436 361375142 706 1
437 636984952 702 1
438 183871802 676 2
439 726573750 675 1
440 104003572 671 1
441 207516690 646 1
442 886960586 645 1
443 796556194 641 1
444 280072790 615 1
445 376646507 614 1
446 670013900 610 1
447 710911370 584 1
448 692062709 583 1
449 945120601 579 2
450 238099067 554 1
451 141946232 553 1
452 363924657 549 1
453 200423540 523 2
454 450386730 522 2
455 501201103 518 1
456 722592147 493 1
457 111175359 492 1
458 695275339 488 1
459 770948173 462 1
460 125366752 461 1
461 495203796 457 1
462 436996037 431 1
463 537753065 430 1
464 870522427 426 1
465 150461691 403 1
466 213932656 402 1
467 141488648 398 1
468 658991952 372 1
469 787118332 371 1
470 453823736 367 1
471 164470486 342 1
472 541106783 341 2
473 922957464 337 1
474 311051490 311 1
475 655629665 310 1
476 547633846 306 1
477 466122789 281 1
478 748946528 280 1
479 432001491 276 1
480 229423752 250 1
481 481974272 249 1
482 117595916 245 1
483 964413002 219 1
484 107966394 218 1
485 351737718 214 2
486 101282939 189 1
487 400238568 188 1
488 179085420 184 1
489 159931628 158 2
490 115738557 157 1
491 291513790 153 1
492 713892472 128 1
493 620731758 127 1
494 856667031 123 1
495 927266285 97 1
496 978689593 96 1
497 381169193 92 1
498 599832757 66 1
499 142513296 65 1
500 921491954 61 2
501 839977040 38 1
502 805264458 37 1
503 423929180 33 2
504 228098407 7 1
505 911305213 6 1
506 116464373 2 1
507 108355497 40 1
508 218698859 5 2
509 638428066 30 1
510 116571429 60 2
511 824441170 35 1
512 934539456 10 1
513 271350601 45 1
514 870787195 6 2
515 284648942 25 1
516 438677999 55 1
517 501435816 27 1
518 180500081 8 1
519 468159641 60 3
520 722956493 60 4
521 560303779 60 5
522 238549424 60 6
523 768396487 59 1
524 517470102 59 2
525 965190270 59 3
526 215903999 59 4
527 478029651 58 1
528 874038847 58 2
529 849913651 58 3
530 761054191 58 4
531 400796832 57 1
532 970704514 57 2
533 556356224 57 3
534 741253588 57 4
535 355733835 56 1
536 323736502 56 2
537 451515758 56 3
538 225990920 56 4
539 992232778 55 2
540 647459911 55 3
541 789334321 55 4
542 717150023 55 5
543 845627271 54 1
544 487627248 54 2
545 839234085 54 3
546 113633678 54 4
547 971665356 53 1
548 934382703 53 2
549 760076948 53 3
550 809509517 53 4
551 596847052 52 1
552 745457603 52 2
553 503874758 52 3
554 646819576 52 4
555 836672490 51 1
556 452049971 51 2
557 147242491 51 3
558 906978237 51 4
559 329394419 50 1
560 797892803 50 2
561 613999829 50 3
562 696139462 50 4
563 887080294 49 1
564 388730039 49 2
565 890037830 49 3
566 581863261 49 4
567 579390300 48 1
568 333715152 48 2
569 523632671 48 3
570 366230483 48 4
571 857547265 47 2
572 109733956 47 3
573 114838736 47 4
574 913691134 47 5
575 531295049 46 2
576 421868682 46 3
577 427214791 46 4
578 221316724 46 5
579 191024248 45 2
580 213602801 45 3
581 614533920 45 4
582 493931718 45 5
583 238314782 44 1
584 710782153 44 2
585 462494012 44 3
586 358897897 44 4
587 210206997 43 1
588 486781355 43 2
589 872028540 43 3
590 972765259 43 4
591 265930733 42 2
592 671569090 42 3
593 579480125 42 4
594 463751608 42 5
595 709403395 41 1
596 173246446 41 2
597 663555479 41 3
598 999954005 41 4
599 608615196 40 2
600 838019513 40 3
601 592119748 40 4
602 126852606 40 5
603 113264316 39 1
604 988673782 39 2
605 331146869 39 3
606 628774637 39 4
607 667988387 38 2
608 853384636 38 3
609 925053987 38 4
610 245176667 38 5
611 126299195 37 2
612 736982561 37 3
613 722196792 37 4
614 591364013 37 5
615 724565500 36 1
616 259676294 36 2
617 907087078 36 3
618 457074841 36 4
619 276057268 35 2
620 792870181 35 3
621 291259938 35 4
622 696660280 35 5
623 375748406 34 1
624 958051707 34 2
625 777603420 34 3
626 235964104 34 4
627 249855189 33 3
628 264355079 33 4
629 565768229 33 5
630 940942156 33 6
631 334860946 32 2
632 974029840 32 3
633 885953975 32 4
634 121142827 32 5
635 439417290 31 1
636 915459717 31 2
637 532456051 31 3
638 961300250 31 4
639 106171276 30 2
640 341023837 30 3
641 655719662 30 4
642 239701820 30 5
643 669321248 29 1
644 380569098 29 2
645 405140021 29 3
646 359640438 29 4
647 509795327 28 1
648 487999378 28 2
649 828335342 28 3
650 418476186 28 4
651 372067537 27 2
652 416154021 27 3
653 504319878 27 4
654 148303022 27 5
655 755070679 26 1
656 718789501 26 2
657 722521549 26 3
658 510505515 26 4
659 189764314 25 2
660 283953036 25 3
661 941354935 25 4
662 722404083 25 5
663 844973537 24 1
664 936745933 24 2
665 659022926 24 3
666 185376101 24 4
667 725191286 23 1
668 321637118 23 2
669 788778448 23 3
670 585477956 23 4
671 605054808 22 1
672 780188639 22 2
673 780018244 22 3
674 857065036 22 4
675 199089854 21 1
676 348192086 21 2
677 289518063 21 3
678 831333771 21 4
679 510792845 20 1
680 234156394 20 2
681 187419584 20 3
682 935322395 20 4
683 348520531 19 2
684 417969553 19 3
685 692795304 19 4
686 213131066 19 5
687 558144531 18 2
688 680562985 18 3
689 370027571 18 4
690 420457647 18 5
691 177953996 17 1
692 211565294 17 2
693 594340749 17 3
694 543836150 17 4
695 520536761 16 1
696 437394817 16 2
697 606478888 16 3
698 507521652 16 4
699 208657583 15 1
700 312837142 15 2
701 236775257 15 3
702 292716353 15 4
703 489753786 14 1
704 932441865 14 2
705 335340858 14 3
706 203222754 14 4
707 735247201 13 1
708 508845275 13 2
709 902053604 13 3
710 810554908 13 4
711 451882915 12 1
712 818503006 12 2
713 760753816 12 3
714 207784823 12 4
715 658437082 11 2
716 687949009 11 3
717 775562720 11 4
718 668017098 11 5
719 434298402 10 2
720 721116817 10 3
721 597672211 10 4
722 113135722 10 5
723 732353307 9 1
724 724984925 9 2
725 952090946 9 3
726 653723454 9 4
727 520076751 8 2
728 785925776 8 3
729 286426950 8 4
730 581197173 8 5
731 778924243 7 2
732 791851102 7 3
733 370405076 7 4
734 417757829 7 5
735 635656498 6 3
736 762929401 6 4
737 856084599 6 5
738 853906992 6 6
739 642991787 5 3
740 929081937 5 4
741 298801582 5 5
742 983831266 5 6
743 153538209 4 2
744 706440996 4 3
745 557497187 4 4
746 966432524 4 5
747 322782940 3 1
748 483498184 3 2
749 741476687 3 3
750 515764137 3 4
751 213705166 2 2
752 405160550 2 3
753 473671974 2 4
754 619813884 2 5
755 197013244 1 1
756 674079750 1 2
757 631878930 1 3
758 457552543 1 4
759 477152158 0 1
760 603928836 0 2
761 225159020 0 3
762 542040855 0 4

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@
"""The data reset for the Mia! Accounting demonstration website.
"""
import json
import csv
import typing as t
from datetime import date, timedelta
from decimal import Decimal
@ -75,46 +75,72 @@ def __populate_sample_data() -> None:
:return: None.
"""
from accounting.models import Account, JournalEntry, JournalEntryLineItem
file: Path = Path(__file__).parent / "data" / "sample.json"
with open(file) as fp:
json_data = json.load(fp)
data_dir: Path = Path(__file__).parent / "data"
today: date = date.today()
user: User | None = current_user()
assert user is not None
def filter_journal_entry(data: list[t.Any]) -> dict[str, t.Any]:
def filter_journal_entry(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry data from JSON.
:param data: The journal entry data.
:return: The journal entry data from JSON.
"""
return {"id": data[0],
"date": today - timedelta(days=data[1]),
"no": data[2],
"note": data[3],
"created_by_id": user.id,
"updated_by_id": user.id}
data = data.copy()
data["id"] = int(data["id"])
data["date"] = today - timedelta(days=int(data["date"]))
data["no"] = int(data["no"])
if data["note"] == "":
data["note"] = None
data["created_by_id"] = user.id
data["updated_by_id"] = user.id
return data
def filter_line_item(data: list[t.Any]) -> dict[str, t.Any]:
def filter_line_item(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry line item data from JSON.
:param data: The journal entry line item data.
:return: The journal entry line item data from JSON.
"""
return {"id": data[0],
"journal_entry_id": data[1],
"original_line_item_id": data[2],
"is_debit": data[3],
"no": data[4],
"account_id": Account.find_by_code(data[5]).id,
"currency_code": data[6],
"description": data[7],
"amount": Decimal(data[8])}
data = data.copy()
data["id"] = int(data["id"])
data["journal_entry_id"] = int(data["journal_entry_id"])
if data["original_line_item_id"] == "":
data["original_line_item_id"] = None
else:
data["original_line_item_id"] = int(data["original_line_item_id"])
data["is_debit"] = bool(data["is_debit"])
data["no"] = int(data["no"])
data["account_id"] = Account.find_by_code(data["account_id"]).id
if data["description"] == "":
data["description"] = None
data["amount"] = Decimal(data["amount"])
return data
def import_journal_entries(file: Path) -> None:
"""Imports the journal entries.
:param file: The CSV file.
:return: None.
"""
with open(file) as fp:
reader: csv.DictReader = csv.DictReader(fp)
db.session.execute(sa.insert(JournalEntry),
[filter_journal_entry(x) for x in json_data[0]])
[filter_journal_entry(x) for x in reader])
def import_line_items(file: Path) -> None:
"""Imports the journal entry line items.
:param file: The CSV file.
:return: None.
"""
with open(file) as fp:
reader: csv.DictReader = csv.DictReader(fp)
db.session.execute(sa.insert(JournalEntryLineItem),
[filter_line_item(x) for x in json_data[1]])
[filter_line_item(x) for x in reader])
import_journal_entries(data_dir / "sample-journal_entries.csv")
import_line_items(data_dir / "sample-journal_entry_line_items.csv")
db.session.commit()
@ -150,4 +176,3 @@ def init_app(app: Flask) -> None:
:return: None.
"""
app.register_blueprint(bp)

View File

@ -19,17 +19,15 @@
"""
from __future__ import annotations
import json
import re
import typing as t
from abc import ABC, abstractmethod
from datetime import date, timedelta
from decimal import Decimal
from secrets import randbelow
from decimal import Decimal
import sqlalchemy as sa
import httpx
import sqlalchemy as sa
from flask import Flask, render_template_string
from test_site import create_app, db
@ -305,14 +303,14 @@ class BaseTestData(ABC):
:param app: The Flask application.
:param username: The username.
"""
self.__app: Flask = app
with self.__app.app_context():
self._app: Flask = app
with self._app.app_context():
current_user: User | None = User.query\
.filter(User.username == username).first()
assert current_user is not None
self.__current_user_id: int = current_user.id
self.__journal_entries: list[dict[str, t.Any]] = []
self.__line_items: list[dict[str, t.Any]] = []
self._journal_entries: list[dict[str, t.Any]] = []
self._line_items: list[dict[str, t.Any]] = []
self._init_data()
@abstractmethod
@ -328,21 +326,23 @@ class BaseTestData(ABC):
:return: None
"""
from accounting.models import JournalEntry, JournalEntryLineItem
with self.__app.app_context():
db.session.execute(sa.insert(JournalEntry), self.__journal_entries)
with self._app.app_context():
db.session.execute(sa.insert(JournalEntry), self._journal_entries)
db.session.execute(sa.insert(JournalEntryLineItem),
self.__line_items)
self._line_items)
db.session.commit()
def json(self) -> str:
"""Returns the data as JSON.
@property
def csv_data(self) -> tuple[list[dict[str, t.Any]],
list[dict[str, t.Any]]]:
"""Returns the data for CSV.
:return: The JSON string.
:return: The data for CSV.
"""
from accounting.models import Account
today: date = date.today()
def filter_journal_entry(data: dict[str, t.Any]) -> list[t.Any]:
def filter_journal_entry(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry data for JSON encoding.
:param data: The journal entry data.
@ -352,30 +352,24 @@ class BaseTestData(ABC):
data["date"] = (today - data["date"]).days
del data["created_by_id"]
del data["updated_by_id"]
return [data[x] for x in ["id", "date", "no", "note"]]
return data
def filter_line_item(data: dict[str, t.Any]) -> list[t.Any]:
def filter_line_item(data: dict[str, t.Any]) -> dict[str, t.Any]:
"""Filters the journal entry line item data for JSON encoding.
:param data: The journal entry line item data.
:return: The journal entry line item data for JSON encoding.
"""
data = data.copy()
with self.__app.app_context():
with self._app.app_context():
data["account_id"] \
= db.session.get(Account, data["account_id"]).code
data["amount"] = str(data["amount"])
if "original_line_item_id" not in data:
data["original_line_item_id"] = None
return [data[x] for x in ["id", "journal_entry_id",
"original_line_item_id", "is_debit",
"no", "account_id", "currency_code",
"description", "amount"]]
return data
return json.dumps(
[[filter_journal_entry(x) for x in self.__journal_entries],
[filter_line_item(x) for x in self.__line_items]],
ensure_ascii=False, separators=(",", ":"))
return [filter_journal_entry(x) for x in self._journal_entries], \
[filter_line_item(x) for x in self._line_items]
@staticmethod
def _couple(description: str, amount: str, debit: str, credit: str) \
@ -398,11 +392,11 @@ class BaseTestData(ABC):
:return: None.
"""
from accounting.models import Account
existing_j_id: set[int] = {x["id"] for x in self.__journal_entries}
existing_l_id: set[int] = {x["id"] for x in self.__line_items}
existing_j_id: set[int] = {x["id"] for x in self._journal_entries}
existing_l_id: set[int] = {x["id"] for x in self._line_items}
journal_entry_data.id = self.__new_id(existing_j_id)
j_date: date = date.today() - timedelta(days=journal_entry_data.days)
self.__journal_entries.append(
self._journal_entries.append(
{"id": journal_entry_data.id,
"date": j_date,
"no": self.__next_j_no(j_date),
@ -430,7 +424,7 @@ class BaseTestData(ABC):
if line_item.original_line_item is not None:
data["original_line_item_id"] \
= line_item.original_line_item.id
self.__line_items.append(data)
self._line_items.append(data)
for line_item in currency.credit:
account: Account | None \
= Account.find_by_code(line_item.account)
@ -449,7 +443,7 @@ class BaseTestData(ABC):
if line_item.original_line_item is not None:
data["original_line_item_id"] \
= line_item.original_line_item.id
self.__line_items.append(data)
self._line_items.append(data)
@staticmethod
def __new_id(existing_id: set[int]) -> int:
@ -470,7 +464,7 @@ class BaseTestData(ABC):
:param j_date: The journal entry date.
:return: The next journal entry number.
"""
existing: set[int] = {x["no"] for x in self.__journal_entries
existing: set[int] = {x["no"] for x in self._journal_entries
if x["date"] == j_date}
return 1 if len(existing) == 0 else max(existing) + 1