mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 19:49:18 +00:00
Compare commits
599 Commits
ankush-pat
...
update-cod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
320f3c1ac0 | ||
|
|
4d79ffe3c6 | ||
|
|
e8b8c51d82 | ||
|
|
3f44ef8790 | ||
|
|
c793fb0bb4 | ||
|
|
c7a540b7e2 | ||
|
|
6c6195bae6 | ||
|
|
0cd69c8700 | ||
|
|
ffa9c6e4d9 | ||
|
|
d3ff289779 | ||
|
|
ef56060166 | ||
|
|
2e43123048 | ||
|
|
9235918d65 | ||
|
|
d5b7f2e49e | ||
|
|
8e40c04494 | ||
|
|
f7fd30fecf | ||
|
|
e69ea17f59 | ||
|
|
5b6128848f | ||
|
|
662ebc5c1a | ||
|
|
d003370f61 | ||
|
|
b0cfb0b9ef | ||
|
|
a58f2e6c03 | ||
|
|
75d9dbca43 | ||
|
|
447310702e | ||
|
|
960085853a | ||
|
|
5faa62c49a | ||
|
|
3014bac293 | ||
|
|
00a4191966 | ||
|
|
770369e5c1 | ||
|
|
86be259341 | ||
|
|
ce748cec3a | ||
|
|
231fe4156f | ||
|
|
c533213225 | ||
|
|
a67284e96d | ||
|
|
4f2553e7b6 | ||
|
|
192a3395a5 | ||
|
|
e5a2b15fba | ||
|
|
148703bfc2 | ||
|
|
ce3f9622cb | ||
|
|
48bb2c942b | ||
|
|
77f6789706 | ||
|
|
b9a7ff7c3d | ||
|
|
b0e8dfc1d0 | ||
|
|
d76759e066 | ||
|
|
a0eb5e5535 | ||
|
|
e4953df4a3 | ||
|
|
0df28c7174 | ||
|
|
201573ab9a | ||
|
|
0efdc6c13a | ||
|
|
ab7293bcd3 | ||
|
|
6ea0a69d3a | ||
|
|
e478a5d0ce | ||
|
|
47c91324b1 | ||
|
|
185c543b73 | ||
|
|
9d8502f406 | ||
|
|
4686217d3c | ||
|
|
52435a3a7f | ||
|
|
396f455258 | ||
|
|
f8270f093d | ||
|
|
05f4b659a7 | ||
|
|
2fedd595a9 | ||
|
|
0352e1dace | ||
|
|
7d794bc70a | ||
|
|
67b5471d09 | ||
|
|
82490d9f55 | ||
|
|
07a0e2b7a8 | ||
|
|
c8cd351b39 | ||
|
|
4a6a7593c3 | ||
|
|
3380dc5dea | ||
|
|
9d0096ad9e | ||
|
|
bb424965ee | ||
|
|
b961321de5 | ||
|
|
2d54bf7199 | ||
|
|
e5da0d7a63 | ||
|
|
8ea9e4576f | ||
|
|
be1f941996 | ||
|
|
c80aaad437 | ||
|
|
dc0ddf8d7e | ||
|
|
ce8a1086a7 | ||
|
|
56356ffbb9 | ||
|
|
d7a665cb84 | ||
|
|
9ae7578b07 | ||
|
|
6d513e2519 | ||
|
|
2afed7de03 | ||
|
|
ae2de3cf65 | ||
|
|
cb1d33880c | ||
|
|
2884738864 | ||
|
|
fbf2d7e9de | ||
|
|
f8c852c54c | ||
|
|
ffeda0cee9 | ||
|
|
2cc7239dd5 | ||
|
|
940ad6e3f2 | ||
|
|
3518d4be1d | ||
|
|
3c7b460fd8 | ||
|
|
103a91ed40 | ||
|
|
9bb64107c5 | ||
|
|
4ac983cf09 | ||
|
|
7156184933 | ||
|
|
c5834c1db4 | ||
|
|
ddb4396117 | ||
|
|
510b265830 | ||
|
|
6ffdeb1af8 | ||
|
|
22d0e1373b | ||
|
|
423f2b5627 | ||
|
|
6e015fd6be | ||
|
|
57c8871de0 | ||
|
|
0b76a26c8a | ||
|
|
bb7fe795fe | ||
|
|
207eeefc85 | ||
|
|
5138ef0160 | ||
|
|
7b3d496ce0 | ||
|
|
be41052dc8 | ||
|
|
b642718f08 | ||
|
|
b3dc22de29 | ||
|
|
e007776ada | ||
|
|
11d165c274 | ||
|
|
3e5f8323b0 | ||
|
|
5d8a2d3d3b | ||
|
|
f487660a7c | ||
|
|
2bad86d8d8 | ||
|
|
5f38859a04 | ||
|
|
d69c839369 | ||
|
|
1f6ab86a65 | ||
|
|
6b781d78e0 | ||
|
|
a34a1f8fd2 | ||
|
|
faecf3ee40 | ||
|
|
6674edface | ||
|
|
428b099f63 | ||
|
|
8abe0ce0ec | ||
|
|
fee0ca8cd9 | ||
|
|
f270880735 | ||
|
|
1b967f37af | ||
|
|
0d7f98b496 | ||
|
|
9e50aa4833 | ||
|
|
3598bcc9a8 | ||
|
|
9dd6b3c950 | ||
|
|
de10f2dc00 | ||
|
|
7e592fdf91 | ||
|
|
a835c1a418 | ||
|
|
b31b850db8 | ||
|
|
c5ca8d74c4 | ||
|
|
e3d7426b47 | ||
|
|
21f425660d | ||
|
|
33b68552f1 | ||
|
|
da323cbb40 | ||
|
|
41222659a6 | ||
|
|
1f4fa90072 | ||
|
|
58dab9ca8b | ||
|
|
def759d2e8 | ||
|
|
a504b6eac0 | ||
|
|
a067a904a1 | ||
|
|
302f5e27be | ||
|
|
840f9d8987 | ||
|
|
a5478c61af | ||
|
|
d155042edd | ||
|
|
84383087a6 | ||
|
|
4e6066f929 | ||
|
|
7800db7c0d | ||
|
|
7d5df407c4 | ||
|
|
bbde1f611f | ||
|
|
9ae3a54ce9 | ||
|
|
b3a216c8f8 | ||
|
|
62141b0b63 | ||
|
|
a3c89dbc10 | ||
|
|
ad437fd5ba | ||
|
|
7a8e89e2fe | ||
|
|
72be489b1b | ||
|
|
547d37b1db | ||
|
|
2f03dcb5b6 | ||
|
|
57c3216683 | ||
|
|
5b76e8b193 | ||
|
|
58dd40a2d7 | ||
|
|
f6f64083d2 | ||
|
|
29bf787313 | ||
|
|
4cbd63edbf | ||
|
|
49aed7ff69 | ||
|
|
e4bceaaf66 | ||
|
|
b5d2eedfa6 | ||
|
|
11b2994fe8 | ||
|
|
02566a02a8 | ||
|
|
d462d6de06 | ||
|
|
1e607cd4c7 | ||
|
|
597ef0a498 | ||
|
|
327b6fdb32 | ||
|
|
a94aa7a79f | ||
|
|
17045f88a1 | ||
|
|
ef90e24931 | ||
|
|
e8e20da78e | ||
|
|
cceb7922a5 | ||
|
|
333b2ae721 | ||
|
|
ecfebfec57 | ||
|
|
2c83fff1a1 | ||
|
|
cc569c955f | ||
|
|
60ec7b6cde | ||
|
|
f89600aee8 | ||
|
|
e8e21ea4b4 | ||
|
|
1de4742ffb | ||
|
|
eee3bd2554 | ||
|
|
6b31c27ed6 | ||
|
|
c4e1f81ccb | ||
|
|
d7522d40c0 | ||
|
|
c6cfacc108 | ||
|
|
db9beb3cdd | ||
|
|
f19212b5c8 | ||
|
|
d97127bff2 | ||
|
|
eeed3356ac | ||
|
|
e68c4e2aa8 | ||
|
|
dbde3a3421 | ||
|
|
c4d3a8a600 | ||
|
|
64f7f3a12a | ||
|
|
1cadef97bf | ||
|
|
e4cf0dced8 | ||
|
|
fb950417bf | ||
|
|
0639d9e32a | ||
|
|
e19161a8ee | ||
|
|
86cf5c89ab | ||
|
|
cebb5a42f4 | ||
|
|
011a4c3faa | ||
|
|
66ae807a26 | ||
|
|
d6915df81d | ||
|
|
20c8873208 | ||
|
|
a144bb01fe | ||
|
|
070bc8badd | ||
|
|
cf7b43f7f0 | ||
|
|
1bcff80074 | ||
|
|
179a31ed5e | ||
|
|
61cd0f98fd | ||
|
|
352dcddd6d | ||
|
|
1769b45d4b | ||
|
|
0ed6552655 | ||
|
|
adaeba1554 | ||
|
|
312625fdc5 | ||
|
|
9627b46ee7 | ||
|
|
56aa1866da | ||
|
|
dceef0397a | ||
|
|
be382054e5 | ||
|
|
333907b7a5 | ||
|
|
8119442c94 | ||
|
|
9069643504 | ||
|
|
b3759890d7 | ||
|
|
2c50f43cdd | ||
|
|
828eaf0930 | ||
|
|
11cf694d9a | ||
|
|
67cf7e1728 | ||
|
|
906ad10d16 | ||
|
|
bfbc9ea8f7 | ||
|
|
242af681e9 | ||
|
|
f70d757b82 | ||
|
|
736afdf85a | ||
|
|
c2b3843d80 | ||
|
|
e22d56484d | ||
|
|
75e52d7108 | ||
|
|
d63258ee9b | ||
|
|
2ca4d3fb71 | ||
|
|
29088e1777 | ||
|
|
afb33f2049 | ||
|
|
232726288a | ||
|
|
cfb0bb1eaa | ||
|
|
e0db2670f9 | ||
|
|
9ed7594f6e | ||
|
|
b26e96cdf4 | ||
|
|
391f42db04 | ||
|
|
f028bd6e69 | ||
|
|
a0e2a93f3f | ||
|
|
6878f40d1d | ||
|
|
434aa594d5 | ||
|
|
974e12c837 | ||
|
|
467a2b5cb4 | ||
|
|
694fc3e20c | ||
|
|
9ab8aa49d6 | ||
|
|
887ae1c434 | ||
|
|
be05aea101 | ||
|
|
aa1f2a7297 | ||
|
|
e0f5ecdad6 | ||
|
|
0f0bc9a462 | ||
|
|
0ed938a490 | ||
|
|
58ad79d3e8 | ||
|
|
a5cbdea8e4 | ||
|
|
ef2bf3c223 | ||
|
|
8a56df695d | ||
|
|
c51f9e0a97 | ||
|
|
f0c0a64984 | ||
|
|
ddc0127e05 | ||
|
|
b559245f2a | ||
|
|
59628f1934 | ||
|
|
a424acbfcb | ||
|
|
461f8e7724 | ||
|
|
d749c4aac2 | ||
|
|
20fe1875e7 | ||
|
|
4d5067d6d4 | ||
|
|
bbe5e5d9d6 | ||
|
|
dd3b79b511 | ||
|
|
6bc8bb26b6 | ||
|
|
ec171fc7c1 | ||
|
|
b56c1ed050 | ||
|
|
f056e9e7c5 | ||
|
|
57a6c37833 | ||
|
|
917b2190aa | ||
|
|
fa4af2acce | ||
|
|
99f5e869e0 | ||
|
|
05df8579cd | ||
|
|
7ee151880a | ||
|
|
d1d4671320 | ||
|
|
7249657d15 | ||
|
|
a4cb0313dd | ||
|
|
1ad1fc4c7d | ||
|
|
44f32f7521 | ||
|
|
789e448f0e | ||
|
|
e35ac4f8c2 | ||
|
|
c717e87c9e | ||
|
|
525f054c45 | ||
|
|
b0baba84a0 | ||
|
|
51b082b43c | ||
|
|
9fd1c3efb4 | ||
|
|
6b0b49ee3f | ||
|
|
bc1bdd58a7 | ||
|
|
f4a1218467 | ||
|
|
348dc32514 | ||
|
|
f6da6ece0a | ||
|
|
ee94127974 | ||
|
|
3ae47ab32c | ||
|
|
524c0994e0 | ||
|
|
c78399c618 | ||
|
|
1a83a67d41 | ||
|
|
ae039777f9 | ||
|
|
d3b74a868e | ||
|
|
9f59330fa9 | ||
|
|
a3ab8f973a | ||
|
|
751bdc98ed | ||
|
|
9a3d947e89 | ||
|
|
d9c91fa072 | ||
|
|
312e51e8b2 | ||
|
|
adb5249257 | ||
|
|
7b6b5ae581 | ||
|
|
e501c2db51 | ||
|
|
357c17214d | ||
|
|
6a4e25c1f9 | ||
|
|
aba83849a6 | ||
|
|
72c2e77a5d | ||
|
|
7c5168eeac | ||
|
|
914b23038c | ||
|
|
23fbe86d51 | ||
|
|
1b78fae6fc | ||
|
|
a7b011aed4 | ||
|
|
b425c2d7ec | ||
|
|
332f4dc028 | ||
|
|
e18b0ebe92 | ||
|
|
49025db33c | ||
|
|
3c393bfdc5 | ||
|
|
d054f37602 | ||
|
|
010718ffed | ||
|
|
98c39c4f5f | ||
|
|
7126d71627 | ||
|
|
239a5f8bf4 | ||
|
|
8d62cdfd5f | ||
|
|
bb4725e9b5 | ||
|
|
12822f7c36 | ||
|
|
ad53ecf2b4 | ||
|
|
48a9cd5ef3 | ||
|
|
6e1ef4f3d0 | ||
|
|
728dc1acf4 | ||
|
|
d072169340 | ||
|
|
c3911a592a | ||
|
|
d65243eb65 | ||
|
|
c716dcc01e | ||
|
|
c764f14f53 | ||
|
|
35c29e0226 | ||
|
|
f1810803e1 | ||
|
|
e2614b8a21 | ||
|
|
3aaa2f5326 | ||
|
|
617518389a | ||
|
|
123920d0bc | ||
|
|
e3a0ce5d63 | ||
|
|
cabaed9ed2 | ||
|
|
882f92e732 | ||
|
|
6f5824cb21 | ||
|
|
8e271fd719 | ||
|
|
0b75aa5390 | ||
|
|
d2686ce75b | ||
|
|
21a09e7431 | ||
|
|
97f8588202 | ||
|
|
c916fb0513 | ||
|
|
57adcc0b03 | ||
|
|
4ff70db668 | ||
|
|
8263bf9a9a | ||
|
|
482116db9f | ||
|
|
6f4e6fafa9 | ||
|
|
6d791cabd1 | ||
|
|
4e2291f52d | ||
|
|
88edc412e3 | ||
|
|
67a7ccf3ce | ||
|
|
8a79efab4b | ||
|
|
7d9f3f23dd | ||
|
|
9858d9d968 | ||
|
|
32f3b64a89 | ||
|
|
7e1b6b3c2a | ||
|
|
03662be150 | ||
|
|
a31e9d3afe | ||
|
|
a0484793c3 | ||
|
|
89229d9b58 | ||
|
|
bfa511cb65 | ||
|
|
40769998c6 | ||
|
|
a05c47e499 | ||
|
|
b17ef34042 | ||
|
|
3e91a56c19 | ||
|
|
8f5d8e0474 | ||
|
|
13c4420f42 | ||
|
|
a26698b88e | ||
|
|
5918bb03f7 | ||
|
|
e684eb32d0 | ||
|
|
81e5f71172 | ||
|
|
6b5276398e | ||
|
|
645869e6ff | ||
|
|
76be35aaea | ||
|
|
ade83cbab3 | ||
|
|
1da14b7ec3 | ||
|
|
925387550e | ||
|
|
9dc1509cf5 | ||
|
|
31c95deb88 | ||
|
|
ff48634cbb | ||
|
|
e25b98b620 | ||
|
|
068df9f815 | ||
|
|
d0dbfec052 | ||
|
|
1ed2230e4c | ||
|
|
eaa04abe29 | ||
|
|
f31612376a | ||
|
|
b1721b79ce | ||
|
|
7851adb49a | ||
|
|
88ce11f03d | ||
|
|
2b4eae5f84 | ||
|
|
65db9cea25 | ||
|
|
2ed86760d7 | ||
|
|
b09eade3e4 | ||
|
|
4ecce242a8 | ||
|
|
67c5cec505 | ||
|
|
6238fd9d9e | ||
|
|
05b6fce03d | ||
|
|
2a4eec245a | ||
|
|
3b66920342 | ||
|
|
0e86cde64b | ||
|
|
9989ccbb02 | ||
|
|
4802d719ed | ||
|
|
6bb22c703a | ||
|
|
50421b3d7d | ||
|
|
b76129c1dd | ||
|
|
5c50a46822 | ||
|
|
5d0b5c8d2a | ||
|
|
1a40c04b72 | ||
|
|
408c89df03 | ||
|
|
da1d8da355 | ||
|
|
56f3ac15d8 | ||
|
|
4bfe2ea572 | ||
|
|
5cbbb5d59e | ||
|
|
ae31ff1c48 | ||
|
|
ac51c27500 | ||
|
|
9a00b3bdbd | ||
|
|
25f0b26a17 | ||
|
|
ae8dd2b2bc | ||
|
|
0f28074e5a | ||
|
|
d126c8030f | ||
|
|
246d3b4075 | ||
|
|
a358f77774 | ||
|
|
a998a8a2da | ||
|
|
dc178984ae | ||
|
|
7f5e761c04 | ||
|
|
3a8a467edb | ||
|
|
076527bb88 | ||
|
|
f73976946e | ||
|
|
b7e9942681 | ||
|
|
9bf2682218 | ||
|
|
26277cfcf3 | ||
|
|
973ef33eb5 | ||
|
|
8717148d9b | ||
|
|
ce9626fead | ||
|
|
d404a03947 | ||
|
|
8eb93004f7 | ||
|
|
21c86bd649 | ||
|
|
6d9d730759 | ||
|
|
410a58b3de | ||
|
|
c99cd74a15 | ||
|
|
41fc3be339 | ||
|
|
36997d9788 | ||
|
|
8534390627 | ||
|
|
22ef342ac7 | ||
|
|
df134c7c5b | ||
|
|
5ea6080a6e | ||
|
|
c5d21b2461 | ||
|
|
3db446e35a | ||
|
|
15e3b7f218 | ||
|
|
f9be137cf5 | ||
|
|
723c64ba73 | ||
|
|
aa787e4030 | ||
|
|
2175784142 | ||
|
|
f20370c5ef | ||
|
|
cb49055aac | ||
|
|
e057e1dfe7 | ||
|
|
78b438f6cf | ||
|
|
7b3316dc31 | ||
|
|
5c0f8ee44f | ||
|
|
7d64bf78cf | ||
|
|
28d4942d6c | ||
|
|
1ea2ba0dea | ||
|
|
b997d1eb87 | ||
|
|
f8cd424559 | ||
|
|
ec6505d747 | ||
|
|
915e0347b0 | ||
|
|
593626f502 | ||
|
|
d512919f5c | ||
|
|
71aa8c5e1c | ||
|
|
d193a14b8f | ||
|
|
90e1b9cb3d | ||
|
|
97ddfcfc7c | ||
|
|
16365bfca3 | ||
|
|
2010b1b6e8 | ||
|
|
77dc8e7966 | ||
|
|
187e1a324a | ||
|
|
1fd73af744 | ||
|
|
7d41f63c5d | ||
|
|
6db52930d8 | ||
|
|
6192af5cf0 | ||
|
|
8e7c8a6482 | ||
|
|
b179514273 | ||
|
|
b6bd408f19 | ||
|
|
0b86b1baca | ||
|
|
447272aa4d | ||
|
|
07c815f35f | ||
|
|
81397ba3ee | ||
|
|
f0487451f7 | ||
|
|
e5a1189bec | ||
|
|
1d37c0143f | ||
|
|
e451639ff6 | ||
|
|
f598da7c81 | ||
|
|
5e0f4eb580 | ||
|
|
632c08f7e0 | ||
|
|
cf1e3dc8ea | ||
|
|
922375c3ba | ||
|
|
a6fe79f29d | ||
|
|
18fc2b5695 | ||
|
|
2cd42dbb10 | ||
|
|
e7d404a30a | ||
|
|
8365d6bdb7 | ||
|
|
7cbb6c4de9 | ||
|
|
b602a0dcb0 | ||
|
|
26adbc6282 | ||
|
|
861aa9e08a | ||
|
|
c1a82dc9e5 | ||
|
|
b1242bc56c | ||
|
|
af1f98e188 | ||
|
|
e5566b31d5 | ||
|
|
a6794c3606 | ||
|
|
19db7e2989 | ||
|
|
d23b5d8f2f | ||
|
|
01b84a9751 | ||
|
|
3aa6f97420 | ||
|
|
63393fa503 | ||
|
|
921f8edde8 | ||
|
|
5853b80d25 | ||
|
|
8301d3b13f | ||
|
|
a26a29f33b | ||
|
|
a074ffa880 | ||
|
|
e526a0e282 | ||
|
|
a2abc879c9 | ||
|
|
748c74ba52 | ||
|
|
d0478ec3b8 | ||
|
|
713330cbf6 | ||
|
|
0581000990 | ||
|
|
7bd0e977bf | ||
|
|
3814db02eb | ||
|
|
55c0770280 | ||
|
|
5f821b93a5 | ||
|
|
ef9d126254 | ||
|
|
83ed93fbb6 | ||
|
|
31db0e7c79 | ||
|
|
2c4eb371a6 | ||
|
|
ca8c827492 | ||
|
|
eb66b749b2 | ||
|
|
083a954b5d | ||
|
|
b741ae143c | ||
|
|
f54838ab56 | ||
|
|
03f7bfbbde | ||
|
|
826f45ad60 | ||
|
|
f20238fa3e | ||
|
|
9b8d6fe411 | ||
|
|
96ede2fcf9 | ||
|
|
06e094b5fc | ||
|
|
7d09440579 | ||
|
|
4e63ba3ac6 | ||
|
|
de17367a36 | ||
|
|
f35b19eac3 | ||
|
|
7db66b0916 | ||
|
|
76f28de7eb | ||
|
|
a66d9f8e8e | ||
|
|
417180e6ba | ||
|
|
ffd41703de | ||
|
|
ca3581d055 | ||
|
|
ed495dc846 | ||
|
|
97ab7bd36b | ||
|
|
710d2452b7 | ||
|
|
5a274176d3 |
3
.github/helper/.flake8_strict
vendored
3
.github/helper/.flake8_strict
vendored
@@ -66,7 +66,8 @@ ignore =
|
||||
F841,
|
||||
E713,
|
||||
E712,
|
||||
B023
|
||||
B023,
|
||||
B028
|
||||
|
||||
|
||||
max-line-length = 200
|
||||
|
||||
99
.github/helper/documentation.py
vendored
99
.github/helper/documentation.py
vendored
@@ -3,52 +3,71 @@ import requests
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
docs_repos = [
|
||||
"frappe_docs",
|
||||
"erpnext_documentation",
|
||||
WEBSITE_REPOS = [
|
||||
"erpnext_com",
|
||||
"frappe_io",
|
||||
]
|
||||
|
||||
DOCUMENTATION_DOMAINS = [
|
||||
"docs.erpnext.com",
|
||||
"frappeframework.com",
|
||||
]
|
||||
|
||||
def uri_validator(x):
|
||||
result = urlparse(x)
|
||||
return all([result.scheme, result.netloc, result.path])
|
||||
|
||||
def docs_link_exists(body):
|
||||
for line in body.splitlines():
|
||||
for word in line.split():
|
||||
if word.startswith('http') and uri_validator(word):
|
||||
parsed_url = urlparse(word)
|
||||
if parsed_url.netloc == "github.com":
|
||||
parts = parsed_url.path.split('/')
|
||||
if len(parts) == 5 and parts[1] == "frappe" and parts[2] in docs_repos:
|
||||
return True
|
||||
elif parsed_url.netloc == "docs.erpnext.com":
|
||||
return True
|
||||
def is_valid_url(url: str) -> bool:
|
||||
parts = urlparse(url)
|
||||
return all((parts.scheme, parts.netloc, parts.path))
|
||||
|
||||
|
||||
def is_documentation_link(word: str) -> bool:
|
||||
if not word.startswith("http") or not is_valid_url(word):
|
||||
return False
|
||||
|
||||
parsed_url = urlparse(word)
|
||||
if parsed_url.netloc in DOCUMENTATION_DOMAINS:
|
||||
return True
|
||||
|
||||
if parsed_url.netloc == "github.com":
|
||||
parts = parsed_url.path.split("/")
|
||||
if len(parts) == 5 and parts[1] == "frappe" and parts[2] in WEBSITE_REPOS:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def contains_documentation_link(body: str) -> bool:
|
||||
return any(
|
||||
is_documentation_link(word)
|
||||
for line in body.splitlines()
|
||||
for word in line.split()
|
||||
)
|
||||
|
||||
|
||||
def check_pull_request(number: str) -> "tuple[int, str]":
|
||||
response = requests.get(f"https://api.github.com/repos/frappe/erpnext/pulls/{number}")
|
||||
if not response.ok:
|
||||
return 1, "Pull Request Not Found! ⚠️"
|
||||
|
||||
payload = response.json()
|
||||
title = (payload.get("title") or "").lower().strip()
|
||||
head_sha = (payload.get("head") or {}).get("sha")
|
||||
body = (payload.get("body") or "").lower()
|
||||
|
||||
if (
|
||||
not title.startswith("feat")
|
||||
or not head_sha
|
||||
or "no-docs" in body
|
||||
or "backport" in body
|
||||
):
|
||||
return 0, "Skipping documentation checks... 🏃"
|
||||
|
||||
if contains_documentation_link(body):
|
||||
return 0, "Documentation Link Found. You're Awesome! 🎉"
|
||||
|
||||
return 1, "Documentation Link Not Found! ⚠️"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pr = sys.argv[1]
|
||||
response = requests.get("https://api.github.com/repos/frappe/erpnext/pulls/{}".format(pr))
|
||||
|
||||
if response.ok:
|
||||
payload = response.json()
|
||||
title = (payload.get("title") or "").lower().strip()
|
||||
head_sha = (payload.get("head") or {}).get("sha")
|
||||
body = (payload.get("body") or "").lower()
|
||||
|
||||
if (title.startswith("feat")
|
||||
and head_sha
|
||||
and "no-docs" not in body
|
||||
and "backport" not in body
|
||||
):
|
||||
if docs_link_exists(body):
|
||||
print("Documentation Link Found. You're Awesome! 🎉")
|
||||
|
||||
else:
|
||||
print("Documentation Link Not Found! ⚠️")
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
print("Skipping documentation checks... 🏃")
|
||||
exit_code, message = check_pull_request(sys.argv[1])
|
||||
print(message)
|
||||
sys.exit(exit_code)
|
||||
|
||||
28
.github/helper/install.sh
vendored
28
.github/helper/install.sh
vendored
@@ -24,15 +24,14 @@ fi
|
||||
|
||||
|
||||
if [ "$DB" == "mariadb" ];then
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"
|
||||
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_frappe"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
|
||||
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -e "FLUSH PRIVILEGES"
|
||||
mysql --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES"
|
||||
fi
|
||||
|
||||
if [ "$DB" == "postgres" ];then
|
||||
@@ -42,12 +41,17 @@ fi
|
||||
|
||||
|
||||
install_whktml() {
|
||||
wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
|
||||
tar -xf /tmp/wkhtmltox.tar.xz -C /tmp
|
||||
sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
|
||||
sudo chmod o+x /usr/local/bin/wkhtmltopdf
|
||||
if [ "$(lsb_release -rs)" = "22.04" ]; then
|
||||
wget -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
|
||||
sudo apt install /tmp/wkhtmltox.deb
|
||||
else
|
||||
echo "Please update this script to support wkhtmltopdf for $(lsb_release -ds)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
install_whktml &
|
||||
wkpid=$!
|
||||
|
||||
|
||||
cd ~/frappe-bench || exit
|
||||
|
||||
@@ -61,6 +65,8 @@ bench get-app erpnext "${GITHUB_WORKSPACE}"
|
||||
|
||||
if [ "$TYPE" == "server" ]; then bench setup requirements --dev; fi
|
||||
|
||||
wait $wkpid
|
||||
|
||||
bench start &> bench_run_logs.txt &
|
||||
CI=Yes bench build --app frappe &
|
||||
bench --site test_site reinstall --yes
|
||||
|
||||
4
.github/helper/site_config_mariadb.json
vendored
4
.github/helper/site_config_mariadb.json
vendored
@@ -9,8 +9,8 @@
|
||||
"mail_password": "test",
|
||||
"admin_password": "admin",
|
||||
"root_login": "root",
|
||||
"root_password": "travis",
|
||||
"root_password": "root",
|
||||
"host_name": "http://test_site:8000",
|
||||
"install_apps": ["erpnext"],
|
||||
"install_apps": ["payments", "erpnext"],
|
||||
"throttle_user_limit": 100
|
||||
}
|
||||
|
||||
2
.github/workflows/patch.yml
vendored
2
.github/workflows/patch.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
mysql:
|
||||
image: mariadb:10.3
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: YES
|
||||
MARIADB_ROOT_PASSWORD: 'root'
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
||||
|
||||
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@@ -13,10 +13,10 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
- name: Setup Node.js v14
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 14
|
||||
node-version: 18
|
||||
- name: Setup dependencies
|
||||
run: |
|
||||
npm install @semantic-release/git @semantic-release/exec --no-save
|
||||
@@ -28,4 +28,4 @@ jobs:
|
||||
GIT_AUTHOR_EMAIL: "developers@frappe.io"
|
||||
GIT_COMMITTER_NAME: "Frappe PR Bot"
|
||||
GIT_COMMITTER_EMAIL: "developers@frappe.io"
|
||||
run: npx semantic-release
|
||||
run: npx semantic-release
|
||||
|
||||
8
.github/workflows/server-tests-mariadb.yml
vendored
8
.github/workflows/server-tests-mariadb.yml
vendored
@@ -16,12 +16,12 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
user:
|
||||
description: 'user'
|
||||
description: 'Frappe Framework repository user (add your username for forks)'
|
||||
required: true
|
||||
default: 'frappe'
|
||||
type: string
|
||||
branch:
|
||||
description: 'Branch name'
|
||||
description: 'Frappe Framework branch'
|
||||
default: 'develop'
|
||||
required: false
|
||||
type: string
|
||||
@@ -45,9 +45,9 @@ jobs:
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mariadb:10.3
|
||||
image: mariadb:10.6
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: YES
|
||||
MARIADB_ROOT_PASSWORD: 'root'
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
||||
|
||||
@@ -32,8 +32,8 @@ repos:
|
||||
- id: black
|
||||
additional_dependencies: ['click==8.0.4']
|
||||
|
||||
- repo: https://github.com/timothycrosley/isort
|
||||
rev: 5.9.1
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
exclude: ".*setup.py$"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# the repo. Unless a later match takes precedence,
|
||||
|
||||
erpnext/accounts/ @nextchamp-saqib @deepeshgarg007 @ruthra-kumar
|
||||
erpnext/assets/ @nextchamp-saqib @deepeshgarg007 @ruthra-kumar
|
||||
erpnext/assets/ @anandbaburajan @deepeshgarg007
|
||||
erpnext/loan_management/ @nextchamp-saqib @deepeshgarg007
|
||||
erpnext/regional @nextchamp-saqib @deepeshgarg007 @ruthra-kumar
|
||||
erpnext/selling @nextchamp-saqib @deepeshgarg007 @ruthra-kumar
|
||||
@@ -16,6 +16,7 @@ erpnext/maintenance/ @rohitwaghchaure @s-aga-r
|
||||
erpnext/manufacturing/ @rohitwaghchaure @s-aga-r
|
||||
erpnext/quality_management/ @rohitwaghchaure @s-aga-r
|
||||
erpnext/stock/ @rohitwaghchaure @s-aga-r
|
||||
erpnext/subcontracting @rohitwaghchaure @s-aga-r
|
||||
|
||||
erpnext/crm/ @NagariaHussain
|
||||
erpnext/education/ @rutwikhdev
|
||||
|
||||
@@ -378,7 +378,7 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None):
|
||||
return
|
||||
|
||||
# check if books nor frozen till endate:
|
||||
if accounts_frozen_upto and (end_date) <= getdate(accounts_frozen_upto):
|
||||
if accounts_frozen_upto and getdate(end_date) <= getdate(accounts_frozen_upto):
|
||||
end_date = get_last_day(add_days(accounts_frozen_upto, 1))
|
||||
|
||||
if via_journal_entry:
|
||||
|
||||
@@ -56,36 +56,41 @@ frappe.treeview_settings["Account"] = {
|
||||
accounts = nodes;
|
||||
}
|
||||
|
||||
const get_balances = frappe.call({
|
||||
method: 'erpnext.accounts.utils.get_account_balances',
|
||||
args: {
|
||||
accounts: accounts,
|
||||
company: cur_tree.args.company
|
||||
},
|
||||
});
|
||||
frappe.db.get_single_value("Accounts Settings", "show_balance_in_coa").then((value) => {
|
||||
if(value) {
|
||||
|
||||
get_balances.then(r => {
|
||||
if (!r.message || r.message.length == 0) return;
|
||||
const get_balances = frappe.call({
|
||||
method: 'erpnext.accounts.utils.get_account_balances',
|
||||
args: {
|
||||
accounts: accounts,
|
||||
company: cur_tree.args.company
|
||||
},
|
||||
});
|
||||
|
||||
for (let account of r.message) {
|
||||
get_balances.then(r => {
|
||||
if (!r.message || r.message.length == 0) return;
|
||||
|
||||
const node = cur_tree.nodes && cur_tree.nodes[account.value];
|
||||
if (!node || node.is_root) continue;
|
||||
for (let account of r.message) {
|
||||
|
||||
// show Dr if positive since balance is calculated as debit - credit else show Cr
|
||||
const balance = account.balance_in_account_currency || account.balance;
|
||||
const dr_or_cr = balance > 0 ? "Dr": "Cr";
|
||||
const format = (value, currency) => format_currency(Math.abs(value), currency);
|
||||
const node = cur_tree.nodes && cur_tree.nodes[account.value];
|
||||
if (!node || node.is_root) continue;
|
||||
|
||||
if (account.balance!==undefined) {
|
||||
node.parent && node.parent.find('.balance-area').remove();
|
||||
$('<span class="balance-area pull-right">'
|
||||
+ (account.balance_in_account_currency ?
|
||||
(format(account.balance_in_account_currency, account.account_currency) + " / ") : "")
|
||||
+ format(account.balance, account.company_currency)
|
||||
+ " " + dr_or_cr
|
||||
+ '</span>').insertBefore(node.$ul);
|
||||
}
|
||||
// show Dr if positive since balance is calculated as debit - credit else show Cr
|
||||
const balance = account.balance_in_account_currency || account.balance;
|
||||
const dr_or_cr = balance > 0 ? "Dr": "Cr";
|
||||
const format = (value, currency) => format_currency(Math.abs(value), currency);
|
||||
|
||||
if (account.balance!==undefined) {
|
||||
node.parent && node.parent.find('.balance-area').remove();
|
||||
$('<span class="balance-area pull-right">'
|
||||
+ (account.balance_in_account_currency ?
|
||||
(format(account.balance_in_account_currency, account.account_currency) + " / ") : "")
|
||||
+ format(account.balance, account.company_currency)
|
||||
+ " " + dr_or_cr
|
||||
+ '</span>').insertBefore(node.$ul);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
{
|
||||
"country_code": "de",
|
||||
"name": "SKR03 mit Kontonummern",
|
||||
"tree": {
|
||||
"Aktiva": {
|
||||
"is_group": 1,
|
||||
"country_code": "de",
|
||||
"name": "SKR03 mit Kontonummern",
|
||||
"tree": {
|
||||
"Aktiva": {
|
||||
"is_group": 1,
|
||||
"root_type": "Asset",
|
||||
"A - Anlagevermögen": {
|
||||
"is_group": 1,
|
||||
"EDV-Software": {
|
||||
"account_number": "0027",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Gesch\u00e4ftsausstattung": {
|
||||
"account_number": "0410",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"B\u00fcroeinrichtung": {
|
||||
"account_number": "0420",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Darlehen": {
|
||||
"account_number": "0565"
|
||||
},
|
||||
"Maschinen": {
|
||||
"account_number": "0210",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Betriebsausstattung": {
|
||||
"account_number": "0400",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Ladeneinrichtung": {
|
||||
"account_number": "0430",
|
||||
"account_type": "Fixed Asset"
|
||||
"A - Anlagevermögen": {
|
||||
"is_group": 1,
|
||||
"EDV-Software": {
|
||||
"account_number": "0027",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Geschäftsausstattung": {
|
||||
"account_number": "0410",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Büroeinrichtung": {
|
||||
"account_number": "0420",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Darlehen": {
|
||||
"account_number": "0565"
|
||||
},
|
||||
"Maschinen": {
|
||||
"account_number": "0210",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Betriebsausstattung": {
|
||||
"account_number": "0400",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Ladeneinrichtung": {
|
||||
"account_number": "0430",
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Accumulated Depreciation": {
|
||||
"account_type": "Accumulated Depreciation"
|
||||
@@ -60,36 +60,46 @@
|
||||
"Durchlaufende Posten": {
|
||||
"account_number": "1590"
|
||||
},
|
||||
"Gewinnermittlung \u00a74/3 nicht Ergebniswirksam": {
|
||||
"Verrechnungskonto Gewinnermittlung § 4 Abs. 3 EStG, nicht ergebniswirksam": {
|
||||
"account_number": "1371"
|
||||
},
|
||||
"Abziehbare Vorsteuer": {
|
||||
"account_type": "Tax",
|
||||
"is_group": 1,
|
||||
"Abziehbare Vorsteuer 7%": {
|
||||
"account_number": "1571"
|
||||
"Abziehbare Vorsteuer 7 %": {
|
||||
"account_number": "1571",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 7.0
|
||||
},
|
||||
"Abziehbare Vorsteuer 19%": {
|
||||
"account_number": "1576"
|
||||
"Abziehbare Vorsteuer 19 %": {
|
||||
"account_number": "1576",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 19.0
|
||||
},
|
||||
"Abziehbare Vorsteuer nach \u00a713b UStG 19%": {
|
||||
"account_number": "1577"
|
||||
},
|
||||
"Leistungen \u00a713b UStG 19% Vorsteuer, 19% Umsatzsteuer": {
|
||||
"account_number": "3120"
|
||||
"Abziehbare Vorsteuer nach § 13b UStG 19 %": {
|
||||
"account_number": "1577",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 19.0
|
||||
}
|
||||
}
|
||||
},
|
||||
"III. Wertpapiere": {
|
||||
"is_group": 1
|
||||
"is_group": 1,
|
||||
"Anteile an verbundenen Unternehmen (Umlaufvermögen)": {
|
||||
"account_number": "1340"
|
||||
},
|
||||
"Anteile an herrschender oder mit Mehrheit beteiligter Gesellschaft": {
|
||||
"account_number": "1344"
|
||||
},
|
||||
"Sonstige Wertpapiere": {
|
||||
"account_number": "1348"
|
||||
}
|
||||
},
|
||||
"IV. Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks.": {
|
||||
"is_group": 1,
|
||||
"Kasse": {
|
||||
"account_type": "Cash",
|
||||
"is_group": 1,
|
||||
"account_type": "Cash",
|
||||
"Kasse": {
|
||||
"is_group": 1,
|
||||
"account_number": "1000",
|
||||
"account_type": "Cash"
|
||||
}
|
||||
@@ -111,21 +121,21 @@
|
||||
"C - Rechnungsabgrenzungsposten": {
|
||||
"is_group": 1,
|
||||
"Aktive Rechnungsabgrenzung": {
|
||||
"account_number": "0980"
|
||||
"account_number": "0980"
|
||||
}
|
||||
},
|
||||
"D - Aktive latente Steuern": {
|
||||
"is_group": 1,
|
||||
"Aktive latente Steuern": {
|
||||
"account_number": "0983"
|
||||
"account_number": "0983"
|
||||
}
|
||||
},
|
||||
"E - Aktiver Unterschiedsbetrag aus der Vermögensverrechnung": {
|
||||
"is_group": 1
|
||||
}
|
||||
},
|
||||
"Passiva": {
|
||||
"is_group": 1,
|
||||
},
|
||||
"Passiva": {
|
||||
"is_group": 1,
|
||||
"root_type": "Liability",
|
||||
"A. Eigenkapital": {
|
||||
"is_group": 1,
|
||||
@@ -200,26 +210,32 @@
|
||||
},
|
||||
"Umsatzsteuer": {
|
||||
"is_group": 1,
|
||||
"account_type": "Tax",
|
||||
"Umsatzsteuer 7%": {
|
||||
"account_number": "1771"
|
||||
"Umsatzsteuer 7 %": {
|
||||
"account_number": "1771",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 7.0
|
||||
},
|
||||
"Umsatzsteuer 19%": {
|
||||
"account_number": "1776"
|
||||
"Umsatzsteuer 19 %": {
|
||||
"account_number": "1776",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 19.0
|
||||
},
|
||||
"Umsatzsteuer-Vorauszahlung": {
|
||||
"account_number": "1780"
|
||||
"account_number": "1780",
|
||||
"account_type": "Tax"
|
||||
},
|
||||
"Umsatzsteuer-Vorauszahlung 1/11": {
|
||||
"account_number": "1781"
|
||||
},
|
||||
"Umsatzsteuer \u00a7 13b UStG 19%": {
|
||||
"account_number": "1787"
|
||||
"Umsatzsteuer nach § 13b UStG 19 %": {
|
||||
"account_number": "1787",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": 19.0
|
||||
},
|
||||
"Umsatzsteuer Vorjahr": {
|
||||
"account_number": "1790"
|
||||
},
|
||||
"Umsatzsteuer fr\u00fchere Jahre": {
|
||||
"Umsatzsteuer frühere Jahre": {
|
||||
"account_number": "1791"
|
||||
}
|
||||
}
|
||||
@@ -234,44 +250,56 @@
|
||||
"E. Passive latente Steuern": {
|
||||
"is_group": 1
|
||||
}
|
||||
},
|
||||
"Erl\u00f6se u. Ertr\u00e4ge 2/8": {
|
||||
"is_group": 1,
|
||||
"root_type": "Income",
|
||||
"Erl\u00f6skonten 8": {
|
||||
},
|
||||
"Erlöse u. Erträge 2/8": {
|
||||
"is_group": 1,
|
||||
"root_type": "Income",
|
||||
"Erlöskonten 8": {
|
||||
"is_group": 1,
|
||||
"Erl\u00f6se": {
|
||||
"account_number": "8200",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Erl\u00f6se USt. 19%": {
|
||||
"account_number": "8400",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Erl\u00f6se USt. 7%": {
|
||||
"account_number": "8300",
|
||||
"account_type": "Income Account"
|
||||
}
|
||||
},
|
||||
"Ertragskonten 2": {
|
||||
"is_group": 1,
|
||||
"sonstige Zinsen und \u00e4hnliche Ertr\u00e4ge": {
|
||||
"account_number": "2650",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Au\u00dferordentliche Ertr\u00e4ge": {
|
||||
"account_number": "2500",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Sonstige Ertr\u00e4ge": {
|
||||
"account_number": "2700",
|
||||
"account_type": "Income Account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Aufwendungen 2/4": {
|
||||
"is_group": 1,
|
||||
"Erlöse": {
|
||||
"account_number": "8200",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Erlöse USt. 19 %": {
|
||||
"account_number": "8400",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Erlöse USt. 7 %": {
|
||||
"account_number": "8300",
|
||||
"account_type": "Income Account"
|
||||
}
|
||||
},
|
||||
"Ertragskonten 2": {
|
||||
"is_group": 1,
|
||||
"sonstige Zinsen und ähnliche Erträge": {
|
||||
"account_number": "2650",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Außerordentliche Erträge": {
|
||||
"account_number": "2500",
|
||||
"account_type": "Income Account"
|
||||
},
|
||||
"Sonstige Erträge": {
|
||||
"account_number": "2700",
|
||||
"account_type": "Income Account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Aufwendungen 2/4": {
|
||||
"is_group": 1,
|
||||
"root_type": "Expense",
|
||||
"Fremdleistungen": {
|
||||
"account_number": "3100",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Fremdleistungen ohne Vorsteuer": {
|
||||
"account_number": "3109",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Bauleistungen eines im Inland ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer": {
|
||||
"account_number": "3120",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Wareneingang": {
|
||||
"account_number": "3200"
|
||||
},
|
||||
@@ -298,234 +326,234 @@
|
||||
"Gegenkonto 4996-4998": {
|
||||
"account_number": "4999"
|
||||
},
|
||||
"Abschreibungen": {
|
||||
"is_group": 1,
|
||||
"Abschreibungen": {
|
||||
"is_group": 1,
|
||||
"Abschreibungen auf Sachanlagen (ohne AfA auf Kfz und Gebäude)": {
|
||||
"account_number": "4830",
|
||||
"account_type": "Accumulated Depreciation"
|
||||
"account_number": "4830",
|
||||
"account_type": "Accumulated Depreciation"
|
||||
},
|
||||
"Abschreibungen auf Gebäude": {
|
||||
"account_number": "4831",
|
||||
"account_type": "Depreciation"
|
||||
"account_number": "4831",
|
||||
"account_type": "Depreciation"
|
||||
},
|
||||
"Abschreibungen auf Kfz": {
|
||||
"account_number": "4832",
|
||||
"account_type": "Depreciation"
|
||||
"account_number": "4832",
|
||||
"account_type": "Depreciation"
|
||||
},
|
||||
"Sofortabschreibung GWG": {
|
||||
"account_number": "4855",
|
||||
"account_type": "Expense Account"
|
||||
"account_number": "4855",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Kfz-Kosten": {
|
||||
"is_group": 1,
|
||||
"Kfz-Steuer": {
|
||||
"account_number": "4510",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Kfz-Versicherungen": {
|
||||
"account_number": "4520",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"laufende Kfz-Betriebskosten": {
|
||||
"account_number": "4530",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Kfz-Reparaturen": {
|
||||
"account_number": "4540",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Fremdfahrzeuge": {
|
||||
"account_number": "4570",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"sonstige Kfz-Kosten": {
|
||||
"account_number": "4580",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Personalkosten": {
|
||||
"is_group": 1,
|
||||
"Geh\u00e4lter": {
|
||||
"account_number": "4120",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"gesetzliche soziale Aufwendungen": {
|
||||
"account_number": "4130",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aufwendungen f\u00fcr Altersvorsorge": {
|
||||
"account_number": "4165",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Verm\u00f6genswirksame Leistungen": {
|
||||
"account_number": "4170",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aushilfsl\u00f6hne": {
|
||||
"account_number": "4190",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Raumkosten": {
|
||||
"is_group": 1,
|
||||
"Miete und Nebenkosten": {
|
||||
"account_number": "4210",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Gas, Wasser, Strom (Verwaltung, Vertrieb)": {
|
||||
"account_number": "4240",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Reinigung": {
|
||||
"account_number": "4250",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Reparatur/Instandhaltung": {
|
||||
"is_group": 1,
|
||||
"Reparatur u. Instandh. von Anlagen/Maschinen u. Betriebs- u. Gesch\u00e4ftsausst.": {
|
||||
"account_number": "4805",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Versicherungsbeitr\u00e4ge": {
|
||||
"is_group": 1,
|
||||
"Versicherungen": {
|
||||
"account_number": "4360",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Beitr\u00e4ge": {
|
||||
"account_number": "4380",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"sonstige Ausgaben": {
|
||||
"account_number": "4390",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"steuerlich abzugsf\u00e4hige Versp\u00e4tungszuschl\u00e4ge und Zwangsgelder": {
|
||||
"account_number": "4396",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Werbe-/Reisekosten": {
|
||||
"is_group": 1,
|
||||
"Werbekosten": {
|
||||
"account_number": "4610",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aufmerksamkeiten": {
|
||||
"account_number": "4653",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"nicht abzugsf\u00e4hige Betriebsausg. aus Werbe-, Repr\u00e4s.- u. Reisekosten": {
|
||||
"account_number": "4665",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Reisekosten Unternehmer": {
|
||||
"account_number": "4670",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"verschiedene Kosten": {
|
||||
"is_group": 1,
|
||||
"Porto": {
|
||||
"account_number": "4910",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Telekom": {
|
||||
"account_number": "4920",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Mobilfunk D2": {
|
||||
"account_number": "4921",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Internet": {
|
||||
"account_number": "4922",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"B\u00fcrobedarf": {
|
||||
"account_number": "4930",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Zeitschriften, B\u00fccher": {
|
||||
"account_number": "4940",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Fortbildungskosten": {
|
||||
"account_number": "4945",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Buchf\u00fchrungskosten": {
|
||||
"account_number": "4955",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Abschlu\u00df- u. Pr\u00fcfungskosten": {
|
||||
"account_number": "4957",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Nebenkosten des Geldverkehrs": {
|
||||
"account_number": "4970",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Werkzeuge und Kleinger\u00e4te": {
|
||||
"account_number": "4985",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Zinsaufwendungen": {
|
||||
"is_group": 1,
|
||||
"Zinsaufwendungen f\u00fcr kurzfristige Verbindlichkeiten": {
|
||||
"account_number": "2110",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Zinsaufwendungen f\u00fcr KFZ Finanzierung": {
|
||||
"account_number": "2121",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Anfangsbestand 9": {
|
||||
"is_group": 1,
|
||||
"root_type": "Equity",
|
||||
"Saldenvortragskonten": {
|
||||
"is_group": 1,
|
||||
"Saldenvortrag Sachkonten": {
|
||||
"account_number": "9000"
|
||||
},
|
||||
"Saldenvortr\u00e4ge Debitoren": {
|
||||
"account_number": "9008"
|
||||
},
|
||||
"Saldenvortr\u00e4ge Kreditoren": {
|
||||
"account_number": "9009"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Privatkonten 1": {
|
||||
"is_group": 1,
|
||||
"root_type": "Equity",
|
||||
"Privatentnahmen/-einlagen": {
|
||||
"is_group": 1,
|
||||
"Privatentnahme allgemein": {
|
||||
"account_number": "1800"
|
||||
},
|
||||
"Privatsteuern": {
|
||||
"account_number": "1810"
|
||||
},
|
||||
"Sonderausgaben beschr\u00e4nkt abzugsf\u00e4hig": {
|
||||
"account_number": "1820"
|
||||
},
|
||||
"Sonderausgaben unbeschr\u00e4nkt abzugsf\u00e4hig": {
|
||||
"account_number": "1830"
|
||||
},
|
||||
"Au\u00dfergew\u00f6hnliche Belastungen": {
|
||||
"account_number": "1850"
|
||||
},
|
||||
"Privateinlagen": {
|
||||
"account_number": "1890"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Kfz-Kosten": {
|
||||
"is_group": 1,
|
||||
"Kfz-Steuer": {
|
||||
"account_number": "4510",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Kfz-Versicherungen": {
|
||||
"account_number": "4520",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"laufende Kfz-Betriebskosten": {
|
||||
"account_number": "4530",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Kfz-Reparaturen": {
|
||||
"account_number": "4540",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Fremdfahrzeuge": {
|
||||
"account_number": "4570",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"sonstige Kfz-Kosten": {
|
||||
"account_number": "4580",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Personalkosten": {
|
||||
"is_group": 1,
|
||||
"Gehälter": {
|
||||
"account_number": "4120",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"gesetzliche soziale Aufwendungen": {
|
||||
"account_number": "4130",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aufwendungen für Altersvorsorge": {
|
||||
"account_number": "4165",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Vermögenswirksame Leistungen": {
|
||||
"account_number": "4170",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aushilfslöhne": {
|
||||
"account_number": "4190",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Raumkosten": {
|
||||
"is_group": 1,
|
||||
"Miete und Nebenkosten": {
|
||||
"account_number": "4210",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Gas, Wasser, Strom (Verwaltung, Vertrieb)": {
|
||||
"account_number": "4240",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Reinigung": {
|
||||
"account_number": "4250",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Reparatur/Instandhaltung": {
|
||||
"is_group": 1,
|
||||
"Reparaturen und Instandhaltungen von anderen Anlagen und Betriebs- und Geschäftsausstattung": {
|
||||
"account_number": "4805",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Versicherungsbeiträge": {
|
||||
"is_group": 1,
|
||||
"Versicherungen": {
|
||||
"account_number": "4360",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Beiträge": {
|
||||
"account_number": "4380",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"sonstige Ausgaben": {
|
||||
"account_number": "4390",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"steuerlich abzugsfähige Verspätungszuschläge und Zwangsgelder": {
|
||||
"account_number": "4396",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Werbe-/Reisekosten": {
|
||||
"is_group": 1,
|
||||
"Werbekosten": {
|
||||
"account_number": "4610",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Aufmerksamkeiten": {
|
||||
"account_number": "4653",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"nicht abzugsfähige Betriebsausg. aus Werbe-, Repräs.- u. Reisekosten": {
|
||||
"account_number": "4665",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Reisekosten Unternehmer": {
|
||||
"account_number": "4670",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"verschiedene Kosten": {
|
||||
"is_group": 1,
|
||||
"Porto": {
|
||||
"account_number": "4910",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Telekom": {
|
||||
"account_number": "4920",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Mobilfunk D2": {
|
||||
"account_number": "4921",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Internet": {
|
||||
"account_number": "4922",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Bürobedarf": {
|
||||
"account_number": "4930",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Zeitschriften, Bücher": {
|
||||
"account_number": "4940",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Fortbildungskosten": {
|
||||
"account_number": "4945",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Buchführungskosten": {
|
||||
"account_number": "4955",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Abschluß- u. Prüfungskosten": {
|
||||
"account_number": "4957",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Nebenkosten des Geldverkehrs": {
|
||||
"account_number": "4970",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Werkzeuge und Kleingeräte": {
|
||||
"account_number": "4985",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
},
|
||||
"Zinsaufwendungen": {
|
||||
"is_group": 1,
|
||||
"Zinsaufwendungen für kurzfristige Verbindlichkeiten": {
|
||||
"account_number": "2110",
|
||||
"account_type": "Expense Account"
|
||||
},
|
||||
"Zinsaufwendungen für KFZ Finanzierung": {
|
||||
"account_number": "2121",
|
||||
"account_type": "Expense Account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Anfangsbestand 9": {
|
||||
"is_group": 1,
|
||||
"root_type": "Equity",
|
||||
"Saldenvortragskonten": {
|
||||
"is_group": 1,
|
||||
"Saldenvortrag Sachkonten": {
|
||||
"account_number": "9000"
|
||||
},
|
||||
"Saldenvorträge Debitoren": {
|
||||
"account_number": "9008"
|
||||
},
|
||||
"Saldenvorträge Kreditoren": {
|
||||
"account_number": "9009"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Privatkonten 1": {
|
||||
"is_group": 1,
|
||||
"root_type": "Equity",
|
||||
"Privatentnahmen/-einlagen": {
|
||||
"is_group": 1,
|
||||
"Privatentnahme allgemein": {
|
||||
"account_number": "1800"
|
||||
},
|
||||
"Privatsteuern": {
|
||||
"account_number": "1810"
|
||||
},
|
||||
"Sonderausgaben beschränkt abzugsfähig": {
|
||||
"account_number": "1820"
|
||||
},
|
||||
"Sonderausgaben unbeschränkt abzugsfähig": {
|
||||
"account_number": "1830"
|
||||
},
|
||||
"Außergewöhnliche Belastungen": {
|
||||
"account_number": "1850"
|
||||
},
|
||||
"Privateinlagen": {
|
||||
"account_number": "1890"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@
|
||||
"acc_frozen_upto",
|
||||
"column_break_25",
|
||||
"frozen_accounts_modifier",
|
||||
"report_settings_sb"
|
||||
"report_settings_sb",
|
||||
"tab_break_dpet",
|
||||
"show_balance_in_coa"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -347,6 +349,17 @@
|
||||
"fieldname": "allow_multi_currency_invoices_against_single_party_account",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow multi-currency invoices against single party account "
|
||||
},
|
||||
{
|
||||
"fieldname": "tab_break_dpet",
|
||||
"fieldtype": "Tab Break",
|
||||
"label": "Chart Of Accounts"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "show_balance_in_coa",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Balances in Chart Of Accounts"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@@ -354,7 +367,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-27 21:49:52.538655",
|
||||
"modified": "2023-01-02 12:07:42.434214",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
|
||||
@@ -37,14 +37,11 @@ frappe.ui.form.on("Bank Clearance", {
|
||||
|
||||
refresh: function(frm) {
|
||||
frm.disable_save();
|
||||
frm.add_custom_button(__('Get Payment Entries'), () =>
|
||||
frm.trigger("get_payment_entries")
|
||||
);
|
||||
|
||||
if (frm.doc.account && frm.doc.from_date && frm.doc.to_date) {
|
||||
frm.add_custom_button(__('Get Payment Entries'), () =>
|
||||
frm.trigger("get_payment_entries")
|
||||
);
|
||||
|
||||
frm.change_custom_button_type('Get Payment Entries', null, 'primary');
|
||||
}
|
||||
frm.change_custom_button_type('Get Payment Entries', null, 'primary');
|
||||
},
|
||||
|
||||
update_clearance_date: function(frm) {
|
||||
|
||||
@@ -21,13 +21,22 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
||||
frm.trigger('bank_account');
|
||||
},
|
||||
|
||||
filter_by_reference_date: function (frm) {
|
||||
if (frm.doc.filter_by_reference_date) {
|
||||
frm.set_value("bank_statement_from_date", "");
|
||||
frm.set_value("bank_statement_to_date", "");
|
||||
} else {
|
||||
frm.set_value("from_reference_date", "");
|
||||
frm.set_value("to_reference_date", "");
|
||||
}
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
frappe.require("bank-reconciliation-tool.bundle.js", () =>
|
||||
frm.trigger("make_reconciliation_tool")
|
||||
);
|
||||
frm.upload_statement_button = frm.page.set_secondary_action(
|
||||
__("Upload Bank Statement"),
|
||||
() =>
|
||||
|
||||
frm.add_custom_button(__("Upload Bank Statement"), () =>
|
||||
frappe.call({
|
||||
method:
|
||||
"erpnext.accounts.doctype.bank_statement_import.bank_statement_import.upload_bank_statement",
|
||||
@@ -49,6 +58,20 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
frm.add_custom_button(__('Auto Reconcile'), function() {
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.auto_reconcile_vouchers",
|
||||
args: {
|
||||
bank_account: frm.doc.bank_account,
|
||||
from_date: frm.doc.bank_statement_from_date,
|
||||
to_date: frm.doc.bank_statement_to_date,
|
||||
filter_by_reference_date: frm.doc.filter_by_reference_date,
|
||||
from_reference_date: frm.doc.from_reference_date,
|
||||
to_reference_date: frm.doc.to_reference_date,
|
||||
},
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
after_save: function (frm) {
|
||||
@@ -160,6 +183,9 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
||||
).$wrapper,
|
||||
bank_statement_from_date: frm.doc.bank_statement_from_date,
|
||||
bank_statement_to_date: frm.doc.bank_statement_to_date,
|
||||
filter_by_reference_date: frm.doc.filter_by_reference_date,
|
||||
from_reference_date: frm.doc.from_reference_date,
|
||||
to_reference_date: frm.doc.to_reference_date,
|
||||
bank_statement_closing_balance:
|
||||
frm.doc.bank_statement_closing_balance,
|
||||
cards_manager: frm.cards_manager,
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
"column_break_1",
|
||||
"bank_statement_from_date",
|
||||
"bank_statement_to_date",
|
||||
"from_reference_date",
|
||||
"to_reference_date",
|
||||
"filter_by_reference_date",
|
||||
"column_break_2",
|
||||
"account_opening_balance",
|
||||
"bank_statement_closing_balance",
|
||||
@@ -36,13 +39,13 @@
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: doc.bank_account",
|
||||
"depends_on": "eval: doc.bank_account && !doc.filter_by_reference_date",
|
||||
"fieldname": "bank_statement_from_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "From Date"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: doc.bank_statement_from_date",
|
||||
"depends_on": "eval: doc.bank_account && !doc.filter_by_reference_date",
|
||||
"fieldname": "bank_statement_to_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "To Date"
|
||||
@@ -81,14 +84,33 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "no_bank_transactions",
|
||||
"fieldtype": "HTML"
|
||||
"fieldtype": "HTML",
|
||||
"options": "<div class=\"text-muted text-center\">No Matching Bank Transactions Found</div>"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.filter_by_reference_date",
|
||||
"fieldname": "from_reference_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "From Reference Date"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.filter_by_reference_date",
|
||||
"fieldname": "to_reference_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "To Reference Date"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "filter_by_reference_date",
|
||||
"fieldtype": "Check",
|
||||
"label": "Filter by Reference Date"
|
||||
}
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-21 11:13:49.831769",
|
||||
"modified": "2023-01-13 13:00:02.022919",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Bank Reconciliation Tool",
|
||||
@@ -107,5 +129,6 @@
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
}
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.utils import flt
|
||||
from frappe.utils import cint, flt
|
||||
|
||||
from erpnext.accounts.doctype.bank_transaction.bank_transaction import get_paid_amount
|
||||
from erpnext.accounts.report.bank_reconciliation_statement.bank_reconciliation_statement import (
|
||||
@@ -50,6 +50,7 @@ def get_bank_transactions(bank_account, from_date=None, to_date=None):
|
||||
"party",
|
||||
],
|
||||
filters=filters,
|
||||
order_by="date",
|
||||
)
|
||||
return transactions
|
||||
|
||||
@@ -265,6 +266,80 @@ def create_payment_entry_bts(
|
||||
return reconcile_vouchers(bank_transaction.name, vouchers)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def auto_reconcile_vouchers(
|
||||
bank_account,
|
||||
from_date=None,
|
||||
to_date=None,
|
||||
filter_by_reference_date=None,
|
||||
from_reference_date=None,
|
||||
to_reference_date=None,
|
||||
):
|
||||
frappe.flags.auto_reconcile_vouchers = True
|
||||
document_types = ["payment_entry", "journal_entry"]
|
||||
bank_transactions = get_bank_transactions(bank_account)
|
||||
matched_transaction = []
|
||||
for transaction in bank_transactions:
|
||||
linked_payments = get_linked_payments(
|
||||
transaction.name,
|
||||
document_types,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
vouchers = []
|
||||
for r in linked_payments:
|
||||
vouchers.append(
|
||||
{
|
||||
"payment_doctype": r[1],
|
||||
"payment_name": r[2],
|
||||
"amount": r[4],
|
||||
}
|
||||
)
|
||||
transaction = frappe.get_doc("Bank Transaction", transaction.name)
|
||||
account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
||||
matched_trans = 0
|
||||
for voucher in vouchers:
|
||||
gl_entry = frappe.db.get_value(
|
||||
"GL Entry",
|
||||
dict(
|
||||
account=account, voucher_type=voucher["payment_doctype"], voucher_no=voucher["payment_name"]
|
||||
),
|
||||
["credit", "debit"],
|
||||
as_dict=1,
|
||||
)
|
||||
gl_amount, transaction_amount = (
|
||||
(gl_entry.credit, transaction.deposit)
|
||||
if gl_entry.credit > 0
|
||||
else (gl_entry.debit, transaction.withdrawal)
|
||||
)
|
||||
allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
|
||||
transaction.append(
|
||||
"payment_entries",
|
||||
{
|
||||
"payment_document": voucher["payment_doctype"],
|
||||
"payment_entry": voucher["payment_name"],
|
||||
"allocated_amount": allocated_amount,
|
||||
},
|
||||
)
|
||||
matched_transaction.append(str(transaction.name))
|
||||
transaction.save()
|
||||
transaction.update_allocations()
|
||||
matched_transaction_len = len(set(matched_transaction))
|
||||
if matched_transaction_len == 0:
|
||||
frappe.msgprint(_("No matching references found for auto reconciliation"))
|
||||
elif matched_transaction_len == 1:
|
||||
frappe.msgprint(_("{0} transaction is reconcilied").format(matched_transaction_len))
|
||||
else:
|
||||
frappe.msgprint(_("{0} transactions are reconcilied").format(matched_transaction_len))
|
||||
|
||||
frappe.flags.auto_reconcile_vouchers = False
|
||||
|
||||
return frappe.get_doc("Bank Transaction", transaction.name)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||
# updated clear date of all the vouchers based on the bank transaction
|
||||
@@ -302,7 +377,7 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||
dict(
|
||||
account=account, voucher_type=voucher["payment_doctype"], voucher_no=voucher["payment_name"]
|
||||
),
|
||||
["credit", "debit"],
|
||||
["credit_in_account_currency as credit", "debit_in_account_currency as debit"],
|
||||
as_dict=1,
|
||||
)
|
||||
gl_amount, transaction_amount = (
|
||||
@@ -327,20 +402,58 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_linked_payments(bank_transaction_name, document_types=None):
|
||||
def get_linked_payments(
|
||||
bank_transaction_name,
|
||||
document_types=None,
|
||||
from_date=None,
|
||||
to_date=None,
|
||||
filter_by_reference_date=None,
|
||||
from_reference_date=None,
|
||||
to_reference_date=None,
|
||||
):
|
||||
# get all matching payments for a bank transaction
|
||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||
bank_account = frappe.db.get_values(
|
||||
"Bank Account", transaction.bank_account, ["account", "company"], as_dict=True
|
||||
)[0]
|
||||
(account, company) = (bank_account.account, bank_account.company)
|
||||
matching = check_matching(account, company, transaction, document_types)
|
||||
matching = check_matching(
|
||||
account,
|
||||
company,
|
||||
transaction,
|
||||
document_types,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
return matching
|
||||
|
||||
|
||||
def check_matching(bank_account, company, transaction, document_types):
|
||||
def check_matching(
|
||||
bank_account,
|
||||
company,
|
||||
transaction,
|
||||
document_types,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
):
|
||||
# combine all types of vouchers
|
||||
subquery = get_queries(bank_account, company, transaction, document_types)
|
||||
subquery = get_queries(
|
||||
bank_account,
|
||||
company,
|
||||
transaction,
|
||||
document_types,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
filters = {
|
||||
"amount": transaction.unallocated_amount,
|
||||
"payment_type": "Receive" if transaction.deposit > 0 else "Pay",
|
||||
@@ -361,11 +474,20 @@ def check_matching(bank_account, company, transaction, document_types):
|
||||
filters,
|
||||
)
|
||||
)
|
||||
|
||||
return sorted(matching_vouchers, key=lambda x: x[0], reverse=True) if matching_vouchers else []
|
||||
|
||||
|
||||
def get_queries(bank_account, company, transaction, document_types):
|
||||
def get_queries(
|
||||
bank_account,
|
||||
company,
|
||||
transaction,
|
||||
document_types,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
):
|
||||
# get queries to get matching vouchers
|
||||
amount_condition = "=" if "exact_match" in document_types else "<="
|
||||
account_from_to = "paid_to" if transaction.deposit > 0 else "paid_from"
|
||||
@@ -381,6 +503,11 @@ def get_queries(bank_account, company, transaction, document_types):
|
||||
document_types,
|
||||
amount_condition,
|
||||
account_from_to,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
or []
|
||||
)
|
||||
@@ -389,15 +516,42 @@ def get_queries(bank_account, company, transaction, document_types):
|
||||
|
||||
|
||||
def get_matching_queries(
|
||||
bank_account, company, transaction, document_types, amount_condition, account_from_to
|
||||
bank_account,
|
||||
company,
|
||||
transaction,
|
||||
document_types,
|
||||
amount_condition,
|
||||
account_from_to,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
):
|
||||
queries = []
|
||||
if "payment_entry" in document_types:
|
||||
pe_amount_matching = get_pe_matching_query(amount_condition, account_from_to, transaction)
|
||||
pe_amount_matching = get_pe_matching_query(
|
||||
amount_condition,
|
||||
account_from_to,
|
||||
transaction,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
queries.extend([pe_amount_matching])
|
||||
|
||||
if "journal_entry" in document_types:
|
||||
je_amount_matching = get_je_matching_query(amount_condition, transaction)
|
||||
je_amount_matching = get_je_matching_query(
|
||||
amount_condition,
|
||||
transaction,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
)
|
||||
queries.extend([je_amount_matching])
|
||||
|
||||
if transaction.deposit > 0 and "sales_invoice" in document_types:
|
||||
@@ -504,47 +658,81 @@ def get_lr_matching_query(bank_account, amount_condition, filters):
|
||||
return vouchers
|
||||
|
||||
|
||||
def get_pe_matching_query(amount_condition, account_from_to, transaction):
|
||||
def get_pe_matching_query(
|
||||
amount_condition,
|
||||
account_from_to,
|
||||
transaction,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
):
|
||||
# get matching payment entries query
|
||||
if transaction.deposit > 0:
|
||||
currency_field = "paid_to_account_currency as currency"
|
||||
else:
|
||||
currency_field = "paid_from_account_currency as currency"
|
||||
filter_by_date = f"AND posting_date between '{from_date}' and '{to_date}'"
|
||||
order_by = " posting_date"
|
||||
filter_by_reference_no = ""
|
||||
if cint(filter_by_reference_date):
|
||||
filter_by_date = f"AND reference_date between '{from_reference_date}' and '{to_reference_date}'"
|
||||
order_by = " reference_date"
|
||||
if frappe.flags.auto_reconcile_vouchers == True:
|
||||
filter_by_reference_no = f"AND reference_no = '{transaction.reference_number}'"
|
||||
return f"""
|
||||
SELECT
|
||||
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
||||
+ 1 ) AS rank,
|
||||
'Payment Entry' as doctype,
|
||||
name,
|
||||
paid_amount,
|
||||
reference_no,
|
||||
reference_date,
|
||||
party,
|
||||
party_type,
|
||||
posting_date,
|
||||
{currency_field}
|
||||
FROM
|
||||
`tabPayment Entry`
|
||||
WHERE
|
||||
paid_amount {amount_condition} %(amount)s
|
||||
AND docstatus = 1
|
||||
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
|
||||
AND ifnull(clearance_date, '') = ""
|
||||
AND {account_from_to} = %(bank_account)s
|
||||
SELECT
|
||||
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
||||
+ 1 ) AS rank,
|
||||
'Payment Entry' as doctype,
|
||||
name,
|
||||
paid_amount,
|
||||
reference_no,
|
||||
reference_date,
|
||||
party,
|
||||
party_type,
|
||||
posting_date,
|
||||
{currency_field}
|
||||
FROM
|
||||
`tabPayment Entry`
|
||||
WHERE
|
||||
paid_amount {amount_condition} %(amount)s
|
||||
AND docstatus = 1
|
||||
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
|
||||
AND ifnull(clearance_date, '') = ""
|
||||
AND {account_from_to} = %(bank_account)s
|
||||
{filter_by_date}
|
||||
{filter_by_reference_no}
|
||||
order by{order_by}
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def get_je_matching_query(amount_condition, transaction):
|
||||
def get_je_matching_query(
|
||||
amount_condition,
|
||||
transaction,
|
||||
from_date,
|
||||
to_date,
|
||||
filter_by_reference_date,
|
||||
from_reference_date,
|
||||
to_reference_date,
|
||||
):
|
||||
# get matching journal entry query
|
||||
|
||||
# We have mapping at the bank level
|
||||
# So one bank could have both types of bank accounts like asset and liability
|
||||
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
|
||||
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
|
||||
|
||||
filter_by_date = f"AND je.posting_date between '{from_date}' and '{to_date}'"
|
||||
order_by = " je.posting_date"
|
||||
filter_by_reference_no = ""
|
||||
if cint(filter_by_reference_date):
|
||||
filter_by_date = f"AND je.cheque_date between '{from_reference_date}' and '{to_reference_date}'"
|
||||
order_by = " je.cheque_date"
|
||||
if frappe.flags.auto_reconcile_vouchers == True:
|
||||
filter_by_reference_no = f"AND je.cheque_no = '{transaction.reference_number}'"
|
||||
return f"""
|
||||
|
||||
SELECT
|
||||
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||
+ 1) AS rank ,
|
||||
@@ -568,6 +756,9 @@ def get_je_matching_query(amount_condition, transaction):
|
||||
AND jea.account = %(bank_account)s
|
||||
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
|
||||
AND je.docstatus = 1
|
||||
{filter_by_date}
|
||||
{filter_by_reference_no}
|
||||
order by {order_by}
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ def get_paid_amount(payment_entry, currency, bank_account):
|
||||
)
|
||||
elif doc.payment_type == "Pay":
|
||||
paid_amount_field = (
|
||||
"paid_amount" if doc.paid_to_account_currency == currency else "base_paid_amount"
|
||||
"paid_amount" if doc.paid_from_account_currency == currency else "base_paid_amount"
|
||||
)
|
||||
|
||||
return frappe.db.get_value(
|
||||
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe import utils
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import (
|
||||
@@ -40,7 +41,12 @@ class TestBankTransaction(FrappeTestCase):
|
||||
"Bank Transaction",
|
||||
dict(description="Re 95282925234 FE/000002917 AT171513000281183046 Conrad Electronic"),
|
||||
)
|
||||
linked_payments = get_linked_payments(bank_transaction.name, ["payment_entry", "exact_match"])
|
||||
linked_payments = get_linked_payments(
|
||||
bank_transaction.name,
|
||||
["payment_entry", "exact_match"],
|
||||
from_date=bank_transaction.date,
|
||||
to_date=utils.today(),
|
||||
)
|
||||
self.assertTrue(linked_payments[0][6] == "Conrad Electronic")
|
||||
|
||||
# This test validates a simple reconciliation leading to the clearance of the bank transaction and the payment
|
||||
@@ -81,7 +87,12 @@ class TestBankTransaction(FrappeTestCase):
|
||||
"Bank Transaction",
|
||||
dict(description="Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07"),
|
||||
)
|
||||
linked_payments = get_linked_payments(bank_transaction.name, ["payment_entry", "exact_match"])
|
||||
linked_payments = get_linked_payments(
|
||||
bank_transaction.name,
|
||||
["payment_entry", "exact_match"],
|
||||
from_date=bank_transaction.date,
|
||||
to_date=utils.today(),
|
||||
)
|
||||
self.assertTrue(linked_payments[0][3])
|
||||
|
||||
# Check error if already reconciled
|
||||
|
||||
@@ -184,6 +184,11 @@ def validate_budget_records(args, budget_records, expense_amount):
|
||||
amount = expense_amount or get_amount(args, budget)
|
||||
yearly_action, monthly_action = get_actions(args, budget)
|
||||
|
||||
if yearly_action in ("Stop", "Warn"):
|
||||
compare_expense_with_budget(
|
||||
args, flt(budget.budget_amount), _("Annual"), yearly_action, budget.budget_against, amount
|
||||
)
|
||||
|
||||
if monthly_action in ["Stop", "Warn"]:
|
||||
budget_amount = get_accumulated_monthly_budget(
|
||||
budget.monthly_distribution, args.posting_date, args.fiscal_year, budget.budget_amount
|
||||
@@ -195,28 +200,28 @@ def validate_budget_records(args, budget_records, expense_amount):
|
||||
args, budget_amount, _("Accumulated Monthly"), monthly_action, budget.budget_against, amount
|
||||
)
|
||||
|
||||
if (
|
||||
yearly_action in ("Stop", "Warn")
|
||||
and monthly_action != "Stop"
|
||||
and yearly_action != monthly_action
|
||||
):
|
||||
compare_expense_with_budget(
|
||||
args, flt(budget.budget_amount), _("Annual"), yearly_action, budget.budget_against, amount
|
||||
)
|
||||
|
||||
|
||||
def compare_expense_with_budget(args, budget_amount, action_for, action, budget_against, amount=0):
|
||||
actual_expense = amount or get_actual_expense(args)
|
||||
if actual_expense > budget_amount:
|
||||
diff = actual_expense - budget_amount
|
||||
actual_expense = get_actual_expense(args)
|
||||
total_expense = actual_expense + amount
|
||||
|
||||
if total_expense > budget_amount:
|
||||
if actual_expense > budget_amount:
|
||||
error_tense = _("is already")
|
||||
diff = actual_expense - budget_amount
|
||||
else:
|
||||
error_tense = _("will be")
|
||||
diff = total_expense - budget_amount
|
||||
|
||||
currency = frappe.get_cached_value("Company", args.company, "default_currency")
|
||||
|
||||
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It will exceed by {5}").format(
|
||||
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It {5} exceed by {6}").format(
|
||||
_(action_for),
|
||||
frappe.bold(args.account),
|
||||
args.budget_against_field,
|
||||
frappe.unscrub(args.budget_against_field),
|
||||
frappe.bold(budget_against),
|
||||
frappe.bold(fmt_money(budget_amount, currency=currency)),
|
||||
error_tense,
|
||||
frappe.bold(fmt_money(diff, currency=currency)),
|
||||
)
|
||||
|
||||
@@ -227,9 +232,9 @@ def compare_expense_with_budget(args, budget_amount, action_for, action, budget_
|
||||
action = "Warn"
|
||||
|
||||
if action == "Stop":
|
||||
frappe.throw(msg, BudgetError)
|
||||
frappe.throw(msg, BudgetError, title=_("Budget Exceeded"))
|
||||
else:
|
||||
frappe.msgprint(msg, indicator="orange")
|
||||
frappe.msgprint(msg, indicator="orange", title=_("Budget Exceeded"))
|
||||
|
||||
|
||||
def get_actions(args, budget):
|
||||
@@ -351,7 +356,9 @@ def get_actual_expense(args):
|
||||
"""
|
||||
select sum(gle.debit) - sum(gle.credit)
|
||||
from `tabGL Entry` gle
|
||||
where gle.account=%(account)s
|
||||
where
|
||||
is_cancelled = 0
|
||||
and gle.account=%(account)s
|
||||
{condition1}
|
||||
and gle.fiscal_year=%(fiscal_year)s
|
||||
and gle.company=%(company)s
|
||||
|
||||
@@ -485,6 +485,10 @@ def set_default_accounts(company):
|
||||
"default_payable_account": frappe.db.get_value(
|
||||
"Account", {"company": company.name, "account_type": "Payable", "is_group": 0}
|
||||
),
|
||||
"default_provisional_account": frappe.db.get_value(
|
||||
"Account",
|
||||
{"company": company.name, "account_type": "Service Received But Not Billed", "is_group": 0},
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -28,9 +28,14 @@ class InvalidDateError(frappe.ValidationError):
|
||||
|
||||
|
||||
class CostCenterAllocation(Document):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CostCenterAllocation, self).__init__(*args, **kwargs)
|
||||
self._skip_from_date_validation = False
|
||||
|
||||
def validate(self):
|
||||
self.validate_total_allocation_percentage()
|
||||
self.validate_from_date_based_on_existing_gle()
|
||||
if not self._skip_from_date_validation:
|
||||
self.validate_from_date_based_on_existing_gle()
|
||||
self.validate_backdated_allocation()
|
||||
self.validate_main_cost_center()
|
||||
self.validate_child_cost_centers()
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"api_details_section",
|
||||
"disabled",
|
||||
"service_provider",
|
||||
"api_endpoint",
|
||||
"url",
|
||||
@@ -77,12 +78,18 @@
|
||||
"label": "Service Provider",
|
||||
"options": "frankfurter.app\nexchangerate.host\nCustom",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "disabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Disabled"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2022-01-10 15:51:14.521174",
|
||||
"modified": "2023-01-09 12:19:03.955906",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Currency Exchange Settings",
|
||||
|
||||
@@ -40,7 +40,7 @@ class Dunning(AccountsController):
|
||||
|
||||
def on_cancel(self):
|
||||
if self.dunning_amount:
|
||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Payment Ledger Entry")
|
||||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||
|
||||
def make_gl_entries(self):
|
||||
|
||||
@@ -26,7 +26,7 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
|
||||
doc: frm.doc,
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
frm.add_custom_button(__('Journal Entry'), function() {
|
||||
frm.add_custom_button(__('Journal Entries'), function() {
|
||||
return frm.events.make_jv(frm);
|
||||
}, __('Create'));
|
||||
}
|
||||
@@ -35,10 +35,11 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
|
||||
}
|
||||
},
|
||||
|
||||
get_entries: function(frm) {
|
||||
get_entries: function(frm, account) {
|
||||
frappe.call({
|
||||
method: "get_accounts_data",
|
||||
doc: cur_frm.doc,
|
||||
account: account,
|
||||
callback: function(r){
|
||||
frappe.model.clear_table(frm.doc, "accounts");
|
||||
if(r.message) {
|
||||
@@ -57,7 +58,6 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
|
||||
|
||||
let total_gain_loss = 0;
|
||||
frm.doc.accounts.forEach((d) => {
|
||||
d.gain_loss = flt(d.new_balance_in_base_currency, precision("new_balance_in_base_currency", d)) - flt(d.balance_in_base_currency, precision("balance_in_base_currency", d));
|
||||
total_gain_loss += flt(d.gain_loss, precision("gain_loss", d));
|
||||
});
|
||||
|
||||
@@ -66,13 +66,19 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
|
||||
},
|
||||
|
||||
make_jv : function(frm) {
|
||||
let revaluation_journal = null;
|
||||
let zero_balance_journal = null;
|
||||
frappe.call({
|
||||
method: "make_jv_entry",
|
||||
method: "make_jv_entries",
|
||||
doc: frm.doc,
|
||||
freeze: true,
|
||||
freeze_message: "Making Journal Entries...",
|
||||
callback: function(r){
|
||||
if (r.message) {
|
||||
var doc = frappe.model.sync(r.message)[0];
|
||||
frappe.set_route("Form", doc.doctype, doc.name);
|
||||
let response = r.message;
|
||||
if(response['revaluation_jv'] || response['zero_balance_jv']) {
|
||||
frappe.msgprint(__("Journals have been created"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"get_entries",
|
||||
"accounts",
|
||||
"section_break_6",
|
||||
"gain_loss_unbooked",
|
||||
"gain_loss_booked",
|
||||
"column_break_10",
|
||||
"total_gain_loss",
|
||||
"amended_from"
|
||||
],
|
||||
@@ -59,13 +62,6 @@
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "total_gain_loss",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Gain/Loss",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
@@ -74,11 +70,37 @@
|
||||
"options": "Exchange Rate Revaluation",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "gain_loss_unbooked",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Gain/Loss from Revaluation",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"description": "Gain/Loss accumulated in foreign currency account. Accounts with '0' balance in either Base or Account currency",
|
||||
"fieldname": "gain_loss_booked",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Gain/Loss already booked",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "total_gain_loss",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Gain/Loss",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_10",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-17 10:28:03.911554",
|
||||
"modified": "2022-12-29 19:38:24.416529",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Exchange Rate Revaluation",
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe import _, qb
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.utils import flt
|
||||
from frappe.query_builder import Criterion, Order
|
||||
from frappe.query_builder.functions import NullIf, Sum
|
||||
from frappe.utils import flt, get_link_to_form
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_balance_on
|
||||
@@ -19,11 +21,25 @@ class ExchangeRateRevaluation(Document):
|
||||
|
||||
def set_total_gain_loss(self):
|
||||
total_gain_loss = 0
|
||||
|
||||
gain_loss_booked = 0
|
||||
gain_loss_unbooked = 0
|
||||
|
||||
for d in self.accounts:
|
||||
d.gain_loss = flt(
|
||||
d.new_balance_in_base_currency, d.precision("new_balance_in_base_currency")
|
||||
) - flt(d.balance_in_base_currency, d.precision("balance_in_base_currency"))
|
||||
if not d.zero_balance:
|
||||
d.gain_loss = flt(
|
||||
d.new_balance_in_base_currency, d.precision("new_balance_in_base_currency")
|
||||
) - flt(d.balance_in_base_currency, d.precision("balance_in_base_currency"))
|
||||
|
||||
if d.zero_balance:
|
||||
gain_loss_booked += flt(d.gain_loss, d.precision("gain_loss"))
|
||||
else:
|
||||
gain_loss_unbooked += flt(d.gain_loss, d.precision("gain_loss"))
|
||||
|
||||
total_gain_loss += flt(d.gain_loss, d.precision("gain_loss"))
|
||||
|
||||
self.gain_loss_booked = gain_loss_booked
|
||||
self.gain_loss_unbooked = gain_loss_unbooked
|
||||
self.total_gain_loss = flt(total_gain_loss, self.precision("total_gain_loss"))
|
||||
|
||||
def validate_mandatory(self):
|
||||
@@ -35,98 +51,206 @@ class ExchangeRateRevaluation(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def check_journal_entry_condition(self):
|
||||
total_debit = frappe.db.get_value(
|
||||
"Journal Entry Account",
|
||||
{"reference_type": "Exchange Rate Revaluation", "reference_name": self.name, "docstatus": 1},
|
||||
"sum(debit) as sum",
|
||||
exchange_gain_loss_account = self.get_for_unrealized_gain_loss_account()
|
||||
|
||||
jea = qb.DocType("Journal Entry Account")
|
||||
journals = (
|
||||
qb.from_(jea)
|
||||
.select(jea.parent)
|
||||
.distinct()
|
||||
.where(
|
||||
(jea.reference_type == "Exchange Rate Revaluation")
|
||||
& (jea.reference_name == self.name)
|
||||
& (jea.docstatus == 1)
|
||||
)
|
||||
.run()
|
||||
)
|
||||
|
||||
total_amt = 0
|
||||
for d in self.accounts:
|
||||
total_amt = total_amt + d.new_balance_in_base_currency
|
||||
if journals:
|
||||
gle = qb.DocType("GL Entry")
|
||||
total_amt = (
|
||||
qb.from_(gle)
|
||||
.select((Sum(gle.credit) - Sum(gle.debit)).as_("total_amount"))
|
||||
.where(
|
||||
(gle.voucher_type == "Journal Entry")
|
||||
& (gle.voucher_no.isin(journals))
|
||||
& (gle.account == exchange_gain_loss_account)
|
||||
& (gle.is_cancelled == 0)
|
||||
)
|
||||
.run()
|
||||
)
|
||||
|
||||
if total_amt != total_debit:
|
||||
return True
|
||||
if total_amt and total_amt[0][0] != self.total_gain_loss:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
return True
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_accounts_data(self, account=None):
|
||||
accounts = []
|
||||
def get_accounts_data(self):
|
||||
self.validate_mandatory()
|
||||
company_currency = erpnext.get_company_currency(self.company)
|
||||
account_details = self.get_account_balance_from_gle(
|
||||
company=self.company, posting_date=self.posting_date, account=None, party_type=None, party=None
|
||||
)
|
||||
accounts_with_new_balance = self.calculate_new_account_balance(
|
||||
self.company, self.posting_date, account_details
|
||||
)
|
||||
|
||||
if not accounts_with_new_balance:
|
||||
self.throw_invalid_response_message(account_details)
|
||||
|
||||
return accounts_with_new_balance
|
||||
|
||||
@staticmethod
|
||||
def get_account_balance_from_gle(company, posting_date, account, party_type, party):
|
||||
account_details = []
|
||||
|
||||
if company and posting_date:
|
||||
company_currency = erpnext.get_company_currency(company)
|
||||
|
||||
acc = qb.DocType("Account")
|
||||
if account:
|
||||
accounts = [account]
|
||||
else:
|
||||
res = (
|
||||
qb.from_(acc)
|
||||
.select(acc.name)
|
||||
.where(
|
||||
(acc.is_group == 0)
|
||||
& (acc.report_type == "Balance Sheet")
|
||||
& (acc.root_type.isin(["Asset", "Liability", "Equity"]))
|
||||
& (acc.account_type != "Stock")
|
||||
& (acc.company == company)
|
||||
& (acc.account_currency != company_currency)
|
||||
)
|
||||
.orderby(acc.name)
|
||||
.run(as_list=True)
|
||||
)
|
||||
accounts = [x[0] for x in res]
|
||||
|
||||
if accounts:
|
||||
having_clause = (qb.Field("balance") != qb.Field("balance_in_account_currency")) & (
|
||||
(qb.Field("balance_in_account_currency") != 0) | (qb.Field("balance") != 0)
|
||||
)
|
||||
|
||||
gle = qb.DocType("GL Entry")
|
||||
|
||||
# conditions
|
||||
conditions = []
|
||||
conditions.append(gle.account.isin(accounts))
|
||||
conditions.append(gle.posting_date.lte(posting_date))
|
||||
conditions.append(gle.is_cancelled == 0)
|
||||
|
||||
if party_type:
|
||||
conditions.append(gle.party_type == party_type)
|
||||
if party:
|
||||
conditions.append(gle.party == party)
|
||||
|
||||
account_details = (
|
||||
qb.from_(gle)
|
||||
.select(
|
||||
gle.account,
|
||||
gle.party_type,
|
||||
gle.party,
|
||||
gle.account_currency,
|
||||
(Sum(gle.debit_in_account_currency) - Sum(gle.credit_in_account_currency)).as_(
|
||||
"balance_in_account_currency"
|
||||
),
|
||||
(Sum(gle.debit) - Sum(gle.credit)).as_("balance"),
|
||||
(Sum(gle.debit) - Sum(gle.credit) == 0)
|
||||
^ (Sum(gle.debit_in_account_currency) - Sum(gle.credit_in_account_currency) == 0).as_(
|
||||
"zero_balance"
|
||||
),
|
||||
)
|
||||
.where(Criterion.all(conditions))
|
||||
.groupby(gle.account, NullIf(gle.party_type, ""), NullIf(gle.party, ""))
|
||||
.having(having_clause)
|
||||
.orderby(gle.account)
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
return account_details
|
||||
|
||||
@staticmethod
|
||||
def calculate_new_account_balance(company, posting_date, account_details):
|
||||
accounts = []
|
||||
company_currency = erpnext.get_company_currency(company)
|
||||
precision = get_field_precision(
|
||||
frappe.get_meta("Exchange Rate Revaluation Account").get_field("new_balance_in_base_currency"),
|
||||
company_currency,
|
||||
)
|
||||
|
||||
account_details = self.get_accounts_from_gle()
|
||||
for d in account_details:
|
||||
current_exchange_rate = (
|
||||
d.balance / d.balance_in_account_currency if d.balance_in_account_currency else 0
|
||||
)
|
||||
new_exchange_rate = get_exchange_rate(d.account_currency, company_currency, self.posting_date)
|
||||
new_balance_in_base_currency = flt(d.balance_in_account_currency * new_exchange_rate)
|
||||
gain_loss = flt(new_balance_in_base_currency, precision) - flt(d.balance, precision)
|
||||
if gain_loss:
|
||||
accounts.append(
|
||||
{
|
||||
"account": d.account,
|
||||
"party_type": d.party_type,
|
||||
"party": d.party,
|
||||
"account_currency": d.account_currency,
|
||||
"balance_in_base_currency": d.balance,
|
||||
"balance_in_account_currency": d.balance_in_account_currency,
|
||||
"current_exchange_rate": current_exchange_rate,
|
||||
"new_exchange_rate": new_exchange_rate,
|
||||
"new_balance_in_base_currency": new_balance_in_base_currency,
|
||||
}
|
||||
if account_details:
|
||||
# Handle Accounts with balance in both Account/Base Currency
|
||||
for d in [x for x in account_details if not x.zero_balance]:
|
||||
current_exchange_rate = (
|
||||
d.balance / d.balance_in_account_currency if d.balance_in_account_currency else 0
|
||||
)
|
||||
new_exchange_rate = get_exchange_rate(d.account_currency, company_currency, posting_date)
|
||||
new_balance_in_base_currency = flt(d.balance_in_account_currency * new_exchange_rate)
|
||||
gain_loss = flt(new_balance_in_base_currency, precision) - flt(d.balance, precision)
|
||||
if gain_loss:
|
||||
accounts.append(
|
||||
{
|
||||
"account": d.account,
|
||||
"party_type": d.party_type,
|
||||
"party": d.party,
|
||||
"account_currency": d.account_currency,
|
||||
"balance_in_base_currency": d.balance,
|
||||
"balance_in_account_currency": d.balance_in_account_currency,
|
||||
"zero_balance": d.zero_balance,
|
||||
"current_exchange_rate": current_exchange_rate,
|
||||
"new_exchange_rate": new_exchange_rate,
|
||||
"new_balance_in_base_currency": new_balance_in_base_currency,
|
||||
"new_balance_in_account_currency": d.balance_in_account_currency,
|
||||
"gain_loss": gain_loss,
|
||||
}
|
||||
)
|
||||
|
||||
if not accounts:
|
||||
self.throw_invalid_response_message(account_details)
|
||||
# Handle Accounts with '0' balance in Account/Base Currency
|
||||
for d in [x for x in account_details if x.zero_balance]:
|
||||
|
||||
# TODO: Set new balance in Base/Account currency
|
||||
if d.balance > 0:
|
||||
current_exchange_rate = new_exchange_rate = 0
|
||||
|
||||
new_balance_in_account_currency = 0 # this will be '0'
|
||||
new_balance_in_base_currency = 0 # this will be '0'
|
||||
gain_loss = flt(new_balance_in_base_currency, precision) - flt(d.balance, precision)
|
||||
else:
|
||||
new_exchange_rate = 0
|
||||
new_balance_in_base_currency = 0
|
||||
new_balance_in_account_currency = 0
|
||||
|
||||
current_exchange_rate = calculate_exchange_rate_using_last_gle(
|
||||
company, d.account, d.party_type, d.party
|
||||
)
|
||||
|
||||
gain_loss = new_balance_in_account_currency - (
|
||||
current_exchange_rate * d.balance_in_account_currency
|
||||
)
|
||||
|
||||
if gain_loss:
|
||||
accounts.append(
|
||||
{
|
||||
"account": d.account,
|
||||
"party_type": d.party_type,
|
||||
"party": d.party,
|
||||
"account_currency": d.account_currency,
|
||||
"balance_in_base_currency": d.balance,
|
||||
"balance_in_account_currency": d.balance_in_account_currency,
|
||||
"zero_balance": d.zero_balance,
|
||||
"current_exchange_rate": current_exchange_rate,
|
||||
"new_exchange_rate": new_exchange_rate,
|
||||
"new_balance_in_base_currency": new_balance_in_base_currency,
|
||||
"new_balance_in_account_currency": new_balance_in_account_currency,
|
||||
"gain_loss": gain_loss,
|
||||
}
|
||||
)
|
||||
|
||||
return accounts
|
||||
|
||||
def get_accounts_from_gle(self):
|
||||
company_currency = erpnext.get_company_currency(self.company)
|
||||
accounts = frappe.db.sql_list(
|
||||
"""
|
||||
select name
|
||||
from tabAccount
|
||||
where is_group = 0
|
||||
and report_type = 'Balance Sheet'
|
||||
and root_type in ('Asset', 'Liability', 'Equity')
|
||||
and account_type != 'Stock'
|
||||
and company=%s
|
||||
and account_currency != %s
|
||||
order by name""",
|
||||
(self.company, company_currency),
|
||||
)
|
||||
|
||||
account_details = []
|
||||
if accounts:
|
||||
account_details = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
account, party_type, party, account_currency,
|
||||
sum(debit_in_account_currency) - sum(credit_in_account_currency) as balance_in_account_currency,
|
||||
sum(debit) - sum(credit) as balance
|
||||
from `tabGL Entry`
|
||||
where account in (%s)
|
||||
and posting_date <= %s
|
||||
and is_cancelled = 0
|
||||
group by account, NULLIF(party_type,''), NULLIF(party,'')
|
||||
having sum(debit) != sum(credit)
|
||||
order by account
|
||||
"""
|
||||
% (", ".join(["%s"] * len(accounts)), "%s"),
|
||||
tuple(accounts + [self.posting_date]),
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
return account_details
|
||||
|
||||
def throw_invalid_response_message(self, account_details):
|
||||
if account_details:
|
||||
message = _("No outstanding invoices require exchange rate revaluation")
|
||||
@@ -134,11 +258,7 @@ class ExchangeRateRevaluation(Document):
|
||||
message = _("No outstanding invoices found")
|
||||
frappe.msgprint(message)
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_jv_entry(self):
|
||||
if self.total_gain_loss == 0:
|
||||
return
|
||||
|
||||
def get_for_unrealized_gain_loss_account(self):
|
||||
unrealized_exchange_gain_loss_account = frappe.get_cached_value(
|
||||
"Company", self.company, "unrealized_exchange_gain_loss_account"
|
||||
)
|
||||
@@ -146,6 +266,130 @@ class ExchangeRateRevaluation(Document):
|
||||
frappe.throw(
|
||||
_("Please set Unrealized Exchange Gain/Loss Account in Company {0}").format(self.company)
|
||||
)
|
||||
return unrealized_exchange_gain_loss_account
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_jv_entries(self):
|
||||
zero_balance_jv = self.make_jv_for_zero_balance()
|
||||
if zero_balance_jv:
|
||||
frappe.msgprint(
|
||||
f"Zero Balance Journal: {get_link_to_form('Journal Entry', zero_balance_jv.name)}"
|
||||
)
|
||||
|
||||
revaluation_jv = self.make_jv_for_revaluation()
|
||||
if revaluation_jv:
|
||||
frappe.msgprint(
|
||||
f"Revaluation Journal: {get_link_to_form('Journal Entry', revaluation_jv.name)}"
|
||||
)
|
||||
|
||||
return {
|
||||
"revaluation_jv": revaluation_jv.name if revaluation_jv else None,
|
||||
"zero_balance_jv": zero_balance_jv.name if zero_balance_jv else None,
|
||||
}
|
||||
|
||||
def make_jv_for_zero_balance(self):
|
||||
if self.gain_loss_booked == 0:
|
||||
return
|
||||
|
||||
accounts = [x for x in self.accounts if x.zero_balance]
|
||||
|
||||
if not accounts:
|
||||
return
|
||||
|
||||
unrealized_exchange_gain_loss_account = self.get_for_unrealized_gain_loss_account()
|
||||
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = "Exchange Gain Or Loss"
|
||||
journal_entry.company = self.company
|
||||
journal_entry.posting_date = self.posting_date
|
||||
journal_entry.multi_currency = 1
|
||||
|
||||
journal_entry_accounts = []
|
||||
for d in accounts:
|
||||
journal_account = frappe._dict(
|
||||
{
|
||||
"account": d.get("account"),
|
||||
"party_type": d.get("party_type"),
|
||||
"party": d.get("party"),
|
||||
"account_currency": d.get("account_currency"),
|
||||
"balance": flt(
|
||||
d.get("balance_in_account_currency"), d.precision("balance_in_account_currency")
|
||||
),
|
||||
"exchange_rate": 0,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"reference_type": "Exchange Rate Revaluation",
|
||||
"reference_name": self.name,
|
||||
}
|
||||
)
|
||||
|
||||
# Account Currency has balance
|
||||
if d.get("balance_in_account_currency") and not d.get("new_balance_in_account_currency"):
|
||||
dr_or_cr = (
|
||||
"credit_in_account_currency"
|
||||
if d.get("balance_in_account_currency") > 0
|
||||
else "debit_in_account_currency"
|
||||
)
|
||||
reverse_dr_or_cr = (
|
||||
"debit_in_account_currency"
|
||||
if dr_or_cr == "credit_in_account_currency"
|
||||
else "credit_in_account_currency"
|
||||
)
|
||||
journal_account.update(
|
||||
{
|
||||
dr_or_cr: flt(
|
||||
abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency")
|
||||
),
|
||||
reverse_dr_or_cr: 0,
|
||||
"debit": 0,
|
||||
"credit": 0,
|
||||
}
|
||||
)
|
||||
elif d.get("balance_in_base_currency") and not d.get("new_balance_in_base_currency"):
|
||||
# Base currency has balance
|
||||
dr_or_cr = "credit" if d.get("balance_in_base_currency") > 0 else "debit"
|
||||
reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
||||
journal_account.update(
|
||||
{
|
||||
dr_or_cr: flt(
|
||||
abs(d.get("balance_in_base_currency")), d.precision("balance_in_base_currency")
|
||||
),
|
||||
reverse_dr_or_cr: 0,
|
||||
"debit_in_account_currency": 0,
|
||||
"credit_in_account_currency": 0,
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry_accounts.append(journal_account)
|
||||
|
||||
journal_entry_accounts.append(
|
||||
{
|
||||
"account": unrealized_exchange_gain_loss_account,
|
||||
"balance": get_balance_on(unrealized_exchange_gain_loss_account),
|
||||
"debit": abs(self.gain_loss_booked) if self.gain_loss_booked < 0 else 0,
|
||||
"credit": abs(self.gain_loss_booked) if self.gain_loss_booked > 0 else 0,
|
||||
"debit_in_account_currency": abs(self.gain_loss_booked) if self.gain_loss_booked < 0 else 0,
|
||||
"credit_in_account_currency": self.gain_loss_booked if self.gain_loss_booked > 0 else 0,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"exchange_rate": 1,
|
||||
"reference_type": "Exchange Rate Revaluation",
|
||||
"reference_name": self.name,
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry.set("accounts", journal_entry_accounts)
|
||||
journal_entry.set_total_debit_credit()
|
||||
journal_entry.save()
|
||||
return journal_entry
|
||||
|
||||
def make_jv_for_revaluation(self):
|
||||
if self.gain_loss_unbooked == 0:
|
||||
return
|
||||
|
||||
accounts = [x for x in self.accounts if not x.zero_balance]
|
||||
if not accounts:
|
||||
return
|
||||
|
||||
unrealized_exchange_gain_loss_account = self.get_for_unrealized_gain_loss_account()
|
||||
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = "Exchange Rate Revaluation"
|
||||
@@ -154,7 +398,7 @@ class ExchangeRateRevaluation(Document):
|
||||
journal_entry.multi_currency = 1
|
||||
|
||||
journal_entry_accounts = []
|
||||
for d in self.accounts:
|
||||
for d in accounts:
|
||||
dr_or_cr = (
|
||||
"debit_in_account_currency"
|
||||
if d.get("balance_in_account_currency") > 0
|
||||
@@ -179,6 +423,7 @@ class ExchangeRateRevaluation(Document):
|
||||
dr_or_cr: flt(
|
||||
abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency")
|
||||
),
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"exchange_rate": flt(d.get("new_exchange_rate"), d.precision("new_exchange_rate")),
|
||||
"reference_type": "Exchange Rate Revaluation",
|
||||
"reference_name": self.name,
|
||||
@@ -196,6 +441,7 @@ class ExchangeRateRevaluation(Document):
|
||||
reverse_dr_or_cr: flt(
|
||||
abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency")
|
||||
),
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"exchange_rate": flt(d.get("current_exchange_rate"), d.precision("current_exchange_rate")),
|
||||
"reference_type": "Exchange Rate Revaluation",
|
||||
"reference_name": self.name,
|
||||
@@ -206,8 +452,11 @@ class ExchangeRateRevaluation(Document):
|
||||
{
|
||||
"account": unrealized_exchange_gain_loss_account,
|
||||
"balance": get_balance_on(unrealized_exchange_gain_loss_account),
|
||||
"debit_in_account_currency": abs(self.total_gain_loss) if self.total_gain_loss < 0 else 0,
|
||||
"credit_in_account_currency": self.total_gain_loss if self.total_gain_loss > 0 else 0,
|
||||
"debit_in_account_currency": abs(self.gain_loss_unbooked)
|
||||
if self.gain_loss_unbooked < 0
|
||||
else 0,
|
||||
"credit_in_account_currency": self.gain_loss_unbooked if self.gain_loss_unbooked > 0 else 0,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"exchange_rate": 1,
|
||||
"reference_type": "Exchange Rate Revaluation",
|
||||
"reference_name": self.name,
|
||||
@@ -217,42 +466,90 @@ class ExchangeRateRevaluation(Document):
|
||||
journal_entry.set("accounts", journal_entry_accounts)
|
||||
journal_entry.set_amounts_in_company_currency()
|
||||
journal_entry.set_total_debit_credit()
|
||||
return journal_entry.as_dict()
|
||||
journal_entry.save()
|
||||
return journal_entry
|
||||
|
||||
|
||||
def calculate_exchange_rate_using_last_gle(company, account, party_type, party):
|
||||
"""
|
||||
Use last GL entry to calculate exchange rate
|
||||
"""
|
||||
last_exchange_rate = None
|
||||
if company and account:
|
||||
gl = qb.DocType("GL Entry")
|
||||
|
||||
# build conditions
|
||||
conditions = []
|
||||
conditions.append(gl.company == company)
|
||||
conditions.append(gl.account == account)
|
||||
conditions.append(gl.is_cancelled == 0)
|
||||
if party_type:
|
||||
conditions.append(gl.party_type == party_type)
|
||||
if party:
|
||||
conditions.append(gl.party == party)
|
||||
|
||||
voucher_type, voucher_no = (
|
||||
qb.from_(gl)
|
||||
.select(gl.voucher_type, gl.voucher_no)
|
||||
.where(Criterion.all(conditions))
|
||||
.orderby(gl.posting_date, order=Order.desc)
|
||||
.limit(1)
|
||||
.run()[0]
|
||||
)
|
||||
|
||||
last_exchange_rate = (
|
||||
qb.from_(gl)
|
||||
.select((gl.debit - gl.credit) / (gl.debit_in_account_currency - gl.credit_in_account_currency))
|
||||
.where(
|
||||
(gl.voucher_type == voucher_type) & (gl.voucher_no == voucher_no) & (gl.account == account)
|
||||
)
|
||||
.orderby(gl.posting_date, order=Order.desc)
|
||||
.limit(1)
|
||||
.run()[0][0]
|
||||
)
|
||||
|
||||
return last_exchange_rate
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_account_details(account, company, posting_date, party_type=None, party=None):
|
||||
def get_account_details(company, posting_date, account, party_type=None, party=None):
|
||||
if not (company and posting_date):
|
||||
frappe.throw(_("Company and Posting Date is mandatory"))
|
||||
|
||||
account_currency, account_type = frappe.get_cached_value(
|
||||
"Account", account, ["account_currency", "account_type"]
|
||||
)
|
||||
|
||||
if account_type in ["Receivable", "Payable"] and not (party_type and party):
|
||||
frappe.throw(_("Party Type and Party is mandatory for {0} account").format(account_type))
|
||||
|
||||
account_details = {}
|
||||
company_currency = erpnext.get_company_currency(company)
|
||||
balance = get_balance_on(
|
||||
account, date=posting_date, party_type=party_type, party=party, in_account_currency=False
|
||||
)
|
||||
|
||||
account_details = {
|
||||
"account_currency": account_currency,
|
||||
}
|
||||
account_balance = ExchangeRateRevaluation.get_account_balance_from_gle(
|
||||
company=company, posting_date=posting_date, account=account, party_type=party_type, party=party
|
||||
)
|
||||
|
||||
if balance:
|
||||
balance_in_account_currency = get_balance_on(
|
||||
account, date=posting_date, party_type=party_type, party=party
|
||||
if account_balance and (
|
||||
account_balance[0].balance or account_balance[0].balance_in_account_currency
|
||||
):
|
||||
account_with_new_balance = ExchangeRateRevaluation.calculate_new_account_balance(
|
||||
company, posting_date, account_balance
|
||||
)
|
||||
current_exchange_rate = (
|
||||
balance / balance_in_account_currency if balance_in_account_currency else 0
|
||||
)
|
||||
new_exchange_rate = get_exchange_rate(account_currency, company_currency, posting_date)
|
||||
new_balance_in_base_currency = balance_in_account_currency * new_exchange_rate
|
||||
account_details = account_details.update(
|
||||
row = account_with_new_balance[0]
|
||||
account_details.update(
|
||||
{
|
||||
"balance_in_base_currency": balance,
|
||||
"balance_in_account_currency": balance_in_account_currency,
|
||||
"current_exchange_rate": current_exchange_rate,
|
||||
"new_exchange_rate": new_exchange_rate,
|
||||
"new_balance_in_base_currency": new_balance_in_base_currency,
|
||||
"balance_in_base_currency": row["balance_in_base_currency"],
|
||||
"balance_in_account_currency": row["balance_in_account_currency"],
|
||||
"current_exchange_rate": row["current_exchange_rate"],
|
||||
"new_exchange_rate": row["new_exchange_rate"],
|
||||
"new_balance_in_base_currency": row["new_balance_in_base_currency"],
|
||||
"new_balance_in_account_currency": row["new_balance_in_account_currency"],
|
||||
"zero_balance": row["zero_balance"],
|
||||
"gain_loss": row["gain_loss"],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -10,14 +10,21 @@
|
||||
"party",
|
||||
"column_break_2",
|
||||
"account_currency",
|
||||
"account_balances",
|
||||
"balance_in_account_currency",
|
||||
"column_break_46yz",
|
||||
"new_balance_in_account_currency",
|
||||
"balances",
|
||||
"current_exchange_rate",
|
||||
"balance_in_base_currency",
|
||||
"column_break_9",
|
||||
"column_break_xown",
|
||||
"new_exchange_rate",
|
||||
"column_break_9",
|
||||
"balance_in_base_currency",
|
||||
"column_break_ukce",
|
||||
"new_balance_in_base_currency",
|
||||
"gain_loss"
|
||||
"section_break_ngrs",
|
||||
"gain_loss",
|
||||
"zero_balance"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -78,7 +85,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_9",
|
||||
"fieldtype": "Column Break"
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "new_exchange_rate",
|
||||
@@ -102,11 +109,45 @@
|
||||
"label": "Gain/Loss",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"description": "This Account has '0' balance in either Base Currency or Account Currency",
|
||||
"fieldname": "zero_balance",
|
||||
"fieldtype": "Check",
|
||||
"label": "Zero Balance"
|
||||
},
|
||||
{
|
||||
"fieldname": "new_balance_in_account_currency",
|
||||
"fieldtype": "Currency",
|
||||
"label": "New Balance In Account Currency",
|
||||
"options": "account_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "account_balances",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_46yz",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_xown",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_ukce",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_ngrs",
|
||||
"fieldtype": "Section Break"
|
||||
}
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-17 10:26:18.302728",
|
||||
"modified": "2022-12-29 19:38:52.915295",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Exchange Rate Revaluation Account",
|
||||
|
||||
@@ -9,10 +9,6 @@ from frappe.model.document import Document
|
||||
from frappe.utils import add_days, add_years, cstr, getdate
|
||||
|
||||
|
||||
class FiscalYearIncorrectDate(frappe.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
class FiscalYear(Document):
|
||||
@frappe.whitelist()
|
||||
def set_as_default(self):
|
||||
@@ -53,23 +49,18 @@ class FiscalYear(Document):
|
||||
)
|
||||
|
||||
def validate_dates(self):
|
||||
self.validate_from_to_dates("year_start_date", "year_end_date")
|
||||
if self.is_short_year:
|
||||
# Fiscal Year can be shorter than one year, in some jurisdictions
|
||||
# under certain circumstances. For example, in the USA and Germany.
|
||||
return
|
||||
|
||||
if getdate(self.year_start_date) > getdate(self.year_end_date):
|
||||
frappe.throw(
|
||||
_("Fiscal Year Start Date should be one year earlier than Fiscal Year End Date"),
|
||||
FiscalYearIncorrectDate,
|
||||
)
|
||||
|
||||
date = getdate(self.year_start_date) + relativedelta(years=1) - relativedelta(days=1)
|
||||
|
||||
if getdate(self.year_end_date) != date:
|
||||
frappe.throw(
|
||||
_("Fiscal Year End Date should be one year after Fiscal Year Start Date"),
|
||||
FiscalYearIncorrectDate,
|
||||
frappe.exceptions.InvalidDates,
|
||||
)
|
||||
|
||||
def on_update(self):
|
||||
@@ -169,5 +160,6 @@ def auto_create_fiscal_year():
|
||||
|
||||
|
||||
def get_from_and_to_date(fiscal_year):
|
||||
fields = ["year_start_date as from_date", "year_end_date as to_date"]
|
||||
return frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)
|
||||
fields = ["year_start_date", "year_end_date"]
|
||||
cached_results = frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)
|
||||
return dict(from_date=cached_results.year_start_date, to_date=cached_results.year_end_date)
|
||||
|
||||
@@ -7,8 +7,6 @@ import unittest
|
||||
import frappe
|
||||
from frappe.utils import now_datetime
|
||||
|
||||
from erpnext.accounts.doctype.fiscal_year.fiscal_year import FiscalYearIncorrectDate
|
||||
|
||||
test_ignore = ["Company"]
|
||||
|
||||
|
||||
@@ -26,7 +24,7 @@ class TestFiscalYear(unittest.TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
self.assertRaises(FiscalYearIncorrectDate, fy.insert)
|
||||
self.assertRaises(frappe.exceptions.InvalidDates, fy.insert)
|
||||
|
||||
|
||||
def test_record_generator():
|
||||
@@ -35,8 +33,8 @@ def test_record_generator():
|
||||
"doctype": "Fiscal Year",
|
||||
"year": "_Test Short Fiscal Year 2011",
|
||||
"is_short_year": 1,
|
||||
"year_end_date": "2011-04-01",
|
||||
"year_start_date": "2011-12-31",
|
||||
"year_start_date": "2011-04-01",
|
||||
"year_end_date": "2011-12-31",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -95,7 +95,15 @@ class GLEntry(Document):
|
||||
)
|
||||
|
||||
# Zero value transaction is not allowed
|
||||
if not (flt(self.debit, self.precision("debit")) or flt(self.credit, self.precision("credit"))):
|
||||
if not (
|
||||
flt(self.debit, self.precision("debit"))
|
||||
or flt(self.credit, self.precision("credit"))
|
||||
or (
|
||||
self.voucher_type == "Journal Entry"
|
||||
and frappe.get_cached_value("Journal Entry", self.voucher_no, "voucher_type")
|
||||
== "Exchange Gain Or Loss"
|
||||
)
|
||||
):
|
||||
frappe.throw(
|
||||
_("{0} {1}: Either debit or credit amount is required for {2}").format(
|
||||
self.voucher_type, self.voucher_no, self.account
|
||||
|
||||
@@ -8,7 +8,7 @@ frappe.provide("erpnext.journal_entry");
|
||||
frappe.ui.form.on("Journal Entry", {
|
||||
setup: function(frm) {
|
||||
frm.add_fetch("bank_account", "account", "account");
|
||||
frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice'];
|
||||
frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry'];
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
"label": "Entry Type",
|
||||
"oldfieldname": "voucher_type",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "Journal Entry\nInter Company Journal Entry\nBank Entry\nCash Entry\nCredit Card Entry\nDebit Note\nCredit Note\nContra Entry\nExcise Entry\nWrite Off Entry\nOpening Entry\nDepreciation Entry\nExchange Rate Revaluation\nDeferred Revenue\nDeferred Expense",
|
||||
"options": "Journal Entry\nInter Company Journal Entry\nBank Entry\nCash Entry\nCredit Card Entry\nDebit Note\nCredit Note\nContra Entry\nExcise Entry\nWrite Off Entry\nOpening Entry\nDepreciation Entry\nExchange Rate Revaluation\nExchange Gain Or Loss\nDeferred Revenue\nDeferred Expense",
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
@@ -137,8 +137,7 @@
|
||||
"fieldname": "finance_book",
|
||||
"fieldtype": "Link",
|
||||
"label": "Finance Book",
|
||||
"options": "Finance Book",
|
||||
"read_only": 1
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname": "2_add_edit_gl_entries",
|
||||
@@ -539,7 +538,7 @@
|
||||
"idx": 176,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-06-23 22:01:32.348337",
|
||||
"modified": "2023-01-17 12:53:53.280620",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Journal Entry",
|
||||
|
||||
@@ -6,7 +6,7 @@ import json
|
||||
|
||||
import frappe
|
||||
from frappe import _, msgprint, scrub
|
||||
from frappe.utils import cint, cstr, flt, fmt_money, formatdate, get_link_to_form, nowdate
|
||||
from frappe.utils import cstr, flt, fmt_money, formatdate, get_link_to_form, nowdate
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.deferred_revenue import get_deferred_booking_accounts
|
||||
@@ -23,6 +23,9 @@ from erpnext.accounts.utils import (
|
||||
get_stock_accounts,
|
||||
get_stock_and_account_balance,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
|
||||
|
||||
@@ -34,9 +37,6 @@ class JournalEntry(AccountsController):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(JournalEntry, self).__init__(*args, **kwargs)
|
||||
|
||||
def get_feed(self):
|
||||
return self.voucher_type
|
||||
|
||||
def validate(self):
|
||||
if self.voucher_type == "Opening Entry":
|
||||
self.is_opening = "Yes"
|
||||
@@ -81,6 +81,7 @@ class JournalEntry(AccountsController):
|
||||
self.check_credit_limit()
|
||||
self.make_gl_entries()
|
||||
self.update_advance_paid()
|
||||
self.update_asset_value()
|
||||
self.update_inter_company_jv()
|
||||
self.update_invoice_discounting()
|
||||
|
||||
@@ -225,6 +226,34 @@ class JournalEntry(AccountsController):
|
||||
for d in to_remove:
|
||||
self.remove(d)
|
||||
|
||||
def update_asset_value(self):
|
||||
if self.voucher_type != "Depreciation Entry":
|
||||
return
|
||||
|
||||
processed_assets = []
|
||||
|
||||
for d in self.get("accounts"):
|
||||
if (
|
||||
d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets
|
||||
):
|
||||
processed_assets.append(d.reference_name)
|
||||
|
||||
asset = frappe.db.get_value(
|
||||
"Asset", d.reference_name, ["calculate_depreciation", "value_after_depreciation"], as_dict=1
|
||||
)
|
||||
|
||||
if asset.calculate_depreciation:
|
||||
continue
|
||||
|
||||
depr_value = d.debit or d.credit
|
||||
|
||||
frappe.db.set_value(
|
||||
"Asset",
|
||||
d.reference_name,
|
||||
"value_after_depreciation",
|
||||
asset.value_after_depreciation - depr_value,
|
||||
)
|
||||
|
||||
def update_inter_company_jv(self):
|
||||
if (
|
||||
self.voucher_type == "Inter Company Journal Entry"
|
||||
@@ -283,19 +312,48 @@ class JournalEntry(AccountsController):
|
||||
d.db_update()
|
||||
|
||||
def unlink_asset_reference(self):
|
||||
if self.voucher_type != "Depreciation Entry":
|
||||
return
|
||||
|
||||
processed_assets = []
|
||||
|
||||
for d in self.get("accounts"):
|
||||
if d.reference_type == "Asset" and d.reference_name:
|
||||
if (
|
||||
d.reference_type == "Asset" and d.reference_name and d.reference_name not in processed_assets
|
||||
):
|
||||
processed_assets.append(d.reference_name)
|
||||
|
||||
asset = frappe.get_doc("Asset", d.reference_name)
|
||||
for s in asset.get("schedules"):
|
||||
if s.journal_entry == self.name:
|
||||
s.db_set("journal_entry", None)
|
||||
|
||||
idx = cint(s.finance_book_id) or 1
|
||||
finance_books = asset.get("finance_books")[idx - 1]
|
||||
finance_books.value_after_depreciation += s.depreciation_amount
|
||||
finance_books.db_update()
|
||||
if asset.calculate_depreciation:
|
||||
je_found = False
|
||||
|
||||
asset.set_status()
|
||||
for row in asset.get("finance_books"):
|
||||
if je_found:
|
||||
break
|
||||
|
||||
depr_schedule = get_depr_schedule(asset.name, "Active", row.finance_book)
|
||||
|
||||
for s in depr_schedule or []:
|
||||
if s.journal_entry == self.name:
|
||||
s.db_set("journal_entry", None)
|
||||
|
||||
row.value_after_depreciation += s.depreciation_amount
|
||||
row.db_update()
|
||||
|
||||
asset.set_status()
|
||||
|
||||
je_found = True
|
||||
break
|
||||
else:
|
||||
depr_value = d.debit or d.credit
|
||||
|
||||
frappe.db.set_value(
|
||||
"Asset",
|
||||
d.reference_name,
|
||||
"value_after_depreciation",
|
||||
asset.value_after_depreciation + depr_value,
|
||||
)
|
||||
|
||||
def unlink_inter_company_jv(self):
|
||||
if (
|
||||
@@ -592,28 +650,30 @@ class JournalEntry(AccountsController):
|
||||
d.against_account = frappe.db.get_value(d.reference_type, d.reference_name, field)
|
||||
else:
|
||||
for d in self.get("accounts"):
|
||||
if flt(d.debit > 0):
|
||||
if flt(d.debit) > 0:
|
||||
accounts_debited.append(d.party or d.account)
|
||||
if flt(d.credit) > 0:
|
||||
accounts_credited.append(d.party or d.account)
|
||||
|
||||
for d in self.get("accounts"):
|
||||
if flt(d.debit > 0):
|
||||
if flt(d.debit) > 0:
|
||||
d.against_account = ", ".join(list(set(accounts_credited)))
|
||||
if flt(d.credit > 0):
|
||||
if flt(d.credit) > 0:
|
||||
d.against_account = ", ".join(list(set(accounts_debited)))
|
||||
|
||||
def validate_debit_credit_amount(self):
|
||||
for d in self.get("accounts"):
|
||||
if not flt(d.debit) and not flt(d.credit):
|
||||
frappe.throw(_("Row {0}: Both Debit and Credit values cannot be zero").format(d.idx))
|
||||
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
|
||||
for d in self.get("accounts"):
|
||||
if not flt(d.debit) and not flt(d.credit):
|
||||
frappe.throw(_("Row {0}: Both Debit and Credit values cannot be zero").format(d.idx))
|
||||
|
||||
def validate_total_debit_and_credit(self):
|
||||
self.set_total_debit_credit()
|
||||
if self.difference:
|
||||
frappe.throw(
|
||||
_("Total Debit must be equal to Total Credit. The difference is {0}").format(self.difference)
|
||||
)
|
||||
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
|
||||
if self.difference:
|
||||
frappe.throw(
|
||||
_("Total Debit must be equal to Total Credit. The difference is {0}").format(self.difference)
|
||||
)
|
||||
|
||||
def set_total_debit_credit(self):
|
||||
self.total_debit, self.total_credit, self.difference = 0, 0, 0
|
||||
@@ -651,16 +711,17 @@ class JournalEntry(AccountsController):
|
||||
self.set_exchange_rate()
|
||||
|
||||
def set_amounts_in_company_currency(self):
|
||||
for d in self.get("accounts"):
|
||||
d.debit_in_account_currency = flt(
|
||||
d.debit_in_account_currency, d.precision("debit_in_account_currency")
|
||||
)
|
||||
d.credit_in_account_currency = flt(
|
||||
d.credit_in_account_currency, d.precision("credit_in_account_currency")
|
||||
)
|
||||
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
|
||||
for d in self.get("accounts"):
|
||||
d.debit_in_account_currency = flt(
|
||||
d.debit_in_account_currency, d.precision("debit_in_account_currency")
|
||||
)
|
||||
d.credit_in_account_currency = flt(
|
||||
d.credit_in_account_currency, d.precision("credit_in_account_currency")
|
||||
)
|
||||
|
||||
d.debit = flt(d.debit_in_account_currency * flt(d.exchange_rate), d.precision("debit"))
|
||||
d.credit = flt(d.credit_in_account_currency * flt(d.exchange_rate), d.precision("credit"))
|
||||
d.debit = flt(d.debit_in_account_currency * flt(d.exchange_rate), d.precision("debit"))
|
||||
d.credit = flt(d.credit_in_account_currency * flt(d.exchange_rate), d.precision("credit"))
|
||||
|
||||
def set_exchange_rate(self):
|
||||
for d in self.get("accounts"):
|
||||
@@ -759,7 +820,7 @@ class JournalEntry(AccountsController):
|
||||
pay_to_recd_from = d.party
|
||||
|
||||
if pay_to_recd_from and pay_to_recd_from == d.party:
|
||||
party_amount += d.debit_in_account_currency or d.credit_in_account_currency
|
||||
party_amount += flt(d.debit_in_account_currency) or flt(d.credit_in_account_currency)
|
||||
party_account_currency = d.account_currency
|
||||
|
||||
elif frappe.get_cached_value("Account", d.account, "account_type") in ["Bank", "Cash"]:
|
||||
@@ -789,7 +850,7 @@ class JournalEntry(AccountsController):
|
||||
def build_gl_map(self):
|
||||
gl_map = []
|
||||
for d in self.get("accounts"):
|
||||
if d.debit or d.credit:
|
||||
if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"):
|
||||
r = [d.user_remark, self.remark]
|
||||
r = [x for x in r if x]
|
||||
remarks = "\n".join(r)
|
||||
@@ -837,7 +898,7 @@ class JournalEntry(AccountsController):
|
||||
make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj, update_outstanding=update_outstanding)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_balance(self):
|
||||
def get_balance(self, difference_account=None):
|
||||
if not self.get("accounts"):
|
||||
msgprint(_("'Entries' cannot be empty"), raise_exception=True)
|
||||
else:
|
||||
@@ -852,7 +913,13 @@ class JournalEntry(AccountsController):
|
||||
blank_row = d
|
||||
|
||||
if not blank_row:
|
||||
blank_row = self.append("accounts", {})
|
||||
blank_row = self.append(
|
||||
"accounts",
|
||||
{
|
||||
"account": difference_account,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
},
|
||||
)
|
||||
|
||||
blank_row.exchange_rate = 1
|
||||
if diff > 0:
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
"depends_on": "paid_from",
|
||||
"fieldname": "paid_from_account_currency",
|
||||
"fieldtype": "Link",
|
||||
"label": "Account Currency",
|
||||
"label": "Account Currency (From)",
|
||||
"options": "Currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1,
|
||||
@@ -249,7 +249,7 @@
|
||||
"depends_on": "paid_from",
|
||||
"fieldname": "paid_from_account_balance",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Account Balance",
|
||||
"label": "Account Balance (From)",
|
||||
"options": "paid_from_account_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
@@ -272,7 +272,7 @@
|
||||
"depends_on": "paid_to",
|
||||
"fieldname": "paid_to_account_currency",
|
||||
"fieldtype": "Link",
|
||||
"label": "Account Currency",
|
||||
"label": "Account Currency (To)",
|
||||
"options": "Currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1,
|
||||
@@ -282,7 +282,7 @@
|
||||
"depends_on": "paid_to",
|
||||
"fieldname": "paid_to_account_balance",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Account Balance",
|
||||
"label": "Account Balance (To)",
|
||||
"options": "paid_to_account_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
@@ -304,7 +304,8 @@
|
||||
{
|
||||
"fieldname": "source_exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Exchange Rate",
|
||||
"label": "Source Exchange Rate",
|
||||
"precision": "9",
|
||||
"print_hide": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
@@ -333,7 +334,8 @@
|
||||
{
|
||||
"fieldname": "target_exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Exchange Rate",
|
||||
"label": "Target Exchange Rate",
|
||||
"precision": "9",
|
||||
"print_hide": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
@@ -631,14 +633,14 @@
|
||||
"depends_on": "eval:doc.party_type == 'Supplier'",
|
||||
"fieldname": "purchase_taxes_and_charges_template",
|
||||
"fieldtype": "Link",
|
||||
"label": "Taxes and Charges Template",
|
||||
"label": "Purchase Taxes and Charges Template",
|
||||
"options": "Purchase Taxes and Charges Template"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: doc.party_type == 'Customer'",
|
||||
"fieldname": "sales_taxes_and_charges_template",
|
||||
"fieldtype": "Link",
|
||||
"label": "Taxes and Charges Template",
|
||||
"label": "Sales Taxes and Charges Template",
|
||||
"options": "Sales Taxes and Charges Template"
|
||||
},
|
||||
{
|
||||
@@ -731,7 +733,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-02-23 20:08:39.559814",
|
||||
"modified": "2023-02-14 04:52:30.478523",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry",
|
||||
|
||||
@@ -247,7 +247,7 @@ class PaymentEntry(AccountsController):
|
||||
self.set_target_exchange_rate(ref_doc)
|
||||
|
||||
def set_source_exchange_rate(self, ref_doc=None):
|
||||
if self.paid_from and not self.source_exchange_rate:
|
||||
if self.paid_from:
|
||||
if self.paid_from_account_currency == self.company_currency:
|
||||
self.source_exchange_rate = 1
|
||||
else:
|
||||
@@ -622,7 +622,7 @@ class PaymentEntry(AccountsController):
|
||||
self.payment_type == "Receive"
|
||||
and self.base_total_allocated_amount < self.base_received_amount + total_deductions
|
||||
and self.total_allocated_amount
|
||||
< self.paid_amount + (total_deductions / self.source_exchange_rate)
|
||||
< flt(self.paid_amount) + (total_deductions / self.source_exchange_rate)
|
||||
):
|
||||
self.unallocated_amount = (
|
||||
self.base_received_amount + total_deductions - self.base_total_allocated_amount
|
||||
@@ -632,7 +632,7 @@ class PaymentEntry(AccountsController):
|
||||
self.payment_type == "Pay"
|
||||
and self.base_total_allocated_amount < (self.base_paid_amount - total_deductions)
|
||||
and self.total_allocated_amount
|
||||
< self.received_amount + (total_deductions / self.target_exchange_rate)
|
||||
< flt(self.received_amount) + (total_deductions / self.target_exchange_rate)
|
||||
):
|
||||
self.unallocated_amount = (
|
||||
self.base_paid_amount - (total_deductions + self.base_total_allocated_amount)
|
||||
@@ -684,35 +684,34 @@ class PaymentEntry(AccountsController):
|
||||
)
|
||||
|
||||
def validate_payment_against_negative_invoice(self):
|
||||
if (self.payment_type == "Pay" and self.party_type == "Customer") or (
|
||||
self.payment_type == "Receive" and self.party_type == "Supplier"
|
||||
if (self.payment_type != "Pay" or self.party_type != "Customer") and (
|
||||
self.payment_type != "Receive" or self.party_type != "Supplier"
|
||||
):
|
||||
return
|
||||
|
||||
total_negative_outstanding = sum(
|
||||
abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0
|
||||
total_negative_outstanding = sum(
|
||||
abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0
|
||||
)
|
||||
|
||||
paid_amount = self.paid_amount if self.payment_type == "Receive" else self.received_amount
|
||||
additional_charges = sum(flt(d.amount) for d in self.deductions)
|
||||
|
||||
if not total_negative_outstanding:
|
||||
if self.party_type == "Customer":
|
||||
msg = _("Cannot pay to Customer without any negative outstanding invoice")
|
||||
else:
|
||||
msg = _("Cannot receive from Supplier without any negative outstanding invoice")
|
||||
|
||||
frappe.throw(msg, InvalidPaymentEntry)
|
||||
|
||||
elif paid_amount - additional_charges > total_negative_outstanding:
|
||||
frappe.throw(
|
||||
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
|
||||
total_negative_outstanding
|
||||
),
|
||||
InvalidPaymentEntry,
|
||||
)
|
||||
|
||||
paid_amount = self.paid_amount if self.payment_type == "Receive" else self.received_amount
|
||||
additional_charges = sum([flt(d.amount) for d in self.deductions])
|
||||
|
||||
if not total_negative_outstanding:
|
||||
frappe.throw(
|
||||
_("Cannot {0} {1} {2} without any negative outstanding invoice").format(
|
||||
_(self.payment_type),
|
||||
(_("to") if self.party_type == "Customer" else _("from")),
|
||||
self.party_type,
|
||||
),
|
||||
InvalidPaymentEntry,
|
||||
)
|
||||
|
||||
elif paid_amount - additional_charges > total_negative_outstanding:
|
||||
frappe.throw(
|
||||
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
|
||||
total_negative_outstanding
|
||||
),
|
||||
InvalidPaymentEntry,
|
||||
)
|
||||
|
||||
def set_title(self):
|
||||
if frappe.flags.in_import and self.title:
|
||||
# do not set title dynamically if title exists during data import.
|
||||
@@ -1188,6 +1187,7 @@ def get_outstanding_reference_documents(args):
|
||||
|
||||
ple = qb.DocType("Payment Ledger Entry")
|
||||
common_filter = []
|
||||
accounting_dimensions_filter = []
|
||||
posting_and_due_date = []
|
||||
|
||||
# confirm that Supplier is not blocked
|
||||
@@ -1217,7 +1217,7 @@ def get_outstanding_reference_documents(args):
|
||||
# Add cost center condition
|
||||
if args.get("cost_center"):
|
||||
condition += " and cost_center='%s'" % args.get("cost_center")
|
||||
common_filter.append(ple.cost_center == args.get("cost_center"))
|
||||
accounting_dimensions_filter.append(ple.cost_center == args.get("cost_center"))
|
||||
|
||||
date_fields_dict = {
|
||||
"posting_date": ["from_posting_date", "to_posting_date"],
|
||||
@@ -1243,6 +1243,7 @@ def get_outstanding_reference_documents(args):
|
||||
posting_date=posting_and_due_date,
|
||||
min_outstanding=args.get("outstanding_amt_greater_than"),
|
||||
max_outstanding=args.get("outstanding_amt_less_than"),
|
||||
accounting_dimensions=accounting_dimensions_filter,
|
||||
)
|
||||
|
||||
outstanding_invoices = split_invoices_based_on_payment_terms(outstanding_invoices)
|
||||
@@ -1639,7 +1640,7 @@ def get_payment_entry(
|
||||
):
|
||||
reference_doc = None
|
||||
doc = frappe.get_doc(dt, dn)
|
||||
if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) > 0:
|
||||
if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) >= 99.99:
|
||||
frappe.throw(_("Can only make payment against unbilled {0}").format(dt))
|
||||
|
||||
if not party_type:
|
||||
@@ -1757,6 +1758,8 @@ def get_payment_entry(
|
||||
pe.setup_party_account_field()
|
||||
pe.set_missing_values()
|
||||
|
||||
update_accounting_dimensions(pe, doc)
|
||||
|
||||
if party_account and bank:
|
||||
pe.set_exchange_rate(ref_doc=reference_doc)
|
||||
pe.set_amounts()
|
||||
@@ -1774,6 +1777,18 @@ def get_payment_entry(
|
||||
return pe
|
||||
|
||||
|
||||
def update_accounting_dimensions(pe, doc):
|
||||
"""
|
||||
Updates accounting dimensions in Payment Entry based on the accounting dimensions in the reference document
|
||||
"""
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
)
|
||||
|
||||
for dimension in get_accounting_dimensions():
|
||||
pe.set(dimension, doc.get(dimension))
|
||||
|
||||
|
||||
def get_bank_cash_account(doc, bank_account):
|
||||
bank = get_default_bank_cash_account(
|
||||
doc.company, "Bank", mode_of_payment=doc.get("mode_of_payment"), account=bank_account
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Type",
|
||||
"options": "DocType",
|
||||
"reqd": 1
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"columns": 2,
|
||||
@@ -35,7 +36,8 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Name",
|
||||
"options": "reference_doctype",
|
||||
"reqd": 1
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "due_date",
|
||||
@@ -104,7 +106,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-26 17:06:55.597389",
|
||||
"modified": "2022-12-12 12:31:44.919895",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry Reference",
|
||||
@@ -113,5 +115,6 @@
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
frappe.ui.form.on('Payment Gateway Account', {
|
||||
refresh(frm) {
|
||||
erpnext.utils.check_payments_app();
|
||||
if(!frm.doc.__islocal) {
|
||||
frm.set_df_property('payment_gateway', 'read_only', 1);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
}
|
||||
|
||||
reconcile() {
|
||||
var show_dialog = this.frm.doc.allocation.filter(d => d.difference_amount && !d.difference_account);
|
||||
var show_dialog = this.frm.doc.allocation.filter(d => d.difference_amount);
|
||||
|
||||
if (show_dialog && show_dialog.length) {
|
||||
|
||||
@@ -179,8 +179,12 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
title: __("Select Difference Account"),
|
||||
fields: [
|
||||
{
|
||||
fieldname: "allocation", fieldtype: "Table", label: __("Allocation"),
|
||||
data: this.data, in_place_edit: true,
|
||||
fieldname: "allocation",
|
||||
fieldtype: "Table",
|
||||
label: __("Allocation"),
|
||||
data: this.data,
|
||||
in_place_edit: true,
|
||||
cannot_add_rows: true,
|
||||
get_data: () => {
|
||||
return this.data;
|
||||
},
|
||||
@@ -218,6 +222,10 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
read_only: 1
|
||||
}]
|
||||
},
|
||||
{
|
||||
fieldtype: 'HTML',
|
||||
options: "<b> New Journal Entry will be posted for the difference amount </b>"
|
||||
}
|
||||
],
|
||||
primary_action: () => {
|
||||
const args = dialog.get_values()["allocation"];
|
||||
@@ -234,7 +242,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
});
|
||||
|
||||
this.frm.doc.allocation.forEach(d => {
|
||||
if (d.difference_amount && !d.difference_account) {
|
||||
if (d.difference_amount) {
|
||||
dialog.fields_dict.allocation.df.data.push({
|
||||
'docname': d.name,
|
||||
'reference_name': d.reference_name,
|
||||
|
||||
@@ -14,7 +14,6 @@ from erpnext.accounts.utils import (
|
||||
QueryPaymentLedger,
|
||||
get_outstanding_invoices,
|
||||
reconcile_against_document,
|
||||
update_reference_in_payment_entry,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import get_advance_payment_entries
|
||||
|
||||
@@ -23,6 +22,7 @@ class PaymentReconciliation(Document):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PaymentReconciliation, self).__init__(*args, **kwargs)
|
||||
self.common_filter_conditions = []
|
||||
self.accounting_dimension_filter_conditions = []
|
||||
self.ple_posting_date_filter = []
|
||||
|
||||
@frappe.whitelist()
|
||||
@@ -69,6 +69,10 @@ class PaymentReconciliation(Document):
|
||||
|
||||
def get_jv_entries(self):
|
||||
condition = self.get_conditions()
|
||||
|
||||
if self.get("cost_center"):
|
||||
condition += f" and t2.cost_center = '{self.cost_center}' "
|
||||
|
||||
dr_or_cr = (
|
||||
"credit_in_account_currency"
|
||||
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||
@@ -79,12 +83,13 @@ class PaymentReconciliation(Document):
|
||||
"t2.against_account like %(bank_cash_account)s" if self.bank_cash_account else "1=1"
|
||||
)
|
||||
|
||||
# nosemgrep
|
||||
journal_entries = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
"Journal Entry" as reference_type, t1.name as reference_name,
|
||||
t1.posting_date, t1.remark as remarks, t2.name as reference_row,
|
||||
{dr_or_cr} as amount, t2.is_advance,
|
||||
{dr_or_cr} as amount, t2.is_advance, t2.exchange_rate,
|
||||
t2.account_currency as currency
|
||||
from
|
||||
`tabJournal Entry` t1, `tabJournal Entry Account` t2
|
||||
@@ -193,6 +198,7 @@ class PaymentReconciliation(Document):
|
||||
posting_date=self.ple_posting_date_filter,
|
||||
min_outstanding=self.minimum_invoice_amount if self.minimum_invoice_amount else None,
|
||||
max_outstanding=self.maximum_invoice_amount if self.maximum_invoice_amount else None,
|
||||
accounting_dimensions=self.accounting_dimension_filter_conditions,
|
||||
)
|
||||
|
||||
if self.invoice_limit:
|
||||
@@ -213,26 +219,26 @@ class PaymentReconciliation(Document):
|
||||
inv.currency = entry.get("currency")
|
||||
inv.outstanding_amount = flt(entry.get("outstanding_amount"))
|
||||
|
||||
def get_difference_amount(self, allocated_entry):
|
||||
if allocated_entry.get("reference_type") != "Payment Entry":
|
||||
return
|
||||
def get_difference_amount(self, payment_entry, invoice, allocated_amount):
|
||||
difference_amount = 0
|
||||
if invoice.get("exchange_rate") and payment_entry.get("exchange_rate", 1) != invoice.get(
|
||||
"exchange_rate", 1
|
||||
):
|
||||
allocated_amount_in_ref_rate = payment_entry.get("exchange_rate", 1) * allocated_amount
|
||||
allocated_amount_in_inv_rate = invoice.get("exchange_rate", 1) * allocated_amount
|
||||
difference_amount = allocated_amount_in_ref_rate - allocated_amount_in_inv_rate
|
||||
|
||||
dr_or_cr = (
|
||||
"credit_in_account_currency"
|
||||
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||
else "debit_in_account_currency"
|
||||
)
|
||||
|
||||
row = self.get_payment_details(allocated_entry, dr_or_cr)
|
||||
|
||||
doc = frappe.get_doc(allocated_entry.reference_type, allocated_entry.reference_name)
|
||||
update_reference_in_payment_entry(row, doc, do_not_save=True)
|
||||
|
||||
return doc.difference_amount
|
||||
return difference_amount
|
||||
|
||||
@frappe.whitelist()
|
||||
def allocate_entries(self, args):
|
||||
self.validate_entries()
|
||||
|
||||
invoice_exchange_map = self.get_invoice_exchange_map(args.get("invoices"), args.get("payments"))
|
||||
default_exchange_gain_loss_account = frappe.get_cached_value(
|
||||
"Company", self.company, "exchange_gain_loss_account"
|
||||
)
|
||||
|
||||
entries = []
|
||||
for pay in args.get("payments"):
|
||||
pay.update({"unreconciled_amount": pay.get("amount")})
|
||||
@@ -246,7 +252,13 @@ class PaymentReconciliation(Document):
|
||||
inv["outstanding_amount"] = flt(inv.get("outstanding_amount")) - flt(pay.get("amount"))
|
||||
pay["amount"] = 0
|
||||
|
||||
res.difference_amount = self.get_difference_amount(res)
|
||||
inv["exchange_rate"] = invoice_exchange_map.get(inv.get("invoice_number"))
|
||||
if pay.get("reference_type") in ["Sales Invoice", "Purchase Invoice"]:
|
||||
pay["exchange_rate"] = invoice_exchange_map.get(pay.get("reference_name"))
|
||||
|
||||
res.difference_amount = self.get_difference_amount(pay, inv, res["allocated_amount"])
|
||||
res.difference_account = default_exchange_gain_loss_account
|
||||
res.exchange_rate = inv.get("exchange_rate")
|
||||
|
||||
if pay.get("amount") == 0:
|
||||
entries.append(res)
|
||||
@@ -276,6 +288,7 @@ class PaymentReconciliation(Document):
|
||||
"amount": pay.get("amount"),
|
||||
"allocated_amount": allocated_amount,
|
||||
"difference_amount": pay.get("difference_amount"),
|
||||
"currency": inv.get("currency"),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -298,7 +311,11 @@ class PaymentReconciliation(Document):
|
||||
else:
|
||||
reconciled_entry = entry_list
|
||||
|
||||
reconciled_entry.append(self.get_payment_details(row, dr_or_cr))
|
||||
payment_details = self.get_payment_details(row, dr_or_cr)
|
||||
reconciled_entry.append(payment_details)
|
||||
|
||||
if payment_details.difference_amount:
|
||||
self.make_difference_entry(payment_details)
|
||||
|
||||
if entry_list:
|
||||
reconcile_against_document(entry_list)
|
||||
@@ -309,6 +326,56 @@ class PaymentReconciliation(Document):
|
||||
msgprint(_("Successfully Reconciled"))
|
||||
self.get_unreconciled_entries()
|
||||
|
||||
def make_difference_entry(self, row):
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = "Exchange Gain Or Loss"
|
||||
journal_entry.company = self.company
|
||||
journal_entry.posting_date = nowdate()
|
||||
journal_entry.multi_currency = 1
|
||||
|
||||
party_account_currency = frappe.get_cached_value(
|
||||
"Account", self.receivable_payable_account, "account_currency"
|
||||
)
|
||||
difference_account_currency = frappe.get_cached_value(
|
||||
"Account", row.difference_account, "account_currency"
|
||||
)
|
||||
|
||||
# Account Currency has balance
|
||||
dr_or_cr = "debit" if self.party_type == "Customer" else "credit"
|
||||
reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
||||
|
||||
journal_account = frappe._dict(
|
||||
{
|
||||
"account": self.receivable_payable_account,
|
||||
"party_type": self.party_type,
|
||||
"party": self.party,
|
||||
"account_currency": party_account_currency,
|
||||
"exchange_rate": 0,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
"reference_type": row.against_voucher_type,
|
||||
"reference_name": row.against_voucher,
|
||||
dr_or_cr: flt(row.difference_amount),
|
||||
dr_or_cr + "_in_account_currency": 0,
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry.append("accounts", journal_account)
|
||||
|
||||
journal_account = frappe._dict(
|
||||
{
|
||||
"account": row.difference_account,
|
||||
"account_currency": difference_account_currency,
|
||||
"exchange_rate": 1,
|
||||
"cost_center": erpnext.get_default_cost_center(self.company),
|
||||
reverse_dr_or_cr + "_in_account_currency": flt(row.difference_amount),
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry.append("accounts", journal_account)
|
||||
|
||||
journal_entry.save()
|
||||
journal_entry.submit()
|
||||
|
||||
def get_payment_details(self, row, dr_or_cr):
|
||||
return frappe._dict(
|
||||
{
|
||||
@@ -318,6 +385,7 @@ class PaymentReconciliation(Document):
|
||||
"against_voucher_type": row.get("invoice_type"),
|
||||
"against_voucher": row.get("invoice_number"),
|
||||
"account": self.receivable_payable_account,
|
||||
"exchange_rate": row.get("exchange_rate"),
|
||||
"party_type": self.party_type,
|
||||
"party": self.party,
|
||||
"is_advance": row.get("is_advance"),
|
||||
@@ -342,6 +410,49 @@ class PaymentReconciliation(Document):
|
||||
if not self.get("payments"):
|
||||
frappe.throw(_("No records found in the Payments table"))
|
||||
|
||||
def get_invoice_exchange_map(self, invoices, payments):
|
||||
sales_invoices = [
|
||||
d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Sales Invoice"
|
||||
]
|
||||
|
||||
sales_invoices.extend(
|
||||
[d.get("reference_name") for d in payments if d.get("reference_type") == "Sales Invoice"]
|
||||
)
|
||||
purchase_invoices = [
|
||||
d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Purchase Invoice"
|
||||
]
|
||||
purchase_invoices.extend(
|
||||
[d.get("reference_name") for d in payments if d.get("reference_type") == "Purchase Invoice"]
|
||||
)
|
||||
|
||||
invoice_exchange_map = frappe._dict()
|
||||
|
||||
if sales_invoices:
|
||||
sales_invoice_map = frappe._dict(
|
||||
frappe.db.get_all(
|
||||
"Sales Invoice",
|
||||
filters={"name": ("in", sales_invoices)},
|
||||
fields=["name", "conversion_rate"],
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
|
||||
invoice_exchange_map.update(sales_invoice_map)
|
||||
|
||||
if purchase_invoices:
|
||||
purchase_invoice_map = frappe._dict(
|
||||
frappe.db.get_all(
|
||||
"Purchase Invoice",
|
||||
filters={"name": ("in", purchase_invoices)},
|
||||
fields=["name", "conversion_rate"],
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
|
||||
invoice_exchange_map.update(purchase_invoice_map)
|
||||
|
||||
return invoice_exchange_map
|
||||
|
||||
def validate_allocation(self):
|
||||
unreconciled_invoices = frappe._dict()
|
||||
|
||||
@@ -375,13 +486,14 @@ class PaymentReconciliation(Document):
|
||||
|
||||
def build_qb_filter_conditions(self, get_invoices=False, get_return_invoices=False):
|
||||
self.common_filter_conditions.clear()
|
||||
self.accounting_dimension_filter_conditions.clear()
|
||||
self.ple_posting_date_filter.clear()
|
||||
ple = qb.DocType("Payment Ledger Entry")
|
||||
|
||||
self.common_filter_conditions.append(ple.company == self.company)
|
||||
|
||||
if self.get("cost_center") and (get_invoices or get_return_invoices):
|
||||
self.common_filter_conditions.append(ple.cost_center == self.cost_center)
|
||||
self.accounting_dimension_filter_conditions.append(ple.cost_center == self.cost_center)
|
||||
|
||||
if get_invoices:
|
||||
if self.from_invoice_date:
|
||||
|
||||
@@ -6,8 +6,10 @@ import unittest
|
||||
import frappe
|
||||
from frappe import qb
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, nowdate
|
||||
from frappe.utils import add_days, flt, nowdate
|
||||
|
||||
from erpnext import get_default_cost_center
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.party import get_party_account
|
||||
@@ -20,6 +22,7 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
self.create_item()
|
||||
self.create_customer()
|
||||
self.create_account()
|
||||
self.create_cost_center()
|
||||
self.clear_old_entries()
|
||||
|
||||
def tearDown(self):
|
||||
@@ -72,33 +75,11 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
self.item = item if isinstance(item, str) else item.item_code
|
||||
|
||||
def create_customer(self):
|
||||
if frappe.db.exists("Customer", "_Test PR Customer"):
|
||||
self.customer = "_Test PR Customer"
|
||||
else:
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = "_Test PR Customer"
|
||||
customer.type = "Individual"
|
||||
customer.save()
|
||||
self.customer = customer.name
|
||||
|
||||
if frappe.db.exists("Customer", "_Test PR Customer 2"):
|
||||
self.customer2 = "_Test PR Customer 2"
|
||||
else:
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = "_Test PR Customer 2"
|
||||
customer.type = "Individual"
|
||||
customer.save()
|
||||
self.customer2 = customer.name
|
||||
|
||||
if frappe.db.exists("Customer", "_Test PR Customer 3"):
|
||||
self.customer3 = "_Test PR Customer 3"
|
||||
else:
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = "_Test PR Customer 3"
|
||||
customer.type = "Individual"
|
||||
customer.default_currency = "EUR"
|
||||
customer.save()
|
||||
self.customer3 = customer.name
|
||||
self.customer = make_customer("_Test PR Customer")
|
||||
self.customer2 = make_customer("_Test PR Customer 2")
|
||||
self.customer3 = make_customer("_Test PR Customer 3", "EUR")
|
||||
self.customer4 = make_customer("_Test PR Customer 4", "EUR")
|
||||
self.customer5 = make_customer("_Test PR Customer 5", "EUR")
|
||||
|
||||
def create_account(self):
|
||||
account_name = "Debtors EUR"
|
||||
@@ -216,6 +197,22 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
)
|
||||
return je
|
||||
|
||||
def create_cost_center(self):
|
||||
# Setup cost center
|
||||
cc_name = "Sub"
|
||||
|
||||
self.main_cc = frappe.get_doc("Cost Center", get_default_cost_center(self.company))
|
||||
|
||||
cc_exists = frappe.db.get_list("Cost Center", filters={"cost_center_name": cc_name})
|
||||
if cc_exists:
|
||||
self.sub_cc = frappe.get_doc("Cost Center", cc_exists[0].name)
|
||||
else:
|
||||
sub_cc = frappe.new_doc("Cost Center")
|
||||
sub_cc.cost_center_name = "Sub"
|
||||
sub_cc.parent_cost_center = self.main_cc.parent_cost_center
|
||||
sub_cc.company = self.main_cc.company
|
||||
self.sub_cc = sub_cc.save()
|
||||
|
||||
def test_filter_min_max(self):
|
||||
# check filter condition minimum and maximum amount
|
||||
self.create_sales_invoice(qty=1, rate=300)
|
||||
@@ -476,6 +473,11 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
invoices = [x.as_dict() for x in pr.get("invoices")]
|
||||
payments = [x.as_dict() for x in pr.get("payments")]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
# Cr Note and Invoice are of the same currency. There shouldn't any difference amount.
|
||||
for row in pr.allocation:
|
||||
self.assertEqual(flt(row.get("difference_amount")), 0.0)
|
||||
|
||||
pr.reconcile()
|
||||
|
||||
pr.get_unreconciled_entries()
|
||||
@@ -509,6 +511,11 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
payments = [x.as_dict() for x in pr.get("payments")]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
pr.allocation[0].allocated_amount = allocated_amount
|
||||
|
||||
# Cr Note and Invoice are of the same currency. There shouldn't any difference amount.
|
||||
for row in pr.allocation:
|
||||
self.assertEqual(flt(row.get("difference_amount")), 0.0)
|
||||
|
||||
pr.reconcile()
|
||||
|
||||
# assert outstanding
|
||||
@@ -578,3 +585,255 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
self.assertEqual(len(pr.payments), 1)
|
||||
self.assertEqual(pr.payments[0].amount, amount)
|
||||
self.assertEqual(pr.payments[0].currency, "EUR")
|
||||
|
||||
def test_difference_amount_via_journal_entry(self):
|
||||
# Make Sale Invoice
|
||||
si = self.create_sales_invoice(
|
||||
qty=1, rate=100, posting_date=nowdate(), do_not_save=True, do_not_submit=True
|
||||
)
|
||||
si.customer = self.customer4
|
||||
si.currency = "EUR"
|
||||
si.conversion_rate = 85
|
||||
si.debit_to = self.debtors_eur
|
||||
si.save().submit()
|
||||
|
||||
# Make payment using Journal Entry
|
||||
je1 = self.create_journal_entry("HDFC - _PR", self.debtors_eur, 100, nowdate())
|
||||
je1.multi_currency = 1
|
||||
je1.accounts[0].exchange_rate = 1
|
||||
je1.accounts[0].credit_in_account_currency = 0
|
||||
je1.accounts[0].credit = 0
|
||||
je1.accounts[0].debit_in_account_currency = 8000
|
||||
je1.accounts[0].debit = 8000
|
||||
je1.accounts[1].party_type = "Customer"
|
||||
je1.accounts[1].party = self.customer4
|
||||
je1.accounts[1].exchange_rate = 80
|
||||
je1.accounts[1].credit_in_account_currency = 100
|
||||
je1.accounts[1].credit = 8000
|
||||
je1.accounts[1].debit_in_account_currency = 0
|
||||
je1.accounts[1].debit = 0
|
||||
je1.save()
|
||||
je1.submit()
|
||||
|
||||
je2 = self.create_journal_entry("HDFC - _PR", self.debtors_eur, 200, nowdate())
|
||||
je2.multi_currency = 1
|
||||
je2.accounts[0].exchange_rate = 1
|
||||
je2.accounts[0].credit_in_account_currency = 0
|
||||
je2.accounts[0].credit = 0
|
||||
je2.accounts[0].debit_in_account_currency = 16000
|
||||
je2.accounts[0].debit = 16000
|
||||
je2.accounts[1].party_type = "Customer"
|
||||
je2.accounts[1].party = self.customer4
|
||||
je2.accounts[1].exchange_rate = 80
|
||||
je2.accounts[1].credit_in_account_currency = 200
|
||||
je1.accounts[1].credit = 16000
|
||||
je1.accounts[1].debit_in_account_currency = 0
|
||||
je1.accounts[1].debit = 0
|
||||
je2.save()
|
||||
je2.submit()
|
||||
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.party = self.customer4
|
||||
pr.receivable_payable_account = self.debtors_eur
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 2)
|
||||
|
||||
# Test exact payment allocation
|
||||
invoices = [x.as_dict() for x in pr.invoices]
|
||||
payments = [pr.payments[0].as_dict()]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
self.assertEqual(pr.allocation[0].allocated_amount, 100)
|
||||
self.assertEqual(pr.allocation[0].difference_amount, -500)
|
||||
|
||||
# Test partial payment allocation (with excess payment entry)
|
||||
pr.set("allocation", [])
|
||||
pr.get_unreconciled_entries()
|
||||
invoices = [x.as_dict() for x in pr.invoices]
|
||||
payments = [pr.payments[1].as_dict()]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
pr.allocation[0].difference_account = "Exchange Gain/Loss - _PR"
|
||||
|
||||
self.assertEqual(pr.allocation[0].allocated_amount, 100)
|
||||
self.assertEqual(pr.allocation[0].difference_amount, -500)
|
||||
|
||||
# Check if difference journal entry gets generated for difference amount after reconciliation
|
||||
pr.reconcile()
|
||||
total_debit_amount = frappe.db.get_all(
|
||||
"Journal Entry Account",
|
||||
{"account": self.debtors_eur, "docstatus": 1, "reference_name": si.name},
|
||||
"sum(debit) as amount",
|
||||
group_by="reference_name",
|
||||
)[0].amount
|
||||
|
||||
self.assertEqual(flt(total_debit_amount, 2), -500)
|
||||
|
||||
def test_difference_amount_via_payment_entry(self):
|
||||
# Make Sale Invoice
|
||||
si = self.create_sales_invoice(
|
||||
qty=1, rate=100, posting_date=nowdate(), do_not_save=True, do_not_submit=True
|
||||
)
|
||||
si.customer = self.customer5
|
||||
si.currency = "EUR"
|
||||
si.conversion_rate = 85
|
||||
si.debit_to = self.debtors_eur
|
||||
si.save().submit()
|
||||
|
||||
# Make payment using Payment Entry
|
||||
pe1 = create_payment_entry(
|
||||
company=self.company,
|
||||
payment_type="Receive",
|
||||
party_type="Customer",
|
||||
party=self.customer5,
|
||||
paid_from=self.debtors_eur,
|
||||
paid_to=self.bank,
|
||||
paid_amount=100,
|
||||
)
|
||||
|
||||
pe1.source_exchange_rate = 80
|
||||
pe1.received_amount = 8000
|
||||
pe1.save()
|
||||
pe1.submit()
|
||||
|
||||
pe2 = create_payment_entry(
|
||||
company=self.company,
|
||||
payment_type="Receive",
|
||||
party_type="Customer",
|
||||
party=self.customer5,
|
||||
paid_from=self.debtors_eur,
|
||||
paid_to=self.bank,
|
||||
paid_amount=200,
|
||||
)
|
||||
|
||||
pe2.source_exchange_rate = 80
|
||||
pe2.received_amount = 16000
|
||||
pe2.save()
|
||||
pe2.submit()
|
||||
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.party = self.customer5
|
||||
pr.receivable_payable_account = self.debtors_eur
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 2)
|
||||
|
||||
invoices = [x.as_dict() for x in pr.invoices]
|
||||
payments = [pr.payments[0].as_dict()]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
self.assertEqual(pr.allocation[0].allocated_amount, 100)
|
||||
self.assertEqual(pr.allocation[0].difference_amount, -500)
|
||||
|
||||
pr.set("allocation", [])
|
||||
pr.get_unreconciled_entries()
|
||||
invoices = [x.as_dict() for x in pr.invoices]
|
||||
payments = [pr.payments[1].as_dict()]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
self.assertEqual(pr.allocation[0].allocated_amount, 100)
|
||||
self.assertEqual(pr.allocation[0].difference_amount, -500)
|
||||
|
||||
def test_differing_cost_center_on_invoice_and_payment(self):
|
||||
"""
|
||||
Cost Center filter should not affect outstanding amount calculation
|
||||
"""
|
||||
|
||||
si = self.create_sales_invoice(qty=1, rate=100, do_not_submit=True)
|
||||
si.cost_center = self.main_cc.name
|
||||
si.submit()
|
||||
pr = get_payment_entry(si.doctype, si.name)
|
||||
pr.cost_center = self.sub_cc.name
|
||||
pr = pr.save().submit()
|
||||
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.cost_center = self.main_cc.name
|
||||
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
# check PR tool output
|
||||
self.assertEqual(len(pr.get("invoices")), 0)
|
||||
self.assertEqual(len(pr.get("payments")), 0)
|
||||
|
||||
def test_cost_center_filter_on_vouchers(self):
|
||||
"""
|
||||
Test Cost Center filter is applied on Invoices, Payment Entries and Journals
|
||||
"""
|
||||
transaction_date = nowdate()
|
||||
rate = 100
|
||||
|
||||
# 'Main - PR' Cost Center
|
||||
si1 = self.create_sales_invoice(
|
||||
qty=1, rate=rate, posting_date=transaction_date, do_not_submit=True
|
||||
)
|
||||
si1.cost_center = self.main_cc.name
|
||||
si1.submit()
|
||||
|
||||
pe1 = self.create_payment_entry(posting_date=transaction_date, amount=rate)
|
||||
pe1.cost_center = self.main_cc.name
|
||||
pe1 = pe1.save().submit()
|
||||
|
||||
je1 = self.create_journal_entry(self.bank, self.debit_to, 100, transaction_date)
|
||||
je1.accounts[0].cost_center = self.main_cc.name
|
||||
je1.accounts[1].cost_center = self.main_cc.name
|
||||
je1.accounts[1].party_type = "Customer"
|
||||
je1.accounts[1].party = self.customer
|
||||
je1 = je1.save().submit()
|
||||
|
||||
# 'Sub - PR' Cost Center
|
||||
si2 = self.create_sales_invoice(
|
||||
qty=1, rate=rate, posting_date=transaction_date, do_not_submit=True
|
||||
)
|
||||
si2.cost_center = self.sub_cc.name
|
||||
si2.submit()
|
||||
|
||||
pe2 = self.create_payment_entry(posting_date=transaction_date, amount=rate)
|
||||
pe2.cost_center = self.sub_cc.name
|
||||
pe2 = pe2.save().submit()
|
||||
|
||||
je2 = self.create_journal_entry(self.bank, self.debit_to, 100, transaction_date)
|
||||
je2.accounts[0].cost_center = self.sub_cc.name
|
||||
je2.accounts[1].cost_center = self.sub_cc.name
|
||||
je2.accounts[1].party_type = "Customer"
|
||||
je2.accounts[1].party = self.customer
|
||||
je2 = je2.save().submit()
|
||||
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.cost_center = self.main_cc.name
|
||||
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
# check PR tool output
|
||||
self.assertEqual(len(pr.get("invoices")), 1)
|
||||
self.assertEqual(pr.get("invoices")[0].get("invoice_number"), si1.name)
|
||||
self.assertEqual(len(pr.get("payments")), 2)
|
||||
payment_vouchers = [x.get("reference_name") for x in pr.get("payments")]
|
||||
self.assertCountEqual(payment_vouchers, [pe1.name, je1.name])
|
||||
|
||||
# Change cost center
|
||||
pr.cost_center = self.sub_cc.name
|
||||
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
# check PR tool output
|
||||
self.assertEqual(len(pr.get("invoices")), 1)
|
||||
self.assertEqual(pr.get("invoices")[0].get("invoice_number"), si2.name)
|
||||
self.assertEqual(len(pr.get("payments")), 2)
|
||||
payment_vouchers = [x.get("reference_name") for x in pr.get("payments")]
|
||||
self.assertCountEqual(payment_vouchers, [je2.name, pe2.name])
|
||||
|
||||
|
||||
def make_customer(customer_name, currency=None):
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = customer_name
|
||||
customer.type = "Individual"
|
||||
|
||||
if currency:
|
||||
customer.default_currency = currency
|
||||
customer.save()
|
||||
return customer.name
|
||||
else:
|
||||
return customer_name
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
"section_break_5",
|
||||
"difference_amount",
|
||||
"column_break_7",
|
||||
"difference_account"
|
||||
"difference_account",
|
||||
"exchange_rate",
|
||||
"currency"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -37,7 +39,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Allocated Amount",
|
||||
"options": "Currency",
|
||||
"options": "currency",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -112,7 +114,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Unreconciled Amount",
|
||||
"options": "Currency",
|
||||
"options": "currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -120,7 +122,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Amount",
|
||||
"options": "Currency",
|
||||
"options": "currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@@ -129,11 +131,24 @@
|
||||
"hidden": 1,
|
||||
"label": "Reference Row",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"label": "Currency",
|
||||
"options": "Currency"
|
||||
},
|
||||
{
|
||||
"fieldname": "exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Exchange Rate",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-10-06 11:48:59.616562",
|
||||
"modified": "2022-12-24 21:01:14.882747",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Reconciliation Allocation",
|
||||
@@ -141,5 +156,6 @@
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -11,7 +11,8 @@
|
||||
"col_break1",
|
||||
"amount",
|
||||
"outstanding_amount",
|
||||
"currency"
|
||||
"currency",
|
||||
"exchange_rate"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -62,11 +63,17 @@
|
||||
"hidden": 1,
|
||||
"label": "Currency",
|
||||
"options": "Currency"
|
||||
},
|
||||
{
|
||||
"fieldname": "exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 1,
|
||||
"label": "Exchange Rate"
|
||||
}
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-08-24 22:42:40.923179",
|
||||
"modified": "2022-11-08 18:18:02.502149",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Reconciliation Invoice",
|
||||
@@ -75,5 +82,6 @@
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -15,7 +15,8 @@
|
||||
"difference_amount",
|
||||
"sec_break1",
|
||||
"remark",
|
||||
"currency"
|
||||
"currency",
|
||||
"exchange_rate"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -91,11 +92,17 @@
|
||||
"label": "Difference Amount",
|
||||
"options": "currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 1,
|
||||
"label": "Exchange Rate"
|
||||
}
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-08-30 10:51:48.140062",
|
||||
"modified": "2022-11-08 18:18:36.268760",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Reconciliation Payment",
|
||||
@@ -103,5 +110,6 @@
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -42,7 +42,7 @@ frappe.ui.form.on("Payment Request", "refresh", function(frm) {
|
||||
});
|
||||
}
|
||||
|
||||
if(!frm.doc.payment_gateway_account && frm.doc.status == "Initiated") {
|
||||
if((!frm.doc.payment_gateway_account || frm.doc.payment_request_type == "Outward") && frm.doc.status == "Initiated") {
|
||||
frm.add_custom_button(__('Create Payment Entry'), function(){
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_entry",
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
"iban",
|
||||
"branch_code",
|
||||
"swift_number",
|
||||
"accounting_dimensions_section",
|
||||
"cost_center",
|
||||
"dimension_col_break",
|
||||
"project",
|
||||
"recipient_and_message",
|
||||
"print_format",
|
||||
"email_to",
|
||||
@@ -362,13 +366,35 @@
|
||||
"label": "Payment Channel",
|
||||
"options": "\nEmail\nPhone",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
"fieldname": "accounting_dimensions_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Accounting Dimensions"
|
||||
},
|
||||
{
|
||||
"fieldname": "cost_center",
|
||||
"fieldtype": "Link",
|
||||
"label": "Cost Center",
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"fieldname": "dimension_col_break",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"label": "Project",
|
||||
"options": "Project"
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-09-30 16:19:43.680025",
|
||||
"modified": "2022-12-21 16:56:40.115737",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Request",
|
||||
|
||||
@@ -9,8 +9,10 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import flt, get_url, nowdate
|
||||
from frappe.utils.background_jobs import enqueue
|
||||
from payments.utils import get_payment_gateway_controller
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
)
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import (
|
||||
get_company_defaults,
|
||||
get_payment_entry,
|
||||
@@ -19,6 +21,14 @@ from erpnext.accounts.doctype.subscription_plan.subscription_plan import get_pla
|
||||
from erpnext.accounts.party import get_party_account, get_party_bank_account
|
||||
from erpnext.accounts.utils import get_account_currency
|
||||
from erpnext.erpnext_integrations.stripe_integration import create_stripe_subscription
|
||||
from erpnext.utilities import payment_app_import_guard
|
||||
|
||||
|
||||
def _get_payment_gateway_controller(*args, **kwargs):
|
||||
with payment_app_import_guard():
|
||||
from payments.utils import get_payment_gateway_controller
|
||||
|
||||
return get_payment_gateway_controller(*args, **kwargs)
|
||||
|
||||
|
||||
class PaymentRequest(Document):
|
||||
@@ -35,21 +45,20 @@ class PaymentRequest(Document):
|
||||
frappe.throw(_("To create a Payment Request reference document is required"))
|
||||
|
||||
def validate_payment_request_amount(self):
|
||||
existing_payment_request_amount = get_existing_payment_request_amount(
|
||||
self.reference_doctype, self.reference_name
|
||||
existing_payment_request_amount = flt(
|
||||
get_existing_payment_request_amount(self.reference_doctype, self.reference_name)
|
||||
)
|
||||
|
||||
if existing_payment_request_amount:
|
||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||
if hasattr(ref_doc, "order_type") and getattr(ref_doc, "order_type") != "Shopping Cart":
|
||||
ref_amount = get_amount(ref_doc, self.payment_account)
|
||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||
if not hasattr(ref_doc, "order_type") or getattr(ref_doc, "order_type") != "Shopping Cart":
|
||||
ref_amount = get_amount(ref_doc, self.payment_account)
|
||||
|
||||
if existing_payment_request_amount + flt(self.grand_total) > ref_amount:
|
||||
frappe.throw(
|
||||
_("Total Payment Request amount cannot be greater than {0} amount").format(
|
||||
self.reference_doctype
|
||||
)
|
||||
if existing_payment_request_amount + flt(self.grand_total) > ref_amount:
|
||||
frappe.throw(
|
||||
_("Total Payment Request amount cannot be greater than {0} amount").format(
|
||||
self.reference_doctype
|
||||
)
|
||||
)
|
||||
|
||||
def validate_currency(self):
|
||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||
@@ -107,7 +116,7 @@ class PaymentRequest(Document):
|
||||
self.request_phone_payment()
|
||||
|
||||
def request_phone_payment(self):
|
||||
controller = get_payment_gateway_controller(self.payment_gateway)
|
||||
controller = _get_payment_gateway_controller(self.payment_gateway)
|
||||
request_amount = self.get_request_amount()
|
||||
|
||||
payment_record = dict(
|
||||
@@ -156,7 +165,7 @@ class PaymentRequest(Document):
|
||||
|
||||
def payment_gateway_validation(self):
|
||||
try:
|
||||
controller = get_payment_gateway_controller(self.payment_gateway)
|
||||
controller = _get_payment_gateway_controller(self.payment_gateway)
|
||||
if hasattr(controller, "on_payment_request_submission"):
|
||||
return controller.on_payment_request_submission(self)
|
||||
else:
|
||||
@@ -189,7 +198,7 @@ class PaymentRequest(Document):
|
||||
)
|
||||
data.update({"company": frappe.defaults.get_defaults().company})
|
||||
|
||||
controller = get_payment_gateway_controller(self.payment_gateway)
|
||||
controller = _get_payment_gateway_controller(self.payment_gateway)
|
||||
controller.validate_transaction_currency(self.currency)
|
||||
|
||||
if hasattr(controller, "validate_minimum_transaction_amount"):
|
||||
@@ -254,6 +263,7 @@ class PaymentRequest(Document):
|
||||
|
||||
payment_entry.update(
|
||||
{
|
||||
"mode_of_payment": self.mode_of_payment,
|
||||
"reference_no": self.name,
|
||||
"reference_date": nowdate(),
|
||||
"remarks": "Payment Entry against {0} {1} via Payment Request {2}".format(
|
||||
@@ -262,6 +272,17 @@ class PaymentRequest(Document):
|
||||
}
|
||||
)
|
||||
|
||||
# Update dimensions
|
||||
payment_entry.update(
|
||||
{
|
||||
"cost_center": self.get("cost_center"),
|
||||
"project": self.get("project"),
|
||||
}
|
||||
)
|
||||
|
||||
for dimension in get_accounting_dimensions():
|
||||
payment_entry.update({dimension: self.get(dimension)})
|
||||
|
||||
if payment_entry.difference_amount:
|
||||
company_details = get_company_defaults(ref_doc.company)
|
||||
|
||||
@@ -403,25 +424,22 @@ def make_payment_request(**args):
|
||||
else ""
|
||||
)
|
||||
|
||||
existing_payment_request = None
|
||||
if args.order_type == "Shopping Cart":
|
||||
existing_payment_request = frappe.db.get_value(
|
||||
"Payment Request",
|
||||
{"reference_doctype": args.dt, "reference_name": args.dn, "docstatus": ("!=", 2)},
|
||||
)
|
||||
draft_payment_request = frappe.db.get_value(
|
||||
"Payment Request",
|
||||
{"reference_doctype": args.dt, "reference_name": args.dn, "docstatus": 0},
|
||||
)
|
||||
|
||||
if existing_payment_request:
|
||||
existing_payment_request_amount = get_existing_payment_request_amount(args.dt, args.dn)
|
||||
|
||||
if existing_payment_request_amount:
|
||||
grand_total -= existing_payment_request_amount
|
||||
|
||||
if draft_payment_request:
|
||||
frappe.db.set_value(
|
||||
"Payment Request", existing_payment_request, "grand_total", grand_total, update_modified=False
|
||||
"Payment Request", draft_payment_request, "grand_total", grand_total, update_modified=False
|
||||
)
|
||||
pr = frappe.get_doc("Payment Request", existing_payment_request)
|
||||
pr = frappe.get_doc("Payment Request", draft_payment_request)
|
||||
else:
|
||||
if args.order_type != "Shopping Cart":
|
||||
existing_payment_request_amount = get_existing_payment_request_amount(args.dt, args.dn)
|
||||
|
||||
if existing_payment_request_amount:
|
||||
grand_total -= existing_payment_request_amount
|
||||
|
||||
pr = frappe.new_doc("Payment Request")
|
||||
pr.update(
|
||||
{
|
||||
@@ -444,6 +462,17 @@ def make_payment_request(**args):
|
||||
}
|
||||
)
|
||||
|
||||
# Update dimensions
|
||||
pr.update(
|
||||
{
|
||||
"cost_center": ref_doc.get("cost_center"),
|
||||
"project": ref_doc.get("project"),
|
||||
}
|
||||
)
|
||||
|
||||
for dimension in get_accounting_dimensions():
|
||||
pr.update({dimension: ref_doc.get(dimension)})
|
||||
|
||||
if args.order_type == "Shopping Cart" or args.mute_email:
|
||||
pr.flags.mute_email = True
|
||||
|
||||
|
||||
@@ -675,7 +675,7 @@ def get_bin_qty(item_code, warehouse):
|
||||
|
||||
def get_pos_reserved_qty(item_code, warehouse):
|
||||
reserved_qty = frappe.db.sql(
|
||||
"""select sum(p_item.qty) as qty
|
||||
"""select sum(p_item.stock_qty) as qty
|
||||
from `tabPOS Invoice` p, `tabPOS Invoice Item` p_item
|
||||
where p.name = p_item.parent
|
||||
and ifnull(p.consolidated_invoice, '') = ''
|
||||
|
||||
@@ -472,7 +472,7 @@
|
||||
"description": "If rate is zero them item will be treated as \"Free Item\"",
|
||||
"fieldname": "free_item_rate",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Rate"
|
||||
"label": "Free Item Rate"
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
@@ -608,7 +608,7 @@
|
||||
"icon": "fa fa-gift",
|
||||
"idx": 1,
|
||||
"links": [],
|
||||
"modified": "2022-10-13 19:05:35.056304",
|
||||
"modified": "2023-02-14 04:53:34.887358",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Pricing Rule",
|
||||
|
||||
@@ -10,7 +10,7 @@ import re
|
||||
import frappe
|
||||
from frappe import _, throw
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint, flt, getdate
|
||||
from frappe.utils import cint, flt
|
||||
|
||||
apply_on_dict = {"Item Code": "items", "Item Group": "item_groups", "Brand": "brands"}
|
||||
|
||||
@@ -184,8 +184,7 @@ class PricingRule(Document):
|
||||
if self.is_cumulative and not (self.valid_from and self.valid_upto):
|
||||
frappe.throw(_("Valid from and valid upto fields are mandatory for the cumulative"))
|
||||
|
||||
if self.valid_from and self.valid_upto and getdate(self.valid_from) > getdate(self.valid_upto):
|
||||
frappe.throw(_("Valid from date must be less than valid upto date"))
|
||||
self.validate_from_to_dates("valid_from", "valid_upto")
|
||||
|
||||
def validate_condition(self):
|
||||
if (
|
||||
@@ -256,7 +255,7 @@ def apply_pricing_rule(args, doc=None):
|
||||
for item in item_list:
|
||||
args_copy = copy.deepcopy(args)
|
||||
args_copy.update(item)
|
||||
data = get_pricing_rule_for_item(args_copy, item.get("price_list_rate"), doc=doc)
|
||||
data = get_pricing_rule_for_item(args_copy, doc=doc)
|
||||
out.append(data)
|
||||
|
||||
if (
|
||||
@@ -293,7 +292,7 @@ def update_pricing_rule_uom(pricing_rule, args):
|
||||
pricing_rule.uom = row.uom
|
||||
|
||||
|
||||
def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=False):
|
||||
def get_pricing_rule_for_item(args, doc=None, for_validate=False):
|
||||
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||
get_applied_pricing_rules,
|
||||
get_pricing_rule_items,
|
||||
|
||||
@@ -1123,7 +1123,7 @@ def make_pricing_rule(**args):
|
||||
"apply_on": args.apply_on or "Item Code",
|
||||
"applicable_for": args.applicable_for,
|
||||
"selling": args.selling or 0,
|
||||
"currency": "USD",
|
||||
"currency": "INR",
|
||||
"apply_discount_on_rate": args.apply_discount_on_rate or 0,
|
||||
"buying": args.buying or 0,
|
||||
"min_qty": args.min_qty or 0.0,
|
||||
|
||||
@@ -250,6 +250,22 @@ def get_other_conditions(conditions, values, args):
|
||||
and ifnull(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
||||
values["transaction_date"] = args.get("transaction_date")
|
||||
|
||||
if args.get("doctype") in [
|
||||
"Quotation",
|
||||
"Quotation Item",
|
||||
"Sales Order",
|
||||
"Sales Order Item",
|
||||
"Delivery Note",
|
||||
"Delivery Note Item",
|
||||
"Sales Invoice",
|
||||
"Sales Invoice Item",
|
||||
"POS Invoice",
|
||||
"POS Invoice Item",
|
||||
]:
|
||||
conditions += """ and ifnull(`tabPricing Rule`.selling, 0) = 1"""
|
||||
else:
|
||||
conditions += """ and ifnull(`tabPricing Rule`.buying, 0) = 1"""
|
||||
|
||||
return conditions
|
||||
|
||||
|
||||
@@ -669,13 +685,23 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None):
|
||||
item_details.free_item_data.append(free_item_data_args)
|
||||
|
||||
|
||||
def apply_pricing_rule_for_free_items(doc, pricing_rule_args, set_missing_values=False):
|
||||
def apply_pricing_rule_for_free_items(doc, pricing_rule_args):
|
||||
if pricing_rule_args:
|
||||
items = tuple((d.item_code, d.pricing_rules) for d in doc.items if d.is_free_item)
|
||||
args = {(d["item_code"], d["pricing_rules"]): d for d in pricing_rule_args}
|
||||
|
||||
for args in pricing_rule_args:
|
||||
if not items or (args.get("item_code"), args.get("pricing_rules")) not in items:
|
||||
doc.append("items", args)
|
||||
for item in doc.items:
|
||||
if not item.is_free_item:
|
||||
continue
|
||||
|
||||
free_item_data = args.get((item.item_code, item.pricing_rules))
|
||||
if free_item_data:
|
||||
free_item_data.pop("item_name")
|
||||
free_item_data.pop("description")
|
||||
item.update(free_item_data)
|
||||
args.pop((item.item_code, item.pricing_rules))
|
||||
|
||||
for free_item in args.values():
|
||||
doc.append("items", free_item)
|
||||
|
||||
|
||||
def get_pricing_rule_items(pr_doc, other_items=False) -> list:
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
<br>
|
||||
{% endif %}
|
||||
|
||||
{{ _("Against") }}: {{ row.against }}
|
||||
<br>{{ _("Remarks") }}: {{ row.remarks }}
|
||||
{% if row.bill_no %}
|
||||
<br>{{ _("Supplier Invoice No") }}: {{ row.bill_no }}
|
||||
|
||||
@@ -64,12 +64,13 @@
|
||||
"tax_withholding_net_total",
|
||||
"base_tax_withholding_net_total",
|
||||
"taxes_section",
|
||||
"tax_category",
|
||||
"taxes_and_charges",
|
||||
"column_break_58",
|
||||
"tax_category",
|
||||
"column_break_49",
|
||||
"shipping_rule",
|
||||
"column_break_49",
|
||||
"incoterm",
|
||||
"named_place",
|
||||
"section_break_51",
|
||||
"taxes",
|
||||
"totals",
|
||||
@@ -1425,6 +1426,7 @@
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "apply_tds",
|
||||
"fieldname": "tax_withholding_net_total",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
@@ -1434,12 +1436,13 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "apply_tds",
|
||||
"fieldname": "base_tax_withholding_net_total",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 1,
|
||||
"label": "Base Tax Withholding Net Total",
|
||||
"no_copy": 1,
|
||||
"options": "currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -1541,13 +1544,19 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Incoterm",
|
||||
"options": "Incoterm"
|
||||
},
|
||||
{
|
||||
"depends_on": "incoterm",
|
||||
"fieldname": "named_place",
|
||||
"fieldtype": "Data",
|
||||
"label": "Named Place"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-file-text",
|
||||
"idx": 204,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-25 12:44:29.935567",
|
||||
"modified": "2023-01-28 19:18:56.586321",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice",
|
||||
|
||||
@@ -231,7 +231,9 @@ class PurchaseInvoice(BuyingController):
|
||||
)
|
||||
|
||||
if (
|
||||
cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate")) and not self.is_return
|
||||
cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate"))
|
||||
and not self.is_return
|
||||
and not self.is_internal_supplier
|
||||
):
|
||||
self.validate_rate_with_reference_doc(
|
||||
[
|
||||
|
||||
@@ -7,7 +7,6 @@ import frappe
|
||||
from frappe import _, qb
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.utils.background_jobs import is_job_queued
|
||||
|
||||
from erpnext.accounts.utils import _delete_pl_entries, create_payment_ledger_entry
|
||||
|
||||
@@ -27,7 +26,7 @@ def start_payment_ledger_repost(docname=None):
|
||||
"""
|
||||
if docname:
|
||||
repost_doc = frappe.get_doc("Repost Payment Ledger", docname)
|
||||
if repost_doc.docstatus == 1 and repost_doc.repost_status in ["Queued", "Failed"]:
|
||||
if repost_doc.docstatus.is_submitted() and repost_doc.repost_status in ["Queued", "Failed"]:
|
||||
try:
|
||||
for entry in repost_doc.repost_vouchers:
|
||||
doc = frappe.get_doc(entry.voucher_type, entry.voucher_no)
|
||||
@@ -102,10 +101,9 @@ def execute_repost_payment_ledger(docname):
|
||||
|
||||
job_name = "payment_ledger_repost_" + docname
|
||||
|
||||
if not is_job_queued(job_name):
|
||||
frappe.enqueue(
|
||||
method="erpnext.accounts.doctype.repost_payment_ledger.repost_payment_ledger.start_payment_ledger_repost",
|
||||
docname=docname,
|
||||
is_async=True,
|
||||
job_name=job_name,
|
||||
)
|
||||
frappe.enqueue(
|
||||
method="erpnext.accounts.doctype.repost_payment_ledger.repost_payment_ledger.start_payment_ledger_repost",
|
||||
docname=docname,
|
||||
is_async=True,
|
||||
job_name=job_name,
|
||||
)
|
||||
|
||||
@@ -61,12 +61,13 @@
|
||||
"total",
|
||||
"net_total",
|
||||
"taxes_section",
|
||||
"tax_category",
|
||||
"taxes_and_charges",
|
||||
"column_break_38",
|
||||
"shipping_rule",
|
||||
"incoterm",
|
||||
"column_break_55",
|
||||
"tax_category",
|
||||
"incoterm",
|
||||
"named_place",
|
||||
"section_break_40",
|
||||
"taxes",
|
||||
"section_break_43",
|
||||
@@ -921,6 +922,7 @@
|
||||
"fieldtype": "Table",
|
||||
"hide_days": 1,
|
||||
"hide_seconds": 1,
|
||||
"label": "Sales Taxes and Charges",
|
||||
"oldfieldname": "other_charges",
|
||||
"oldfieldtype": "Table",
|
||||
"options": "Sales Taxes and Charges"
|
||||
@@ -1774,6 +1776,8 @@
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"fetch_from": "sales_partner.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
"fieldtype": "Float",
|
||||
"hide_days": 1,
|
||||
@@ -2121,6 +2125,12 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Incoterm",
|
||||
"options": "Incoterm"
|
||||
},
|
||||
{
|
||||
"depends_on": "incoterm",
|
||||
"fieldname": "named_place",
|
||||
"fieldtype": "Data",
|
||||
"label": "Named Place"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-file-text",
|
||||
@@ -2133,7 +2143,7 @@
|
||||
"link_fieldname": "consolidated_invoice"
|
||||
}
|
||||
],
|
||||
"modified": "2022-11-17 17:17:10.883487",
|
||||
"modified": "2023-01-28 19:45:47.538163",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice",
|
||||
|
||||
@@ -1185,11 +1185,24 @@ class SalesInvoice(SellingController):
|
||||
if asset.calculate_depreciation:
|
||||
posting_date = frappe.db.get_value("Sales Invoice", self.return_against, "posting_date")
|
||||
reverse_depreciation_entry_made_after_disposal(asset, posting_date)
|
||||
reset_depreciation_schedule(asset, self.posting_date)
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was returned after being sold through Sales Invoice {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
reset_depreciation_schedule(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
else:
|
||||
if asset.calculate_depreciation:
|
||||
depreciate_asset(asset, self.posting_date)
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was sold through Sales Invoice {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
|
||||
@@ -21,6 +21,9 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_inter_comp
|
||||
from erpnext.accounts.utils import PaymentEntryUnlinkError
|
||||
from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries
|
||||
from erpnext.assets.doctype.asset.test_asset import create_asset, create_asset_data
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import update_invoice_status
|
||||
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
|
||||
from erpnext.exceptions import InvalidAccountCurrency, InvalidCurrency
|
||||
@@ -1166,6 +1169,46 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
frappe.db.sql("delete from `tabPOS Profile`")
|
||||
|
||||
def test_bin_details_of_packed_item(self):
|
||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
# test Update Items with product bundle
|
||||
if not frappe.db.exists("Item", "_Test Product Bundle Item New"):
|
||||
bundle_item = make_item("_Test Product Bundle Item New", {"is_stock_item": 0})
|
||||
bundle_item.append(
|
||||
"item_defaults", {"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"}
|
||||
)
|
||||
bundle_item.save(ignore_permissions=True)
|
||||
|
||||
make_item("_Packed Item New 1", {"is_stock_item": 1})
|
||||
make_product_bundle("_Test Product Bundle Item New", ["_Packed Item New 1"], 2)
|
||||
|
||||
si = create_sales_invoice(
|
||||
item_code="_Test Product Bundle Item New",
|
||||
update_stock=1,
|
||||
warehouse="_Test Warehouse - _TC",
|
||||
transaction_date=add_days(nowdate(), -1),
|
||||
do_not_submit=1,
|
||||
)
|
||||
|
||||
make_stock_entry(item="_Packed Item New 1", target="_Test Warehouse - _TC", qty=120, rate=100)
|
||||
|
||||
bin_details = frappe.db.get_value(
|
||||
"Bin",
|
||||
{"item_code": "_Packed Item New 1", "warehouse": "_Test Warehouse - _TC"},
|
||||
["actual_qty", "projected_qty", "ordered_qty"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
si.transaction_date = nowdate()
|
||||
si.save()
|
||||
|
||||
packed_item = si.packed_items[0]
|
||||
self.assertEqual(flt(bin_details.actual_qty), flt(packed_item.actual_qty))
|
||||
self.assertEqual(flt(bin_details.projected_qty), flt(packed_item.projected_qty))
|
||||
self.assertEqual(flt(bin_details.ordered_qty), flt(packed_item.ordered_qty))
|
||||
|
||||
def test_pos_si_without_payment(self):
|
||||
make_pos_profile()
|
||||
|
||||
@@ -2774,7 +2817,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
["2021-09-30", 5041.1, 26407.22],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
@@ -2805,7 +2848,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
expected_values = [["2020-12-31", 30000, 30000], ["2021-12-31", 30000, 60000]]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
@@ -2834,7 +2877,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
["2025-06-06", 18633.88, 100000.0, False],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
|
||||
@@ -890,7 +890,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-02 12:53:12.693217",
|
||||
"modified": "2022-12-28 16:17:33.484531",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Item",
|
||||
|
||||
@@ -280,7 +280,8 @@ class Subscription(Document):
|
||||
self.validate_plans_billing_cycle(self.get_billing_cycle_and_interval())
|
||||
self.validate_end_date()
|
||||
self.validate_to_follow_calendar_months()
|
||||
self.cost_center = erpnext.get_default_cost_center(self.get("company"))
|
||||
if not self.cost_center:
|
||||
self.cost_center = erpnext.get_default_cost_center(self.get("company"))
|
||||
|
||||
def validate_trial_period(self):
|
||||
"""
|
||||
|
||||
@@ -5,5 +5,9 @@ frappe.ui.form.on('Subscription Plan', {
|
||||
price_determination: function(frm) {
|
||||
frm.toggle_reqd("cost", frm.doc.price_determination === 'Fixed rate');
|
||||
frm.toggle_reqd("price_list", frm.doc.price_determination === 'Based on price list');
|
||||
}
|
||||
},
|
||||
|
||||
subscription_plan: function (frm) {
|
||||
erpnext.utils.check_payments_app();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ class TaxRule(Document):
|
||||
|
||||
def validate(self):
|
||||
self.validate_tax_template()
|
||||
self.validate_date()
|
||||
self.validate_from_to_dates("from_date", "to_date")
|
||||
self.validate_filters()
|
||||
self.validate_use_for_shopping_cart()
|
||||
|
||||
@@ -51,10 +51,6 @@ class TaxRule(Document):
|
||||
if not (self.sales_tax_template or self.purchase_tax_template):
|
||||
frappe.throw(_("Tax Template is mandatory."))
|
||||
|
||||
def validate_date(self):
|
||||
if self.from_date and self.to_date and self.from_date > self.to_date:
|
||||
frappe.throw(_("From Date cannot be greater than To Date"))
|
||||
|
||||
def validate_filters(self):
|
||||
filters = {
|
||||
"tax_type": self.tax_type,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "autoincrement",
|
||||
"autoname": "hash",
|
||||
"creation": "2022-09-13 16:18:59.404842",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
@@ -36,11 +36,11 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-09-13 23:40:41.479208",
|
||||
"modified": "2023-01-13 13:40:41.479208",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Tax Withheld Vouchers",
|
||||
"naming_rule": "Autoincrement",
|
||||
"naming_rule": "Random",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
|
||||
@@ -121,12 +121,24 @@ def get_party_tax_withholding_details(inv, tax_withholding_category=None):
|
||||
else:
|
||||
tax_row = get_tax_row_for_tcs(inv, tax_details, tax_amount, tax_deducted)
|
||||
|
||||
cost_center = get_cost_center(inv)
|
||||
tax_row.update({"cost_center": cost_center})
|
||||
|
||||
if inv.doctype == "Purchase Invoice":
|
||||
return tax_row, tax_deducted_on_advances, voucher_wise_amount
|
||||
else:
|
||||
return tax_row
|
||||
|
||||
|
||||
def get_cost_center(inv):
|
||||
cost_center = frappe.get_cached_value("Company", inv.company, "cost_center")
|
||||
|
||||
if len(inv.get("taxes", [])) > 0:
|
||||
cost_center = inv.get("taxes")[0].cost_center
|
||||
|
||||
return cost_center
|
||||
|
||||
|
||||
def get_tax_withholding_details(tax_withholding_category, posting_date, company):
|
||||
tax_withholding = frappe.get_doc("Tax Withholding Category", tax_withholding_category)
|
||||
|
||||
@@ -247,9 +259,7 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N
|
||||
if tax_deducted:
|
||||
net_total = inv.tax_withholding_net_total
|
||||
if ldc:
|
||||
tax_amount = get_tds_amount_from_ldc(
|
||||
ldc, parties, pan_no, tax_details, posting_date, net_total
|
||||
)
|
||||
tax_amount = get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total)
|
||||
else:
|
||||
tax_amount = net_total * tax_details.rate / 100 if net_total > 0 else 0
|
||||
|
||||
@@ -400,12 +410,26 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers):
|
||||
tds_amount = 0
|
||||
invoice_filters = {"name": ("in", vouchers), "docstatus": 1, "apply_tds": 1}
|
||||
|
||||
## for TDS to be deducted on advances
|
||||
payment_entry_filters = {
|
||||
"party_type": "Supplier",
|
||||
"party": ("in", parties),
|
||||
"docstatus": 1,
|
||||
"apply_tax_withholding_amount": 1,
|
||||
"unallocated_amount": (">", 0),
|
||||
"posting_date": ["between", (tax_details.from_date, tax_details.to_date)],
|
||||
"tax_withholding_category": tax_details.get("tax_withholding_category"),
|
||||
}
|
||||
|
||||
field = "sum(tax_withholding_net_total)"
|
||||
|
||||
if cint(tax_details.consider_party_ledger_amount):
|
||||
invoice_filters.pop("apply_tds", None)
|
||||
field = "sum(grand_total)"
|
||||
|
||||
payment_entry_filters.pop("apply_tax_withholding_amount", None)
|
||||
payment_entry_filters.pop("tax_withholding_category", None)
|
||||
|
||||
supp_credit_amt = frappe.db.get_value("Purchase Invoice", invoice_filters, field) or 0.0
|
||||
|
||||
supp_jv_credit_amt = (
|
||||
@@ -417,14 +441,28 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers):
|
||||
"party": ("in", parties),
|
||||
"reference_type": ("!=", "Purchase Invoice"),
|
||||
},
|
||||
"sum(credit_in_account_currency)",
|
||||
"sum(credit_in_account_currency - debit_in_account_currency)",
|
||||
)
|
||||
or 0.0
|
||||
)
|
||||
|
||||
# Get Amount via payment entry
|
||||
payment_entry_amounts = frappe.db.get_all(
|
||||
"Payment Entry",
|
||||
filters=payment_entry_filters,
|
||||
fields=["sum(unallocated_amount) as amount", "payment_type"],
|
||||
group_by="payment_type",
|
||||
)
|
||||
|
||||
supp_credit_amt += supp_jv_credit_amt
|
||||
supp_credit_amt += inv.tax_withholding_net_total
|
||||
|
||||
for type in payment_entry_amounts:
|
||||
if type.payment_type == "Pay":
|
||||
supp_credit_amt += type.amount
|
||||
else:
|
||||
supp_credit_amt -= type.amount
|
||||
|
||||
threshold = tax_details.get("threshold", 0)
|
||||
cumulative_threshold = tax_details.get("cumulative_threshold", 0)
|
||||
|
||||
@@ -526,7 +564,7 @@ def get_invoice_total_without_tcs(inv, tax_details):
|
||||
return inv.grand_total - tcs_tax_row_amount
|
||||
|
||||
|
||||
def get_tds_amount_from_ldc(ldc, parties, pan_no, tax_details, posting_date, net_total):
|
||||
def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total):
|
||||
tds_amount = 0
|
||||
limit_consumed = frappe.db.get_value(
|
||||
"Purchase Invoice",
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
||||
def setUpClass(self):
|
||||
# create relevant supplier, etc
|
||||
create_records()
|
||||
create_tax_with_holding_category()
|
||||
create_tax_withholding_category_records()
|
||||
|
||||
def tearDown(self):
|
||||
cancel_invoices()
|
||||
@@ -38,7 +38,7 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
||||
pi = create_purchase_invoice(supplier="Test TDS Supplier")
|
||||
pi.submit()
|
||||
|
||||
# assert equal tax deduction on total invoice amount uptil now
|
||||
# assert equal tax deduction on total invoice amount until now
|
||||
self.assertEqual(pi.taxes_and_charges_deducted, 3000)
|
||||
self.assertEqual(pi.grand_total, 7000)
|
||||
invoices.append(pi)
|
||||
@@ -47,7 +47,7 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
||||
pi = create_purchase_invoice(supplier="Test TDS Supplier", rate=5000)
|
||||
pi.submit()
|
||||
|
||||
# assert equal tax deduction on total invoice amount uptil now
|
||||
# assert equal tax deduction on total invoice amount until now
|
||||
self.assertEqual(pi.taxes_and_charges_deducted, 500)
|
||||
invoices.append(pi)
|
||||
|
||||
@@ -130,7 +130,7 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
||||
invoices.append(si)
|
||||
|
||||
# create another invoice whose total when added to previously created invoice,
|
||||
# surpasses cumulative threshhold
|
||||
# surpasses cumulative threshold
|
||||
si = create_sales_invoice(customer="Test TCS Customer", rate=12000)
|
||||
si.submit()
|
||||
|
||||
@@ -329,6 +329,38 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
||||
for d in reversed(invoices):
|
||||
d.cancel()
|
||||
|
||||
def test_tax_withholding_via_payment_entry_for_advances(self):
|
||||
frappe.db.set_value(
|
||||
"Supplier", "Test TDS Supplier7", "tax_withholding_category", "Advance TDS Category"
|
||||
)
|
||||
|
||||
# create payment entry
|
||||
pe1 = create_payment_entry(
|
||||
payment_type="Pay", party_type="Supplier", party="Test TDS Supplier7", paid_amount=4000
|
||||
)
|
||||
pe1.submit()
|
||||
|
||||
self.assertFalse(pe1.get("taxes"))
|
||||
|
||||
pe2 = create_payment_entry(
|
||||
payment_type="Pay", party_type="Supplier", party="Test TDS Supplier7", paid_amount=4000
|
||||
)
|
||||
pe2.submit()
|
||||
|
||||
self.assertFalse(pe2.get("taxes"))
|
||||
|
||||
pe3 = create_payment_entry(
|
||||
payment_type="Pay", party_type="Supplier", party="Test TDS Supplier7", paid_amount=4000
|
||||
)
|
||||
pe3.apply_tax_withholding_amount = 1
|
||||
pe3.save()
|
||||
pe3.submit()
|
||||
|
||||
self.assertEquals(pe3.get("taxes")[0].tax_amount, 1200)
|
||||
pe1.cancel()
|
||||
pe2.cancel()
|
||||
pe3.cancel()
|
||||
|
||||
|
||||
def cancel_invoices():
|
||||
purchase_invoices = frappe.get_all(
|
||||
@@ -450,6 +482,32 @@ def create_sales_invoice(**args):
|
||||
return si
|
||||
|
||||
|
||||
def create_payment_entry(**args):
|
||||
# return payment entry doc object
|
||||
args = frappe._dict(args)
|
||||
pe = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Payment Entry",
|
||||
"posting_date": today(),
|
||||
"payment_type": args.payment_type,
|
||||
"party_type": args.party_type,
|
||||
"party": args.party,
|
||||
"company": "_Test Company",
|
||||
"paid_from": "Cash - _TC",
|
||||
"paid_to": "Creditors - _TC",
|
||||
"paid_amount": args.paid_amount or 10000,
|
||||
"received_amount": args.paid_amount or 10000,
|
||||
"reference_no": args.reference_no or "12345",
|
||||
"reference_date": today(),
|
||||
"paid_from_account_currency": "INR",
|
||||
"paid_to_account_currency": "INR",
|
||||
}
|
||||
)
|
||||
|
||||
pe.save()
|
||||
return pe
|
||||
|
||||
|
||||
def create_records():
|
||||
# create a new suppliers
|
||||
for name in [
|
||||
@@ -460,6 +518,7 @@ def create_records():
|
||||
"Test TDS Supplier4",
|
||||
"Test TDS Supplier5",
|
||||
"Test TDS Supplier6",
|
||||
"Test TDS Supplier7",
|
||||
]:
|
||||
if frappe.db.exists("Supplier", name):
|
||||
continue
|
||||
@@ -530,142 +589,129 @@ def create_records():
|
||||
).insert()
|
||||
|
||||
|
||||
def create_tax_with_holding_category():
|
||||
def create_tax_withholding_category_records():
|
||||
fiscal_year = get_fiscal_year(today(), company="_Test Company")
|
||||
from_date = fiscal_year[1]
|
||||
to_date = fiscal_year[2]
|
||||
|
||||
# Cumulative threshold
|
||||
if not frappe.db.exists("Tax Withholding Category", "Cumulative Threshold TDS"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Cumulative Threshold TDS",
|
||||
"category_name": "10% TDS",
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 0,
|
||||
"cumulative_threshold": 30000.00,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
create_tax_withholding_category(
|
||||
category_name="Cumulative Threshold TDS",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=0,
|
||||
cumulative_threshold=30000.00,
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Tax Withholding Category", "Cumulative Threshold TCS"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Cumulative Threshold TCS",
|
||||
"category_name": "10% TCS",
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 0,
|
||||
"cumulative_threshold": 30000.00,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TCS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
# Category for TCS
|
||||
create_tax_withholding_category(
|
||||
category_name="Cumulative Threshold TCS",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TCS - _TC",
|
||||
single_threshold=0,
|
||||
cumulative_threshold=30000.00,
|
||||
)
|
||||
|
||||
# Single thresold
|
||||
if not frappe.db.exists("Tax Withholding Category", "Single Threshold TDS"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Single Threshold TDS",
|
||||
"category_name": "10% TDS",
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 20000.00,
|
||||
"cumulative_threshold": 0,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
# Single threshold
|
||||
create_tax_withholding_category(
|
||||
category_name="Single Threshold TDS",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=20000,
|
||||
cumulative_threshold=0,
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Tax Withholding Category", "New TDS Category"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "New TDS Category",
|
||||
"category_name": "New TDS Category",
|
||||
"round_off_tax_amount": 1,
|
||||
"consider_party_ledger_amount": 1,
|
||||
"tax_on_excess_amount": 1,
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 0,
|
||||
"cumulative_threshold": 30000,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
create_tax_withholding_category(
|
||||
category_name="New TDS Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=0,
|
||||
cumulative_threshold=30000,
|
||||
round_off_tax_amount=1,
|
||||
consider_party_ledger_amount=1,
|
||||
tax_on_excess_amount=1,
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Tax Withholding Category", "Test Service Category"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Test Service Category",
|
||||
"category_name": "Test Service Category",
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 2000,
|
||||
"cumulative_threshold": 2000,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
create_tax_withholding_category(
|
||||
category_name="Test Service Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=2000,
|
||||
cumulative_threshold=2000,
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Tax Withholding Category", "Test Goods Category"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Test Goods Category",
|
||||
"category_name": "Test Goods Category",
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 2000,
|
||||
"cumulative_threshold": 2000,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
}
|
||||
).insert()
|
||||
create_tax_withholding_category(
|
||||
category_name="Test Goods Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=2000,
|
||||
cumulative_threshold=2000,
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Tax Withholding Category", "Test Multi Invoice Category"):
|
||||
create_tax_withholding_category(
|
||||
category_name="Test Multi Invoice Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=5000,
|
||||
cumulative_threshold=10000,
|
||||
)
|
||||
|
||||
create_tax_withholding_category(
|
||||
category_name="Advance TDS Category",
|
||||
rate=10,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
account="TDS - _TC",
|
||||
single_threshold=5000,
|
||||
cumulative_threshold=10000,
|
||||
consider_party_ledger_amount=1,
|
||||
)
|
||||
|
||||
|
||||
def create_tax_withholding_category(
|
||||
category_name,
|
||||
rate,
|
||||
from_date,
|
||||
to_date,
|
||||
account,
|
||||
single_threshold=0,
|
||||
cumulative_threshold=0,
|
||||
round_off_tax_amount=0,
|
||||
consider_party_ledger_amount=0,
|
||||
tax_on_excess_amount=0,
|
||||
):
|
||||
if not frappe.db.exists("Tax Withholding Category", category_name):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Tax Withholding Category",
|
||||
"name": "Test Multi Invoice Category",
|
||||
"category_name": "Test Multi Invoice Category",
|
||||
"name": category_name,
|
||||
"category_name": category_name,
|
||||
"round_off_tax_amount": round_off_tax_amount,
|
||||
"consider_party_ledger_amount": consider_party_ledger_amount,
|
||||
"tax_on_excess_amount": tax_on_excess_amount,
|
||||
"rates": [
|
||||
{
|
||||
"from_date": fiscal_year[1],
|
||||
"to_date": fiscal_year[2],
|
||||
"tax_withholding_rate": 10,
|
||||
"single_threshold": 5000,
|
||||
"cumulative_threshold": 10000,
|
||||
"from_date": from_date,
|
||||
"to_date": to_date,
|
||||
"tax_withholding_rate": rate,
|
||||
"single_threshold": single_threshold,
|
||||
"cumulative_threshold": cumulative_threshold,
|
||||
}
|
||||
],
|
||||
"accounts": [{"company": "_Test Company", "account": "TDS - _TC"}],
|
||||
"accounts": [{"company": "_Test Company", "account": account}],
|
||||
}
|
||||
).insert()
|
||||
|
||||
@@ -199,7 +199,14 @@ def merge_similar_entries(gl_map, precision=None):
|
||||
|
||||
# filter zero debit and credit entries
|
||||
merged_gl_map = filter(
|
||||
lambda x: flt(x.debit, precision) != 0 or flt(x.credit, precision) != 0, merged_gl_map
|
||||
lambda x: flt(x.debit, precision) != 0
|
||||
or flt(x.credit, precision) != 0
|
||||
or (
|
||||
x.voucher_type == "Journal Entry"
|
||||
and frappe.get_cached_value("Journal Entry", x.voucher_no, "voucher_type")
|
||||
== "Exchange Gain Or Loss"
|
||||
),
|
||||
merged_gl_map,
|
||||
)
|
||||
merged_gl_map = list(merged_gl_map)
|
||||
|
||||
@@ -350,15 +357,26 @@ def process_debit_credit_difference(gl_map):
|
||||
allowance = get_debit_credit_allowance(voucher_type, precision)
|
||||
|
||||
debit_credit_diff = get_debit_credit_difference(gl_map, precision)
|
||||
|
||||
if abs(debit_credit_diff) > allowance:
|
||||
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
|
||||
if not (
|
||||
voucher_type == "Journal Entry"
|
||||
and frappe.get_cached_value("Journal Entry", voucher_no, "voucher_type")
|
||||
== "Exchange Gain Or Loss"
|
||||
):
|
||||
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
|
||||
|
||||
elif abs(debit_credit_diff) >= (1.0 / (10**precision)):
|
||||
make_round_off_gle(gl_map, debit_credit_diff, precision)
|
||||
|
||||
debit_credit_diff = get_debit_credit_difference(gl_map, precision)
|
||||
if abs(debit_credit_diff) > allowance:
|
||||
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
|
||||
if not (
|
||||
voucher_type == "Journal Entry"
|
||||
and frappe.get_cached_value("Journal Entry", voucher_no, "voucher_type")
|
||||
== "Exchange Gain Or Loss"
|
||||
):
|
||||
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
|
||||
|
||||
|
||||
def get_debit_credit_difference(gl_map, precision):
|
||||
|
||||
@@ -211,7 +211,13 @@ def set_address_details(
|
||||
else:
|
||||
party_details.update(get_company_address(company))
|
||||
|
||||
if doctype and doctype in ["Delivery Note", "Sales Invoice", "Sales Order", "Quotation"]:
|
||||
if doctype and doctype in [
|
||||
"Delivery Note",
|
||||
"Sales Invoice",
|
||||
"Sales Order",
|
||||
"Quotation",
|
||||
"POS Invoice",
|
||||
]:
|
||||
if party_details.company_address:
|
||||
party_details.update(
|
||||
get_fetch_values(doctype, "company_address", party_details.company_address)
|
||||
@@ -544,7 +550,7 @@ def get_due_date_from_template(template_name, posting_date, bill_date):
|
||||
elif term.due_date_based_on == "Day(s) after the end of the invoice month":
|
||||
due_date = max(due_date, add_days(get_last_day(due_date), term.credit_days))
|
||||
else:
|
||||
due_date = max(due_date, add_months(get_last_day(due_date), term.credit_months))
|
||||
due_date = max(due_date, get_last_day(add_months(due_date, term.credit_months)))
|
||||
return due_date
|
||||
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ class ReceivablePayableReport(object):
|
||||
# Get return entries
|
||||
self.get_return_entries()
|
||||
|
||||
# Get Exchange Rate Revaluations
|
||||
self.get_exchange_rate_revaluations()
|
||||
|
||||
self.data = []
|
||||
|
||||
for ple in self.ple_entries:
|
||||
@@ -251,7 +254,8 @@ class ReceivablePayableReport(object):
|
||||
row.invoice_grand_total = row.invoiced
|
||||
|
||||
if (abs(row.outstanding) > 1.0 / 10**self.currency_precision) and (
|
||||
abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision
|
||||
(abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision)
|
||||
or (row.voucher_no in self.err_journals)
|
||||
):
|
||||
|
||||
# non-zero oustanding, we must consider this row
|
||||
@@ -794,19 +798,19 @@ class ReceivablePayableReport(object):
|
||||
|
||||
if self.filters.get("payment_terms_template"):
|
||||
self.qb_selection_filter.append(
|
||||
self.ple.party_isin(
|
||||
qb.from_(self.customer).where(
|
||||
self.customer.payment_terms == self.filters.get("payment_terms_template")
|
||||
)
|
||||
self.ple.party.isin(
|
||||
qb.from_(self.customer)
|
||||
.select(self.customer.name)
|
||||
.where(self.customer.payment_terms == self.filters.get("payment_terms_template"))
|
||||
)
|
||||
)
|
||||
|
||||
if self.filters.get("sales_partner"):
|
||||
self.qb_selection_filter.append(
|
||||
self.ple.party_isin(
|
||||
qb.from_(self.customer).where(
|
||||
self.customer.default_sales_partner == self.filters.get("payment_terms_template")
|
||||
)
|
||||
self.ple.party.isin(
|
||||
qb.from_(self.customer)
|
||||
.select(self.customer.name)
|
||||
.where(self.customer.default_sales_partner == self.filters.get("sales_partner"))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -865,10 +869,15 @@ class ReceivablePayableReport(object):
|
||||
def get_party_details(self, party):
|
||||
if not party in self.party_details:
|
||||
if self.party_type == "Customer":
|
||||
fields = ["customer_name", "territory", "customer_group", "customer_primary_contact"]
|
||||
|
||||
if self.filters.get("sales_partner"):
|
||||
fields.append("default_sales_partner")
|
||||
|
||||
self.party_details[party] = frappe.db.get_value(
|
||||
"Customer",
|
||||
party,
|
||||
["customer_name", "territory", "customer_group", "customer_primary_contact"],
|
||||
fields,
|
||||
as_dict=True,
|
||||
)
|
||||
else:
|
||||
@@ -969,6 +978,9 @@ class ReceivablePayableReport(object):
|
||||
if self.filters.show_sales_person:
|
||||
self.add_column(label=_("Sales Person"), fieldname="sales_person", fieldtype="Data")
|
||||
|
||||
if self.filters.sales_partner:
|
||||
self.add_column(label=_("Sales Partner"), fieldname="default_sales_partner", fieldtype="Data")
|
||||
|
||||
if self.filters.party_type == "Supplier":
|
||||
self.add_column(
|
||||
label=_("Supplier Group"),
|
||||
@@ -1028,3 +1040,17 @@ class ReceivablePayableReport(object):
|
||||
"data": {"labels": self.ageing_column_labels, "datasets": rows},
|
||||
"type": "percentage",
|
||||
}
|
||||
|
||||
def get_exchange_rate_revaluations(self):
|
||||
je = qb.DocType("Journal Entry")
|
||||
results = (
|
||||
qb.from_(je)
|
||||
.select(je.name)
|
||||
.where(
|
||||
(je.company == self.filters.company)
|
||||
& (je.posting_date.lte(self.filters.report_date))
|
||||
& (je.voucher_type == "Exchange Rate Revaluation")
|
||||
)
|
||||
.run()
|
||||
)
|
||||
self.err_journals = [x[0] for x in results] if results else []
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, getdate, today
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
from frappe.utils import add_days, flt, getdate, today
|
||||
|
||||
from erpnext import get_default_cost_center
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute
|
||||
@@ -17,10 +18,37 @@ class TestAccountsReceivable(FrappeTestCase):
|
||||
frappe.db.sql("delete from `tabPayment Entry` where company='_Test Company 2'")
|
||||
frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 2'")
|
||||
frappe.db.sql("delete from `tabPayment Ledger Entry` where company='_Test Company 2'")
|
||||
frappe.db.sql("delete from `tabJournal Entry` where company='_Test Company 2'")
|
||||
frappe.db.sql("delete from `tabExchange Rate Revaluation` where company='_Test Company 2'")
|
||||
|
||||
self.create_usd_account()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
||||
|
||||
def create_usd_account(self):
|
||||
name = "Debtors USD"
|
||||
exists = frappe.db.get_list(
|
||||
"Account", filters={"company": "_Test Company 2", "account_name": "Debtors USD"}
|
||||
)
|
||||
if exists:
|
||||
self.debtors_usd = exists[0].name
|
||||
else:
|
||||
debtors = frappe.get_doc(
|
||||
"Account",
|
||||
frappe.db.get_list(
|
||||
"Account", filters={"company": "_Test Company 2", "account_name": "Debtors"}
|
||||
)[0].name,
|
||||
)
|
||||
|
||||
debtors_usd = frappe.new_doc("Account")
|
||||
debtors_usd.company = debtors.company
|
||||
debtors_usd.account_name = "Debtors USD"
|
||||
debtors_usd.account_currency = "USD"
|
||||
debtors_usd.parent_account = debtors.parent_account
|
||||
debtors_usd.account_type = debtors.account_type
|
||||
self.debtors_usd = debtors_usd.save().name
|
||||
|
||||
def test_accounts_receivable(self):
|
||||
filters = {
|
||||
"company": "_Test Company 2",
|
||||
@@ -33,7 +61,7 @@ class TestAccountsReceivable(FrappeTestCase):
|
||||
}
|
||||
|
||||
# check invoice grand total and invoiced column's value for 3 payment terms
|
||||
name = make_sales_invoice()
|
||||
name = make_sales_invoice().name
|
||||
report = execute(filters)
|
||||
|
||||
expected_data = [[100, 30], [100, 50], [100, 20]]
|
||||
@@ -118,8 +146,72 @@ class TestAccountsReceivable(FrappeTestCase):
|
||||
],
|
||||
)
|
||||
|
||||
@change_settings(
|
||||
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
|
||||
)
|
||||
def test_exchange_revaluation_for_party(self):
|
||||
"""
|
||||
Exchange Revaluation for party on Receivable/Payable shoule be included
|
||||
"""
|
||||
|
||||
def make_sales_invoice():
|
||||
company = "_Test Company 2"
|
||||
customer = "_Test Customer 2"
|
||||
|
||||
# Using Exchange Gain/Loss account for unrealized as well.
|
||||
company_doc = frappe.get_doc("Company", company)
|
||||
company_doc.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account
|
||||
company_doc.save()
|
||||
|
||||
si = make_sales_invoice(no_payment_schedule=True, do_not_submit=True)
|
||||
si.currency = "USD"
|
||||
si.conversion_rate = 0.90
|
||||
si.debit_to = self.debtors_usd
|
||||
si = si.save().submit()
|
||||
|
||||
# Exchange Revaluation
|
||||
err = frappe.new_doc("Exchange Rate Revaluation")
|
||||
err.company = company
|
||||
err.posting_date = today()
|
||||
accounts = err.get_accounts_data()
|
||||
err.extend("accounts", accounts)
|
||||
err.accounts[0].new_exchange_rate = 0.95
|
||||
row = err.accounts[0]
|
||||
row.new_balance_in_base_currency = flt(
|
||||
row.new_exchange_rate * flt(row.balance_in_account_currency)
|
||||
)
|
||||
row.gain_loss = row.new_balance_in_base_currency - flt(row.balance_in_base_currency)
|
||||
err.set_total_gain_loss()
|
||||
err = err.save().submit()
|
||||
|
||||
# Submit JV for ERR
|
||||
err_journals = err.make_jv_entries()
|
||||
je = frappe.get_doc("Journal Entry", err_journals.get("revaluation_jv"))
|
||||
je = je.submit()
|
||||
|
||||
filters = {
|
||||
"company": company,
|
||||
"report_date": today(),
|
||||
"range1": 30,
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
}
|
||||
report = execute(filters)
|
||||
|
||||
expected_data_for_err = [0, -5, 0, 5]
|
||||
row = [x for x in report[1] if x.voucher_type == je.doctype and x.voucher_no == je.name][0]
|
||||
self.assertEqual(
|
||||
expected_data_for_err,
|
||||
[
|
||||
row.invoiced,
|
||||
row.paid,
|
||||
row.credit_note,
|
||||
row.outstanding,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def make_sales_invoice(no_payment_schedule=False, do_not_submit=False):
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
si = create_sales_invoice(
|
||||
@@ -134,22 +226,26 @@ def make_sales_invoice():
|
||||
do_not_save=1,
|
||||
)
|
||||
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 30)), invoice_portion=30.00, payment_amount=30),
|
||||
)
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 60)), invoice_portion=50.00, payment_amount=50),
|
||||
)
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 90)), invoice_portion=20.00, payment_amount=20),
|
||||
)
|
||||
if not no_payment_schedule:
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 30)), invoice_portion=30.00, payment_amount=30),
|
||||
)
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 60)), invoice_portion=50.00, payment_amount=50),
|
||||
)
|
||||
si.append(
|
||||
"payment_schedule",
|
||||
dict(due_date=getdate(add_days(today(), 90)), invoice_portion=20.00, payment_amount=20),
|
||||
)
|
||||
|
||||
si.submit()
|
||||
si = si.save()
|
||||
|
||||
return si.name
|
||||
if not do_not_submit:
|
||||
si = si.submit()
|
||||
|
||||
return si
|
||||
|
||||
|
||||
def make_payment(docname):
|
||||
|
||||
@@ -121,6 +121,9 @@ class AccountsReceivableSummary(ReceivablePayableReport):
|
||||
if row.sales_person:
|
||||
self.party_total[row.party].sales_person.append(row.sales_person)
|
||||
|
||||
if self.filters.sales_partner:
|
||||
self.party_total[row.party]["default_sales_partner"] = row.get("default_sales_partner")
|
||||
|
||||
def get_columns(self):
|
||||
self.columns = []
|
||||
self.add_column(
|
||||
@@ -160,6 +163,10 @@ class AccountsReceivableSummary(ReceivablePayableReport):
|
||||
)
|
||||
if self.filters.show_sales_person:
|
||||
self.add_column(label=_("Sales Person"), fieldname="sales_person", fieldtype="Data")
|
||||
|
||||
if self.filters.sales_partner:
|
||||
self.add_column(label=_("Sales Partner"), fieldname="default_sales_partner", fieldtype="Data")
|
||||
|
||||
else:
|
||||
self.add_column(
|
||||
label=_("Supplier Group"),
|
||||
|
||||
@@ -131,8 +131,36 @@ def get_assets(filters):
|
||||
else
|
||||
0
|
||||
end), 0) as depreciation_amount_during_the_period
|
||||
from `tabAsset` a, `tabDepreciation Schedule` ds
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and a.name = ds.parent and ifnull(ds.journal_entry, '') != ''
|
||||
from `tabAsset` a, `tabAsset Depreciation Schedule` ads, `tabDepreciation Schedule` ds
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and ads.asset = a.name and ads.docstatus=1 and ads.name = ds.parent and ifnull(ds.journal_entry, '') != ''
|
||||
group by a.asset_category
|
||||
union
|
||||
SELECT a.asset_category,
|
||||
ifnull(sum(case when gle.posting_date < %(from_date)s and (ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s) then
|
||||
gle.debit
|
||||
else
|
||||
0
|
||||
end), 0) as accumulated_depreciation_as_on_from_date,
|
||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0 and a.disposal_date >= %(from_date)s
|
||||
and a.disposal_date <= %(to_date)s and gle.posting_date <= a.disposal_date then
|
||||
gle.debit
|
||||
else
|
||||
0
|
||||
end), 0) as depreciation_eliminated_during_the_period,
|
||||
ifnull(sum(case when gle.posting_date >= %(from_date)s and gle.posting_date <= %(to_date)s
|
||||
and (ifnull(a.disposal_date, 0) = 0 or gle.posting_date <= a.disposal_date) then
|
||||
gle.debit
|
||||
else
|
||||
0
|
||||
end), 0) as depreciation_amount_during_the_period
|
||||
from `tabGL Entry` gle
|
||||
join `tabAsset` a on
|
||||
gle.against_voucher = a.name
|
||||
join `tabAsset Category Account` aca on
|
||||
aca.parent = a.asset_category and aca.company_name = %(company)s
|
||||
join `tabCompany` company on
|
||||
company.name = %(company)s
|
||||
where a.docstatus=1 and a.company=%(company)s and a.calculate_depreciation=0 and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account)
|
||||
group by a.asset_category
|
||||
union
|
||||
SELECT a.asset_category,
|
||||
|
||||
@@ -8,6 +8,7 @@ from frappe.utils import cint, cstr
|
||||
|
||||
from erpnext.accounts.report.financial_statements import (
|
||||
get_columns,
|
||||
get_cost_centers_with_children,
|
||||
get_data,
|
||||
get_filtered_list_for_consolidated_report,
|
||||
get_period_list,
|
||||
@@ -160,10 +161,11 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
||||
total = 0
|
||||
for period in period_list:
|
||||
start_date = get_start_date(period, accumulated_values, company)
|
||||
filters.start_date = start_date
|
||||
filters.end_date = period["to_date"]
|
||||
filters.account_type = account_type
|
||||
|
||||
amount = get_account_type_based_gl_data(
|
||||
company, start_date, period["to_date"], account_type, filters
|
||||
)
|
||||
amount = get_account_type_based_gl_data(company, filters)
|
||||
|
||||
if amount and account_type == "Depreciation":
|
||||
amount *= -1
|
||||
@@ -175,7 +177,7 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
||||
return data
|
||||
|
||||
|
||||
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters=None):
|
||||
def get_account_type_based_gl_data(company, filters=None):
|
||||
cond = ""
|
||||
filters = frappe._dict(filters or {})
|
||||
|
||||
@@ -191,17 +193,21 @@ def get_account_type_based_gl_data(company, start_date, end_date, account_type,
|
||||
frappe.db.escape(cstr(filters.finance_book))
|
||||
)
|
||||
|
||||
if filters.get("cost_center"):
|
||||
filters.cost_center = get_cost_centers_with_children(filters.cost_center)
|
||||
cond += " and cost_center in %(cost_center)s"
|
||||
|
||||
gl_sum = frappe.db.sql_list(
|
||||
"""
|
||||
select sum(credit) - sum(debit)
|
||||
from `tabGL Entry`
|
||||
where company=%s and posting_date >= %s and posting_date <= %s
|
||||
where company=%(company)s and posting_date >= %(start_date)s and posting_date <= %(end_date)s
|
||||
and voucher_type != 'Period Closing Voucher'
|
||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %s) {cond}
|
||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %(account_type)s) {cond}
|
||||
""".format(
|
||||
cond=cond
|
||||
),
|
||||
(company, start_date, end_date, account_type),
|
||||
filters,
|
||||
)
|
||||
|
||||
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
||||
|
||||
@@ -268,10 +268,12 @@ def get_cash_flow_data(fiscal_year, companies, filters):
|
||||
def get_account_type_based_data(account_type, companies, fiscal_year, filters):
|
||||
data = {}
|
||||
total = 0
|
||||
filters.account_type = account_type
|
||||
filters.start_date = fiscal_year.year_start_date
|
||||
filters.end_date = fiscal_year.year_end_date
|
||||
|
||||
for company in companies:
|
||||
amount = get_account_type_based_gl_data(
|
||||
company, fiscal_year.year_start_date, fiscal_year.year_end_date, account_type, filters
|
||||
)
|
||||
amount = get_account_type_based_gl_data(company, filters)
|
||||
|
||||
if amount and account_type == "Depreciation":
|
||||
amount *= -1
|
||||
@@ -533,12 +535,13 @@ def get_accounts(root_type, companies):
|
||||
],
|
||||
filters={"company": company, "root_type": root_type},
|
||||
):
|
||||
if account.account_name not in added_accounts:
|
||||
if account.account_number:
|
||||
account_key = account.account_number + "-" + account.account_name
|
||||
else:
|
||||
account_key = account.account_name
|
||||
|
||||
if account_key not in added_accounts:
|
||||
accounts.append(account)
|
||||
if account.account_number:
|
||||
account_key = account.account_number + "-" + account.account_name
|
||||
else:
|
||||
account_key = account.account_name
|
||||
added_accounts.append(account_key)
|
||||
|
||||
return accounts
|
||||
|
||||
@@ -26,6 +26,7 @@ class PartyLedgerSummaryReport(object):
|
||||
)
|
||||
|
||||
self.get_gl_entries()
|
||||
self.get_additional_columns()
|
||||
self.get_return_invoices()
|
||||
self.get_party_adjustment_amounts()
|
||||
|
||||
@@ -33,6 +34,42 @@ class PartyLedgerSummaryReport(object):
|
||||
data = self.get_data()
|
||||
return columns, data
|
||||
|
||||
def get_additional_columns(self):
|
||||
"""
|
||||
Additional Columns for 'User Permission' based access control
|
||||
"""
|
||||
from frappe import qb
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
self.territories = frappe._dict({})
|
||||
self.customer_group = frappe._dict({})
|
||||
|
||||
customer = qb.DocType("Customer")
|
||||
result = (
|
||||
frappe.qb.from_(customer)
|
||||
.select(
|
||||
customer.name, customer.territory, customer.customer_group, customer.default_sales_partner
|
||||
)
|
||||
.where((customer.disabled == 0))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
for x in result:
|
||||
self.territories[x.name] = x.territory
|
||||
self.customer_group[x.name] = x.customer_group
|
||||
else:
|
||||
self.supplier_group = frappe._dict({})
|
||||
supplier = qb.DocType("Supplier")
|
||||
result = (
|
||||
frappe.qb.from_(supplier)
|
||||
.select(supplier.name, supplier.supplier_group)
|
||||
.where((supplier.disabled == 0))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
for x in result:
|
||||
self.supplier_group[x.name] = x.supplier_group
|
||||
|
||||
def get_columns(self):
|
||||
columns = [
|
||||
{
|
||||
@@ -116,6 +153,35 @@ class PartyLedgerSummaryReport(object):
|
||||
},
|
||||
]
|
||||
|
||||
# Hidden columns for handling 'User Permissions'
|
||||
if self.filters.party_type == "Customer":
|
||||
columns += [
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
"hidden": 1,
|
||||
},
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
"hidden": 1,
|
||||
},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Supplier Group"),
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier Group",
|
||||
"hidden": 1,
|
||||
}
|
||||
]
|
||||
|
||||
return columns
|
||||
|
||||
def get_data(self):
|
||||
@@ -143,6 +209,12 @@ class PartyLedgerSummaryReport(object):
|
||||
),
|
||||
)
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
self.party_data[gle.party].update({"territory": self.territories.get(gle.party)})
|
||||
self.party_data[gle.party].update({"customer_group": self.customer_group.get(gle.party)})
|
||||
else:
|
||||
self.party_data[gle.party].update({"supplier_group": self.supplier_group.get(gle.party)})
|
||||
|
||||
amount = gle.get(invoice_dr_or_cr) - gle.get(reverse_dr_or_cr)
|
||||
self.party_data[gle.party].closing_balance += amount
|
||||
|
||||
|
||||
@@ -378,15 +378,14 @@ class Deferred_Revenue_and_Expense_Report(object):
|
||||
ret += [{}]
|
||||
|
||||
# add total row
|
||||
if ret is not []:
|
||||
if self.filters.type == "Revenue":
|
||||
total_row = frappe._dict({"name": "Total Deferred Income"})
|
||||
elif self.filters.type == "Expense":
|
||||
total_row = frappe._dict({"name": "Total Deferred Expense"})
|
||||
if self.filters.type == "Revenue":
|
||||
total_row = frappe._dict({"name": "Total Deferred Income"})
|
||||
elif self.filters.type == "Expense":
|
||||
total_row = frappe._dict({"name": "Total Deferred Expense"})
|
||||
|
||||
for idx, period in enumerate(self.period_list, 0):
|
||||
total_row[period.key] = self.period_total[idx].total
|
||||
ret.append(total_row)
|
||||
for idx, period in enumerate(self.period_list, 0):
|
||||
total_row[period.key] = self.period_total[idx].total
|
||||
ret.append(total_row)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 12%">{%= __("Date") %}</th>
|
||||
<th style="width: 15%">{%= __("Ref") %}</th>
|
||||
<th style="width: 25%">{%= __("Party") %}</th>
|
||||
<th style="width: 15%">{%= __("Reference") %}</th>
|
||||
<th style="width: 25%">{%= __("Remarks") %}</th>
|
||||
<th style="width: 15%">{%= __("Debit") %}</th>
|
||||
<th style="width: 15%">{%= __("Credit") %}</th>
|
||||
<th style="width: 18%">{%= __("Balance (Dr - Cr)") %}</th>
|
||||
@@ -45,7 +45,6 @@
|
||||
<br>
|
||||
{% } %}
|
||||
|
||||
{{ __("Against") }}: {%= data[i].against %}
|
||||
<br>{%= __("Remarks") %}: {%= data[i].remarks %}
|
||||
{% if(data[i].bill_no) { %}
|
||||
<br>{%= __("Supplier Invoice No") %}: {%= data[i].bill_no %}
|
||||
|
||||
@@ -239,7 +239,7 @@ def get_conditions(filters):
|
||||
):
|
||||
conditions.append("(posting_date >=%(from_date)s or is_opening = 'Yes')")
|
||||
|
||||
conditions.append("(posting_date <=%(to_date)s)")
|
||||
conditions.append("(posting_date <=%(to_date)s or is_opening = 'Yes')")
|
||||
|
||||
if filters.get("project"):
|
||||
conditions.append("project in %(project)s")
|
||||
@@ -526,7 +526,7 @@ def get_columns(filters):
|
||||
"options": "GL Entry",
|
||||
"hidden": 1,
|
||||
},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 90},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 100},
|
||||
{
|
||||
"label": _("Account"),
|
||||
"fieldname": "account",
|
||||
@@ -538,13 +538,13 @@ def get_columns(filters):
|
||||
"label": _("Debit ({0})").format(currency),
|
||||
"fieldname": "debit",
|
||||
"fieldtype": "Float",
|
||||
"width": 100,
|
||||
"width": 130,
|
||||
},
|
||||
{
|
||||
"label": _("Credit ({0})").format(currency),
|
||||
"fieldname": "credit",
|
||||
"fieldtype": "Float",
|
||||
"width": 100,
|
||||
"width": 130,
|
||||
},
|
||||
{
|
||||
"label": _("Balance ({0})").format(currency),
|
||||
|
||||
@@ -109,8 +109,7 @@ class TestGeneralLedger(FrappeTestCase):
|
||||
frappe.db.set_value(
|
||||
"Company", company, "unrealized_exchange_gain_loss_account", "_Test Exchange Gain/Loss - _TC"
|
||||
)
|
||||
revaluation_jv = revaluation.make_jv_entry()
|
||||
revaluation_jv = frappe.get_doc(revaluation_jv)
|
||||
revaluation_jv = revaluation.make_jv_for_revaluation()
|
||||
revaluation_jv.cost_center = "_Test Cost Center - _TC"
|
||||
for acc in revaluation_jv.get("accounts"):
|
||||
acc.cost_center = "_Test Cost Center - _TC"
|
||||
|
||||
@@ -50,6 +50,20 @@ frappe.query_reports["Gross Profit"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Person"
|
||||
},
|
||||
{
|
||||
"fieldname": "warehouse",
|
||||
"label": __("Warehouse"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Warehouse",
|
||||
"get_query": function () {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: [
|
||||
["Warehouse", "company", "=", company]
|
||||
]
|
||||
};
|
||||
},
|
||||
},
|
||||
],
|
||||
"tree": true,
|
||||
"name_field": "parent",
|
||||
|
||||
@@ -439,6 +439,18 @@ class GrossProfitGenerator(object):
|
||||
row.delivery_note, frappe._dict()
|
||||
)
|
||||
row.item_row = row.dn_detail
|
||||
# Update warehouse and base_amount from 'Packed Item' List
|
||||
if product_bundles and not row.parent:
|
||||
# For Packed Items, row.parent_invoice will be the Bundle name
|
||||
product_bundle = product_bundles.get(row.parent_invoice)
|
||||
if product_bundle:
|
||||
for packed_item in product_bundle:
|
||||
if (
|
||||
packed_item.get("item_code") == row.item_code
|
||||
and packed_item.get("parent_detail_docname") == row.item_row
|
||||
):
|
||||
row.warehouse = packed_item.warehouse
|
||||
row.base_amount = packed_item.base_amount
|
||||
|
||||
# get buying amount
|
||||
if row.item_code in product_bundles:
|
||||
@@ -503,7 +515,7 @@ class GrossProfitGenerator(object):
|
||||
invoice_portion = 100
|
||||
elif row.invoice_portion:
|
||||
invoice_portion = row.invoice_portion
|
||||
else:
|
||||
elif row.payment_amount:
|
||||
invoice_portion = row.payment_amount * 100 / row.base_net_amount
|
||||
|
||||
if i == 0:
|
||||
@@ -589,7 +601,9 @@ class GrossProfitGenerator(object):
|
||||
buying_amount = 0.0
|
||||
for packed_item in product_bundle:
|
||||
if packed_item.get("parent_detail_docname") == row.item_row:
|
||||
buying_amount += self.get_buying_amount(row, packed_item.item_code)
|
||||
packed_item_row = row.copy()
|
||||
packed_item_row.warehouse = packed_item.warehouse
|
||||
buying_amount += self.get_buying_amount(packed_item_row, packed_item.item_code)
|
||||
|
||||
return flt(buying_amount, self.currency_precision)
|
||||
|
||||
@@ -607,6 +621,7 @@ class GrossProfitGenerator(object):
|
||||
return abs(previous_stock_value - flt(sle.stock_value)) * flt(row.qty) / abs(flt(sle.qty))
|
||||
else:
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
return 0.0
|
||||
|
||||
def get_buying_amount(self, row, item_code):
|
||||
# IMP NOTE
|
||||
@@ -640,10 +655,35 @@ class GrossProfitGenerator(object):
|
||||
return self.calculate_buying_amount_from_sle(
|
||||
row, my_sle, parenttype, parent, item_row, item_code
|
||||
)
|
||||
elif row.sales_order and row.so_detail:
|
||||
incoming_amount = self.get_buying_amount_from_so_dn(row.sales_order, row.so_detail, item_code)
|
||||
if incoming_amount:
|
||||
return incoming_amount
|
||||
else:
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
|
||||
return 0.0
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
|
||||
def get_buying_amount_from_so_dn(self, sales_order, so_detail, item_code):
|
||||
from frappe.query_builder.functions import Sum
|
||||
|
||||
delivery_note = frappe.qb.DocType("Delivery Note")
|
||||
delivery_note_item = frappe.qb.DocType("Delivery Note Item")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(delivery_note)
|
||||
.inner_join(delivery_note_item)
|
||||
.on(delivery_note.name == delivery_note_item.parent)
|
||||
.select(Sum(delivery_note_item.incoming_rate * delivery_note_item.stock_qty))
|
||||
.where(delivery_note.docstatus == 1)
|
||||
.where(delivery_note_item.item_code == item_code)
|
||||
.where(delivery_note_item.against_sales_order == sales_order)
|
||||
.where(delivery_note_item.so_detail == so_detail)
|
||||
.groupby(delivery_note_item.item_code)
|
||||
)
|
||||
|
||||
incoming_amount = query.run()
|
||||
return flt(incoming_amount[0][0]) if incoming_amount else 0
|
||||
|
||||
def get_average_buying_rate(self, row, item_code):
|
||||
args = row
|
||||
@@ -735,6 +775,13 @@ class GrossProfitGenerator(object):
|
||||
if self.filters.get("item_code"):
|
||||
conditions += " and `tabSales Invoice Item`.item_code = %(item_code)s"
|
||||
|
||||
if self.filters.get("warehouse"):
|
||||
warehouse_details = frappe.db.get_value(
|
||||
"Warehouse", self.filters.get("warehouse"), ["lft", "rgt"], as_dict=1
|
||||
)
|
||||
if warehouse_details:
|
||||
conditions += f" and `tabSales Invoice Item`.warehouse in (select name from `tabWarehouse` wh where wh.lft >= {warehouse_details.lft} and wh.rgt <= {warehouse_details.rgt} and warehouse = wh.name)"
|
||||
|
||||
self.si_list = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
@@ -745,7 +792,8 @@ class GrossProfitGenerator(object):
|
||||
`tabSales Invoice`.territory, `tabSales Invoice Item`.item_code,
|
||||
`tabSales Invoice Item`.item_name, `tabSales Invoice Item`.description,
|
||||
`tabSales Invoice Item`.warehouse, `tabSales Invoice Item`.item_group,
|
||||
`tabSales Invoice Item`.brand, `tabSales Invoice Item`.dn_detail,
|
||||
`tabSales Invoice Item`.brand, `tabSales Invoice Item`.so_detail,
|
||||
`tabSales Invoice Item`.sales_order, `tabSales Invoice Item`.dn_detail,
|
||||
`tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty,
|
||||
`tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount,
|
||||
`tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return,
|
||||
@@ -921,12 +969,25 @@ class GrossProfitGenerator(object):
|
||||
def load_product_bundle(self):
|
||||
self.product_bundles = {}
|
||||
|
||||
for d in frappe.db.sql(
|
||||
"""select parenttype, parent, parent_item,
|
||||
item_code, warehouse, -1*qty as total_qty, parent_detail_docname
|
||||
from `tabPacked Item` where docstatus=1""",
|
||||
as_dict=True,
|
||||
):
|
||||
pki = qb.DocType("Packed Item")
|
||||
|
||||
pki_query = (
|
||||
frappe.qb.from_(pki)
|
||||
.select(
|
||||
pki.parenttype,
|
||||
pki.parent,
|
||||
pki.parent_item,
|
||||
pki.item_code,
|
||||
pki.warehouse,
|
||||
(-1 * pki.qty).as_("total_qty"),
|
||||
pki.rate,
|
||||
(pki.rate * pki.qty).as_("base_amount"),
|
||||
pki.parent_detail_docname,
|
||||
)
|
||||
.where(pki.docstatus == 1)
|
||||
)
|
||||
|
||||
for d in pki_query.run(as_dict=True):
|
||||
self.product_bundles.setdefault(d.parenttype, frappe._dict()).setdefault(
|
||||
d.parent, frappe._dict()
|
||||
).setdefault(d.parent_item, []).append(d)
|
||||
|
||||
@@ -6,6 +6,8 @@ from frappe.utils import add_days, flt, nowdate
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.report.gross_profit.gross_profit import execute
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
|
||||
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
|
||||
@@ -14,6 +16,7 @@ class TestGrossProfit(FrappeTestCase):
|
||||
def setUp(self):
|
||||
self.create_company()
|
||||
self.create_item()
|
||||
self.create_bundle()
|
||||
self.create_customer()
|
||||
self.create_sales_invoice()
|
||||
self.clear_old_entries()
|
||||
@@ -42,6 +45,7 @@ class TestGrossProfit(FrappeTestCase):
|
||||
self.company = company.name
|
||||
self.cost_center = company.cost_center
|
||||
self.warehouse = "Stores - " + abbr
|
||||
self.finished_warehouse = "Finished Goods - " + abbr
|
||||
self.income_account = "Sales - " + abbr
|
||||
self.expense_account = "Cost of Goods Sold - " + abbr
|
||||
self.debit_to = "Debtors - " + abbr
|
||||
@@ -53,6 +57,23 @@ class TestGrossProfit(FrappeTestCase):
|
||||
)
|
||||
self.item = item if isinstance(item, str) else item.item_code
|
||||
|
||||
def create_bundle(self):
|
||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||
|
||||
item2 = create_item(
|
||||
item_code="_Test GP Item 2", is_stock_item=1, company=self.company, warehouse=self.warehouse
|
||||
)
|
||||
self.item2 = item2 if isinstance(item2, str) else item2.item_code
|
||||
|
||||
# This will be parent item
|
||||
bundle = create_item(
|
||||
item_code="_Test GP bundle", is_stock_item=0, company=self.company, warehouse=self.warehouse
|
||||
)
|
||||
self.bundle = bundle if isinstance(bundle, str) else bundle.item_code
|
||||
|
||||
# Create Product Bundle
|
||||
self.product_bundle = make_product_bundle(parent=self.bundle, items=[self.item, self.item2])
|
||||
|
||||
def create_customer(self):
|
||||
name = "_Test GP Customer"
|
||||
if frappe.db.exists("Customer", name):
|
||||
@@ -93,6 +114,28 @@ class TestGrossProfit(FrappeTestCase):
|
||||
)
|
||||
return sinv
|
||||
|
||||
def create_delivery_note(
|
||||
self, item=None, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False
|
||||
):
|
||||
"""
|
||||
Helper function to populate default values in Delivery Note
|
||||
"""
|
||||
dnote = create_delivery_note(
|
||||
company=self.company,
|
||||
customer=self.customer,
|
||||
currency="INR",
|
||||
item=item or self.item,
|
||||
qty=qty,
|
||||
rate=rate,
|
||||
cost_center=self.cost_center,
|
||||
warehouse=self.warehouse,
|
||||
return_against=None,
|
||||
expense_account=self.expense_account,
|
||||
do_not_save=do_not_save,
|
||||
do_not_submit=do_not_submit,
|
||||
)
|
||||
return dnote
|
||||
|
||||
def clear_old_entries(self):
|
||||
doctype_list = [
|
||||
"Sales Invoice",
|
||||
@@ -207,3 +250,134 @@ class TestGrossProfit(FrappeTestCase):
|
||||
}
|
||||
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||
self.assertDictContainsSubset(expected_entry_with_dn, gp_entry[0])
|
||||
|
||||
def test_bundled_delivery_note_with_different_warehouses(self):
|
||||
"""
|
||||
Test Delivery Note with bundled item. Packed Item from the bundle having different warehouses
|
||||
"""
|
||||
se = make_stock_entry(
|
||||
company=self.company,
|
||||
item_code=self.item,
|
||||
target=self.warehouse,
|
||||
qty=1,
|
||||
basic_rate=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
item = se.items[0]
|
||||
se.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": self.item2,
|
||||
"s_warehouse": "",
|
||||
"t_warehouse": self.finished_warehouse,
|
||||
"qty": 1,
|
||||
"basic_rate": 100,
|
||||
"conversion_factor": item.conversion_factor or 1.0,
|
||||
"transfer_qty": flt(item.qty) * (flt(item.conversion_factor) or 1.0),
|
||||
"serial_no": item.serial_no,
|
||||
"batch_no": item.batch_no,
|
||||
"cost_center": item.cost_center,
|
||||
"expense_account": item.expense_account,
|
||||
},
|
||||
)
|
||||
se = se.save().submit()
|
||||
|
||||
# Make a Delivery note with Product bundle
|
||||
# Packed Items will have different warehouses
|
||||
dnote = self.create_delivery_note(item=self.bundle, qty=1, rate=200, do_not_submit=True)
|
||||
dnote.packed_items[1].warehouse = self.finished_warehouse
|
||||
dnote = dnote.submit()
|
||||
|
||||
# make Sales Invoice for above delivery note
|
||||
sinv = make_sales_invoice(dnote.name)
|
||||
sinv = sinv.save().submit()
|
||||
|
||||
filters = frappe._dict(
|
||||
company=self.company,
|
||||
from_date=nowdate(),
|
||||
to_date=nowdate(),
|
||||
group_by="Invoice",
|
||||
sales_invoice=sinv.name,
|
||||
)
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
self.assertGreater(len(data), 0)
|
||||
|
||||
def test_order_connected_dn_and_inv(self):
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
|
||||
"""
|
||||
Test gp calculation when invoice and delivery note aren't directly connected.
|
||||
SO -- INV
|
||||
|
|
||||
DN
|
||||
"""
|
||||
se = make_stock_entry(
|
||||
company=self.company,
|
||||
item_code=self.item,
|
||||
target=self.warehouse,
|
||||
qty=3,
|
||||
basic_rate=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
item = se.items[0]
|
||||
se.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": item.item_code,
|
||||
"s_warehouse": item.s_warehouse,
|
||||
"t_warehouse": item.t_warehouse,
|
||||
"qty": 10,
|
||||
"basic_rate": 200,
|
||||
"conversion_factor": item.conversion_factor or 1.0,
|
||||
"transfer_qty": flt(item.qty) * (flt(item.conversion_factor) or 1.0),
|
||||
"serial_no": item.serial_no,
|
||||
"batch_no": item.batch_no,
|
||||
"cost_center": item.cost_center,
|
||||
"expense_account": item.expense_account,
|
||||
},
|
||||
)
|
||||
se = se.save().submit()
|
||||
|
||||
so = make_sales_order(
|
||||
customer=self.customer,
|
||||
company=self.company,
|
||||
warehouse=self.warehouse,
|
||||
item=self.item,
|
||||
qty=4,
|
||||
do_not_save=False,
|
||||
do_not_submit=False,
|
||||
)
|
||||
|
||||
from erpnext.selling.doctype.sales_order.sales_order import (
|
||||
make_delivery_note,
|
||||
make_sales_invoice,
|
||||
)
|
||||
|
||||
make_delivery_note(so.name).submit()
|
||||
sinv = make_sales_invoice(so.name).submit()
|
||||
|
||||
filters = frappe._dict(
|
||||
company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice"
|
||||
)
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
expected_entry = {
|
||||
"parent_invoice": sinv.name,
|
||||
"currency": "INR",
|
||||
"sales_invoice": self.item,
|
||||
"customer": self.customer,
|
||||
"posting_date": frappe.utils.datetime.date.fromisoformat(nowdate()),
|
||||
"item_code": self.item,
|
||||
"item_name": self.item,
|
||||
"warehouse": "Stores - _GP",
|
||||
"qty": 4.0,
|
||||
"avg._selling_rate": 100.0,
|
||||
"valuation_rate": 125.0,
|
||||
"selling_amount": 400.0,
|
||||
"buying_amount": 500.0,
|
||||
"gross_profit": -100.0,
|
||||
"gross_profit_%": -25.0,
|
||||
}
|
||||
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||
self.assertDictContainsSubset(expected_entry, gp_entry[0])
|
||||
|
||||
@@ -53,9 +53,6 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum
|
||||
item_details = get_item_details()
|
||||
|
||||
for d in item_list:
|
||||
if not d.stock_qty:
|
||||
continue
|
||||
|
||||
item_record = item_details.get(d.item_code)
|
||||
|
||||
purchase_receipt = None
|
||||
@@ -94,7 +91,7 @@ def _execute(filters=None, additional_table_columns=None, additional_query_colum
|
||||
"expense_account": expense_account,
|
||||
"stock_qty": d.stock_qty,
|
||||
"stock_uom": d.stock_uom,
|
||||
"rate": d.base_net_amount / d.stock_qty,
|
||||
"rate": d.base_net_amount / d.stock_qty if d.stock_qty else d.base_net_amount,
|
||||
"amount": d.base_net_amount,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -63,24 +63,6 @@ frappe.query_reports["Supplier Ledger Summary"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Payment Terms Template"
|
||||
},
|
||||
{
|
||||
"fieldname":"territory",
|
||||
"label": __("Territory"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory"
|
||||
},
|
||||
{
|
||||
"fieldname":"sales_partner",
|
||||
"label": __("Sales Partner"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Partner"
|
||||
},
|
||||
{
|
||||
"fieldname":"sales_person",
|
||||
"label": __("Sales Person"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Person"
|
||||
},
|
||||
{
|
||||
"fieldname":"tax_id",
|
||||
"label": __("Tax Id"),
|
||||
|
||||
@@ -234,8 +234,11 @@ def modify_report_columns(doctype, field, column):
|
||||
if field in ["item_tax_rate", "base_net_amount"]:
|
||||
return None
|
||||
|
||||
if doctype == "GL Entry" and field in ["debit", "credit"]:
|
||||
column.update({"label": _("Amount"), "fieldname": "amount"})
|
||||
if doctype == "GL Entry":
|
||||
if field in ["debit", "credit"]:
|
||||
column.update({"label": _("Amount"), "fieldname": "amount"})
|
||||
elif field == "voucher_type":
|
||||
column.update({"fieldtype": "Data", "options": ""})
|
||||
|
||||
if field == "taxes_and_charges":
|
||||
column.update({"label": _("Taxes and Charges Template")})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -65,6 +66,12 @@ def get_result(
|
||||
else:
|
||||
total_amount_credited += entry.credit
|
||||
|
||||
## Check if ldc is applied and show rate as per ldc
|
||||
actual_rate = (tds_deducted / total_amount_credited) * 100
|
||||
|
||||
if flt(actual_rate) < flt(rate):
|
||||
rate = actual_rate
|
||||
|
||||
if tds_deducted:
|
||||
row = {
|
||||
"pan"
|
||||
|
||||
@@ -28,7 +28,7 @@ def get_currency(filters):
|
||||
filters["presentation_currency"] if filters.get("presentation_currency") else company_currency
|
||||
)
|
||||
|
||||
report_date = filters.get("to_date")
|
||||
report_date = filters.get("to_date") or filters.get("period_end_date")
|
||||
|
||||
if not report_date:
|
||||
fiscal_year_to_date = get_from_and_to_date(filters.get("to_fiscal_year"))["to_date"]
|
||||
@@ -101,11 +101,8 @@ def convert_to_presentation_currency(gl_entries, currency_info, company):
|
||||
account_currency = entry["account_currency"]
|
||||
|
||||
if len(account_currencies) == 1 and account_currency == presentation_currency:
|
||||
if debit_in_account_currency:
|
||||
entry["debit"] = debit_in_account_currency
|
||||
|
||||
if credit_in_account_currency:
|
||||
entry["credit"] = credit_in_account_currency
|
||||
entry["debit"] = debit_in_account_currency
|
||||
entry["credit"] = credit_in_account_currency
|
||||
else:
|
||||
date = currency_info["report_date"]
|
||||
converted_debit_value = convert(debit, presentation_currency, company_currency, date)
|
||||
|
||||
@@ -3,11 +3,14 @@ import unittest
|
||||
import frappe
|
||||
from frappe.test_runner import make_test_objects
|
||||
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.accounts.party import get_party_shipping_address
|
||||
from erpnext.accounts.utils import (
|
||||
get_future_stock_vouchers,
|
||||
get_voucherwise_gl_entries,
|
||||
sort_stock_vouchers_by_posting_date,
|
||||
update_reference_in_payment_entry,
|
||||
)
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
|
||||
@@ -73,6 +76,47 @@ class TestUtils(unittest.TestCase):
|
||||
sorted_vouchers = sort_stock_vouchers_by_posting_date(list(reversed(vouchers)))
|
||||
self.assertEqual(sorted_vouchers, vouchers)
|
||||
|
||||
def test_update_reference_in_payment_entry(self):
|
||||
item = make_item().name
|
||||
|
||||
purchase_invoice = make_purchase_invoice(
|
||||
item=item, supplier="_Test Supplier USD", currency="USD", conversion_rate=82.32
|
||||
)
|
||||
purchase_invoice.submit()
|
||||
|
||||
payment_entry = get_payment_entry(purchase_invoice.doctype, purchase_invoice.name)
|
||||
payment_entry.target_exchange_rate = 62.9
|
||||
payment_entry.paid_amount = 15725
|
||||
payment_entry.deductions = []
|
||||
payment_entry.insert()
|
||||
|
||||
self.assertEqual(payment_entry.difference_amount, -4855.00)
|
||||
payment_entry.references = []
|
||||
payment_entry.submit()
|
||||
|
||||
payment_reconciliation = frappe.new_doc("Payment Reconciliation")
|
||||
payment_reconciliation.company = payment_entry.company
|
||||
payment_reconciliation.party_type = "Supplier"
|
||||
payment_reconciliation.party = purchase_invoice.supplier
|
||||
payment_reconciliation.receivable_payable_account = payment_entry.paid_to
|
||||
payment_reconciliation.get_unreconciled_entries()
|
||||
payment_reconciliation.allocate_entries(
|
||||
{
|
||||
"payments": [d.__dict__ for d in payment_reconciliation.payments],
|
||||
"invoices": [d.__dict__ for d in payment_reconciliation.invoices],
|
||||
}
|
||||
)
|
||||
for d in payment_reconciliation.invoices:
|
||||
# Reset invoice outstanding_amount because allocate_entries will zero this value out.
|
||||
d.outstanding_amount = d.amount
|
||||
for d in payment_reconciliation.allocation:
|
||||
d.difference_account = "Exchange Gain/Loss - _TC"
|
||||
payment_reconciliation.reconcile()
|
||||
|
||||
payment_entry.load_from_db()
|
||||
self.assertEqual(len(payment_entry.references), 1)
|
||||
self.assertEqual(payment_entry.difference_amount, 0)
|
||||
|
||||
|
||||
ADDRESS_RECORDS = [
|
||||
{
|
||||
|
||||
@@ -439,8 +439,7 @@ def reconcile_against_document(args): # nosemgrep
|
||||
# cancel advance entry
|
||||
doc = frappe.get_doc(voucher_type, voucher_no)
|
||||
frappe.flags.ignore_party_validation = True
|
||||
gl_map = doc.build_gl_map()
|
||||
create_payment_ledger_entry(gl_map, cancel=1, adv_adj=1)
|
||||
_delete_pl_entries(voucher_type, voucher_no)
|
||||
|
||||
for entry in entries:
|
||||
check_if_advance_entry_modified(entry)
|
||||
@@ -452,11 +451,23 @@ def reconcile_against_document(args): # nosemgrep
|
||||
else:
|
||||
update_reference_in_payment_entry(entry, doc, do_not_save=True)
|
||||
|
||||
if doc.doctype == "Journal Entry":
|
||||
try:
|
||||
doc.validate_total_debit_and_credit()
|
||||
except Exception as validation_exception:
|
||||
raise frappe.ValidationError(_(f"Validation Error for {doc.name}")) from validation_exception
|
||||
|
||||
doc.save(ignore_permissions=True)
|
||||
# re-submit advance entry
|
||||
doc = frappe.get_doc(entry.voucher_type, entry.voucher_no)
|
||||
gl_map = doc.build_gl_map()
|
||||
create_payment_ledger_entry(gl_map, cancel=0, adv_adj=1)
|
||||
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)
|
||||
|
||||
# Only update outstanding for newly linked vouchers
|
||||
for entry in entries:
|
||||
update_voucher_outstanding(
|
||||
entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party
|
||||
)
|
||||
|
||||
frappe.flags.ignore_party_validation = False
|
||||
|
||||
@@ -611,11 +622,6 @@ def update_reference_in_payment_entry(d, payment_entry, do_not_save=False):
|
||||
new_row.docstatus = 1
|
||||
new_row.update(reference_details)
|
||||
|
||||
payment_entry.flags.ignore_validate_update_after_submit = True
|
||||
payment_entry.setup_party_account_field()
|
||||
payment_entry.set_missing_values()
|
||||
payment_entry.set_amounts()
|
||||
|
||||
if d.difference_amount and d.difference_account:
|
||||
account_details = {
|
||||
"account": d.difference_account,
|
||||
@@ -627,6 +633,11 @@ def update_reference_in_payment_entry(d, payment_entry, do_not_save=False):
|
||||
|
||||
payment_entry.set_gain_or_loss(account_details=account_details)
|
||||
|
||||
payment_entry.flags.ignore_validate_update_after_submit = True
|
||||
payment_entry.setup_party_account_field()
|
||||
payment_entry.set_missing_values()
|
||||
payment_entry.set_amounts()
|
||||
|
||||
if not do_not_save:
|
||||
payment_entry.save(ignore_permissions=True)
|
||||
|
||||
@@ -836,6 +847,7 @@ def get_outstanding_invoices(
|
||||
posting_date=None,
|
||||
min_outstanding=None,
|
||||
max_outstanding=None,
|
||||
accounting_dimensions=None,
|
||||
):
|
||||
|
||||
ple = qb.DocType("Payment Ledger Entry")
|
||||
@@ -866,6 +878,7 @@ def get_outstanding_invoices(
|
||||
min_outstanding=min_outstanding,
|
||||
max_outstanding=max_outstanding,
|
||||
get_invoices=True,
|
||||
accounting_dimensions=accounting_dimensions or [],
|
||||
)
|
||||
|
||||
for d in invoice_list:
|
||||
@@ -1499,9 +1512,12 @@ def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, pa
|
||||
ref_doc = frappe.get_doc(voucher_type, voucher_no)
|
||||
|
||||
# Didn't use db_set for optimisation purpose
|
||||
ref_doc.outstanding_amount = outstanding["outstanding_in_account_currency"]
|
||||
ref_doc.outstanding_amount = outstanding["outstanding_in_account_currency"] or 0.0
|
||||
frappe.db.set_value(
|
||||
voucher_type, voucher_no, "outstanding_amount", outstanding["outstanding_in_account_currency"]
|
||||
voucher_type,
|
||||
voucher_no,
|
||||
"outstanding_amount",
|
||||
outstanding["outstanding_in_account_currency"] or 0.0,
|
||||
)
|
||||
|
||||
ref_doc.set_status(update=True)
|
||||
@@ -1615,6 +1631,7 @@ class QueryPaymentLedger(object):
|
||||
.where(ple.delinked == 0)
|
||||
.where(Criterion.all(filter_on_voucher_no))
|
||||
.where(Criterion.all(self.common_filter))
|
||||
.where(Criterion.all(self.dimensions_filter))
|
||||
.where(Criterion.all(self.voucher_posting_date))
|
||||
.groupby(ple.voucher_type, ple.voucher_no, ple.party_type, ple.party)
|
||||
)
|
||||
@@ -1702,6 +1719,7 @@ class QueryPaymentLedger(object):
|
||||
max_outstanding=None,
|
||||
get_payments=False,
|
||||
get_invoices=False,
|
||||
accounting_dimensions=None,
|
||||
):
|
||||
"""
|
||||
Fetch voucher amount and outstanding amount from Payment Ledger using Database CTE
|
||||
@@ -1717,6 +1735,7 @@ class QueryPaymentLedger(object):
|
||||
self.reset()
|
||||
self.vouchers = vouchers
|
||||
self.common_filter = common_filter or []
|
||||
self.dimensions_filter = accounting_dimensions or []
|
||||
self.voucher_posting_date = posting_date or []
|
||||
self.min_outstanding = min_outstanding
|
||||
self.max_outstanding = max_outstanding
|
||||
|
||||
@@ -76,7 +76,6 @@ frappe.ui.form.on('Asset', {
|
||||
refresh: function(frm) {
|
||||
frappe.ui.form.trigger("Asset", "is_existing_asset");
|
||||
frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1);
|
||||
frm.events.make_schedules_editable(frm);
|
||||
|
||||
if (frm.doc.docstatus==1) {
|
||||
if (in_list(["Submitted", "Partially Depreciated", "Fully Depreciated"], frm.doc.status)) {
|
||||
@@ -136,6 +135,10 @@ frappe.ui.form.on('Asset', {
|
||||
}, __("Manage"));
|
||||
}
|
||||
|
||||
if (frm.doc.depr_entry_posting_status === "Failed") {
|
||||
frm.trigger("set_depr_posting_failure_alert");
|
||||
}
|
||||
|
||||
frm.trigger("setup_chart");
|
||||
}
|
||||
|
||||
@@ -146,6 +149,19 @@ frappe.ui.form.on('Asset', {
|
||||
}
|
||||
},
|
||||
|
||||
set_depr_posting_failure_alert: function (frm) {
|
||||
const alert = `
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<span class="indicator whitespace-nowrap red">
|
||||
<span>Failed to post depreciation entries</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
frm.dashboard.set_headline_alert(alert);
|
||||
},
|
||||
|
||||
toggle_reference_doc: function(frm) {
|
||||
if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) {
|
||||
frm.set_df_property('purchase_invoice', 'read_only', 1);
|
||||
@@ -188,39 +204,67 @@ frappe.ui.form.on('Asset', {
|
||||
})
|
||||
},
|
||||
|
||||
setup_chart: function(frm) {
|
||||
var x_intervals = [frm.doc.purchase_date];
|
||||
var asset_values = [frm.doc.gross_purchase_amount];
|
||||
var last_depreciation_date = frm.doc.purchase_date;
|
||||
|
||||
if(frm.doc.opening_accumulated_depreciation) {
|
||||
last_depreciation_date = frappe.datetime.add_months(frm.doc.next_depreciation_date,
|
||||
-1*frm.doc.frequency_of_depreciation);
|
||||
|
||||
x_intervals.push(last_depreciation_date);
|
||||
asset_values.push(flt(frm.doc.gross_purchase_amount) -
|
||||
flt(frm.doc.opening_accumulated_depreciation));
|
||||
setup_chart: async function(frm) {
|
||||
if(frm.doc.finance_books.length > 1) {
|
||||
return
|
||||
}
|
||||
|
||||
$.each(frm.doc.schedules || [], function(i, v) {
|
||||
x_intervals.push(v.schedule_date);
|
||||
var asset_value = flt(frm.doc.gross_purchase_amount) - flt(v.accumulated_depreciation_amount);
|
||||
if(v.journal_entry) {
|
||||
last_depreciation_date = v.schedule_date;
|
||||
asset_values.push(asset_value);
|
||||
} else {
|
||||
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||
asset_values.push(null);
|
||||
} else {
|
||||
asset_values.push(asset_value)
|
||||
}
|
||||
var x_intervals = [frappe.format(frm.doc.purchase_date, { fieldtype: 'Date' })];
|
||||
var asset_values = [frm.doc.gross_purchase_amount];
|
||||
|
||||
if(frm.doc.calculate_depreciation) {
|
||||
if(frm.doc.opening_accumulated_depreciation) {
|
||||
var depreciation_date = frappe.datetime.add_months(
|
||||
frm.doc.finance_books[0].depreciation_start_date,
|
||||
-1 * frm.doc.finance_books[0].frequency_of_depreciation
|
||||
);
|
||||
x_intervals.push(frappe.format(depreciation_date, { fieldtype: 'Date' }));
|
||||
asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount')));
|
||||
}
|
||||
});
|
||||
|
||||
let depr_schedule = (await frappe.call(
|
||||
"erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule.get_depr_schedule",
|
||||
{
|
||||
asset_name: frm.doc.name,
|
||||
status: frm.doc.docstatus ? "Active" : "Draft",
|
||||
finance_book: frm.doc.finance_books[0].finance_book || null
|
||||
}
|
||||
)).message;
|
||||
|
||||
$.each(depr_schedule || [], function(i, v) {
|
||||
x_intervals.push(frappe.format(v.schedule_date, { fieldtype: 'Date' }));
|
||||
var asset_value = flt(frm.doc.gross_purchase_amount - v.accumulated_depreciation_amount, precision('gross_purchase_amount'));
|
||||
if(v.journal_entry) {
|
||||
asset_values.push(asset_value);
|
||||
} else {
|
||||
if (in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||
asset_values.push(null);
|
||||
} else {
|
||||
asset_values.push(asset_value)
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(frm.doc.opening_accumulated_depreciation) {
|
||||
x_intervals.push(frappe.format(frm.doc.creation.split(" ")[0], { fieldtype: 'Date' }));
|
||||
asset_values.push(flt(frm.doc.gross_purchase_amount - frm.doc.opening_accumulated_depreciation, precision('gross_purchase_amount')));
|
||||
}
|
||||
|
||||
let depr_entries = (await frappe.call({
|
||||
method: "get_manual_depreciation_entries",
|
||||
doc: frm.doc,
|
||||
})).message;
|
||||
|
||||
$.each(depr_entries || [], function(i, v) {
|
||||
x_intervals.push(frappe.format(v.posting_date, { fieldtype: 'Date' }));
|
||||
let last_asset_value = asset_values[asset_values.length - 1]
|
||||
asset_values.push(last_asset_value - v.value);
|
||||
});
|
||||
}
|
||||
|
||||
if(in_list(["Scrapped", "Sold"], frm.doc.status)) {
|
||||
x_intervals.push(frm.doc.disposal_date);
|
||||
x_intervals.push(frappe.format(frm.doc.disposal_date, { fieldtype: 'Date' }));
|
||||
asset_values.push(0);
|
||||
last_depreciation_date = frm.doc.disposal_date;
|
||||
}
|
||||
|
||||
frm.dashboard.render_graph({
|
||||
@@ -266,21 +310,6 @@ frappe.ui.form.on('Asset', {
|
||||
// frm.toggle_reqd("next_depreciation_date", (!frm.doc.is_existing_asset && frm.doc.calculate_depreciation));
|
||||
},
|
||||
|
||||
opening_accumulated_depreciation: function(frm) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
},
|
||||
|
||||
make_schedules_editable: function(frm) {
|
||||
if (frm.doc.finance_books) {
|
||||
var is_editable = frm.doc.finance_books.filter(d => d.depreciation_method == "Manual").length > 0
|
||||
? true : false;
|
||||
|
||||
frm.toggle_enable("schedules", is_editable);
|
||||
frm.fields_dict["schedules"].grid.toggle_enable("schedule_date", is_editable);
|
||||
frm.fields_dict["schedules"].grid.toggle_enable("depreciation_amount", is_editable);
|
||||
}
|
||||
},
|
||||
|
||||
make_sales_invoice: function(frm) {
|
||||
frappe.call({
|
||||
args: {
|
||||
@@ -476,7 +505,6 @@ frappe.ui.form.on('Asset Finance Book', {
|
||||
depreciation_method: function(frm, cdt, cdn) {
|
||||
const row = locals[cdt][cdn];
|
||||
frm.events.set_depreciation_rate(frm, row);
|
||||
frm.events.make_schedules_editable(frm);
|
||||
},
|
||||
|
||||
expected_value_after_useful_life: function(frm, cdt, cdn) {
|
||||
@@ -512,41 +540,6 @@ frappe.ui.form.on('Asset Finance Book', {
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Depreciation Schedule', {
|
||||
make_depreciation_entry: function(frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (!row.journal_entry) {
|
||||
frappe.call({
|
||||
method: "erpnext.assets.doctype.asset.depreciation.make_depreciation_entry",
|
||||
args: {
|
||||
"asset_name": frm.doc.name,
|
||||
"date": row.schedule_date
|
||||
},
|
||||
callback: function(r) {
|
||||
frappe.model.sync(r.message);
|
||||
frm.refresh();
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
depreciation_amount: function(frm, cdt, cdn) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm) {
|
||||
if(frm.doc.depreciation_method != "Manual") return;
|
||||
|
||||
var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation);
|
||||
$.each(frm.doc.schedules || [], function(i, row) {
|
||||
accumulated_depreciation += flt(row.depreciation_amount);
|
||||
frappe.model.set_value(row.doctype, row.name,
|
||||
"accumulated_depreciation_amount", accumulated_depreciation);
|
||||
})
|
||||
};
|
||||
|
||||
erpnext.asset.scrap_asset = function(frm) {
|
||||
frappe.confirm(__("Do you really want to scrap this asset?"), function () {
|
||||
frappe.call({
|
||||
|
||||
@@ -52,8 +52,6 @@
|
||||
"column_break_24",
|
||||
"frequency_of_depreciation",
|
||||
"next_depreciation_date",
|
||||
"section_break_14",
|
||||
"schedules",
|
||||
"insurance_details",
|
||||
"policy_number",
|
||||
"insurer",
|
||||
@@ -70,6 +68,7 @@
|
||||
"column_break_51",
|
||||
"purchase_receipt_amount",
|
||||
"default_finance_book",
|
||||
"depr_entry_posting_status",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
@@ -307,19 +306,6 @@
|
||||
"label": "Next Depreciation Date",
|
||||
"no_copy": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "calculate_depreciation",
|
||||
"fieldname": "section_break_14",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Depreciation Schedule"
|
||||
},
|
||||
{
|
||||
"fieldname": "schedules",
|
||||
"fieldtype": "Table",
|
||||
"label": "Depreciation Schedule",
|
||||
"no_copy": 1,
|
||||
"options": "Depreciation Schedule"
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
"fieldname": "insurance_details",
|
||||
@@ -488,6 +474,16 @@
|
||||
"fieldtype": "Int",
|
||||
"label": "Asset Quantity",
|
||||
"read_only_depends_on": "eval:!doc.is_existing_asset"
|
||||
},
|
||||
{
|
||||
"fieldname": "depr_entry_posting_status",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 1,
|
||||
"label": "Depreciation Entry Posting Status",
|
||||
"no_copy": 1,
|
||||
"options": "\nSuccessful\nFailed",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"idx": 72,
|
||||
@@ -502,15 +498,26 @@
|
||||
{
|
||||
"group": "Repair",
|
||||
"link_doctype": "Asset Repair",
|
||||
"link_fieldname": "asset_name"
|
||||
"link_fieldname": "asset"
|
||||
},
|
||||
{
|
||||
"group": "Value",
|
||||
"link_doctype": "Asset Value Adjustment",
|
||||
"link_fieldname": "asset"
|
||||
},
|
||||
{
|
||||
"group": "Depreciation",
|
||||
"link_doctype": "Asset Depreciation Schedule",
|
||||
"link_fieldname": "asset"
|
||||
},
|
||||
{
|
||||
"group": "Journal Entry",
|
||||
"link_doctype": "Journal Entry",
|
||||
"link_fieldname": "reference_name",
|
||||
"table_fieldname": "accounts"
|
||||
}
|
||||
],
|
||||
"modified": "2022-07-20 10:15:12.887372",
|
||||
"modified": "2023-02-02 00:03:11.706427",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset",
|
||||
|
||||
@@ -8,14 +8,15 @@ import math
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
add_months,
|
||||
cint,
|
||||
date_diff,
|
||||
flt,
|
||||
get_datetime,
|
||||
get_last_day,
|
||||
get_link_to_form,
|
||||
getdate,
|
||||
is_last_day_of_the_month,
|
||||
month_diff,
|
||||
nowdate,
|
||||
today,
|
||||
@@ -28,6 +29,15 @@ from erpnext.assets.doctype.asset.depreciation import (
|
||||
get_disposal_account_and_cost_center,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
cancel_asset_depr_schedules,
|
||||
convert_draft_asset_depr_schedules_into_active,
|
||||
get_asset_depr_schedule_doc,
|
||||
get_depr_schedule,
|
||||
make_draft_asset_depr_schedules,
|
||||
make_draft_asset_depr_schedules_if_not_present,
|
||||
update_draft_asset_depr_schedules,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
|
||||
|
||||
@@ -40,9 +50,9 @@ class Asset(AccountsController):
|
||||
self.set_missing_values()
|
||||
if not self.split_from:
|
||||
self.prepare_depreciation_data()
|
||||
update_draft_asset_depr_schedules(self)
|
||||
self.validate_gross_and_purchase_amount()
|
||||
if self.get("schedules"):
|
||||
self.validate_expected_value_after_useful_life()
|
||||
self.validate_expected_value_after_useful_life()
|
||||
|
||||
self.status = self.get_status()
|
||||
|
||||
@@ -52,16 +62,24 @@ class Asset(AccountsController):
|
||||
self.make_asset_movement()
|
||||
if not self.booked_fixed_asset and self.validate_make_gl_entry():
|
||||
self.make_gl_entries()
|
||||
if not self.split_from:
|
||||
make_draft_asset_depr_schedules_if_not_present(self)
|
||||
convert_draft_asset_depr_schedules_into_active(self)
|
||||
|
||||
def on_cancel(self):
|
||||
self.validate_cancellation()
|
||||
self.cancel_movement_entries()
|
||||
self.delete_depreciation_entries()
|
||||
cancel_asset_depr_schedules(self)
|
||||
self.set_status()
|
||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
||||
make_reverse_gl_entries(voucher_type="Asset", voucher_no=self.name)
|
||||
self.db_set("booked_fixed_asset", 0)
|
||||
|
||||
def after_insert(self):
|
||||
if not self.split_from:
|
||||
make_draft_asset_depr_schedules(self)
|
||||
|
||||
def validate_asset_and_reference(self):
|
||||
if self.purchase_invoice or self.purchase_receipt:
|
||||
reference_doc = "Purchase Invoice" if self.purchase_invoice else "Purchase Receipt"
|
||||
@@ -79,12 +97,10 @@ class Asset(AccountsController):
|
||||
_("Purchase Invoice cannot be made against an existing asset {0}").format(self.name)
|
||||
)
|
||||
|
||||
def prepare_depreciation_data(self, date_of_disposal=None, date_of_return=None):
|
||||
def prepare_depreciation_data(self):
|
||||
if self.calculate_depreciation:
|
||||
self.value_after_depreciation = 0
|
||||
self.set_depreciation_rate()
|
||||
self.make_depreciation_schedule(date_of_disposal)
|
||||
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
|
||||
else:
|
||||
self.finance_books = []
|
||||
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(
|
||||
@@ -223,211 +239,6 @@ class Asset(AccountsController):
|
||||
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
|
||||
)
|
||||
|
||||
def make_depreciation_schedule(self, date_of_disposal):
|
||||
if "Manual" not in [d.depreciation_method for d in self.finance_books] and not self.get(
|
||||
"schedules"
|
||||
):
|
||||
self.schedules = []
|
||||
|
||||
if not self.available_for_use_date:
|
||||
return
|
||||
|
||||
start = self.clear_depreciation_schedule()
|
||||
|
||||
for finance_book in self.get("finance_books"):
|
||||
self._make_depreciation_schedule(finance_book, start, date_of_disposal)
|
||||
|
||||
def _make_depreciation_schedule(self, finance_book, start, date_of_disposal):
|
||||
self.validate_asset_finance_books(finance_book)
|
||||
|
||||
value_after_depreciation = self._get_value_after_depreciation(finance_book)
|
||||
finance_book.value_after_depreciation = value_after_depreciation
|
||||
|
||||
number_of_pending_depreciations = cint(finance_book.total_number_of_depreciations) - cint(
|
||||
self.number_of_depreciations_booked
|
||||
)
|
||||
|
||||
has_pro_rata = self.check_is_pro_rata(finance_book)
|
||||
if has_pro_rata:
|
||||
number_of_pending_depreciations += 1
|
||||
|
||||
skip_row = False
|
||||
should_get_last_day = is_last_day_of_the_month(finance_book.depreciation_start_date)
|
||||
|
||||
for n in range(start[finance_book.idx - 1], number_of_pending_depreciations):
|
||||
# If depreciation is already completed (for double declining balance)
|
||||
if skip_row:
|
||||
continue
|
||||
|
||||
depreciation_amount = get_depreciation_amount(self, value_after_depreciation, finance_book)
|
||||
|
||||
if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1:
|
||||
schedule_date = add_months(
|
||||
finance_book.depreciation_start_date, n * cint(finance_book.frequency_of_depreciation)
|
||||
)
|
||||
|
||||
if should_get_last_day:
|
||||
schedule_date = get_last_day(schedule_date)
|
||||
|
||||
# schedule date will be a year later from start date
|
||||
# so monthly schedule date is calculated by removing 11 months from it
|
||||
monthly_schedule_date = add_months(schedule_date, -finance_book.frequency_of_depreciation + 1)
|
||||
|
||||
# if asset is being sold
|
||||
if date_of_disposal:
|
||||
from_date = self.get_from_date(finance_book.finance_book)
|
||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
||||
finance_book, depreciation_amount, from_date, date_of_disposal
|
||||
)
|
||||
|
||||
if depreciation_amount > 0:
|
||||
self._add_depreciation_row(
|
||||
date_of_disposal,
|
||||
depreciation_amount,
|
||||
finance_book.depreciation_method,
|
||||
finance_book.finance_book,
|
||||
finance_book.idx,
|
||||
)
|
||||
|
||||
break
|
||||
|
||||
# For first row
|
||||
if has_pro_rata and not self.opening_accumulated_depreciation and n == 0:
|
||||
from_date = add_days(
|
||||
self.available_for_use_date, -1
|
||||
) # needed to calc depr amount for available_for_use_date too
|
||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
||||
finance_book, depreciation_amount, from_date, finance_book.depreciation_start_date
|
||||
)
|
||||
|
||||
# For first depr schedule date will be the start date
|
||||
# so monthly schedule date is calculated by removing month difference between use date and start date
|
||||
monthly_schedule_date = add_months(finance_book.depreciation_start_date, -months + 1)
|
||||
|
||||
# For last row
|
||||
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
|
||||
if not self.flags.increase_in_asset_life:
|
||||
# In case of increase_in_asset_life, the self.to_date is already set on asset_repair submission
|
||||
self.to_date = add_months(
|
||||
self.available_for_use_date,
|
||||
(n + self.number_of_depreciations_booked) * cint(finance_book.frequency_of_depreciation),
|
||||
)
|
||||
|
||||
depreciation_amount_without_pro_rata = depreciation_amount
|
||||
|
||||
depreciation_amount, days, months = self.get_pro_rata_amt(
|
||||
finance_book, depreciation_amount, schedule_date, self.to_date
|
||||
)
|
||||
|
||||
depreciation_amount = self.get_adjusted_depreciation_amount(
|
||||
depreciation_amount_without_pro_rata, depreciation_amount, finance_book.finance_book
|
||||
)
|
||||
|
||||
monthly_schedule_date = add_months(schedule_date, 1)
|
||||
schedule_date = add_days(schedule_date, days)
|
||||
last_schedule_date = schedule_date
|
||||
|
||||
if not depreciation_amount:
|
||||
continue
|
||||
value_after_depreciation -= flt(depreciation_amount, self.precision("gross_purchase_amount"))
|
||||
|
||||
# Adjust depreciation amount in the last period based on the expected value after useful life
|
||||
if finance_book.expected_value_after_useful_life and (
|
||||
(
|
||||
n == cint(number_of_pending_depreciations) - 1
|
||||
and value_after_depreciation != finance_book.expected_value_after_useful_life
|
||||
)
|
||||
or value_after_depreciation < finance_book.expected_value_after_useful_life
|
||||
):
|
||||
depreciation_amount += value_after_depreciation - finance_book.expected_value_after_useful_life
|
||||
skip_row = True
|
||||
|
||||
if depreciation_amount > 0:
|
||||
self._add_depreciation_row(
|
||||
schedule_date,
|
||||
depreciation_amount,
|
||||
finance_book.depreciation_method,
|
||||
finance_book.finance_book,
|
||||
finance_book.idx,
|
||||
)
|
||||
|
||||
def _add_depreciation_row(
|
||||
self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id
|
||||
):
|
||||
self.append(
|
||||
"schedules",
|
||||
{
|
||||
"schedule_date": schedule_date,
|
||||
"depreciation_amount": depreciation_amount,
|
||||
"depreciation_method": depreciation_method,
|
||||
"finance_book": finance_book,
|
||||
"finance_book_id": finance_book_id,
|
||||
},
|
||||
)
|
||||
|
||||
def _get_value_after_depreciation(self, finance_book):
|
||||
# value_after_depreciation - current Asset value
|
||||
if self.docstatus == 1 and finance_book.value_after_depreciation:
|
||||
value_after_depreciation = flt(finance_book.value_after_depreciation)
|
||||
else:
|
||||
value_after_depreciation = flt(self.gross_purchase_amount) - flt(
|
||||
self.opening_accumulated_depreciation
|
||||
)
|
||||
|
||||
return value_after_depreciation
|
||||
|
||||
# depreciation schedules need to be cleared before modification due to increase in asset life/asset sales
|
||||
# JE: Journal Entry, FB: Finance Book
|
||||
def clear_depreciation_schedule(self):
|
||||
start = []
|
||||
num_of_depreciations_completed = 0
|
||||
depr_schedule = []
|
||||
|
||||
for schedule in self.get("schedules"):
|
||||
# to update start when there are JEs linked with all the schedule rows corresponding to an FB
|
||||
if len(start) == (int(schedule.finance_book_id) - 2):
|
||||
start.append(num_of_depreciations_completed)
|
||||
num_of_depreciations_completed = 0
|
||||
|
||||
# to ensure that start will only be updated once for each FB
|
||||
if len(start) == (int(schedule.finance_book_id) - 1):
|
||||
if schedule.journal_entry:
|
||||
num_of_depreciations_completed += 1
|
||||
depr_schedule.append(schedule)
|
||||
else:
|
||||
start.append(num_of_depreciations_completed)
|
||||
num_of_depreciations_completed = 0
|
||||
|
||||
# to update start when all the schedule rows corresponding to the last FB are linked with JEs
|
||||
if len(start) == (len(self.finance_books) - 1):
|
||||
start.append(num_of_depreciations_completed)
|
||||
|
||||
# when the Depreciation Schedule is being created for the first time
|
||||
if start == []:
|
||||
start = [0] * len(self.finance_books)
|
||||
else:
|
||||
self.schedules = depr_schedule
|
||||
|
||||
return start
|
||||
|
||||
def get_from_date(self, finance_book):
|
||||
if not self.get("schedules"):
|
||||
return self.available_for_use_date
|
||||
|
||||
if len(self.finance_books) == 1:
|
||||
return self.schedules[-1].schedule_date
|
||||
|
||||
from_date = ""
|
||||
for schedule in self.get("schedules"):
|
||||
if schedule.finance_book == finance_book:
|
||||
from_date = schedule.schedule_date
|
||||
|
||||
if from_date:
|
||||
return from_date
|
||||
|
||||
# since depr for available_for_use_date is not yet booked
|
||||
return add_days(self.available_for_use_date, -1)
|
||||
|
||||
# if it returns True, depreciation_amount will not be equal for the first and last rows
|
||||
def check_is_pro_rata(self, row):
|
||||
has_pro_rata = False
|
||||
@@ -512,83 +323,15 @@ class Asset(AccountsController):
|
||||
).format(row.idx)
|
||||
)
|
||||
|
||||
# to ensure that final accumulated depreciation amount is accurate
|
||||
def get_adjusted_depreciation_amount(
|
||||
self, depreciation_amount_without_pro_rata, depreciation_amount_for_last_row, finance_book
|
||||
):
|
||||
if not self.opening_accumulated_depreciation:
|
||||
depreciation_amount_for_first_row = self.get_depreciation_amount_for_first_row(finance_book)
|
||||
|
||||
if (
|
||||
depreciation_amount_for_first_row + depreciation_amount_for_last_row
|
||||
!= depreciation_amount_without_pro_rata
|
||||
):
|
||||
depreciation_amount_for_last_row = (
|
||||
depreciation_amount_without_pro_rata - depreciation_amount_for_first_row
|
||||
)
|
||||
|
||||
return depreciation_amount_for_last_row
|
||||
|
||||
def get_depreciation_amount_for_first_row(self, finance_book):
|
||||
if self.has_only_one_finance_book():
|
||||
return self.schedules[0].depreciation_amount
|
||||
else:
|
||||
for schedule in self.schedules:
|
||||
if schedule.finance_book == finance_book:
|
||||
return schedule.depreciation_amount
|
||||
|
||||
def has_only_one_finance_book(self):
|
||||
if len(self.finance_books) == 1:
|
||||
return True
|
||||
|
||||
def set_accumulated_depreciation(
|
||||
self, date_of_sale=None, date_of_return=None, ignore_booked_entry=False
|
||||
):
|
||||
straight_line_idx = [
|
||||
d.idx for d in self.get("schedules") if d.depreciation_method == "Straight Line"
|
||||
]
|
||||
finance_books = []
|
||||
|
||||
for i, d in enumerate(self.get("schedules")):
|
||||
if ignore_booked_entry and d.journal_entry:
|
||||
continue
|
||||
|
||||
if int(d.finance_book_id) not in finance_books:
|
||||
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
||||
value_after_depreciation = flt(self.get_value_after_depreciation(d.finance_book_id))
|
||||
finance_books.append(int(d.finance_book_id))
|
||||
|
||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||
value_after_depreciation -= flt(depreciation_amount)
|
||||
|
||||
# for the last row, if depreciation method = Straight Line
|
||||
if (
|
||||
straight_line_idx
|
||||
and i == max(straight_line_idx) - 1
|
||||
and not date_of_sale
|
||||
and not date_of_return
|
||||
):
|
||||
book = self.get("finance_books")[cint(d.finance_book_id) - 1]
|
||||
depreciation_amount += flt(
|
||||
value_after_depreciation - flt(book.expected_value_after_useful_life),
|
||||
d.precision("depreciation_amount"),
|
||||
)
|
||||
|
||||
d.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += d.depreciation_amount
|
||||
d.accumulated_depreciation_amount = flt(
|
||||
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
||||
)
|
||||
|
||||
def get_value_after_depreciation(self, idx):
|
||||
return flt(self.get("finance_books")[cint(idx) - 1].value_after_depreciation)
|
||||
|
||||
def validate_expected_value_after_useful_life(self):
|
||||
for row in self.get("finance_books"):
|
||||
depr_schedule = get_depr_schedule(self.name, "Draft", row.finance_book)
|
||||
|
||||
if not depr_schedule:
|
||||
continue
|
||||
|
||||
accumulated_depreciation_after_full_schedule = [
|
||||
d.accumulated_depreciation_amount
|
||||
for d in self.get("schedules")
|
||||
if cint(d.finance_book_id) == row.idx
|
||||
d.accumulated_depreciation_amount for d in depr_schedule
|
||||
]
|
||||
|
||||
if accumulated_depreciation_after_full_schedule:
|
||||
@@ -637,15 +380,23 @@ class Asset(AccountsController):
|
||||
movement.cancel()
|
||||
|
||||
def delete_depreciation_entries(self):
|
||||
for d in self.get("schedules"):
|
||||
if d.journal_entry:
|
||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||
d.db_set("journal_entry", None)
|
||||
if self.calculate_depreciation:
|
||||
for row in self.get("finance_books"):
|
||||
depr_schedule = get_depr_schedule(self.name, "Active", row.finance_book)
|
||||
|
||||
self.db_set(
|
||||
"value_after_depreciation",
|
||||
(flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)),
|
||||
)
|
||||
for d in depr_schedule or []:
|
||||
if d.journal_entry:
|
||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||
else:
|
||||
depr_entries = self.get_manual_depreciation_entries()
|
||||
|
||||
for depr_entry in depr_entries or []:
|
||||
frappe.get_doc("Journal Entry", depr_entry.name).cancel()
|
||||
|
||||
self.db_set(
|
||||
"value_after_depreciation",
|
||||
(flt(self.gross_purchase_amount) - flt(self.opening_accumulated_depreciation)),
|
||||
)
|
||||
|
||||
def set_status(self, status=None):
|
||||
"""Get and update status"""
|
||||
@@ -676,6 +427,19 @@ class Asset(AccountsController):
|
||||
status = "Cancelled"
|
||||
return status
|
||||
|
||||
def get_value_after_depreciation(self, finance_book=None):
|
||||
if not self.calculate_depreciation:
|
||||
return flt(self.value_after_depreciation, self.precision("gross_purchase_amount"))
|
||||
|
||||
if not finance_book:
|
||||
return flt(
|
||||
self.get("finance_books")[0].value_after_depreciation, self.precision("gross_purchase_amount")
|
||||
)
|
||||
|
||||
for row in self.get("finance_books"):
|
||||
if finance_book == row.finance_book:
|
||||
return flt(row.value_after_depreciation, self.precision("gross_purchase_amount"))
|
||||
|
||||
def get_default_finance_book_idx(self):
|
||||
if not self.get("default_finance_book") and self.company:
|
||||
self.default_finance_book = erpnext.get_default_finance_book(self.company)
|
||||
@@ -685,6 +449,43 @@ class Asset(AccountsController):
|
||||
if d.finance_book == self.default_finance_book:
|
||||
return cint(d.idx) - 1
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_manual_depreciation_entries(self):
|
||||
(_, _, depreciation_expense_account) = get_depreciation_accounts(self)
|
||||
|
||||
gle = frappe.qb.DocType("GL Entry")
|
||||
|
||||
records = (
|
||||
frappe.qb.from_(gle)
|
||||
.select(gle.voucher_no.as_("name"), gle.debit.as_("value"), gle.posting_date)
|
||||
.where(gle.against_voucher == self.name)
|
||||
.where(gle.account == depreciation_expense_account)
|
||||
.where(gle.debit != 0)
|
||||
.where(gle.is_cancelled == 0)
|
||||
.orderby(gle.posting_date)
|
||||
).run(as_dict=True)
|
||||
|
||||
return records
|
||||
|
||||
@erpnext.allow_regional
|
||||
def get_depreciation_amount(self, depreciable_value, fb_row):
|
||||
if fb_row.depreciation_method in ("Straight Line", "Manual"):
|
||||
# if the Depreciation Schedule is being prepared for the first time
|
||||
if not self.flags.increase_in_asset_life:
|
||||
depreciation_amount = (
|
||||
flt(self.gross_purchase_amount) - flt(fb_row.expected_value_after_useful_life)
|
||||
) / flt(fb_row.total_number_of_depreciations)
|
||||
|
||||
# if the Depreciation Schedule is being modified after Asset Repair
|
||||
else:
|
||||
depreciation_amount = (
|
||||
flt(fb_row.value_after_depreciation) - flt(fb_row.expected_value_after_useful_life)
|
||||
) / (date_diff(self.to_date, self.available_for_use_date) / 365)
|
||||
else:
|
||||
depreciation_amount = flt(depreciable_value * (flt(fb_row.rate_of_depreciation) / 100))
|
||||
|
||||
return depreciation_amount
|
||||
|
||||
def validate_make_gl_entry(self):
|
||||
purchase_document = self.get_purchase_document()
|
||||
if not purchase_document:
|
||||
@@ -845,7 +646,6 @@ def update_maintenance_status():
|
||||
|
||||
|
||||
def make_post_gl_entry():
|
||||
|
||||
asset_categories = frappe.db.get_all("Asset Category", fields=["name", "enable_cwip_accounting"])
|
||||
|
||||
for asset_category in asset_categories:
|
||||
@@ -998,7 +798,7 @@ def make_journal_entry(asset_name):
|
||||
depreciation_expense_account,
|
||||
) = get_depreciation_accounts(asset)
|
||||
|
||||
depreciation_cost_center, depreciation_series = frappe.db.get_value(
|
||||
depreciation_cost_center, depreciation_series = frappe.get_cached_value(
|
||||
"Company", asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]
|
||||
)
|
||||
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
||||
@@ -1063,6 +863,13 @@ def is_cwip_accounting_enabled(asset_category):
|
||||
return cint(frappe.db.get_value("Asset Category", asset_category, "enable_cwip_accounting"))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_asset_value_after_depreciation(asset_name, finance_book=None):
|
||||
asset = frappe.get_doc("Asset", asset_name)
|
||||
|
||||
return asset.get_value_after_depreciation(finance_book)
|
||||
|
||||
|
||||
def get_total_days(date, frequency):
|
||||
period_start_date = add_months(date, cint(frequency) * -1)
|
||||
|
||||
@@ -1072,32 +879,6 @@ def get_total_days(date, frequency):
|
||||
return date_diff(date, period_start_date)
|
||||
|
||||
|
||||
def is_last_day_of_the_month(date):
|
||||
last_day_of_the_month = get_last_day(date)
|
||||
|
||||
return getdate(last_day_of_the_month) == getdate(date)
|
||||
|
||||
|
||||
@erpnext.allow_regional
|
||||
def get_depreciation_amount(asset, depreciable_value, row):
|
||||
if row.depreciation_method in ("Straight Line", "Manual"):
|
||||
# if the Depreciation Schedule is being prepared for the first time
|
||||
if not asset.flags.increase_in_asset_life:
|
||||
depreciation_amount = (
|
||||
flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)
|
||||
) / flt(row.total_number_of_depreciations)
|
||||
|
||||
# if the Depreciation Schedule is being modified after Asset Repair
|
||||
else:
|
||||
depreciation_amount = (
|
||||
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||
) / (date_diff(asset.to_date, asset.available_for_use_date) / 365)
|
||||
else:
|
||||
depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100))
|
||||
|
||||
return depreciation_amount
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def split_asset(asset_name, split_qty):
|
||||
asset = frappe.get_doc("Asset", asset_name)
|
||||
@@ -1109,12 +890,12 @@ def split_asset(asset_name, split_qty):
|
||||
remaining_qty = asset.asset_quantity - split_qty
|
||||
|
||||
new_asset = create_new_asset_after_split(asset, split_qty)
|
||||
update_existing_asset(asset, remaining_qty)
|
||||
update_existing_asset(asset, remaining_qty, new_asset.name)
|
||||
|
||||
return new_asset
|
||||
|
||||
|
||||
def update_existing_asset(asset, remaining_qty):
|
||||
def update_existing_asset(asset, remaining_qty, new_asset_name):
|
||||
remaining_gross_purchase_amount = flt(
|
||||
(asset.gross_purchase_amount * remaining_qty) / asset.asset_quantity
|
||||
)
|
||||
@@ -1132,34 +913,49 @@ def update_existing_asset(asset, remaining_qty):
|
||||
},
|
||||
)
|
||||
|
||||
for finance_book in asset.get("finance_books"):
|
||||
for row in asset.get("finance_books"):
|
||||
value_after_depreciation = flt(
|
||||
(finance_book.value_after_depreciation * remaining_qty) / asset.asset_quantity
|
||||
(row.value_after_depreciation * remaining_qty) / asset.asset_quantity
|
||||
)
|
||||
expected_value_after_useful_life = flt(
|
||||
(finance_book.expected_value_after_useful_life * remaining_qty) / asset.asset_quantity
|
||||
(row.expected_value_after_useful_life * remaining_qty) / asset.asset_quantity
|
||||
)
|
||||
frappe.db.set_value(
|
||||
"Asset Finance Book", finance_book.name, "value_after_depreciation", value_after_depreciation
|
||||
"Asset Finance Book", row.name, "value_after_depreciation", value_after_depreciation
|
||||
)
|
||||
frappe.db.set_value(
|
||||
"Asset Finance Book",
|
||||
finance_book.name,
|
||||
row.name,
|
||||
"expected_value_after_useful_life",
|
||||
expected_value_after_useful_life,
|
||||
)
|
||||
|
||||
accumulated_depreciation = 0
|
||||
current_asset_depr_schedule_doc = get_asset_depr_schedule_doc(
|
||||
asset.name, "Active", row.finance_book
|
||||
)
|
||||
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
||||
|
||||
for term in asset.get("schedules"):
|
||||
depreciation_amount = flt((term.depreciation_amount * remaining_qty) / asset.asset_quantity)
|
||||
frappe.db.set_value(
|
||||
"Depreciation Schedule", term.name, "depreciation_amount", depreciation_amount
|
||||
)
|
||||
accumulated_depreciation += depreciation_amount
|
||||
frappe.db.set_value(
|
||||
"Depreciation Schedule", term.name, "accumulated_depreciation_amount", accumulated_depreciation
|
||||
new_asset_depr_schedule_doc.set_draft_asset_depr_schedule_details(asset, row)
|
||||
|
||||
accumulated_depreciation = 0
|
||||
|
||||
for term in new_asset_depr_schedule_doc.get("depreciation_schedule"):
|
||||
depreciation_amount = flt((term.depreciation_amount * remaining_qty) / asset.asset_quantity)
|
||||
term.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += depreciation_amount
|
||||
term.accumulated_depreciation_amount = accumulated_depreciation
|
||||
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was updated after being split into new Asset {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name), get_link_to_form(asset.doctype, new_asset_name)
|
||||
)
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
current_asset_depr_schedule_doc.flags.should_not_cancel_depreciation_entries = True
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
||||
|
||||
def create_new_asset_after_split(asset, split_qty):
|
||||
@@ -1173,31 +969,49 @@ def create_new_asset_after_split(asset, split_qty):
|
||||
new_asset.opening_accumulated_depreciation = opening_accumulated_depreciation
|
||||
new_asset.asset_quantity = split_qty
|
||||
new_asset.split_from = asset.name
|
||||
accumulated_depreciation = 0
|
||||
|
||||
for finance_book in new_asset.get("finance_books"):
|
||||
finance_book.value_after_depreciation = flt(
|
||||
(finance_book.value_after_depreciation * split_qty) / asset.asset_quantity
|
||||
for row in new_asset.get("finance_books"):
|
||||
row.value_after_depreciation = flt(
|
||||
(row.value_after_depreciation * split_qty) / asset.asset_quantity
|
||||
)
|
||||
finance_book.expected_value_after_useful_life = flt(
|
||||
(finance_book.expected_value_after_useful_life * split_qty) / asset.asset_quantity
|
||||
row.expected_value_after_useful_life = flt(
|
||||
(row.expected_value_after_useful_life * split_qty) / asset.asset_quantity
|
||||
)
|
||||
|
||||
for term in new_asset.get("schedules"):
|
||||
depreciation_amount = flt((term.depreciation_amount * split_qty) / asset.asset_quantity)
|
||||
term.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += depreciation_amount
|
||||
term.accumulated_depreciation_amount = accumulated_depreciation
|
||||
|
||||
new_asset.submit()
|
||||
new_asset.set_status()
|
||||
|
||||
for term in new_asset.get("schedules"):
|
||||
# Update references in JV
|
||||
if term.journal_entry:
|
||||
add_reference_in_jv_on_split(
|
||||
term.journal_entry, new_asset.name, asset.name, term.depreciation_amount
|
||||
)
|
||||
for row in new_asset.get("finance_books"):
|
||||
current_asset_depr_schedule_doc = get_asset_depr_schedule_doc(
|
||||
asset.name, "Active", row.finance_book
|
||||
)
|
||||
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
||||
|
||||
new_asset_depr_schedule_doc.set_draft_asset_depr_schedule_details(new_asset, row)
|
||||
|
||||
accumulated_depreciation = 0
|
||||
|
||||
for term in new_asset_depr_schedule_doc.get("depreciation_schedule"):
|
||||
depreciation_amount = flt((term.depreciation_amount * split_qty) / asset.asset_quantity)
|
||||
term.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += depreciation_amount
|
||||
term.accumulated_depreciation_amount = accumulated_depreciation
|
||||
|
||||
notes = _("This schedule was created when new Asset {0} was split from Asset {1}.").format(
|
||||
get_link_to_form(new_asset.doctype, new_asset.name), get_link_to_form(asset.doctype, asset.name)
|
||||
)
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
||||
for row in new_asset.get("finance_books"):
|
||||
depr_schedule = get_depr_schedule(new_asset.name, "Active", row.finance_book)
|
||||
for term in depr_schedule:
|
||||
# Update references in JV
|
||||
if term.journal_entry:
|
||||
add_reference_in_jv_on_split(
|
||||
term.journal_entry, new_asset.name, asset.name, term.depreciation_amount
|
||||
)
|
||||
|
||||
return new_asset
|
||||
|
||||
|
||||
@@ -4,15 +4,32 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import add_months, cint, flt, getdate, nowdate, today
|
||||
from frappe.utils import (
|
||||
add_months,
|
||||
cint,
|
||||
flt,
|
||||
get_last_day,
|
||||
get_link_to_form,
|
||||
getdate,
|
||||
is_last_day_of_the_month,
|
||||
nowdate,
|
||||
today,
|
||||
)
|
||||
from frappe.utils.user import get_users_with_role
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_checks_for_pl_and_bs_accounts,
|
||||
)
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_asset_depr_schedule_doc,
|
||||
get_asset_depr_schedule_name,
|
||||
get_temp_asset_depr_schedule_doc,
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones,
|
||||
)
|
||||
|
||||
|
||||
def post_depreciation_entries(date=None, commit=True):
|
||||
def post_depreciation_entries(date=None):
|
||||
# Return if automatic booking of asset depreciation is disabled
|
||||
if not cint(
|
||||
frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically")
|
||||
@@ -21,30 +38,58 @@ def post_depreciation_entries(date=None, commit=True):
|
||||
|
||||
if not date:
|
||||
date = today()
|
||||
for asset in get_depreciable_assets(date):
|
||||
make_depreciation_entry(asset, date)
|
||||
if commit:
|
||||
|
||||
failed_asset_names = []
|
||||
|
||||
for asset_name in get_depreciable_assets(date):
|
||||
asset_doc = frappe.get_doc("Asset", asset_name)
|
||||
|
||||
try:
|
||||
make_depreciation_entry_for_all_asset_depr_schedules(asset_doc, date)
|
||||
frappe.db.commit()
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
failed_asset_names.append(asset_name)
|
||||
|
||||
if failed_asset_names:
|
||||
set_depr_entry_posting_status_for_failed_assets(failed_asset_names)
|
||||
notify_depr_entry_posting_error(failed_asset_names)
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
|
||||
def get_depreciable_assets(date):
|
||||
return frappe.db.sql_list(
|
||||
"""select distinct a.name
|
||||
from tabAsset a, `tabDepreciation Schedule` ds
|
||||
where a.name = ds.parent and a.docstatus=1 and ds.schedule_date<=%s and a.calculate_depreciation = 1
|
||||
from tabAsset a, `tabAsset Depreciation Schedule` ads, `tabDepreciation Schedule` ds
|
||||
where a.name = ads.asset and ads.name = ds.parent and a.docstatus=1 and ads.docstatus=1
|
||||
and a.status in ('Submitted', 'Partially Depreciated')
|
||||
and a.calculate_depreciation = 1
|
||||
and ds.schedule_date<=%s
|
||||
and ifnull(ds.journal_entry, '')=''""",
|
||||
date,
|
||||
)
|
||||
|
||||
|
||||
def make_depreciation_entry_for_all_asset_depr_schedules(asset_doc, date=None):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
asset_depr_schedule_name = get_asset_depr_schedule_name(
|
||||
asset_doc.name, "Active", row.finance_book
|
||||
)
|
||||
make_depreciation_entry(asset_depr_schedule_name, date)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_depreciation_entry(asset_name, date=None):
|
||||
def make_depreciation_entry(asset_depr_schedule_name, date=None):
|
||||
frappe.has_permission("Journal Entry", throw=True)
|
||||
|
||||
if not date:
|
||||
date = today()
|
||||
|
||||
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", asset_depr_schedule_name)
|
||||
|
||||
asset_name = asset_depr_schedule_doc.asset
|
||||
|
||||
asset = frappe.get_doc("Asset", asset_name)
|
||||
(
|
||||
fixed_asset_account,
|
||||
@@ -60,14 +105,14 @@ def make_depreciation_entry(asset_name, date=None):
|
||||
|
||||
accounting_dimensions = get_checks_for_pl_and_bs_accounts()
|
||||
|
||||
for d in asset.get("schedules"):
|
||||
for d in asset_depr_schedule_doc.get("depreciation_schedule"):
|
||||
if not d.journal_entry and getdate(d.schedule_date) <= getdate(date):
|
||||
je = frappe.new_doc("Journal Entry")
|
||||
je.voucher_type = "Depreciation Entry"
|
||||
je.naming_series = depreciation_series
|
||||
je.posting_date = d.schedule_date
|
||||
je.company = asset.company
|
||||
je.finance_book = d.finance_book
|
||||
je.finance_book = asset_depr_schedule_doc.finance_book
|
||||
je.remark = "Depreciation Entry against {0} worth {1}".format(asset_name, d.depreciation_amount)
|
||||
|
||||
credit_account, debit_account = get_credit_and_debit_accounts(
|
||||
@@ -118,14 +163,16 @@ def make_depreciation_entry(asset_name, date=None):
|
||||
|
||||
d.db_set("journal_entry", je.name)
|
||||
|
||||
idx = cint(d.finance_book_id)
|
||||
finance_books = asset.get("finance_books")[idx - 1]
|
||||
finance_books.value_after_depreciation -= d.depreciation_amount
|
||||
finance_books.db_update()
|
||||
idx = cint(asset_depr_schedule_doc.finance_book_id)
|
||||
row = asset.get("finance_books")[idx - 1]
|
||||
row.value_after_depreciation -= d.depreciation_amount
|
||||
row.db_update()
|
||||
|
||||
frappe.db.set_value("Asset", asset_name, "depr_entry_posting_status", "Successful")
|
||||
|
||||
asset.set_status()
|
||||
|
||||
return asset
|
||||
return asset_depr_schedule_doc
|
||||
|
||||
|
||||
def get_depreciation_accounts(asset):
|
||||
@@ -186,6 +233,42 @@ def get_credit_and_debit_accounts(accumulated_depreciation_account, depreciation
|
||||
return credit_account, debit_account
|
||||
|
||||
|
||||
def set_depr_entry_posting_status_for_failed_assets(failed_asset_names):
|
||||
for asset_name in failed_asset_names:
|
||||
frappe.db.set_value("Asset", asset_name, "depr_entry_posting_status", "Failed")
|
||||
|
||||
|
||||
def notify_depr_entry_posting_error(failed_asset_names):
|
||||
recipients = get_users_with_role("Accounts Manager")
|
||||
|
||||
if not recipients:
|
||||
recipients = get_users_with_role("System Manager")
|
||||
|
||||
subject = _("Error while posting depreciation entries")
|
||||
|
||||
asset_links = get_comma_separated_asset_links(failed_asset_names)
|
||||
|
||||
message = (
|
||||
_("Hi,")
|
||||
+ "<br>"
|
||||
+ _("The following assets have failed to post depreciation entries: {0}").format(asset_links)
|
||||
+ "."
|
||||
)
|
||||
|
||||
frappe.sendmail(recipients=recipients, subject=subject, message=message)
|
||||
|
||||
|
||||
def get_comma_separated_asset_links(asset_names):
|
||||
asset_links = []
|
||||
|
||||
for asset_name in asset_names:
|
||||
asset_links.append(get_link_to_form("Asset", asset_name))
|
||||
|
||||
asset_links = ", ".join(asset_links)
|
||||
|
||||
return asset_links
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def scrap_asset(asset_name):
|
||||
asset = frappe.get_doc("Asset", asset_name)
|
||||
@@ -199,7 +282,11 @@ def scrap_asset(asset_name):
|
||||
|
||||
date = today()
|
||||
|
||||
depreciate_asset(asset, date)
|
||||
notes = _("This schedule was created when Asset {0} was scrapped.").format(
|
||||
get_link_to_form(asset.doctype, asset.name)
|
||||
)
|
||||
|
||||
depreciate_asset(asset, date, notes)
|
||||
asset.reload()
|
||||
|
||||
depreciation_series = frappe.get_cached_value(
|
||||
@@ -232,10 +319,15 @@ def restore_asset(asset_name):
|
||||
asset = frappe.get_doc("Asset", asset_name)
|
||||
|
||||
reverse_depreciation_entry_made_after_disposal(asset, asset.disposal_date)
|
||||
reset_depreciation_schedule(asset, asset.disposal_date)
|
||||
|
||||
je = asset.journal_entry_for_scrap
|
||||
|
||||
notes = _("This schedule was created when Asset {0} was restored.").format(
|
||||
get_link_to_form(asset.doctype, asset.name)
|
||||
)
|
||||
|
||||
reset_depreciation_schedule(asset, asset.disposal_date, notes)
|
||||
|
||||
asset.db_set("disposal_date", None)
|
||||
asset.db_set("journal_entry_for_scrap", None)
|
||||
|
||||
@@ -244,25 +336,31 @@ def restore_asset(asset_name):
|
||||
asset.set_status()
|
||||
|
||||
|
||||
def depreciate_asset(asset, date):
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
asset.prepare_depreciation_data(date_of_disposal=date)
|
||||
asset.save()
|
||||
def depreciate_asset(asset_doc, date, notes):
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
|
||||
make_depreciation_entry(asset.name, date)
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
asset_doc, notes, date_of_disposal=date
|
||||
)
|
||||
|
||||
asset_doc.save()
|
||||
|
||||
make_depreciation_entry_for_all_asset_depr_schedules(asset_doc, date)
|
||||
|
||||
|
||||
def reset_depreciation_schedule(asset, date):
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
def reset_depreciation_schedule(asset_doc, date, notes):
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
|
||||
# recreate original depreciation schedule of the asset
|
||||
asset.prepare_depreciation_data(date_of_return=date)
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
asset_doc, notes, date_of_return=date
|
||||
)
|
||||
|
||||
modify_depreciation_schedule_for_asset_repairs(asset)
|
||||
asset.save()
|
||||
modify_depreciation_schedule_for_asset_repairs(asset_doc, notes)
|
||||
|
||||
asset_doc.save()
|
||||
|
||||
|
||||
def modify_depreciation_schedule_for_asset_repairs(asset):
|
||||
def modify_depreciation_schedule_for_asset_repairs(asset, notes):
|
||||
asset_repairs = frappe.get_all(
|
||||
"Asset Repair", filters={"asset": asset.name}, fields=["name", "increase_in_asset_life"]
|
||||
)
|
||||
@@ -271,35 +369,32 @@ def modify_depreciation_schedule_for_asset_repairs(asset):
|
||||
if repair.increase_in_asset_life:
|
||||
asset_repair = frappe.get_doc("Asset Repair", repair.name)
|
||||
asset_repair.modify_depreciation_schedule()
|
||||
asset.prepare_depreciation_data()
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(asset, notes)
|
||||
|
||||
|
||||
def reverse_depreciation_entry_made_after_disposal(asset, date):
|
||||
row = -1
|
||||
finance_book = asset.get("schedules")[0].get("finance_book")
|
||||
for schedule in asset.get("schedules"):
|
||||
if schedule.finance_book != finance_book:
|
||||
row = 0
|
||||
finance_book = schedule.finance_book
|
||||
else:
|
||||
row += 1
|
||||
for row in asset.get("finance_books"):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, "Active", row.finance_book)
|
||||
|
||||
if schedule.schedule_date == date:
|
||||
if not disposal_was_made_on_original_schedule_date(
|
||||
asset, schedule, row, date
|
||||
) or disposal_happens_in_the_future(date):
|
||||
for schedule_idx, schedule in enumerate(asset_depr_schedule_doc.get("depreciation_schedule")):
|
||||
if schedule.schedule_date == date:
|
||||
if not disposal_was_made_on_original_schedule_date(
|
||||
schedule_idx, row, date
|
||||
) or disposal_happens_in_the_future(date):
|
||||
|
||||
reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
|
||||
reverse_journal_entry.posting_date = nowdate()
|
||||
frappe.flags.is_reverse_depr_entry = True
|
||||
reverse_journal_entry.submit()
|
||||
reverse_journal_entry = make_reverse_journal_entry(schedule.journal_entry)
|
||||
reverse_journal_entry.posting_date = nowdate()
|
||||
frappe.flags.is_reverse_depr_entry = True
|
||||
reverse_journal_entry.submit()
|
||||
|
||||
frappe.flags.is_reverse_depr_entry = False
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
schedule.journal_entry = None
|
||||
depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
|
||||
asset.finance_books[0].value_after_depreciation += depreciation_amount
|
||||
asset.save()
|
||||
frappe.flags.is_reverse_depr_entry = False
|
||||
asset_depr_schedule_doc.flags.ignore_validate_update_after_submit = True
|
||||
asset.flags.ignore_validate_update_after_submit = True
|
||||
schedule.journal_entry = None
|
||||
depreciation_amount = get_depreciation_amount_in_je(reverse_journal_entry)
|
||||
row.value_after_depreciation += depreciation_amount
|
||||
asset_depr_schedule_doc.save()
|
||||
asset.save()
|
||||
|
||||
|
||||
def get_depreciation_amount_in_je(journal_entry):
|
||||
@@ -310,15 +405,17 @@ def get_depreciation_amount_in_je(journal_entry):
|
||||
|
||||
|
||||
# if the invoice had been posted on the date the depreciation was initially supposed to happen, the depreciation shouldn't be undone
|
||||
def disposal_was_made_on_original_schedule_date(asset, schedule, row, posting_date_of_disposal):
|
||||
for finance_book in asset.get("finance_books"):
|
||||
if schedule.finance_book == finance_book.finance_book:
|
||||
orginal_schedule_date = add_months(
|
||||
finance_book.depreciation_start_date, row * cint(finance_book.frequency_of_depreciation)
|
||||
)
|
||||
def disposal_was_made_on_original_schedule_date(schedule_idx, row, posting_date_of_disposal):
|
||||
orginal_schedule_date = add_months(
|
||||
row.depreciation_start_date, schedule_idx * cint(row.frequency_of_depreciation)
|
||||
)
|
||||
|
||||
if is_last_day_of_the_month(row.depreciation_start_date):
|
||||
orginal_schedule_date = get_last_day(orginal_schedule_date)
|
||||
|
||||
if orginal_schedule_date == posting_date_of_disposal:
|
||||
return True
|
||||
|
||||
if orginal_schedule_date == posting_date_of_disposal:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -436,18 +533,8 @@ def get_asset_details(asset, finance_book=None):
|
||||
disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
|
||||
depreciation_cost_center = asset.cost_center or depreciation_cost_center
|
||||
|
||||
idx = 1
|
||||
if finance_book:
|
||||
for d in asset.finance_books:
|
||||
if d.finance_book == finance_book:
|
||||
idx = d.idx
|
||||
break
|
||||
value_after_depreciation = asset.get_value_after_depreciation(finance_book)
|
||||
|
||||
value_after_depreciation = (
|
||||
asset.finance_books[idx - 1].value_after_depreciation
|
||||
if asset.calculate_depreciation
|
||||
else asset.value_after_depreciation
|
||||
)
|
||||
accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(value_after_depreciation)
|
||||
|
||||
return (
|
||||
@@ -499,24 +586,27 @@ def get_disposal_account_and_cost_center(company):
|
||||
def get_value_after_depreciation_on_disposal_date(asset, disposal_date, finance_book=None):
|
||||
asset_doc = frappe.get_doc("Asset", asset)
|
||||
|
||||
if asset_doc.calculate_depreciation:
|
||||
asset_doc.prepare_depreciation_data(getdate(disposal_date))
|
||||
|
||||
finance_book_id = 1
|
||||
if finance_book:
|
||||
for fb in asset_doc.finance_books:
|
||||
if fb.finance_book == finance_book:
|
||||
finance_book_id = fb.idx
|
||||
break
|
||||
|
||||
asset_schedules = [
|
||||
sch for sch in asset_doc.schedules if cint(sch.finance_book_id) == finance_book_id
|
||||
]
|
||||
accumulated_depr_amount = asset_schedules[-1].accumulated_depreciation_amount
|
||||
|
||||
return flt(
|
||||
flt(asset_doc.gross_purchase_amount) - accumulated_depr_amount,
|
||||
asset_doc.precision("gross_purchase_amount"),
|
||||
)
|
||||
else:
|
||||
if not asset_doc.calculate_depreciation:
|
||||
return flt(asset_doc.value_after_depreciation)
|
||||
|
||||
idx = 1
|
||||
if finance_book:
|
||||
for d in asset.finance_books:
|
||||
if d.finance_book == finance_book:
|
||||
idx = d.idx
|
||||
break
|
||||
|
||||
row = asset_doc.finance_books[idx - 1]
|
||||
|
||||
temp_asset_depreciation_schedule = get_temp_asset_depr_schedule_doc(
|
||||
asset_doc, row, getdate(disposal_date)
|
||||
)
|
||||
|
||||
accumulated_depr_amount = temp_asset_depreciation_schedule.get("depreciation_schedule")[
|
||||
-1
|
||||
].accumulated_depreciation_amount
|
||||
|
||||
return flt(
|
||||
flt(asset_doc.gross_purchase_amount) - accumulated_depr_amount,
|
||||
asset_doc.precision("gross_purchase_amount"),
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ from frappe.utils import (
|
||||
nowdate,
|
||||
)
|
||||
|
||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.assets.doctype.asset.asset import (
|
||||
make_sales_invoice,
|
||||
@@ -27,6 +28,10 @@ from erpnext.assets.doctype.asset.depreciation import (
|
||||
restore_asset,
|
||||
scrap_asset,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_asset_depr_schedule_doc,
|
||||
get_depr_schedule,
|
||||
)
|
||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
|
||||
make_purchase_invoice as make_invoice,
|
||||
)
|
||||
@@ -205,6 +210,9 @@ class TestAsset(AssetSetup):
|
||||
submit=1,
|
||||
)
|
||||
|
||||
first_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||
|
||||
post_depreciation_entries(date=add_months(purchase_date, 2))
|
||||
asset.load_from_db()
|
||||
|
||||
@@ -216,6 +224,11 @@ class TestAsset(AssetSetup):
|
||||
|
||||
scrap_asset(asset.name)
|
||||
asset.load_from_db()
|
||||
first_asset_depr_schedule.load_from_db()
|
||||
|
||||
second_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||
|
||||
accumulated_depr_amount = flt(
|
||||
asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
|
||||
@@ -256,6 +269,11 @@ class TestAsset(AssetSetup):
|
||||
self.assertSequenceEqual(gle, expected_gle)
|
||||
|
||||
restore_asset(asset.name)
|
||||
second_asset_depr_schedule.load_from_db()
|
||||
|
||||
third_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(third_asset_depr_schedule.status, "Active")
|
||||
self.assertEquals(second_asset_depr_schedule.status, "Cancelled")
|
||||
|
||||
asset.load_from_db()
|
||||
self.assertFalse(asset.journal_entry_for_scrap)
|
||||
@@ -283,6 +301,9 @@ class TestAsset(AssetSetup):
|
||||
submit=1,
|
||||
)
|
||||
|
||||
first_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||
|
||||
post_depreciation_entries(date=add_months(purchase_date, 2))
|
||||
|
||||
si = make_sales_invoice(asset=asset.name, item_code="Macbook Pro", company="_Test Company")
|
||||
@@ -294,6 +315,12 @@ class TestAsset(AssetSetup):
|
||||
|
||||
self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold")
|
||||
|
||||
first_asset_depr_schedule.load_from_db()
|
||||
|
||||
second_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||
|
||||
pro_rata_amount, _, _ = asset.get_pro_rata_amt(
|
||||
asset.finance_books[0], 9000, get_last_day(add_months(purchase_date, 1)), date
|
||||
)
|
||||
@@ -370,6 +397,9 @@ class TestAsset(AssetSetup):
|
||||
submit=1,
|
||||
)
|
||||
|
||||
first_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||
|
||||
post_depreciation_entries(date="2021-01-01")
|
||||
|
||||
self.assertEqual(asset.asset_quantity, 10)
|
||||
@@ -378,21 +408,31 @@ class TestAsset(AssetSetup):
|
||||
|
||||
new_asset = split_asset(asset.name, 2)
|
||||
asset.load_from_db()
|
||||
first_asset_depr_schedule.load_from_db()
|
||||
|
||||
second_asset_depr_schedule = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
first_asset_depr_schedule_of_new_asset = get_asset_depr_schedule_doc(new_asset.name, "Active")
|
||||
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule_of_new_asset.status, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||
|
||||
depr_schedule_of_asset = second_asset_depr_schedule.get("depreciation_schedule")
|
||||
depr_schedule_of_new_asset = first_asset_depr_schedule_of_new_asset.get("depreciation_schedule")
|
||||
|
||||
self.assertEqual(new_asset.asset_quantity, 2)
|
||||
self.assertEqual(new_asset.gross_purchase_amount, 24000)
|
||||
self.assertEqual(new_asset.opening_accumulated_depreciation, 4000)
|
||||
self.assertEqual(new_asset.split_from, asset.name)
|
||||
self.assertEqual(new_asset.schedules[0].depreciation_amount, 4000)
|
||||
self.assertEqual(new_asset.schedules[1].depreciation_amount, 4000)
|
||||
self.assertEqual(depr_schedule_of_new_asset[0].depreciation_amount, 4000)
|
||||
self.assertEqual(depr_schedule_of_new_asset[1].depreciation_amount, 4000)
|
||||
|
||||
self.assertEqual(asset.asset_quantity, 8)
|
||||
self.assertEqual(asset.gross_purchase_amount, 96000)
|
||||
self.assertEqual(asset.opening_accumulated_depreciation, 16000)
|
||||
self.assertEqual(asset.schedules[0].depreciation_amount, 16000)
|
||||
self.assertEqual(asset.schedules[1].depreciation_amount, 16000)
|
||||
self.assertEqual(depr_schedule_of_asset[0].depreciation_amount, 16000)
|
||||
self.assertEqual(depr_schedule_of_asset[1].depreciation_amount, 16000)
|
||||
|
||||
journal_entry = asset.schedules[0].journal_entry
|
||||
journal_entry = depr_schedule_of_asset[0].journal_entry
|
||||
|
||||
jv = frappe.get_doc("Journal Entry", journal_entry)
|
||||
self.assertEqual(jv.accounts[0].credit_in_account_currency, 16000)
|
||||
@@ -629,7 +669,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
|
||||
schedules = [
|
||||
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -651,7 +691,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
expected_schedules = [["2032-12-31", 30000.0, 77095.89], ["2033-06-06", 12904.11, 90000.0]]
|
||||
schedules = [
|
||||
[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -678,7 +718,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
|
||||
schedules = [
|
||||
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -703,7 +743,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
|
||||
schedules = [
|
||||
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -733,7 +773,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
flt(d.depreciation_amount, 2),
|
||||
flt(d.accumulated_depreciation_amount, 2),
|
||||
]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -765,7 +805,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
flt(d.depreciation_amount, 2),
|
||||
flt(d.accumulated_depreciation_amount, 2),
|
||||
]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -798,7 +838,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
flt(d.depreciation_amount, 2),
|
||||
flt(d.accumulated_depreciation_amount, 2),
|
||||
]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
@@ -831,7 +871,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
flt(d.depreciation_amount, 2),
|
||||
flt(d.accumulated_depreciation_amount, 2),
|
||||
]
|
||||
for d in asset.get("schedules")
|
||||
for d in get_depr_schedule(asset.name, "Draft")
|
||||
]
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
|
||||
@@ -854,7 +894,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
["2022-12-31", 30000, 90000],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
@@ -877,16 +917,13 @@ class TestDepreciationBasics(AssetSetup):
|
||||
["2023-01-01", 15000, 90000],
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
self.assertEqual(expected_values[i][2], schedule.accumulated_depreciation_amount)
|
||||
|
||||
def test_get_depreciation_amount(self):
|
||||
"""Tests if get_depreciation_amount() returns the right value."""
|
||||
|
||||
from erpnext.assets.doctype.asset.asset import get_depreciation_amount
|
||||
|
||||
asset = create_asset(item_code="Macbook Pro", available_for_use_date="2019-12-31")
|
||||
|
||||
asset.calculate_depreciation = 1
|
||||
@@ -901,11 +938,11 @@ class TestDepreciationBasics(AssetSetup):
|
||||
},
|
||||
)
|
||||
|
||||
depreciation_amount = get_depreciation_amount(asset, 100000, asset.finance_books[0])
|
||||
depreciation_amount = asset.get_depreciation_amount(100000, asset.finance_books[0])
|
||||
self.assertEqual(depreciation_amount, 30000)
|
||||
|
||||
def test_make_depreciation_schedule(self):
|
||||
"""Tests if make_depreciation_schedule() returns the right values."""
|
||||
def test_make_depr_schedule(self):
|
||||
"""Tests if make_depr_schedule() returns the right values."""
|
||||
|
||||
asset = create_asset(
|
||||
item_code="Macbook Pro",
|
||||
@@ -920,7 +957,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
|
||||
expected_values = [["2020-12-31", 30000.0], ["2021-12-31", 30000.0], ["2022-12-31", 30000.0]]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Draft")):
|
||||
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
|
||||
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)
|
||||
|
||||
@@ -940,7 +977,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
|
||||
expected_values = [30000.0, 60000.0, 90000.0]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Draft")):
|
||||
self.assertEqual(expected_values[i], schedule.accumulated_depreciation_amount)
|
||||
|
||||
def test_check_is_pro_rata(self):
|
||||
@@ -1120,9 +1157,11 @@ class TestDepreciationBasics(AssetSetup):
|
||||
post_depreciation_entries(date="2021-06-01")
|
||||
asset.load_from_db()
|
||||
|
||||
self.assertTrue(asset.schedules[0].journal_entry)
|
||||
self.assertFalse(asset.schedules[1].journal_entry)
|
||||
self.assertFalse(asset.schedules[2].journal_entry)
|
||||
depr_schedule = get_depr_schedule(asset.name, "Active")
|
||||
|
||||
self.assertTrue(depr_schedule[0].journal_entry)
|
||||
self.assertFalse(depr_schedule[1].journal_entry)
|
||||
self.assertFalse(depr_schedule[2].journal_entry)
|
||||
|
||||
def test_depr_entry_posting_when_depr_expense_account_is_an_expense_account(self):
|
||||
"""Tests if the Depreciation Expense Account gets debited and the Accumulated Depreciation Account gets credited when the former's an Expense Account."""
|
||||
@@ -1141,7 +1180,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
post_depreciation_entries(date="2021-06-01")
|
||||
asset.load_from_db()
|
||||
|
||||
je = frappe.get_doc("Journal Entry", asset.schedules[0].journal_entry)
|
||||
je = frappe.get_doc("Journal Entry", get_depr_schedule(asset.name, "Active")[0].journal_entry)
|
||||
accounting_entries = [
|
||||
{"account": entry.account, "debit": entry.debit, "credit": entry.credit}
|
||||
for entry in je.accounts
|
||||
@@ -1177,7 +1216,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
post_depreciation_entries(date="2021-06-01")
|
||||
asset.load_from_db()
|
||||
|
||||
je = frappe.get_doc("Journal Entry", asset.schedules[0].journal_entry)
|
||||
je = frappe.get_doc("Journal Entry", get_depr_schedule(asset.name, "Active")[0].journal_entry)
|
||||
accounting_entries = [
|
||||
{"account": entry.account, "debit": entry.debit, "credit": entry.credit}
|
||||
for entry in je.accounts
|
||||
@@ -1196,8 +1235,8 @@ class TestDepreciationBasics(AssetSetup):
|
||||
depr_expense_account.parent_account = "Expenses - _TC"
|
||||
depr_expense_account.save()
|
||||
|
||||
def test_clear_depreciation_schedule(self):
|
||||
"""Tests if clear_depreciation_schedule() works as expected."""
|
||||
def test_clear_depr_schedule(self):
|
||||
"""Tests if clear_depr_schedule() works as expected."""
|
||||
|
||||
asset = create_asset(
|
||||
item_code="Macbook Pro",
|
||||
@@ -1213,17 +1252,20 @@ class TestDepreciationBasics(AssetSetup):
|
||||
post_depreciation_entries(date="2021-06-01")
|
||||
asset.load_from_db()
|
||||
|
||||
asset.clear_depreciation_schedule()
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, "Active")
|
||||
|
||||
self.assertEqual(len(asset.schedules), 1)
|
||||
asset_depr_schedule_doc.clear_depr_schedule()
|
||||
|
||||
def test_clear_depreciation_schedule_for_multiple_finance_books(self):
|
||||
self.assertEqual(len(asset_depr_schedule_doc.get("depreciation_schedule")), 1)
|
||||
|
||||
def test_clear_depr_schedule_for_multiple_finance_books(self):
|
||||
asset = create_asset(item_code="Macbook Pro", available_for_use_date="2019-12-31", do_not_save=1)
|
||||
|
||||
asset.calculate_depreciation = 1
|
||||
asset.append(
|
||||
"finance_books",
|
||||
{
|
||||
"finance_book": "Test Finance Book 1",
|
||||
"depreciation_method": "Straight Line",
|
||||
"frequency_of_depreciation": 1,
|
||||
"total_number_of_depreciations": 3,
|
||||
@@ -1234,6 +1276,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.append(
|
||||
"finance_books",
|
||||
{
|
||||
"finance_book": "Test Finance Book 2",
|
||||
"depreciation_method": "Straight Line",
|
||||
"frequency_of_depreciation": 1,
|
||||
"total_number_of_depreciations": 6,
|
||||
@@ -1244,6 +1287,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.append(
|
||||
"finance_books",
|
||||
{
|
||||
"finance_book": "Test Finance Book 3",
|
||||
"depreciation_method": "Straight Line",
|
||||
"frequency_of_depreciation": 12,
|
||||
"total_number_of_depreciations": 3,
|
||||
@@ -1256,15 +1300,23 @@ class TestDepreciationBasics(AssetSetup):
|
||||
post_depreciation_entries(date="2020-04-01")
|
||||
asset.load_from_db()
|
||||
|
||||
asset.clear_depreciation_schedule()
|
||||
asset_depr_schedule_doc_1 = get_asset_depr_schedule_doc(
|
||||
asset.name, "Active", "Test Finance Book 1"
|
||||
)
|
||||
asset_depr_schedule_doc_1.clear_depr_schedule()
|
||||
self.assertEqual(len(asset_depr_schedule_doc_1.get("depreciation_schedule")), 3)
|
||||
|
||||
self.assertEqual(len(asset.schedules), 6)
|
||||
asset_depr_schedule_doc_2 = get_asset_depr_schedule_doc(
|
||||
asset.name, "Active", "Test Finance Book 2"
|
||||
)
|
||||
asset_depr_schedule_doc_2.clear_depr_schedule()
|
||||
self.assertEqual(len(asset_depr_schedule_doc_2.get("depreciation_schedule")), 3)
|
||||
|
||||
for schedule in asset.schedules:
|
||||
if schedule.idx <= 3:
|
||||
self.assertEqual(schedule.finance_book_id, "1")
|
||||
else:
|
||||
self.assertEqual(schedule.finance_book_id, "2")
|
||||
asset_depr_schedule_doc_3 = get_asset_depr_schedule_doc(
|
||||
asset.name, "Active", "Test Finance Book 3"
|
||||
)
|
||||
asset_depr_schedule_doc_3.clear_depr_schedule()
|
||||
self.assertEqual(len(asset_depr_schedule_doc_3.get("depreciation_schedule")), 0)
|
||||
|
||||
def test_depreciation_schedules_are_set_up_for_multiple_finance_books(self):
|
||||
asset = create_asset(item_code="Macbook Pro", available_for_use_date="2019-12-31", do_not_save=1)
|
||||
@@ -1273,6 +1325,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.append(
|
||||
"finance_books",
|
||||
{
|
||||
"finance_book": "Test Finance Book 1",
|
||||
"depreciation_method": "Straight Line",
|
||||
"frequency_of_depreciation": 12,
|
||||
"total_number_of_depreciations": 3,
|
||||
@@ -1283,6 +1336,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.append(
|
||||
"finance_books",
|
||||
{
|
||||
"finance_book": "Test Finance Book 2",
|
||||
"depreciation_method": "Straight Line",
|
||||
"frequency_of_depreciation": 12,
|
||||
"total_number_of_depreciations": 6,
|
||||
@@ -1292,13 +1346,15 @@ class TestDepreciationBasics(AssetSetup):
|
||||
)
|
||||
asset.save()
|
||||
|
||||
self.assertEqual(len(asset.schedules), 9)
|
||||
asset_depr_schedule_doc_1 = get_asset_depr_schedule_doc(
|
||||
asset.name, "Draft", "Test Finance Book 1"
|
||||
)
|
||||
self.assertEqual(len(asset_depr_schedule_doc_1.get("depreciation_schedule")), 3)
|
||||
|
||||
for schedule in asset.schedules:
|
||||
if schedule.idx <= 3:
|
||||
self.assertEqual(schedule.finance_book_id, 1)
|
||||
else:
|
||||
self.assertEqual(schedule.finance_book_id, 2)
|
||||
asset_depr_schedule_doc_2 = get_asset_depr_schedule_doc(
|
||||
asset.name, "Draft", "Test Finance Book 2"
|
||||
)
|
||||
self.assertEqual(len(asset_depr_schedule_doc_2.get("depreciation_schedule")), 6)
|
||||
|
||||
def test_depreciation_entry_cancellation(self):
|
||||
asset = create_asset(
|
||||
@@ -1318,12 +1374,12 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.load_from_db()
|
||||
|
||||
# cancel depreciation entry
|
||||
depr_entry = asset.get("schedules")[0].journal_entry
|
||||
depr_entry = get_depr_schedule(asset.name, "Active")[0].journal_entry
|
||||
self.assertTrue(depr_entry)
|
||||
|
||||
frappe.get_doc("Journal Entry", depr_entry).cancel()
|
||||
|
||||
asset.load_from_db()
|
||||
depr_entry = asset.get("schedules")[0].journal_entry
|
||||
depr_entry = get_depr_schedule(asset.name, "Active")[0].journal_entry
|
||||
self.assertFalse(depr_entry)
|
||||
|
||||
def test_asset_expected_value_after_useful_life(self):
|
||||
@@ -1338,7 +1394,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
)
|
||||
|
||||
accumulated_depreciation_after_full_schedule = max(
|
||||
d.accumulated_depreciation_amount for d in asset.get("schedules")
|
||||
d.accumulated_depreciation_amount for d in get_depr_schedule(asset.name, "Draft")
|
||||
)
|
||||
|
||||
asset_value_after_full_schedule = flt(asset.gross_purchase_amount) - flt(
|
||||
@@ -1369,7 +1425,7 @@ class TestDepreciationBasics(AssetSetup):
|
||||
asset.load_from_db()
|
||||
|
||||
# check depreciation entry series
|
||||
self.assertEqual(asset.get("schedules")[0].journal_entry[:4], "DEPR")
|
||||
self.assertEqual(get_depr_schedule(asset.name, "Active")[0].journal_entry[:4], "DEPR")
|
||||
|
||||
expected_gle = (
|
||||
("_Test Accumulated Depreciations - _TC", 0.0, 30000.0),
|
||||
@@ -1439,9 +1495,39 @@ class TestDepreciationBasics(AssetSetup):
|
||||
"2020-07-15",
|
||||
]
|
||||
|
||||
for i, schedule in enumerate(asset.schedules):
|
||||
for i, schedule in enumerate(get_depr_schedule(asset.name, "Active")):
|
||||
self.assertEqual(getdate(expected_dates[i]), getdate(schedule.schedule_date))
|
||||
|
||||
def test_manual_depreciation_for_existing_asset(self):
|
||||
asset = create_asset(
|
||||
item_code="Macbook Pro",
|
||||
is_existing_asset=1,
|
||||
purchase_date="2020-01-30",
|
||||
available_for_use_date="2020-01-30",
|
||||
submit=1,
|
||||
)
|
||||
|
||||
self.assertEqual(asset.status, "Submitted")
|
||||
self.assertEqual(asset.get("value_after_depreciation"), 100000)
|
||||
|
||||
jv = make_journal_entry(
|
||||
"_Test Depreciations - _TC", "_Test Accumulated Depreciations - _TC", 100, save=False
|
||||
)
|
||||
for d in jv.accounts:
|
||||
d.reference_type = "Asset"
|
||||
d.reference_name = asset.name
|
||||
jv.voucher_type = "Depreciation Entry"
|
||||
jv.insert()
|
||||
jv.submit()
|
||||
|
||||
asset.reload()
|
||||
self.assertEqual(asset.get("value_after_depreciation"), 99900)
|
||||
|
||||
jv.cancel()
|
||||
|
||||
asset.reload()
|
||||
self.assertEqual(asset.get("value_after_depreciation"), 100000)
|
||||
|
||||
|
||||
def create_asset_data():
|
||||
if not frappe.db.exists("Asset Category", "Computers"):
|
||||
@@ -1453,6 +1539,15 @@ def create_asset_data():
|
||||
if not frappe.db.exists("Location", "Test Location"):
|
||||
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()
|
||||
|
||||
if not frappe.db.exists("Finance Book", "Test Finance Book 1"):
|
||||
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 1"}).insert()
|
||||
|
||||
if not frappe.db.exists("Finance Book", "Test Finance Book 2"):
|
||||
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 2"}).insert()
|
||||
|
||||
if not frappe.db.exists("Finance Book", "Test Finance Book 3"):
|
||||
frappe.get_doc({"doctype": "Finance Book", "finance_book_name": "Test Finance Book 3"}).insert()
|
||||
|
||||
|
||||
def create_asset(**args):
|
||||
args = frappe._dict(args)
|
||||
@@ -1479,6 +1574,7 @@ def create_asset(**args):
|
||||
"asset_owner": args.asset_owner or "Company",
|
||||
"is_existing_asset": args.is_existing_asset or 1,
|
||||
"asset_quantity": args.get("asset_quantity") or 1,
|
||||
"depr_entry_posting_status": args.depr_entry_posting_status or "",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import frappe
|
||||
|
||||
# import erpnext
|
||||
from frappe import _
|
||||
from frappe.utils import cint, flt
|
||||
from six import string_types
|
||||
from frappe.utils import cint, flt, get_link_to_form
|
||||
|
||||
import erpnext
|
||||
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
|
||||
from erpnext.assets.doctype.asset.depreciation import (
|
||||
depreciate_asset,
|
||||
get_gl_entries_on_asset_disposal,
|
||||
@@ -19,8 +19,8 @@ from erpnext.assets.doctype.asset.depreciation import (
|
||||
reverse_depreciation_entry_made_after_disposal,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
|
||||
from erpnext.assets.doctype.asset_value_adjustment.asset_value_adjustment import (
|
||||
get_current_asset_value,
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones,
|
||||
)
|
||||
from erpnext.controllers.stock_controller import StockController
|
||||
from erpnext.setup.doctype.brand.brand import get_brand_defaults
|
||||
@@ -259,7 +259,9 @@ class AssetCapitalization(StockController):
|
||||
for d in self.get("asset_items"):
|
||||
if d.asset:
|
||||
finance_book = d.get("finance_book") or self.get("finance_book")
|
||||
d.current_asset_value = flt(get_current_asset_value(d.asset, finance_book=finance_book))
|
||||
d.current_asset_value = flt(
|
||||
get_asset_value_after_depreciation(d.asset, finance_book=finance_book)
|
||||
)
|
||||
d.asset_value = get_value_after_depreciation_on_disposal_date(
|
||||
d.asset, self.posting_date, finance_book=finance_book
|
||||
)
|
||||
@@ -427,7 +429,12 @@ class AssetCapitalization(StockController):
|
||||
asset = self.get_asset(item)
|
||||
|
||||
if asset.calculate_depreciation:
|
||||
depreciate_asset(asset, self.posting_date)
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was consumed through Asset Capitalization {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name), get_link_to_form(self.doctype, self.get("name"))
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
@@ -513,7 +520,12 @@ class AssetCapitalization(StockController):
|
||||
asset_doc.purchase_date = self.posting_date
|
||||
asset_doc.gross_purchase_amount = total_target_asset_value
|
||||
asset_doc.purchase_receipt_amount = total_target_asset_value
|
||||
asset_doc.prepare_depreciation_data()
|
||||
notes = _(
|
||||
"This schedule was created when target Asset {0} was updated through Asset Capitalization {1}."
|
||||
).format(
|
||||
get_link_to_form(asset_doc.doctype, asset_doc.name), get_link_to_form(self.doctype, self.name)
|
||||
)
|
||||
make_new_active_asset_depr_schedules_and_cancel_current_ones(asset_doc, notes)
|
||||
asset_doc.flags.ignore_validate_update_after_submit = True
|
||||
asset_doc.save()
|
||||
elif self.docstatus == 2:
|
||||
@@ -524,7 +536,12 @@ class AssetCapitalization(StockController):
|
||||
|
||||
if asset.calculate_depreciation:
|
||||
reverse_depreciation_entry_made_after_disposal(asset, self.posting_date)
|
||||
reset_depreciation_schedule(asset, self.posting_date)
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was restored on Asset Capitalization {1}'s cancellation."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name), get_link_to_form(self.doctype, self.name)
|
||||
)
|
||||
reset_depreciation_schedule(asset, self.posting_date, notes)
|
||||
|
||||
def get_asset(self, item):
|
||||
asset = frappe.get_doc("Asset", item.asset)
|
||||
@@ -608,7 +625,7 @@ def get_target_asset_details(asset=None, company=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_consumed_stock_item_details(args):
|
||||
if isinstance(args, string_types):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
args = frappe._dict(args)
|
||||
@@ -660,7 +677,7 @@ def get_consumed_stock_item_details(args):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_warehouse_details(args):
|
||||
if isinstance(args, string_types):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
args = frappe._dict(args)
|
||||
@@ -676,7 +693,7 @@ def get_warehouse_details(args):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_consumed_asset_details(args):
|
||||
if isinstance(args, string_types):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
args = frappe._dict(args)
|
||||
@@ -696,7 +713,7 @@ def get_consumed_asset_details(args):
|
||||
|
||||
if args.asset:
|
||||
out.current_asset_value = flt(
|
||||
get_current_asset_value(args.asset, finance_book=args.finance_book)
|
||||
get_asset_value_after_depreciation(args.asset, finance_book=args.finance_book)
|
||||
)
|
||||
out.asset_value = get_value_after_depreciation_on_disposal_date(
|
||||
args.asset, args.posting_date, finance_book=args.finance_book
|
||||
@@ -728,7 +745,7 @@ def get_consumed_asset_details(args):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_service_item_details(args):
|
||||
if isinstance(args, string_types):
|
||||
if isinstance(args, str):
|
||||
args = json.loads(args)
|
||||
|
||||
args = frappe._dict(args)
|
||||
|
||||
@@ -12,6 +12,9 @@ from erpnext.assets.doctype.asset.test_asset import (
|
||||
create_asset_data,
|
||||
set_depreciation_settings_in_company,
|
||||
)
|
||||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
|
||||
get_asset_depr_schedule_doc,
|
||||
)
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
|
||||
@@ -253,6 +256,9 @@ class TestAssetCapitalization(unittest.TestCase):
|
||||
submit=1,
|
||||
)
|
||||
|
||||
first_asset_depr_schedule = get_asset_depr_schedule_doc(consumed_asset.name, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Active")
|
||||
|
||||
# Create and submit Asset Captitalization
|
||||
asset_capitalization = create_asset_capitalization(
|
||||
entry_type="Decapitalization",
|
||||
@@ -282,8 +288,18 @@ class TestAssetCapitalization(unittest.TestCase):
|
||||
consumed_asset.reload()
|
||||
self.assertEqual(consumed_asset.status, "Decapitalized")
|
||||
|
||||
first_asset_depr_schedule.load_from_db()
|
||||
|
||||
second_asset_depr_schedule = get_asset_depr_schedule_doc(consumed_asset.name, "Active")
|
||||
self.assertEquals(second_asset_depr_schedule.status, "Active")
|
||||
self.assertEquals(first_asset_depr_schedule.status, "Cancelled")
|
||||
|
||||
depr_schedule_of_consumed_asset = second_asset_depr_schedule.get("depreciation_schedule")
|
||||
|
||||
consumed_depreciation_schedule = [
|
||||
d for d in consumed_asset.schedules if getdate(d.schedule_date) == getdate(capitalization_date)
|
||||
d
|
||||
for d in depr_schedule_of_consumed_asset
|
||||
if getdate(d.schedule_date) == getdate(capitalization_date)
|
||||
]
|
||||
self.assertTrue(
|
||||
consumed_depreciation_schedule and consumed_depreciation_schedule[0].journal_entry
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
frappe.provide("erpnext.asset");
|
||||
|
||||
frappe.ui.form.on('Asset Depreciation Schedule', {
|
||||
onload: function(frm) {
|
||||
frm.events.make_schedules_editable(frm);
|
||||
},
|
||||
|
||||
make_schedules_editable: function(frm) {
|
||||
var is_editable = frm.doc.depreciation_method == "Manual" ? true : false;
|
||||
|
||||
frm.toggle_enable("depreciation_schedule", is_editable);
|
||||
frm.fields_dict["depreciation_schedule"].grid.toggle_enable("schedule_date", is_editable);
|
||||
frm.fields_dict["depreciation_schedule"].grid.toggle_enable("depreciation_amount", is_editable);
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Depreciation Schedule', {
|
||||
make_depreciation_entry: function(frm, cdt, cdn) {
|
||||
var row = locals[cdt][cdn];
|
||||
if (!row.journal_entry) {
|
||||
frappe.call({
|
||||
method: "erpnext.assets.doctype.asset.depreciation.make_depreciation_entry",
|
||||
args: {
|
||||
"asset_depr_schedule_name": frm.doc.name,
|
||||
"date": row.schedule_date
|
||||
},
|
||||
callback: function(r) {
|
||||
frappe.model.sync(r.message);
|
||||
frm.refresh();
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
depreciation_amount: function(frm, cdt, cdn) {
|
||||
erpnext.asset.set_accumulated_depreciation(frm);
|
||||
}
|
||||
});
|
||||
|
||||
erpnext.asset.set_accumulated_depreciation = function(frm) {
|
||||
if(frm.doc.depreciation_method != "Manual") return;
|
||||
|
||||
var accumulated_depreciation = flt(frm.doc.opening_accumulated_depreciation);
|
||||
$.each(frm.doc.schedules || [], function(i, row) {
|
||||
accumulated_depreciation += flt(row.depreciation_amount);
|
||||
frappe.model.set_value(row.doctype, row.name,
|
||||
"accumulated_depreciation_amount", accumulated_depreciation);
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,202 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "naming_series:",
|
||||
"creation": "2022-10-31 15:03:35.424877",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"asset",
|
||||
"naming_series",
|
||||
"column_break_2",
|
||||
"opening_accumulated_depreciation",
|
||||
"finance_book",
|
||||
"finance_book_id",
|
||||
"depreciation_details_section",
|
||||
"depreciation_method",
|
||||
"total_number_of_depreciations",
|
||||
"rate_of_depreciation",
|
||||
"column_break_8",
|
||||
"frequency_of_depreciation",
|
||||
"expected_value_after_useful_life",
|
||||
"depreciation_schedule_section",
|
||||
"depreciation_schedule",
|
||||
"details_section",
|
||||
"notes",
|
||||
"status",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "asset",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Asset",
|
||||
"options": "Asset",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "naming_series",
|
||||
"fieldtype": "Select",
|
||||
"label": "Naming Series",
|
||||
"options": "ACC-ADS-.YYYY.-"
|
||||
},
|
||||
{
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
"label": "Amended From",
|
||||
"no_copy": 1,
|
||||
"options": "Asset Depreciation Schedule",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
"fieldname": "depreciation_details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Depreciation Details"
|
||||
},
|
||||
{
|
||||
"fieldname": "finance_book",
|
||||
"fieldtype": "Link",
|
||||
"label": "Finance Book",
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_method",
|
||||
"fieldtype": "Select",
|
||||
"label": "Depreciation Method",
|
||||
"options": "\nStraight Line\nDouble Declining Balance\nWritten Down Value\nManual",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.depreciation_method == 'Written Down Value'",
|
||||
"description": "In Percentage",
|
||||
"fieldname": "rate_of_depreciation",
|
||||
"fieldtype": "Percent",
|
||||
"label": "Rate of Depreciation",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_8",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "total_number_of_depreciations",
|
||||
"fieldname": "total_number_of_depreciations",
|
||||
"fieldtype": "Int",
|
||||
"label": "Total Number of Depreciations",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_schedule_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Depreciation Schedule"
|
||||
},
|
||||
{
|
||||
"fieldname": "depreciation_schedule",
|
||||
"fieldtype": "Table",
|
||||
"label": "Depreciation Schedule",
|
||||
"options": "Depreciation Schedule"
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
"collapsible_depends_on": "notes",
|
||||
"fieldname": "details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Details"
|
||||
},
|
||||
{
|
||||
"fieldname": "notes",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Notes",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 1,
|
||||
"label": "Status",
|
||||
"options": "Draft\nActive\nCancelled",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "frequency_of_depreciation",
|
||||
"fieldname": "frequency_of_depreciation",
|
||||
"fieldtype": "Int",
|
||||
"label": "Frequency of Depreciation (Months)",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "expected_value_after_useful_life",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Expected Value After Useful Life",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "finance_book_id",
|
||||
"fieldtype": "Int",
|
||||
"hidden": 1,
|
||||
"label": "Finance Book Id",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "opening_accumulated_depreciation",
|
||||
"fieldname": "opening_accumulated_depreciation",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Opening Accumulated Depreciation",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-01-16 21:08:21.421260",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Depreciation Schedule",
|
||||
"naming_rule": "By \"Naming Series\" field",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 1,
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Accounts User",
|
||||
"share": 1,
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Quality Manager",
|
||||
"share": 1,
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import add_days, add_months, cint, flt, get_last_day, is_last_day_of_the_month
|
||||
|
||||
|
||||
class AssetDepreciationSchedule(Document):
|
||||
def before_save(self):
|
||||
if not self.finance_book_id:
|
||||
self.prepare_draft_asset_depr_schedule_data_from_asset_name_and_fb_name(
|
||||
self.asset, self.finance_book
|
||||
)
|
||||
|
||||
def validate(self):
|
||||
self.validate_another_asset_depr_schedule_does_not_exist()
|
||||
|
||||
def validate_another_asset_depr_schedule_does_not_exist(self):
|
||||
finance_book_filter = ["finance_book", "is", "not set"]
|
||||
if self.finance_book:
|
||||
finance_book_filter = ["finance_book", "=", self.finance_book]
|
||||
|
||||
asset_depr_schedule = frappe.db.exists(
|
||||
"Asset Depreciation Schedule",
|
||||
[
|
||||
["asset", "=", self.asset],
|
||||
finance_book_filter,
|
||||
["docstatus", "<", 2],
|
||||
],
|
||||
)
|
||||
|
||||
if asset_depr_schedule and asset_depr_schedule != self.name:
|
||||
if self.finance_book:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Asset Depreciation Schedule {0} for Asset {1} and Finance Book {2} already exists."
|
||||
).format(asset_depr_schedule, self.asset, self.finance_book)
|
||||
)
|
||||
else:
|
||||
frappe.throw(
|
||||
_("Asset Depreciation Schedule {0} for Asset {1} already exists.").format(
|
||||
asset_depr_schedule, self.asset
|
||||
)
|
||||
)
|
||||
|
||||
def on_submit(self):
|
||||
self.db_set("status", "Active")
|
||||
|
||||
def before_cancel(self):
|
||||
if not self.flags.should_not_cancel_depreciation_entries:
|
||||
self.cancel_depreciation_entries()
|
||||
|
||||
def cancel_depreciation_entries(self):
|
||||
for d in self.get("depreciation_schedule"):
|
||||
if d.journal_entry:
|
||||
frappe.get_doc("Journal Entry", d.journal_entry).cancel()
|
||||
|
||||
def on_cancel(self):
|
||||
self.db_set("status", "Cancelled")
|
||||
|
||||
def prepare_draft_asset_depr_schedule_data_from_asset_name_and_fb_name(self, asset_name, fb_name):
|
||||
asset_doc = frappe.get_doc("Asset", asset_name)
|
||||
|
||||
finance_book_filter = ["finance_book", "is", "not set"]
|
||||
if fb_name:
|
||||
finance_book_filter = ["finance_book", "=", fb_name]
|
||||
|
||||
asset_finance_book_name = frappe.db.get_value(
|
||||
doctype="Asset Finance Book",
|
||||
filters=[["parent", "=", asset_name], finance_book_filter],
|
||||
)
|
||||
asset_finance_book_doc = frappe.get_doc("Asset Finance Book", asset_finance_book_name)
|
||||
|
||||
self.prepare_draft_asset_depr_schedule_data(asset_doc, asset_finance_book_doc)
|
||||
|
||||
def prepare_draft_asset_depr_schedule_data(
|
||||
self,
|
||||
asset_doc,
|
||||
row,
|
||||
date_of_disposal=None,
|
||||
date_of_return=None,
|
||||
update_asset_finance_book_row=True,
|
||||
):
|
||||
self.set_draft_asset_depr_schedule_details(asset_doc, row)
|
||||
self.make_depr_schedule(asset_doc, row, date_of_disposal, update_asset_finance_book_row)
|
||||
self.set_accumulated_depreciation(row, date_of_disposal, date_of_return)
|
||||
|
||||
def set_draft_asset_depr_schedule_details(self, asset_doc, row):
|
||||
self.asset = asset_doc.name
|
||||
self.finance_book = row.finance_book
|
||||
self.finance_book_id = row.idx
|
||||
self.opening_accumulated_depreciation = asset_doc.opening_accumulated_depreciation
|
||||
self.depreciation_method = row.depreciation_method
|
||||
self.total_number_of_depreciations = row.total_number_of_depreciations
|
||||
self.frequency_of_depreciation = row.frequency_of_depreciation
|
||||
self.rate_of_depreciation = row.rate_of_depreciation
|
||||
self.expected_value_after_useful_life = row.expected_value_after_useful_life
|
||||
self.status = "Draft"
|
||||
|
||||
def make_depr_schedule(
|
||||
self, asset_doc, row, date_of_disposal, update_asset_finance_book_row=True
|
||||
):
|
||||
if row.depreciation_method != "Manual" and not self.get("depreciation_schedule"):
|
||||
self.depreciation_schedule = []
|
||||
|
||||
if not asset_doc.available_for_use_date:
|
||||
return
|
||||
|
||||
start = self.clear_depr_schedule()
|
||||
|
||||
self._make_depr_schedule(asset_doc, row, start, date_of_disposal, update_asset_finance_book_row)
|
||||
|
||||
def clear_depr_schedule(self):
|
||||
start = 0
|
||||
num_of_depreciations_completed = 0
|
||||
depr_schedule = []
|
||||
|
||||
for schedule in self.get("depreciation_schedule"):
|
||||
if schedule.journal_entry:
|
||||
num_of_depreciations_completed += 1
|
||||
depr_schedule.append(schedule)
|
||||
else:
|
||||
start = num_of_depreciations_completed
|
||||
break
|
||||
|
||||
self.depreciation_schedule = depr_schedule
|
||||
|
||||
return start
|
||||
|
||||
def _make_depr_schedule(
|
||||
self, asset_doc, row, start, date_of_disposal, update_asset_finance_book_row
|
||||
):
|
||||
asset_doc.validate_asset_finance_books(row)
|
||||
|
||||
value_after_depreciation = _get_value_after_depreciation_for_making_schedule(asset_doc, row)
|
||||
row.value_after_depreciation = value_after_depreciation
|
||||
|
||||
if update_asset_finance_book_row:
|
||||
row.db_update()
|
||||
|
||||
number_of_pending_depreciations = cint(row.total_number_of_depreciations) - cint(
|
||||
asset_doc.number_of_depreciations_booked
|
||||
)
|
||||
|
||||
has_pro_rata = asset_doc.check_is_pro_rata(row)
|
||||
if has_pro_rata:
|
||||
number_of_pending_depreciations += 1
|
||||
|
||||
skip_row = False
|
||||
should_get_last_day = is_last_day_of_the_month(row.depreciation_start_date)
|
||||
|
||||
for n in range(start, number_of_pending_depreciations):
|
||||
# If depreciation is already completed (for double declining balance)
|
||||
if skip_row:
|
||||
continue
|
||||
|
||||
depreciation_amount = asset_doc.get_depreciation_amount(value_after_depreciation, row)
|
||||
|
||||
if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1:
|
||||
schedule_date = add_months(
|
||||
row.depreciation_start_date, n * cint(row.frequency_of_depreciation)
|
||||
)
|
||||
|
||||
if should_get_last_day:
|
||||
schedule_date = get_last_day(schedule_date)
|
||||
|
||||
# schedule date will be a year later from start date
|
||||
# so monthly schedule date is calculated by removing 11 months from it
|
||||
monthly_schedule_date = add_months(schedule_date, -row.frequency_of_depreciation + 1)
|
||||
|
||||
# if asset is being sold or scrapped
|
||||
if date_of_disposal:
|
||||
from_date = asset_doc.available_for_use_date
|
||||
if self.depreciation_schedule:
|
||||
from_date = self.depreciation_schedule[-1].schedule_date
|
||||
|
||||
depreciation_amount, days, months = asset_doc.get_pro_rata_amt(
|
||||
row, depreciation_amount, from_date, date_of_disposal
|
||||
)
|
||||
|
||||
if depreciation_amount > 0:
|
||||
self.add_depr_schedule_row(
|
||||
date_of_disposal,
|
||||
depreciation_amount,
|
||||
row.depreciation_method,
|
||||
)
|
||||
|
||||
break
|
||||
|
||||
# For first row
|
||||
if has_pro_rata and not asset_doc.opening_accumulated_depreciation and n == 0:
|
||||
from_date = add_days(
|
||||
asset_doc.available_for_use_date, -1
|
||||
) # needed to calc depr amount for available_for_use_date too
|
||||
depreciation_amount, days, months = asset_doc.get_pro_rata_amt(
|
||||
row, depreciation_amount, from_date, row.depreciation_start_date
|
||||
)
|
||||
|
||||
# For first depr schedule date will be the start date
|
||||
# so monthly schedule date is calculated by removing
|
||||
# month difference between use date and start date
|
||||
monthly_schedule_date = add_months(row.depreciation_start_date, -months + 1)
|
||||
|
||||
# For last row
|
||||
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
|
||||
if not asset_doc.flags.increase_in_asset_life:
|
||||
# In case of increase_in_asset_life, the asset.to_date is already set on asset_repair submission
|
||||
asset_doc.to_date = add_months(
|
||||
asset_doc.available_for_use_date,
|
||||
(n + asset_doc.number_of_depreciations_booked) * cint(row.frequency_of_depreciation),
|
||||
)
|
||||
|
||||
depreciation_amount_without_pro_rata = depreciation_amount
|
||||
|
||||
depreciation_amount, days, months = asset_doc.get_pro_rata_amt(
|
||||
row, depreciation_amount, schedule_date, asset_doc.to_date
|
||||
)
|
||||
|
||||
depreciation_amount = self.get_adjusted_depreciation_amount(
|
||||
depreciation_amount_without_pro_rata, depreciation_amount
|
||||
)
|
||||
|
||||
monthly_schedule_date = add_months(schedule_date, 1)
|
||||
schedule_date = add_days(schedule_date, days)
|
||||
last_schedule_date = schedule_date
|
||||
|
||||
if not depreciation_amount:
|
||||
continue
|
||||
value_after_depreciation -= flt(
|
||||
depreciation_amount, asset_doc.precision("gross_purchase_amount")
|
||||
)
|
||||
|
||||
# Adjust depreciation amount in the last period based on the expected value after useful life
|
||||
if row.expected_value_after_useful_life and (
|
||||
(
|
||||
n == cint(number_of_pending_depreciations) - 1
|
||||
and value_after_depreciation != row.expected_value_after_useful_life
|
||||
)
|
||||
or value_after_depreciation < row.expected_value_after_useful_life
|
||||
):
|
||||
depreciation_amount += value_after_depreciation - row.expected_value_after_useful_life
|
||||
skip_row = True
|
||||
|
||||
if depreciation_amount > 0:
|
||||
self.add_depr_schedule_row(
|
||||
schedule_date,
|
||||
depreciation_amount,
|
||||
row.depreciation_method,
|
||||
)
|
||||
|
||||
# to ensure that final accumulated depreciation amount is accurate
|
||||
def get_adjusted_depreciation_amount(
|
||||
self, depreciation_amount_without_pro_rata, depreciation_amount_for_last_row
|
||||
):
|
||||
if not self.opening_accumulated_depreciation:
|
||||
depreciation_amount_for_first_row = self.get_depreciation_amount_for_first_row()
|
||||
|
||||
if (
|
||||
depreciation_amount_for_first_row + depreciation_amount_for_last_row
|
||||
!= depreciation_amount_without_pro_rata
|
||||
):
|
||||
depreciation_amount_for_last_row = (
|
||||
depreciation_amount_without_pro_rata - depreciation_amount_for_first_row
|
||||
)
|
||||
|
||||
return depreciation_amount_for_last_row
|
||||
|
||||
def get_depreciation_amount_for_first_row(self):
|
||||
return self.get("depreciation_schedule")[0].depreciation_amount
|
||||
|
||||
def add_depr_schedule_row(
|
||||
self,
|
||||
schedule_date,
|
||||
depreciation_amount,
|
||||
depreciation_method,
|
||||
):
|
||||
self.append(
|
||||
"depreciation_schedule",
|
||||
{
|
||||
"schedule_date": schedule_date,
|
||||
"depreciation_amount": depreciation_amount,
|
||||
"depreciation_method": depreciation_method,
|
||||
},
|
||||
)
|
||||
|
||||
def set_accumulated_depreciation(
|
||||
self,
|
||||
row,
|
||||
date_of_disposal=None,
|
||||
date_of_return=None,
|
||||
ignore_booked_entry=False,
|
||||
):
|
||||
straight_line_idx = [
|
||||
d.idx for d in self.get("depreciation_schedule") if d.depreciation_method == "Straight Line"
|
||||
]
|
||||
|
||||
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
|
||||
value_after_depreciation = flt(row.value_after_depreciation)
|
||||
|
||||
for i, d in enumerate(self.get("depreciation_schedule")):
|
||||
if ignore_booked_entry and d.journal_entry:
|
||||
continue
|
||||
|
||||
depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount"))
|
||||
value_after_depreciation -= flt(depreciation_amount)
|
||||
|
||||
# for the last row, if depreciation method = Straight Line
|
||||
if (
|
||||
straight_line_idx
|
||||
and i == max(straight_line_idx) - 1
|
||||
and not date_of_disposal
|
||||
and not date_of_return
|
||||
):
|
||||
depreciation_amount += flt(
|
||||
value_after_depreciation - flt(row.expected_value_after_useful_life),
|
||||
d.precision("depreciation_amount"),
|
||||
)
|
||||
|
||||
d.depreciation_amount = depreciation_amount
|
||||
accumulated_depreciation += d.depreciation_amount
|
||||
d.accumulated_depreciation_amount = flt(
|
||||
accumulated_depreciation, d.precision("accumulated_depreciation_amount")
|
||||
)
|
||||
|
||||
|
||||
def _get_value_after_depreciation_for_making_schedule(asset_doc, fb_row):
|
||||
if asset_doc.docstatus == 1 and fb_row.value_after_depreciation:
|
||||
value_after_depreciation = flt(fb_row.value_after_depreciation)
|
||||
else:
|
||||
value_after_depreciation = flt(asset_doc.gross_purchase_amount) - flt(
|
||||
asset_doc.opening_accumulated_depreciation
|
||||
)
|
||||
|
||||
return value_after_depreciation
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedules_if_not_present(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
draft_asset_depr_schedule_name = get_asset_depr_schedule_name(
|
||||
asset_doc.name, "Draft", row.finance_book
|
||||
)
|
||||
|
||||
active_asset_depr_schedule_name = get_asset_depr_schedule_name(
|
||||
asset_doc.name, "Active", row.finance_book
|
||||
)
|
||||
|
||||
if not draft_asset_depr_schedule_name and not active_asset_depr_schedule_name:
|
||||
make_draft_asset_depr_schedule(asset_doc, row)
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedules(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
make_draft_asset_depr_schedule(asset_doc, row)
|
||||
|
||||
|
||||
def make_draft_asset_depr_schedule(asset_doc, row):
|
||||
asset_depr_schedule_doc = frappe.new_doc("Asset Depreciation Schedule")
|
||||
|
||||
asset_depr_schedule_doc.prepare_draft_asset_depr_schedule_data(asset_doc, row)
|
||||
|
||||
asset_depr_schedule_doc.insert()
|
||||
|
||||
|
||||
def update_draft_asset_depr_schedules(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset_doc.name, "Draft", row.finance_book)
|
||||
|
||||
if not asset_depr_schedule_doc:
|
||||
continue
|
||||
|
||||
asset_depr_schedule_doc.prepare_draft_asset_depr_schedule_data(asset_doc, row)
|
||||
|
||||
asset_depr_schedule_doc.save()
|
||||
|
||||
|
||||
def convert_draft_asset_depr_schedules_into_active(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset_doc.name, "Draft", row.finance_book)
|
||||
|
||||
if not asset_depr_schedule_doc:
|
||||
continue
|
||||
|
||||
asset_depr_schedule_doc.submit()
|
||||
|
||||
|
||||
def cancel_asset_depr_schedules(asset_doc):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset_doc.name, "Active", row.finance_book)
|
||||
|
||||
if not asset_depr_schedule_doc:
|
||||
continue
|
||||
|
||||
asset_depr_schedule_doc.cancel()
|
||||
|
||||
|
||||
def make_new_active_asset_depr_schedules_and_cancel_current_ones(
|
||||
asset_doc, notes, date_of_disposal=None, date_of_return=None
|
||||
):
|
||||
for row in asset_doc.get("finance_books"):
|
||||
current_asset_depr_schedule_doc = get_asset_depr_schedule_doc(
|
||||
asset_doc.name, "Active", row.finance_book
|
||||
)
|
||||
|
||||
if not current_asset_depr_schedule_doc:
|
||||
frappe.throw(
|
||||
_("Asset Depreciation Schedule not found for Asset {0} and Finance Book {1}").format(
|
||||
asset_doc.name, row.finance_book
|
||||
)
|
||||
)
|
||||
|
||||
new_asset_depr_schedule_doc = frappe.copy_doc(current_asset_depr_schedule_doc)
|
||||
|
||||
new_asset_depr_schedule_doc.make_depr_schedule(asset_doc, row, date_of_disposal)
|
||||
new_asset_depr_schedule_doc.set_accumulated_depreciation(row, date_of_disposal, date_of_return)
|
||||
|
||||
new_asset_depr_schedule_doc.notes = notes
|
||||
|
||||
current_asset_depr_schedule_doc.flags.should_not_cancel_depreciation_entries = True
|
||||
current_asset_depr_schedule_doc.cancel()
|
||||
|
||||
new_asset_depr_schedule_doc.submit()
|
||||
|
||||
|
||||
def get_temp_asset_depr_schedule_doc(
|
||||
asset_doc, row, date_of_disposal=None, date_of_return=None, update_asset_finance_book_row=False
|
||||
):
|
||||
asset_depr_schedule_doc = frappe.new_doc("Asset Depreciation Schedule")
|
||||
|
||||
asset_depr_schedule_doc.prepare_draft_asset_depr_schedule_data(
|
||||
asset_doc,
|
||||
row,
|
||||
date_of_disposal,
|
||||
date_of_return,
|
||||
update_asset_finance_book_row,
|
||||
)
|
||||
|
||||
return asset_depr_schedule_doc
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_depr_schedule(asset_name, status, finance_book=None):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset_name, status, finance_book)
|
||||
|
||||
if not asset_depr_schedule_doc:
|
||||
return
|
||||
|
||||
return asset_depr_schedule_doc.get("depreciation_schedule")
|
||||
|
||||
|
||||
def get_asset_depr_schedule_doc(asset_name, status, finance_book=None):
|
||||
asset_depr_schedule_name = get_asset_depr_schedule_name(asset_name, status, finance_book)
|
||||
|
||||
if not asset_depr_schedule_name:
|
||||
return
|
||||
|
||||
asset_depr_schedule_doc = frappe.get_doc("Asset Depreciation Schedule", asset_depr_schedule_name)
|
||||
|
||||
return asset_depr_schedule_doc
|
||||
|
||||
|
||||
def get_asset_depr_schedule_name(asset_name, status, finance_book=None):
|
||||
finance_book_filter = ["finance_book", "is", "not set"]
|
||||
if finance_book:
|
||||
finance_book_filter = ["finance_book", "=", finance_book]
|
||||
|
||||
return frappe.db.get_value(
|
||||
doctype="Asset Depreciation Schedule",
|
||||
filters=[
|
||||
["asset", "=", asset_name],
|
||||
finance_book_filter,
|
||||
["status", "=", status],
|
||||
],
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user