Compare commits

...

207 Commits

Author SHA1 Message Date
Frappe PR Bot
b95ab3425a chore(release): Bumped to Version 14.37.0
# [14.37.0](https://github.com/frappe/erpnext/compare/v14.36.0...v14.37.0) (2023-08-30)

### Bug Fixes

* added valuation field type (Float/Currency) in the filter (backport [#36866](https://github.com/frappe/erpnext/issues/36866)) ([#36868](https://github.com/frappe/erpnext/issues/36868)) ([22247cf](22247cfa17))
* Allow to make return against sales invoice which has closed sales order ([0f98cc8](0f98cc85e9))
* Asset Category filter is not working in asset depreciation([#36806](https://github.com/frappe/erpnext/issues/36806)) ([bd41cb2](bd41cb221b))
* create entries for only PR items present in LCV ([#36852](https://github.com/frappe/erpnext/issues/36852)) ([d2091cc](d2091cc22c))
* error in report when data is not available to load chart in report (backport [#36842](https://github.com/frappe/erpnext/issues/36842)) ([#36853](https://github.com/frappe/erpnext/issues/36853)) ([9789b7b](9789b7bdef))
* error listindexoutofrange when save a production plan ([#36807](https://github.com/frappe/erpnext/issues/36807)) ([fd41594](fd4159423d))
* fetch JVs in tax withholding report without party values ([bc6bd81](bc6bd81f87))
* fetch rounded total while pulling reference details on SO ([adc87f1](adc87f16a3))
* missing company flag for regional fn ([#36791](https://github.com/frappe/erpnext/issues/36791)) ([c07548a](c07548a612))
* SCR return status (backport [#36793](https://github.com/frappe/erpnext/issues/36793)) ([#36796](https://github.com/frappe/erpnext/issues/36796)) ([6edfcf4](6edfcf4de8))
* Tax withholding reversal on Debit Notes ([e8dc63c](e8dc63c89c))

### Features

* **MR:** Project and Cost Center in Connections (backport [#36794](https://github.com/frappe/erpnext/issues/36794)) ([#36795](https://github.com/frappe/erpnext/issues/36795)) ([4fa0777](4fa07777e9))
2023-08-30 13:56:17 +00:00
Deepesh Garg
16edf3ac36 Merge pull request #36861 from frappe/version-14-hotfix
chore: release v14
2023-08-30 19:24:48 +05:30
mergify[bot]
22247cfa17 fix: added valuation field type (Float/Currency) in the filter (backport #36866) (#36868)
fix: added valuation field type (Float/Currency) in the filter (#36866)

(cherry picked from commit dea802dc41)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
2023-08-29 16:57:59 +05:30
mergify[bot]
d2091cc22c fix: create entries for only PR items present in LCV (#36852)
fix: create entries for only PR items present in LCV (#36852)

* fix: check if item code exists in lcv before creating gle

* refactor: use qb to fetch lcv items

(cherry picked from commit 26e8b8f959)

Co-authored-by: Gursheen Kaur Anand <40693548+GursheenK@users.noreply.github.com>
2023-08-29 11:01:40 +05:30
mergify[bot]
9789b7bdef fix: error in report when data is not available to load chart in report (backport #36842) (#36853)
fix: error in report when data is not available to load chart in report (#36842)

(cherry picked from commit 3a2933db4d)

Co-authored-by: ViralKansodiya <141210323+viralkansodiya@users.noreply.github.com>
2023-08-28 18:17:50 +05:30
ruthra kumar
e8d7d30682 Merge pull request #36847 from frappe/mergify/bp/version-14-hotfix/pr-36844
fix: allocation error on partial payment against sales order (backport #36844)
2023-08-28 15:43:30 +05:30
ruthra kumar
05f657e690 test: assert rounded amount is calculated
(cherry picked from commit 2fdbe82835)
2023-08-28 09:42:41 +00:00
ruthra kumar
0350c69856 test: allocation err misfire on Sales Order
(cherry picked from commit 67a0969b78)
2023-08-28 09:42:40 +00:00
ruthra kumar
adc87f16a3 fix: fetch rounded total while pulling reference details on SO
(cherry picked from commit 714b8289c1)
2023-08-28 09:42:40 +00:00
mergify[bot]
bd41cb221b fix: Asset Category filter is not working in asset depreciation(#36806)
fix: Asset Category filter is not working in asset depreciation

fix: Asset Category filter is not working in asset depreciation and balances

Co-authored-by: ubuntu <viralkansodiya167@gmail.com>
(cherry picked from commit 388a42ec7e)

Co-authored-by: ViralKansodiya <141210323+viralkansodiya@users.noreply.github.com>
2023-08-28 11:53:11 +05:30
ruthra kumar
7a5b454e97 Merge pull request #36832 from frappe/mergify/bp/version-14-hotfix/pr-36830
test: Exchange Rate Revaluation functions and its impact on ledger (backport #36830)
2023-08-27 16:05:03 +05:30
ruthra kumar
256c3c81a4 test: Exchange Rate Revaluation functions and its impact on ledger
(cherry picked from commit d40504b973)
2023-08-27 09:41:12 +00:00
mergify[bot]
9b2a84f259 chore: update fr translation for Naming Series (#36785)
* chore: update fr translation for Naming Series (#36785)

* chore: update fr translation for Naming Series

* chore: update fr translation

* chore: update fr translation

* chore: update fr translation

(cherry picked from commit e462edc628)

# Conflicts:
#	erpnext/translations/fr.csv

* chore: resolve conflicts

---------

Co-authored-by: HENRY Florian <florian.henry@open-concept.pro>
Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
2023-08-26 19:29:57 +05:30
mergify[bot]
c07548a612 fix: missing company flag for regional fn (#36791)
fix: missing company flag for regional fn (#36791)

* fix: missing company flag for regional fn

(cherry picked from commit 9bc5952dd5)

Co-authored-by: Dany Robert <danyrt@wahni.com>
2023-08-26 19:29:15 +05:30
Gourav Saini
0f98cc85e9 fix: Allow to make return against sales invoice which has closed sales order
fix: Allow to make return against sales invoice which has closed sales order
2023-08-26 18:04:01 +05:30
Deepesh Garg
aad91c02f3 Merge pull request #36815 from GursheenK/v_14_tax_withholding_jvs_with_no_partytype
fix: fetch JVs in tax withholding report with no party type
2023-08-25 19:41:31 +05:30
ruthra kumar
587283e787 Merge pull request #36822 from frappe/mergify/bp/version-14-hotfix/pr-36821
test: use mixin and increase coverage in receivable report (backport #36821)
2023-08-25 18:46:13 +05:30
ruthra kumar
78b0a52d41 test: increase coverage in ar/ap report
(cherry picked from commit ce81ffd844)
2023-08-25 12:42:23 +00:00
ruthra kumar
c4d338a59b refactor(test): make use of mixin in ar/ap report tests
(cherry picked from commit bb7bed4c1a)
2023-08-25 12:42:22 +00:00
Gursheen Anand
bc6bd81f87 fix: fetch JVs in tax withholding report without party values 2023-08-25 15:05:26 +05:30
ViralKansodiya
fd4159423d fix: error listindexoutofrange when save a production plan (#36807)
fix: error listindexoutof range when save a production plan
2023-08-25 13:43:53 +05:30
Deepesh Garg
95a6e1d855 Merge pull request #36809 from frappe/mergify/bp/version-14-hotfix/pr-36799
fix: Tax withholding reversal on Debit Notes (#36799)
2023-08-25 09:41:07 +05:30
Deepesh Garg
e8dc63c89c fix: Tax withholding reversal on Debit Notes
(cherry picked from commit 6d9cebfee9)
2023-08-24 14:02:32 +00:00
mergify[bot]
6edfcf4de8 fix: SCR return status (backport #36793) (#36796)
fix: SCR return status (#36793)

(cherry picked from commit 723563c167)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
2023-08-24 10:42:59 +05:30
mergify[bot]
4fa07777e9 feat(MR): Project and Cost Center in Connections (backport #36794) (#36795)
feat(MR): Project and Cost Center in Connections (#36794)

(cherry picked from commit 54ffe41b54)

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
2023-08-24 10:15:05 +05:30
ruthra kumar
b1ebd81f77 Merge pull request #36778 from frappe/mergify/bp/version-14-hotfix/pr-36650
perf: improve responsiveness of payment reconciliation tool (backport #36650)
2023-08-23 15:08:47 +05:30
ruthra kumar
20c45c7975 chore: linter fix 2023-08-23 14:15:35 +05:30
ruthra kumar
4a4cba0715 chore: resolve conflict 2023-08-23 13:22:10 +05:30
ruthra kumar
ab9da5281e refactor: filter for journal entries
(cherry picked from commit d01f0f2e96)
2023-08-23 03:43:29 +00:00
ruthra kumar
c5080abd46 refactor: filter on advance payments
(cherry picked from commit 86bac2cf52)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
#	erpnext/controllers/accounts_controller.py
2023-08-23 03:43:29 +00:00
ruthra kumar
a8c53eeb93 refactor: filter on cr/dr notes
(cherry picked from commit 52f609e67a)
2023-08-23 03:43:28 +00:00
ruthra kumar
d727a13562 refactor: trigger on value change
(cherry picked from commit e48f8139eb)
2023-08-23 03:43:28 +00:00
ruthra kumar
4556c36736 refactor: limit output to 50 in reconciliation tool
(cherry picked from commit 7a381affce)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json
2023-08-23 03:43:28 +00:00
Frappe PR Bot
d1b2ce35b6 chore(release): Bumped to Version 14.36.0
# [14.36.0](https://github.com/frappe/erpnext/compare/v14.35.2...v14.36.0) (2023-08-23)

### Bug Fixes

* Accounts Payable Currency bug ([94612b9](94612b90ef))
* Add company filters for account ([e62ffa9](e62ffa990d))
* add missing items labels back ([#36737](https://github.com/frappe/erpnext/issues/36737)) ([3634e80](3634e80341))
* broken advance field in Accounts Receivable summary rpt ([296a4d7](296a4d7a12))
* broken consolidated report due to finance book filter ([5bd2a09](5bd2a0923f))
* check tax and charges if it is passed ([1f76c69](1f76c6972b))
* clear dimension defaults after test ([2a467a9](2a467a9fbf))
* dict value for dimension for gl entries defined without the dimension ([11ba553](11ba553dbd))
* dimension name in remark ([01ae513](01ae513f70))
* divide offsetting amount for multiple dimensions ([1269f2d](1269f2d301))
* divide offsetting amount only when account exists ([2c8c3a0](2c8c3a022c))
* Document Name link validation in Bank Reconciliation Tool ([#36495](https://github.com/frappe/erpnext/issues/36495)) ([83cbc1b](83cbc1bef6)), closes [#35540](https://github.com/frappe/erpnext/issues/35540) [#35540](https://github.com/frappe/erpnext/issues/35540)
* don't throw if item does not have default BOM (backport [#36709](https://github.com/frappe/erpnext/issues/36709)) ([#36734](https://github.com/frappe/erpnext/issues/36734)) ([e1bd9a7](e1bd9a7e8d))
* duplicate acc dimension in test ([cdb66bf](cdb66bf198))
* fetch acc dimensions correctly when fieldname is different from name ([7ac35b4](7ac35b496a))
* fetch accounting dimension details specific to company ([c1f1a21](c1f1a21714))
* include gain/loss journal in AR/AP reports ([4606079](4606079568))
* incorrect gl balance on multi company setup ([cb9aad3](cb9aad3e87))
* incorrect schedule in asset value adjustment ([#36725](https://github.com/frappe/erpnext/issues/36725)) ([a0575ed](a0575ed2b0))
* make offsetting entry for acc dimensions ([3198f26](3198f2669d))
* make offsetting entry for all doctypes ([f578c32](f578c3219d))
* mode of payment fetched from pos profile company in POS ([c74a414](c74a414313))
* not able to make stock entry ([#36759](https://github.com/frappe/erpnext/issues/36759)) ([873ee38](873ee384a1))
* Procurement Tracker report not showing material request items ([#36768](https://github.com/frappe/erpnext/issues/36768)) ([6a9935c](6a9935c00e))
* reset dimension defaults when company changedin test ([37ef6e9](37ef6e959b))
* **RFQ:** make "update password" and "submit quotation" buttons the same size (backport [#36667](https://github.com/frappe/erpnext/issues/36667)) ([#36686](https://github.com/frappe/erpnext/issues/36686)) ([36147ec](36147ec02c))
* timeout error coming during reposting ([#36715](https://github.com/frappe/erpnext/issues/36715)) ([620b21f](620b21fec5))
* **ux:** change batch selection message to alert (backport [#36500](https://github.com/frappe/erpnext/issues/36500)) ([#36697](https://github.com/frappe/erpnext/issues/36697)) ([0a4947a](0a4947a8f6))
* **UX:** Ignore prepared report ([3e23e1f](3e23e1fb91))

### Features

* **RFQ:** make email message fully configurable (backport [#36353](https://github.com/frappe/erpnext/issues/36353)) ([#36531](https://github.com/frappe/erpnext/issues/36531)) ([c308bd5](c308bd5309))
* Tick on checkbox to include draft timesheets (backport [#36577](https://github.com/frappe/erpnext/issues/36577)) ([#36640](https://github.com/frappe/erpnext/issues/36640)) ([9668615](9668615f7e))
* utility to repost accounting ledgers without cancellation ([#36469](https://github.com/frappe/erpnext/issues/36469)) ([f8d6fe6](f8d6fe6be0))

### Performance Improvements

* pull latest details only for referenced vouchers ([47345e8](47345e81a1))
2023-08-23 02:59:58 +00:00
Deepesh Garg
a0a3519cd3 Merge pull request #36763 from frappe/version-14-hotfix
chore: release v14
2023-08-23 08:28:36 +05:30
Deepesh Garg
f16386bd07 Merge pull request #36776 from frappe/mergify/bp/version-14-hotfix/pr-36758
fix: Accounts Payable Currency bug (#36758)
2023-08-22 22:37:39 +05:30
RitvikSardana
94612b90ef fix: Accounts Payable Currency bug
(cherry picked from commit 9349bc77c5)
2023-08-22 17:00:23 +00:00
rohitwaghchaure
6a9935c00e fix: Procurement Tracker report not showing material request items (#36768) 2023-08-22 19:25:50 +05:30
rohitwaghchaure
873ee384a1 fix: not able to make stock entry (#36759) 2023-08-22 16:57:08 +05:30
Deepesh Garg
13b1263723 Merge pull request #36738 from frappe/mergify/bp/version-14-hotfix/pr-36737
fix: add missing items label back (#36737)
2023-08-22 07:58:41 +05:30
ruthra kumar
6761874e28 Merge pull request #36749 from frappe/mergify/bp/version-14-hotfix/pr-36748
chore: clean up stale code in reconciliation tool (backport #36748)
2023-08-22 06:47:41 +05:30
ruthra kumar
19eb6af65f chore: clean up stale code in reconciliation tool
(cherry picked from commit e93b927051)
2023-08-22 00:50:48 +00:00
ruthra kumar
0dc0e287a3 Merge pull request #36741 from frappe/mergify/bp/version-14-hotfix/pr-36727
fix: broken advance field in Accounts Receivable summary rpt (backport #36727)
2023-08-22 06:05:54 +05:30
Anand Baburajan
a0575ed2b0 fix: incorrect schedule in asset value adjustment (#36725)
* fix: incorrect schedule in asset value adjustment

* chore: remove unnecessary commented code

* test: check schedules in test

* test: improving the test

* chore: better function name

* chore: use None instead of 0 for default value after depr

* chore: typo
2023-08-22 01:40:42 +05:30
ruthra kumar
cb9aad3e87 fix: incorrect gl balance on multi company setup 2023-08-21 21:35:26 +05:30
ruthra kumar
37cee42561 test: add test for receivable summary report
(cherry picked from commit af52f21ece)
2023-08-21 15:24:11 +00:00
ruthra kumar
928e475824 refactor: use payment ledger to fetch advance amount
(cherry picked from commit 0dc5e5c430)
2023-08-21 15:24:11 +00:00
ruthra kumar
296a4d7a12 fix: broken advance field in Accounts Receivable summary rpt
(cherry picked from commit 896b123fb1)
2023-08-21 15:24:10 +00:00
ruthra kumar
fe78076cde Merge pull request #36740 from frappe/mergify/bp/version-14-hotfix/pr-36728
fix: include gain/loss journal in AR/AP reports (backport #36728)
2023-08-21 20:20:35 +05:30
Deepesh Garg
d082e68e83 Merge pull request #36707 from frappe/mergify/bp/version-14-hotfix/pr-36149
fix: make offsetting entry for acc dimensions in general ledger (#36149)
2023-08-21 18:02:56 +05:30
ruthra kumar
4606079568 fix: include gain/loss journal in AR/AP reports
(cherry picked from commit e3104f1898)
2023-08-21 11:53:41 +00:00
Ankush Menat
3634e80341 fix: add missing items labels back (#36737)
[skip ci]

(cherry picked from commit 86cac1e1d2)
2023-08-21 10:37:24 +00:00
mergify[bot]
e1bd9a7e8d fix: don't throw if item does not have default BOM (backport #36709) (#36734)
* fix: don't throw if item does not have default BOM

(cherry picked from commit 268c19e745)

* fix: throw if `BOM No` is not set

(cherry picked from commit 2e22b019a0)

---------

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
2023-08-21 15:21:11 +05:30
Deepesh Garg
72d9dc6c85 chore: resolve more conflicts 2023-08-21 10:04:20 +05:30
Deepesh Garg
9ec11d9502 Merge pull request #36726 from frappe/mergify/bp/version-14-hotfix/pr-36696
fix: mode of payment fetched from pos profile company in POS (#36696)
2023-08-20 16:05:05 +05:30
Deepesh Garg
2f92981afe chore: resolve conflicts 2023-08-20 15:47:17 +05:30
Ritvik Sardana
c74a414313 fix: mode of payment fetched from pos profile company in POS
(cherry picked from commit 1bdd43d0f6)
2023-08-20 10:07:56 +00:00
ruthra kumar
e8f1c82089 Merge pull request #36672 from frappe/mergify/bp/version-14-hotfix/pr-36469
feat: utility to repost accounting ledgers without cancellation (backport #36469)
2023-08-19 19:54:55 +05:30
ruthra kumar
6366f5aadb Merge pull request #36679 from frappe/mergify/bp/version-14-hotfix/pr-36649
perf: pull latest details only for referenced vouchers (backport #36649)
2023-08-19 19:29:00 +05:30
Deepesh Garg
933d4bfceb Merge pull request #36711 from frappe/mergify/bp/version-14-hotfix/pr-36710
fix: broken consolidated report due to finance book filter (#36710)
2023-08-19 10:25:11 +05:30
Frappe PR Bot
de3b67c327 chore(release): Bumped to Version 14.35.2
## [14.35.2](https://github.com/frappe/erpnext/compare/v14.35.1...v14.35.2) (2023-08-18)

### Bug Fixes

* timeout error coming during reposting (backport [#36715](https://github.com/frappe/erpnext/issues/36715)) ([#36716](https://github.com/frappe/erpnext/issues/36716)) ([d5a596d](d5a596dff1))
2023-08-18 15:30:59 +00:00
mergify[bot]
d5a596dff1 fix: timeout error coming during reposting (backport #36715) (#36716)
fix: timeout error coming during reposting (#36715)

(cherry picked from commit 620b21fec5)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
2023-08-18 20:59:20 +05:30
rohitwaghchaure
620b21fec5 fix: timeout error coming during reposting (#36715) 2023-08-18 18:33:04 +05:30
ruthra kumar
5bd2a0923f fix: broken consolidated report due to finance book filter
(cherry picked from commit 96847db0ec)
2023-08-18 09:25:18 +00:00
Deepesh Garg
e62ffa990d fix: Add company filters for account
(cherry picked from commit ecca9cb023)

# Conflicts:
#	erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
2023-08-18 07:08:21 +00:00
Gursheen Anand
01ae513f70 fix: dimension name in remark
(cherry picked from commit 4f9242d699)
2023-08-18 07:08:21 +00:00
Gursheen Anand
37ef6e959b fix: reset dimension defaults when company changedin test
(cherry picked from commit 3f5afb9cac)
2023-08-18 07:08:21 +00:00
Gursheen Anand
2a467a9fbf fix: clear dimension defaults after test
(cherry picked from commit 23e56d3ec1)
2023-08-18 07:08:20 +00:00
Gursheen Anand
7ac35b496a fix: fetch acc dimensions correctly when fieldname is different from name
(cherry picked from commit e19a6f5dcb)
2023-08-18 07:08:20 +00:00
Gursheen Anand
cdb66bf198 fix: duplicate acc dimension in test
(cherry picked from commit b3f6d991b5)
2023-08-18 07:08:20 +00:00
Gursheen Anand
8530a28c62 test: PI offsetting entry for accounting dimension
(cherry picked from commit 77deac4fb9)

# Conflicts:
#	erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
2023-08-18 07:08:20 +00:00
Gursheen Anand
2c8c3a022c fix: divide offsetting amount only when account exists
(cherry picked from commit 3a3ffa2307)
2023-08-18 07:08:19 +00:00
Gursheen Anand
1269f2d301 fix: divide offsetting amount for multiple dimensions
(cherry picked from commit 1e1e4b93c1)
2023-08-18 07:08:19 +00:00
Gursheen Anand
11ba553dbd fix: dict value for dimension for gl entries defined without the dimension
(cherry picked from commit ed3bef1840)
2023-08-18 07:08:19 +00:00
Gursheen Anand
248d4082c0 test: TB report balanced whenfiltered using acc dimension
(cherry picked from commit 4004427892)
2023-08-18 07:08:19 +00:00
Gursheen Anand
f578c3219d fix: make offsetting entry for all doctypes
(cherry picked from commit 22ba12172f)
2023-08-18 07:08:18 +00:00
Gursheen Anand
c1f1a21714 fix: fetch accounting dimension details specific to company
(cherry picked from commit 4e09de4db2)
2023-08-18 07:08:18 +00:00
Gursheen Anand
3198f2669d fix: make offsetting entry for acc dimensions
(cherry picked from commit d3759b3971)
2023-08-18 07:08:18 +00:00
Deepesh Garg
a623469778 Merge pull request #36645 from frappe/mergify/bp/version-14-hotfix/pr-36495
fix: Document Name link validation in Bank Reconciliation Tool (#36495)
2023-08-18 09:27:10 +05:30
Deepesh Garg
ee5a1d91ff chore: resolve conflicts 2023-08-17 20:45:53 +05:30
mergify[bot]
0a4947a8f6 fix(ux): change batch selection message to alert (backport #36500) (#36697)
fix(ux): change batch selection message to alert (#36500)

* fix(ux): change batch selection message to alert

* chore: linters

(cherry picked from commit 641fe7738c)

Co-authored-by: Dany Robert <danyrt@wahni.com>
2023-08-17 18:03:58 +05:30
Frappe PR Bot
2aa3b30b56 chore(release): Bumped to Version 14.35.1
## [14.35.1](https://github.com/frappe/erpnext/compare/v14.35.0...v14.35.1) (2023-08-17)

### Bug Fixes

* **ux:** change batch selection message to alert ([#36500](https://github.com/frappe/erpnext/issues/36500)) ([641fe77](641fe7738c))
2023-08-17 12:32:49 +00:00
Dany Robert
641fe7738c fix(ux): change batch selection message to alert (#36500)
* fix(ux): change batch selection message to alert

* chore: linters
2023-08-17 18:01:15 +05:30
mergify[bot]
9668615f7e feat: Tick on checkbox to include draft timesheets (backport #36577) (#36640)
feat: Tick on checkbox to include draft timesheets (#36577)

feat: Tick on Check box to include Draft Timesheets
(cherry picked from commit 75652799cd)

Co-authored-by: ViralKansodiya <141210323+viralkansodiya@users.noreply.github.com>
2023-08-17 17:13:51 +05:30
Deepesh Garg
506ac10119 Merge pull request #36678 from frappe/mergify/bp/version-14-hotfix/pr-36677
fix(UX): Ignore prepared report (#36677)
2023-08-17 16:08:36 +05:30
mergify[bot]
36147ec02c fix(RFQ): make "update password" and "submit quotation" buttons the same size (backport #36667) (#36686)
fix(RFQ): make "update password" and "submit quotation" buttons the same size (#36667)

fix(RFQ): button styling

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
2023-08-17 16:00:17 +05:30
Shariq Ansari
3dd642441b Merge pull request #36689 from frappe/mergify/bp/version-14-hotfix/pr-36685
fix: check tax and charges if it is passed (backport #36685)
2023-08-17 13:10:42 +05:30
Shariq Ansari
f186015f58 chore: linter fix
(cherry picked from commit 21c1141fdb)
2023-08-17 07:40:10 +00:00
Shariq Ansari
1f76c6972b fix: check tax and charges if it is passed
(cherry picked from commit 7ec6909159)
2023-08-17 07:40:10 +00:00
mergify[bot]
c308bd5309 feat(RFQ): make email message fully configurable (backport #36353) (#36531)
* feat(RFQ): make email message fully configurable (#36353)

feat: make RFQ message fully configurable
(cherry picked from commit 21080afd92)

* fix(RFQ): hide description in print and report

---------

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
2023-08-17 12:11:37 +05:30
ruthra kumar
3f33d4cf76 chore: resolve conflicts 2023-08-17 11:07:59 +05:30
ruthra kumar
47345e81a1 perf: pull latest details only for referenced vouchers
(cherry picked from commit deb0d71294)

# Conflicts:
#	erpnext/accounts/doctype/payment_entry/payment_entry.py
2023-08-17 03:31:54 +00:00
Deepesh Garg
3e23e1fb91 fix(UX): Ignore prepared report
(cherry picked from commit 124c0dbd88)
2023-08-16 16:03:01 +00:00
ruthra kumar
b6134749c3 chore: resolve conflict 2023-08-16 16:44:07 +05:30
ruthra kumar
f8d6fe6be0 feat: utility to repost accounting ledgers without cancellation (#36469)
* feat: introduce doctypes for repost

* refactor: basic filters and validations

* chore: basic validations

* chore: added barebones function to generate ledger entries

* chore: repost on submit

* chore: repost in background

* chore: include payment entry and journal entry

* chore: ignore repost doc on cancel

* chore: preview method

* chore: rudimentary form of preview

* refactor: preview template

* refactor: basic background colors to differentiate old and new

* chore: remove commented code

* test: basic functionality

* chore: fix conflict

* chore: prevent repost on invoices with deferred accounting

* refactor(test): rename and test basic validations and methods

* refactor(test): test all validations

* fix(test): use proper name account name

* refactor(test): fix failing test case

* refactor(test): clear old entries

* refactor(test): simpler logic to clear old records

* refactor(test): make use of deletion flag

* refactor(test): split into multiple test cases

(cherry picked from commit e64b004eca)

# Conflicts:
#	erpnext/accounts/doctype/journal_entry/journal_entry.js
2023-08-16 11:04:45 +00:00
Frappe PR Bot
b773465b41 chore(release): Bumped to Version 14.35.0
# [14.35.0](https://github.com/frappe/erpnext/compare/v14.34.3...v14.35.0) (2023-08-16)

### Bug Fixes

* Allow backdated repayment cancels for term loans ([1377cf4](1377cf4cf1))
* allow negative stock condition for batch item ([#36586](https://github.com/frappe/erpnext/issues/36586)) ([ee04c6d](ee04c6d5c5))
* AR/AP report based on payment terms ([#36574](https://github.com/frappe/erpnext/issues/36574)) ([ac0fff7](ac0fff7e94))
* better remarks on Cr note created by Reconciliation ([5443592](5443592d84))
* Button Alignment center in hero slider ([#36607](https://github.com/frappe/erpnext/issues/36607)) ([b131f70](b131f70ed6)), closes [#36561](https://github.com/frappe/erpnext/issues/36561)
* cr/dr note should be posted for exc gain/loss ([349601b](349601b4b9))
* disallow mulitple SO with same PO No ([b901cfd](b901cfdbe2))
* don't show disabled items in `Item Shortage Report` (backport [#36550](https://github.com/frappe/erpnext/issues/36550)) ([#36571](https://github.com/frappe/erpnext/issues/36571)) ([19cfcea](19cfcea78e))
* fetch `Stock UOM` from Item if not set (backport [#36606](https://github.com/frappe/erpnext/issues/36606)) ([#36617](https://github.com/frappe/erpnext/issues/36617)) ([8b13185](8b13185c25))
* Group Account total not showing in Financial Statements ([2912648](2912648151))
* incorrect available qty for backdated stock reco with batch ([#36581](https://github.com/frappe/erpnext/issues/36581)) ([2800ad3](2800ad39d2))
* incorrect gain/loss on allocation change on reconciliation tool ([39c439d](39c439dc4b))
* Make default sales update frequency as monthly instead of each transaction ([4ca1f3b](4ca1f3b9cf))
* move company rename to long queue ([8083c0b](8083c0b59e))
* precision issue while submitting the stock entry ([#36575](https://github.com/frappe/erpnext/issues/36575)) ([a864e07](a864e07d4f))
* re-add permission that was unintentionally removed ([#36663](https://github.com/frappe/erpnext/issues/36663)) ([99777d3](99777d3fa4))
* **RFQ:** link to supplier portal ([eb2f68e](eb2f68ec98))
* standard formula to calculate the "difference" ([#36612](https://github.com/frappe/erpnext/issues/36612)) ([716d5c0](716d5c0b98))
* Tax withholding post LDC limit consumed ([#36611](https://github.com/frappe/erpnext/issues/36611)) ([1deebe8](1deebe8757))
* **test:** replace hardcoded reference to adv with dynamic one ([2e6bfa3](2e6bfa36de))
* **test:** test case breakage in Github Actions ([3542df7](3542df70f6))
* unhide `uom` and `stock_uom` fields in print view ([b49309c](b49309c160))
* validation blocks partial payment for SO and PO ([ce08f03](ce08f038d2))
* wrap none type rate under flt (backport [#36602](https://github.com/frappe/erpnext/issues/36602)) ([#36604](https://github.com/frappe/erpnext/issues/36604)) ([63c061e](63c061e5e8))
* wrong currency on financial-statement based reports ([#36524](https://github.com/frappe/erpnext/issues/36524)) ([3044f46](3044f46c52))

### Features

* add voucher totals in tds payable report ([#36568](https://github.com/frappe/erpnext/issues/36568)) ([90b390c](90b390c2c5))
* daily asset depreciation method ([#36587](https://github.com/frappe/erpnext/issues/36587)) ([2918127](29181274c8))
* Reallow customizing company abbreviation on setup. ([#36646](https://github.com/frappe/erpnext/issues/36646)) ([ca34b63](ca34b63470))

### Performance Improvements

* **invoice:** Faster return amount query (backport [#36556](https://github.com/frappe/erpnext/issues/36556)) ([#36557](https://github.com/frappe/erpnext/issues/36557)) ([fe41be9](fe41be953d))
2023-08-16 06:34:09 +00:00
Deepesh Garg
787118d00b Merge pull request #36658 from frappe/version-14-hotfix
chore: release v14
2023-08-16 12:02:35 +05:30
Deepesh Garg
67c8350f70 Merge branch 'version-14' into version-14-hotfix 2023-08-16 11:08:08 +05:30
ruthra kumar
cba1c63beb Merge pull request #36651 from frappe/mergify/bp/version-14-hotfix/pr-36642
refactor: toggle for negative item rates in Selling Settings (backport #36642)
2023-08-16 10:30:24 +05:30
ruthra kumar
2f0e7fcb4a Merge branch 'version-14-hotfix' into mergify/bp/version-14-hotfix/pr-36642 2023-08-16 09:58:31 +05:30
ruthra kumar
44c1b91ca7 Merge pull request #36633 from frappe/mergify/bp/version-14-hotfix/pr-35644
refactor: booking exchange gain/loss amount through journal (backport #35644)
2023-08-16 09:41:25 +05:30
mergify[bot]
1deebe8757 fix: Tax withholding post LDC limit consumed (#36611)
* fix: Tax withholding post LDC limit consumed (#36611)

* fix: Tax withholding post LDC limit consumed

* fix: LDC condition check

(cherry picked from commit 985ff9781b)

# Conflicts:
#	erpnext/accounts/doctype/tax_withholding_category/test_tax_withholding_category.py

* chore: resolve conflicts

* chore: linting issues

---------

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
2023-08-16 08:09:38 +05:30
mergify[bot]
99777d3fa4 fix: re-add permission that was unintentionally removed (#36663)
fix: re-add permission that was unintentionally removed

Remove `Reversal OF ITC` and re-add permissions. Both of them
unintended changes

(cherry picked from commit 45662fa646)

Co-authored-by: ruthra kumar <ruthra@erpnext.com>
2023-08-16 08:09:04 +05:30
mergify[bot]
33d5250cec chore: add validation for depreciation expense account in asset category (backport #36659) (#36661)
chore: add validation for depreciation expense account in asset category (#36659)

(cherry picked from commit e0c79d3b53)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
2023-08-15 18:27:01 +05:30
ruthra kumar
e55c160438 chore: resolve conflicts 2023-08-15 08:56:37 +05:30
ruthra kumar
3a82eb4ccf refactor: toggle for negative rates in Selling Settings
(cherry picked from commit a0fc68538f)

# Conflicts:
#	erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
#	erpnext/patches.txt
#	erpnext/selling/doctype/selling_settings/selling_settings.json
2023-08-15 02:43:54 +00:00
Devin Slauenwhite
ca34b63470 feat: Reallow customizing company abbreviation on setup. (#36646)
Co-authored-by: Bernd Oliver Sünderhauf <pancho@mailbox.org>
2023-08-14 21:44:03 +05:30
Kevin Shenk
83cbc1bef6 fix: Document Name link validation in Bank Reconciliation Tool (#36495)
fix: format_row broke Document Name link validation

#35540 broke Voucher Matching, leading to an invalid link exception on submission. This is because the format_row() function overwrites the row data instead of just providing a formatter on the DataTable column, and therefore passes through the formatted (linked) column data instead of the Document Name only.

This patch moves the appropriate frappe.form.formatters.Link function to a dedicated format hook on the DataTable columns definition, both fixing the error and retaining the functionality of #35540.

(cherry picked from commit 7ab55b1bb2)

# Conflicts:
#	erpnext/public/js/bank_reconciliation_tool/dialog_manager.js
2023-08-14 13:34:31 +00:00
mergify[bot]
716d5c0b98 fix: standard formula to calculate the "difference" (#36612)
fix: standard formula to calculate the "difference" (#36612)

(cherry picked from commit 843e77e72d)

Co-authored-by: HarryPaulo <paulo_fabris@hotmail.com>
2023-08-14 18:55:16 +05:30
Gursheen Kaur Anand
90b390c2c5 feat: add voucher totals in tds payable report (#36568)
* feat: voucher totals in tds payable monthly

* fix: naming series column in tds payable report

* fix: tds computation summary columns
2023-08-14 18:15:21 +05:30
ViralKansodiya
b131f70ed6 fix: Button Alignment center in hero slider (#36607)
fix: speling in CSS (Button alignment center is not working on hero slider)#36561
2023-08-14 16:20:58 +05:30
ruthra kumar
18cf93d1c8 refactor(test): import missing functions 2023-08-14 11:49:46 +05:30
ruthra kumar
2e6bfa36de fix(test): replace hardcoded reference to adv with dynamic one 2023-08-14 11:30:35 +05:30
ruthra kumar
b3f4c14a26 chore: resolve conflict in payment_reconciliation.py
backport will merge the better remarks PR
https://github.com/frappe/erpnext/pull/36573 wil exchange gain/loss
booking refactor
2023-08-14 10:56:48 +05:30
ruthra kumar
946aadb0c0 chore: resolve conflict in test_sales_invoice.py 2023-08-14 10:52:49 +05:30
ruthra kumar
f92453ae45 chore: resolve merge conflict in accounts/utils.py and its tests 2023-08-14 10:50:31 +05:30
ruthra kumar
7469018d3e chore: resolve merge conflict 2023-08-14 10:37:56 +05:30
ruthra kumar
61afffc908 chore: cancel gain/loss je while posting reverse gl
(cherry picked from commit 46ea814400)
2023-08-14 04:51:46 +00:00
ruthra kumar
ed0881dacb chore: don't make gain/loss journal for base currency transactions
(cherry picked from commit 567c0ce1e8)
2023-08-14 04:51:46 +00:00
ruthra kumar
efb293398a chore(test): use existing company for unit test
(cherry picked from commit 804afaa647)
2023-08-14 04:51:46 +00:00
ruthra kumar
8d32a1f4b3 chore: rename some internal variables
(cherry picked from commit d9d6856153)
2023-08-14 04:51:46 +00:00
ruthra kumar
4c527d6bba chore: add msgprint for exc JE
(cherry picked from commit acc7322874)
2023-08-14 04:51:45 +00:00
ruthra kumar
2a61d854d3 chore: use frappetestcase
(cherry picked from commit 47bbb37291)
2023-08-14 04:51:45 +00:00
ruthra kumar
052abcb075 refactor(test): assert ledger outstanding
(cherry picked from commit 025091161e)

# Conflicts:
#	erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
2023-08-14 04:51:45 +00:00
ruthra kumar
3542df70f6 fix(test): test case breakage in Github Actions
(cherry picked from commit bfa54d5335)
2023-08-14 04:51:45 +00:00
ruthra kumar
c5c440b7bc test: assert ledger after cr note cancellation
(cherry picked from commit ae424fdfed)
2023-08-14 04:51:45 +00:00
ruthra kumar
349601b4b9 fix: cr/dr note should be posted for exc gain/loss
(cherry picked from commit 95543225cf)
2023-08-14 04:51:44 +00:00
ruthra kumar
09e9b16b93 test: cr notes against invoice
(cherry picked from commit e3d2a2c5bd)
2023-08-14 04:51:44 +00:00
ruthra kumar
39c439dc4b fix: incorrect gain/loss on allocation change on reconciliation tool
(cherry picked from commit 506a5775f9)
2023-08-14 04:51:44 +00:00
ruthra kumar
72a507f888 refactor: create gain/loss on Cr/Dr notes with different exc rates
(cherry picked from commit ba1f065765)
2023-08-14 04:51:44 +00:00
ruthra kumar
22dbe52586 refactor: convert class method to standalone function
(cherry picked from commit 1ea1bfebc4)
2023-08-14 04:51:44 +00:00
ruthra kumar
1999132c28 refactor: split make_exchage_gain_loss_journal into smaller function
(cherry picked from commit c0b3b069b5)
2023-08-14 04:51:43 +00:00
ruthra kumar
57af6d9c21 refactor: cr/dr note will be on single exchange rate
(cherry picked from commit c87332d5da)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
2023-08-14 04:51:43 +00:00
ruthra kumar
a9faa92796 chore: type info
(cherry picked from commit 6628632fbb)
2023-08-14 04:51:43 +00:00
ruthra kumar
d9219dc7d2 chore(test): fix broken test case
(cherry picked from commit 37895a361c)
2023-08-14 04:51:43 +00:00
ruthra kumar
395f87a0f8 chore(test): fix broken unit test
(cherry picked from commit 70dd9d0671)

# Conflicts:
#	erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
2023-08-14 04:51:43 +00:00
ruthra kumar
4094fbc3e5 test: journals against sales invoice
(cherry picked from commit f3363e813a)
2023-08-14 04:51:42 +00:00
ruthra kumar
513721c338 refactor: handle diff amount in various names
(cherry picked from commit f4a65cccc4)
2023-08-14 04:51:42 +00:00
ruthra kumar
077d98e0fa refactor: unit tests for journals
(cherry picked from commit 5695d6a5a6)
2023-08-14 04:51:42 +00:00
ruthra kumar
8be312b73e refactor: dr/cr logic for journals as payments
(cherry picked from commit 0567243772)
2023-08-14 04:51:42 +00:00
ruthra kumar
197e5881aa refactor: assert payment ledger outstanding in both currencies
(cherry picked from commit 73cc1ba654)
2023-08-14 04:51:41 +00:00
ruthra kumar
7c3fc7eb3b refactor: cancel gain/loss JE on Journal as payment cancellation
(cherry picked from commit 6e18bb6456)
2023-08-14 04:51:41 +00:00
ruthra kumar
01953bc0e3 refactor: linkage between journal as payment and gain/loss journal
(cherry picked from commit f119a1e115)

# Conflicts:
#	erpnext/accounts/doctype/gl_entry/gl_entry.py
2023-08-14 04:51:41 +00:00
ruthra kumar
075a7dfe2e chore: code cleanup
(cherry picked from commit cd42b26839)
2023-08-14 04:51:41 +00:00
ruthra kumar
86aead3d45 refactor: remove call for setting deductions in payment entry
(cherry picked from commit 1bcb728c85)

# Conflicts:
#	erpnext/accounts/utils.py
2023-08-14 04:51:40 +00:00
ruthra kumar
e20b213737 refactor(test): difference amount no updated for exchange gain/loss
(cherry picked from commit 72bc5b3a11)

# Conflicts:
#	erpnext/accounts/test/test_utils.py
2023-08-14 04:51:40 +00:00
ruthra kumar
4025442491 refactor(test): exc gain/loss journal for advance in purchase invoice
(cherry picked from commit 5b06bd1af4)
2023-08-14 04:51:40 +00:00
ruthra kumar
f6bb6b78db refactor: only post on base currency for exchange gain/loss
(cherry picked from commit 78bc712756)
2023-08-14 04:51:40 +00:00
ruthra kumar
00a26ea6e6 refactor(test): payment will have same exch rate - no gain/loss
while making payment entry using reference to sales/purchase invoice,
it herits the parent docs exchange rate. so, there will be no exchange
gain/loss

(cherry picked from commit ee2d1fa36e)
2023-08-14 04:51:39 +00:00
ruthra kumar
e2c35f8c85 refactor(test): assert Exc journal when reconciling Journa to invoic
(cherry picked from commit 389cadf157)
2023-08-14 04:51:39 +00:00
ruthra kumar
72e88d22ed chore: remove debugging statements and fixing failing unit tests
(cherry picked from commit ee3ce82ea8)
2023-08-14 04:51:39 +00:00
ruthra kumar
220bf24555 refactor: exc booking logic for Journal Entry
(cherry picked from commit 7b516f8463)
2023-08-14 04:51:39 +00:00
ruthra kumar
1f76dde025 refactor(test): exc gain/loss booked through journal
(cherry picked from commit 00a2e42a47)
2023-08-14 04:51:38 +00:00
ruthra kumar
59b7e96255 refactor: assert exchange gain/loss amount in reference table
(cherry picked from commit 4ff53e1062)
2023-08-14 04:51:38 +00:00
ruthra kumar
d030f4a100 refactor: remove unused variable, pe should pull in parent exc rate
1. 'reference_doc' variable is never set. Hence, removing.
2. set_exchange_rate() relies on ref_doc, which was never
set due to point [1]. Replacing it with 'doc'.
3. Sales/Purchase Invoice has 'conversion_rate' field for tracking
exchange rate. Added a get statement for them as well.

(cherry picked from commit 92ae9c2201)
2023-08-14 04:51:38 +00:00
ruthra kumar
6c6acef78e refactor: helper method
(cherry picked from commit c1184585ed)
2023-08-14 04:51:38 +00:00
ruthra kumar
a9da619903 chore: fix logic for purchase invoice and some typos
(cherry picked from commit 34b5e849a2)
2023-08-14 04:51:38 +00:00
ruthra kumar
72005bdb39 refactor: add new reference type in journal entry account
(cherry picked from commit 13febcac81)
2023-08-14 04:51:38 +00:00
ruthra kumar
287af687cf chore: patch to update property setter for Journal Entry Accounts
(cherry picked from commit 0587338435)
2023-08-14 04:51:37 +00:00
ruthra kumar
db46987d4b refactor: replace with new method in purchase invoice
(cherry picked from commit 7e94a1c51b)
2023-08-14 04:51:37 +00:00
ruthra kumar
44110860b4 test: different scenarios for exchange booking
(cherry picked from commit 5e1cd1f227)
2023-08-14 04:51:37 +00:00
ruthra kumar
c06a6bfc09 refactor: book exchange gain/loss through journal
(cherry picked from commit 81cd7873d3)
2023-08-14 04:51:37 +00:00
mergify[bot]
ac0fff7e94 fix: AR/AP report based on payment terms (#36574)
fix: AR/AP report based on payment terms (#36574)

* fix: AR/AP report based on payment terms

* fix: AR/AP report based on payment terms

(cherry picked from commit fbb5058531)

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
2023-08-14 09:46:41 +05:30
mergify[bot]
3044f46c52 fix: wrong currency on financial-statement based reports (#36524)
fix: wrong currency on financial-statement based reports (#36524)

* add missing field options on financial_statement Total field

* format financial statement code

(cherry picked from commit ce25f9e8c9)

Co-authored-by: Naufal Afif <naufalafif58@gmail.com>
2023-08-13 17:11:47 +05:30
Deepesh Garg
0a832bc979 Merge pull request #36609 from frappe/mergify/bp/version-14-hotfix/pr-36564
fix: Make default sales update frequency as monthly instead of each transaction (#36564)
2023-08-13 13:20:27 +05:30
Deepesh Garg
e5bc888798 Merge pull request #36614 from deepeshgarg007/loan_repayment_cancel_v14
fix: Allow backdated repayment cancels for term loans
2023-08-13 11:57:49 +05:30
ruthra kumar
9172985a9b Merge pull request #36621 from frappe/mergify/bp/version-14-hotfix/pr-36309
fix: allocation validation blocks partial payment for SO and PO (backport #36309)
2023-08-13 11:39:27 +05:30
Deepesh Garg
a3032910a7 chore: resolve conflicts 2023-08-13 11:37:40 +05:30
ruthra kumar
ce08f038d2 fix: validation blocks partial payment for SO and PO
(cherry picked from commit cb2bfabb6f)
2023-08-13 10:58:55 +05:30
ruthra kumar
df632d7ecb Merge pull request #36620 from frappe/mergify/bp/version-14-hotfix/pr-36590
fix: disallow mulitple SO with same Purchase Order No if not enabled in Settings (backport #36590)
2023-08-13 08:48:27 +05:30
ruthra kumar
1693905703 Merge pull request #36619 from frappe/mergify/bp/version-14-hotfix/pr-36593
chore: update permissions for Process Payment Reconciliation (backport #36593)
2023-08-13 08:43:00 +05:30
ruthra kumar
21d3fb0625 chore: resolve merge conflict 2023-08-13 08:24:01 +05:30
ruthra kumar
c83f10f638 refactor(test): don't set po_no by default
(cherry picked from commit 64614cd915)

# Conflicts:
#	erpnext/stock/doctype/delivery_note/test_delivery_note.py
2023-08-13 02:40:42 +00:00
ruthra kumar
b901cfdbe2 fix: disallow mulitple SO with same PO No
(cherry picked from commit dbd3fdbb41)
2023-08-13 02:40:42 +00:00
ruthra kumar
cbcdf30840 chore: update permissions for Process Payment Reconciliation
(cherry picked from commit cd28d15292)
2023-08-13 02:40:38 +00:00
mergify[bot]
8b13185c25 fix: fetch Stock UOM from Item if not set (backport #36606) (#36617)
fix: fetch `Stock UOM` from Item if not set (#36606)

(cherry picked from commit 539cfd08f0)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
2023-08-12 23:25:05 +05:30
Deepesh Garg
1377cf4cf1 fix: Allow backdated repayment cancels for term loans 2023-08-12 20:01:04 +05:30
Deepesh Garg
4ca1f3b9cf fix: Make default sales update frequency as monthly instead of each transaction
(cherry picked from commit 32863b4922)

# Conflicts:
#	erpnext/selling/doctype/selling_settings/selling_settings.json
2023-08-11 17:10:07 +00:00
Deepesh Garg
347c67a0f1 Merge pull request #36608 from frappe/mergify/bp/version-14-hotfix/pr-36582
fix: Group Account total not showing in Financial Statements (#36582)
2023-08-11 22:33:35 +05:30
Deepesh Garg
2912648151 fix: Group Account total not showing in Financial Statements
(cherry picked from commit baf5cddd1b)
2023-08-11 16:27:53 +00:00
Frappe PR Bot
ddcf555486 chore(release): Bumped to Version 14.34.3
## [14.34.3](https://github.com/frappe/erpnext/compare/v14.34.2...v14.34.3) (2023-08-11)

### Bug Fixes

* wrap none type rate under flt (backport [#36602](https://github.com/frappe/erpnext/issues/36602)) (backport [#36604](https://github.com/frappe/erpnext/issues/36604)) ([#36605](https://github.com/frappe/erpnext/issues/36605)) ([e4e1f03](e4e1f03bac))
2023-08-11 13:28:22 +00:00
mergify[bot]
e4e1f03bac fix: wrap none type rate under flt (backport #36602) (backport #36604) (#36605)
fix: wrap none type rate under flt (backport #36602) (#36604)

fix: wrap none type rate under flt (#36602)

(cherry picked from commit 627986efa1)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
(cherry picked from commit 63c061e5e8)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2023-08-11 18:56:29 +05:30
mergify[bot]
63c061e5e8 fix: wrap none type rate under flt (backport #36602) (#36604)
fix: wrap none type rate under flt (#36602)

(cherry picked from commit 627986efa1)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
2023-08-11 12:55:25 +00:00
mergify[bot]
96663d7e28 chore: set default filter dates if missing (backport #36597) (#36598)
chore: set default filter dates if missing (#36597)

(cherry picked from commit 98e82e0d99)

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
2023-08-11 09:19:14 +00:00
rohitwaghchaure
ee04c6d5c5 fix: allow negative stock condition for batch item (#36586)
* fix: allow negative stock condition for batch item

* fix: test case
2023-08-11 13:57:27 +05:30
ruthra kumar
a4d6e0092c Merge pull request #36594 from frappe/mergify/bp/version-14/pr-36593
chore: update permissions for Process Payment Reconciliation (backport #36593)
2023-08-11 12:14:48 +05:30
ruthra kumar
9821f90350 chore: update permissions for Process Payment Reconciliation
(cherry picked from commit cd28d15292)
2023-08-11 06:14:34 +00:00
ruthra kumar
5488785fd8 Merge pull request #36579 from frappe/mergify/bp/version-14-hotfix/pr-36573
refactor: 'is system generated' field and better remarks in Journal Entry (backport #36573)
2023-08-11 09:43:53 +05:30
ruthra kumar
25ac0ce1cc Merge pull request #36580 from frappe/mergify/bp/version-14-hotfix/pr-36578
fix: unhide `uom` and `stock_uom` fields in print view (backport #36578)
2023-08-11 09:16:07 +05:30
ruthra kumar
727a379581 chore: remove unwanted 'Reversal of ITC' and merge conflicts 2023-08-11 09:12:11 +05:30
Anand Baburajan
29181274c8 feat: daily asset depreciation method (#36587)
* feat: daily asset depreciation method

* chore: hide depr schedule if no schedules
2023-08-10 22:47:16 +05:30
Frappe PR Bot
35450d7bd9 chore(release): Bumped to Version 14.34.2
## [14.34.2](https://github.com/frappe/erpnext/compare/v14.34.1...v14.34.2) (2023-08-10)

### Bug Fixes

* incorrect available qty for backdated stock reco with batch (backport [#36581](https://github.com/frappe/erpnext/issues/36581)) ([#36585](https://github.com/frappe/erpnext/issues/36585)) ([bb112ec](bb112eca05))
2023-08-10 12:28:54 +00:00
mergify[bot]
bb112eca05 fix: incorrect available qty for backdated stock reco with batch (backport #36581) (#36585)
fix: incorrect available qty for backdated stock reco with batch (#36581)

(cherry picked from commit 2800ad39d2)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
2023-08-10 17:57:17 +05:30
rohitwaghchaure
2800ad39d2 fix: incorrect available qty for backdated stock reco with batch (#36581) 2023-08-10 17:22:14 +05:30
ruthra kumar
b49309c160 fix: unhide uom and stock_uom fields in print view
(cherry picked from commit 11cd163db7)
2023-08-10 10:18:36 +00:00
ruthra kumar
a04471024d refactor: enable 'no-copy'
(cherry picked from commit 4ed4b0240d)
2023-08-10 10:09:26 +00:00
ruthra kumar
9b0d30c56b refactor: set flag display condition
(cherry picked from commit de17eaef38)
2023-08-10 10:09:25 +00:00
ruthra kumar
00c7dbceaa refactor: add is_system_generated field to Journal Entry
(cherry picked from commit 3997aa77d4)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
2023-08-10 10:09:25 +00:00
ruthra kumar
5443592d84 fix: better remarks on Cr note created by Reconciliation
(cherry picked from commit 47cb349362)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
2023-08-10 10:09:25 +00:00
rohitwaghchaure
a864e07d4f fix: precision issue while submitting the stock entry (#36575)
fix: precision issue while submmiting the stock entry
2023-08-10 13:32:31 +05:30
mergify[bot]
19cfcea78e fix: don't show disabled items in Item Shortage Report (backport #36550) (#36571)
fix: don't show disabled items in `Item Shortage Report` (#36550)

(cherry picked from commit 4a7fc1506f)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
2023-08-10 11:29:20 +05:30
Ankush Menat
8083c0b59e fix: move company rename to long queue
(cherry picked from commit 5169006085)
2023-08-10 10:03:22 +05:30
Anand Baburajan
8abc0adb18 chore: add warning for lending separation (#36569) 2023-08-09 15:07:40 +00:00
mergify[bot]
fe41be953d perf(invoice): Faster return amount query (backport #36556) (#36557)
perf(invoice): Faster return amount query (#36556)

perf: Faster return amount query
(cherry picked from commit b0c79a0467)

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-08-09 14:07:48 +05:30
s-aga-r
c2b5417cb8 Merge pull request #36552 from frappe/mergify/bp/version-14-hotfix/pr-36551
fix(RFQ): link to supplier portal (backport #36551)
2023-08-09 13:55:28 +05:30
barredterra
d273948d7a test(RFQ): get_link
(cherry picked from commit 68ad62f7d0)
2023-08-08 11:25:39 +00:00
barredterra
eb2f68ec98 fix(RFQ): link to supplier portal
(cherry picked from commit fd91f2c2e0)
2023-08-08 11:25:39 +00:00
114 changed files with 4707 additions and 1044 deletions

View File

@@ -3,7 +3,7 @@ import inspect
import frappe
__version__ = "14.34.1"
__version__ = "14.37.0"
def get_default_company(user=None):

View File

@@ -15,6 +15,17 @@ frappe.ui.form.on('Accounting Dimension', {
};
});
frm.set_query("offsetting_account", "dimension_defaults", function(doc, cdt, cdn) {
let d = locals[cdt][cdn];
return {
filters: {
company: d.company,
root_type: ["in", ["Asset", "Liability"]],
is_group: 0
}
}
});
if (!frm.is_new()) {
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
frappe.set_route("List", frm.doc.document_type);

View File

@@ -39,6 +39,8 @@ class AccountingDimension(Document):
if not self.is_new():
self.validate_document_type_change()
self.validate_dimension_defaults()
def validate_document_type_change(self):
doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type")
if doctype_before_save != self.document_type:
@@ -46,6 +48,14 @@ class AccountingDimension(Document):
message += _("Please create a new Accounting Dimension if required.")
frappe.throw(message)
def validate_dimension_defaults(self):
companies = []
for default in self.get("dimension_defaults"):
if default.company not in companies:
companies.append(default.company)
else:
frappe.throw(_("Company {0} is added more than once").format(frappe.bold(default.company)))
def after_insert(self):
if frappe.flags.in_test:
make_dimension_in_accounting_doctypes(doc=self)

View File

@@ -8,7 +8,10 @@
"reference_document",
"default_dimension",
"mandatory_for_bs",
"mandatory_for_pl"
"mandatory_for_pl",
"column_break_lqns",
"automatically_post_balancing_accounting_entry",
"offsetting_account"
],
"fields": [
{
@@ -50,6 +53,23 @@
"fieldtype": "Check",
"in_list_view": 1,
"label": "Mandatory For Profit and Loss Account"
},
{
"default": "0",
"fieldname": "automatically_post_balancing_accounting_entry",
"fieldtype": "Check",
"label": "Automatically post balancing accounting entry"
},
{
"fieldname": "offsetting_account",
"fieldtype": "Link",
"label": "Offsetting Account",
"mandatory_depends_on": "eval: doc.automatically_post_balancing_accounting_entry",
"options": "Account"
},
{
"fieldname": "column_break_lqns",
"fieldtype": "Column Break"
}
],
"istable": 1,

View File

@@ -3,6 +3,296 @@
import unittest
import frappe
from frappe import qb
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, flt, today
class TestExchangeRateRevaluation(unittest.TestCase):
pass
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.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.party import get_party_account
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.stock.doctype.item.test_item import create_item
class TestExchangeRateRevaluation(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.create_company()
self.create_usd_receivable_account()
self.create_item()
self.create_customer()
self.clear_old_entries()
self.set_system_and_company_settings()
def tearDown(self):
frappe.db.rollback()
def set_system_and_company_settings(self):
# set number and currency precision
system_settings = frappe.get_doc("System Settings")
system_settings.float_precision = 2
system_settings.currency_precision = 2
system_settings.save()
# Using Exchange Gain/Loss account for unrealized as well.
company_doc = frappe.get_doc("Company", self.company)
company_doc.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account
company_doc.save()
@change_settings(
"Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
)
def test_01_revaluation_of_forex_balance(self):
"""
Test Forex account balance and Journal creation post Revaluation
"""
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debtors_usd,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_submit=1,
)
si.currency = "USD"
si.conversion_rate = 80
si.save().submit()
err = frappe.new_doc("Exchange Rate Revaluation")
err.company = (self.company,)
err.posting_date = today()
accounts = err.get_accounts_data()
err.extend("accounts", accounts)
row = err.accounts[0]
row.new_exchange_rate = 85
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()
# Create JV for ERR
err_journals = err.make_jv_entries()
je = frappe.get_doc("Journal Entry", err_journals.get("revaluation_jv"))
je = je.submit()
je.reload()
self.assertEqual(je.voucher_type, "Exchange Rate Revaluation")
self.assertEqual(je.total_debit, 8500.0)
self.assertEqual(je.total_credit, 8500.0)
acc_balance = frappe.db.get_all(
"GL Entry",
filters={"account": self.debtors_usd, "is_cancelled": 0},
fields=["sum(debit)-sum(credit) as balance"],
)[0]
self.assertEqual(acc_balance.balance, 8500.0)
@change_settings(
"Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
)
def test_02_accounts_only_with_base_currency_balance(self):
"""
Test Revaluation on Forex account with balance only in base currency
"""
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debtors_usd,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_submit=1,
)
si.currency = "USD"
si.conversion_rate = 80
si.save().submit()
pe = get_payment_entry(si.doctype, si.name)
pe.source_exchange_rate = 85
pe.received_amount = 8500
pe.save().submit()
# Cancel the auto created gain/loss JE to simulate balance only in base currency
je = frappe.db.get_all(
"Journal Entry Account", filters={"reference_name": si.name}, pluck="parent"
)[0]
frappe.get_doc("Journal Entry", je).cancel()
err = frappe.new_doc("Exchange Rate Revaluation")
err.company = (self.company,)
err.posting_date = today()
err.fetch_and_calculate_accounts_data()
err = err.save().submit()
# Create JV for ERR
self.assertTrue(err.check_journal_entry_condition())
err_journals = err.make_jv_entries()
je = frappe.get_doc("Journal Entry", err_journals.get("zero_balance_jv"))
je = je.submit()
je.reload()
self.assertEqual(je.voucher_type, "Exchange Gain Or Loss")
self.assertEqual(len(je.accounts), 2)
# Only base currency fields will be posted to
for acc in je.accounts:
self.assertEqual(acc.debit_in_account_currency, 0)
self.assertEqual(acc.credit_in_account_currency, 0)
self.assertEqual(je.total_debit, 500.0)
self.assertEqual(je.total_credit, 500.0)
acc_balance = frappe.db.get_all(
"GL Entry",
filters={"account": self.debtors_usd, "is_cancelled": 0},
fields=[
"sum(debit)-sum(credit) as balance",
"sum(debit_in_account_currency)-sum(credit_in_account_currency) as balance_in_account_currency",
],
)[0]
# account shouldn't have balance in base and account currency
self.assertEqual(acc_balance.balance, 0.0)
self.assertEqual(acc_balance.balance_in_account_currency, 0.0)
@change_settings(
"Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
)
def test_03_accounts_only_with_account_currency_balance(self):
"""
Test Revaluation on Forex account with balance only in account currency
"""
precision = frappe.db.get_single_value("System Settings", "currency_precision")
# posting on previous date to make sure that ERR picks up the Payment entry's exchange
# rate while calculating gain/loss for account currency balance
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debtors_usd,
posting_date=add_days(today(), -1),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_submit=1,
)
si.currency = "USD"
si.conversion_rate = 80
si.save().submit()
pe = get_payment_entry(si.doctype, si.name)
pe.paid_amount = 95
pe.source_exchange_rate = 84.211
pe.received_amount = 8000
pe.references = []
pe.save().submit()
acc_balance = frappe.db.get_all(
"GL Entry",
filters={"account": self.debtors_usd, "is_cancelled": 0},
fields=[
"sum(debit)-sum(credit) as balance",
"sum(debit_in_account_currency)-sum(credit_in_account_currency) as balance_in_account_currency",
],
)[0]
# account should have balance only in account currency
self.assertEqual(flt(acc_balance.balance, precision), 0.0)
self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 5.0) # in USD
err = frappe.new_doc("Exchange Rate Revaluation")
err.company = (self.company,)
err.posting_date = today()
err.fetch_and_calculate_accounts_data()
err.set_total_gain_loss()
err = err.save().submit()
# Create JV for ERR
self.assertTrue(err.check_journal_entry_condition())
err_journals = err.make_jv_entries()
je = frappe.get_doc("Journal Entry", err_journals.get("zero_balance_jv"))
je = je.submit()
je.reload()
self.assertEqual(je.voucher_type, "Exchange Gain Or Loss")
self.assertEqual(len(je.accounts), 2)
# Only account currency fields will be posted to
for acc in je.accounts:
self.assertEqual(flt(acc.debit, precision), 0.0)
self.assertEqual(flt(acc.credit, precision), 0.0)
row = [x for x in je.accounts if x.account == self.debtors_usd][0]
self.assertEqual(flt(row.credit_in_account_currency, precision), 5.0) # in USD
row = [x for x in je.accounts if x.account != self.debtors_usd][0]
self.assertEqual(flt(row.debit_in_account_currency, precision), 421.06) # in INR
# total_debit and total_credit will be 0.0, as JV is posting only to account currency fields
self.assertEqual(flt(je.total_debit, precision), 0.0)
self.assertEqual(flt(je.total_credit, precision), 0.0)
acc_balance = frappe.db.get_all(
"GL Entry",
filters={"account": self.debtors_usd, "is_cancelled": 0},
fields=[
"sum(debit)-sum(credit) as balance",
"sum(debit_in_account_currency)-sum(credit_in_account_currency) as balance_in_account_currency",
],
)[0]
# account shouldn't have balance in base and account currency post revaluation
self.assertEqual(flt(acc_balance.balance, precision), 0.0)
self.assertEqual(flt(acc_balance.balance_in_account_currency, precision), 0.0)
@change_settings(
"Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
)
def test_04_get_account_details_function(self):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debtors_usd,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_submit=1,
)
si.currency = "USD"
si.conversion_rate = 80
si.save().submit()
from erpnext.accounts.doctype.exchange_rate_revaluation.exchange_rate_revaluation import (
get_account_details,
)
account_details = get_account_details(
self.company, si.posting_date, self.debtors_usd, "Customer", self.customer, 0.05
)
# not checking for new exchange rate and balances as it is dependent on live exchange rates
expected_data = {
"account_currency": "USD",
"balance_in_base_currency": 8000.0,
"balance_in_account_currency": 100.0,
"current_exchange_rate": 80.0,
"zero_balance": False,
"new_balance_in_account_currency": 100.0,
}
for key, val in expected_data.items():
self.assertEqual(expected_data.get(key), account_details.get(key))

View File

@@ -58,7 +58,14 @@ class GLEntry(Document):
validate_balance_type(self.account, adv_adj)
validate_frozen_account(self.account, adv_adj)
if frappe.db.get_value("Account", self.account, "account_type") not in [
if (
self.voucher_type == "Journal Entry"
and frappe.get_cached_value("Journal Entry", self.voucher_no, "voucher_type")
== "Exchange Gain Or Loss"
):
return
if frappe.get_cached_value("Account", self.account, "account_type") not in [
"Receivable",
"Payable",
]:

View File

@@ -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', 'Journal Entry', "Repost Payment Ledger", 'Asset', 'Asset Movement'];
frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', 'Repost Payment Ledger', 'Asset', 'Asset Movement', 'Repost Accounting Ledger'];
},
refresh: function(frm) {

View File

@@ -9,6 +9,7 @@
"engine": "InnoDB",
"field_order": [
"entry_type_and_date",
"is_system_generated",
"title",
"voucher_type",
"naming_series",
@@ -533,13 +534,22 @@
"label": "Process Deferred Accounting",
"options": "Process Deferred Accounting",
"read_only": 1
},
{
"default": "0",
"depends_on": "eval:doc.is_system_generated == 1;",
"fieldname": "is_system_generated",
"fieldtype": "Check",
"label": "Is System Generated",
"no_copy": 1,
"read_only": 1
}
],
"icon": "fa fa-file-text",
"idx": 176,
"is_submittable": 1,
"links": [],
"modified": "2023-03-01 14:58:59.286591",
"modified": "2023-08-10 14:32:22.366895",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry",

View File

@@ -18,6 +18,7 @@ from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category
)
from erpnext.accounts.party import get_party_account
from erpnext.accounts.utils import (
cancel_exchange_gain_loss_journal,
get_account_currency,
get_balance_on,
get_stock_accounts,
@@ -87,15 +88,16 @@ class JournalEntry(AccountsController):
self.update_invoice_discounting()
def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
unlink_ref_doc_from_payment_entries(self)
# References for this Journal are removed on the `on_cancel` event in accounts_controller
super(JournalEntry, self).on_cancel()
self.ignore_linked_doctypes = (
"GL Entry",
"Stock Ledger Entry",
"Payment Ledger Entry",
"Repost Payment Ledger",
"Repost Payment Ledger Items",
"Repost Accounting Ledger",
"Repost Accounting Ledger Items",
)
self.make_gl_entries(1)
self.update_advance_paid()
@@ -487,11 +489,12 @@ class JournalEntry(AccountsController):
)
if not against_entries:
frappe.throw(
_(
"Journal Entry {0} does not have account {1} or already matched against other voucher"
).format(d.reference_name, d.account)
)
if self.voucher_type != "Exchange Gain Or Loss":
frappe.throw(
_(
"Journal Entry {0} does not have account {1} or already matched against other voucher"
).format(d.reference_name, d.account)
)
else:
dr_or_cr = "debit" if d.credit > 0 else "credit"
valid = False
@@ -574,7 +577,9 @@ class JournalEntry(AccountsController):
else:
party_account = against_voucher[1]
if against_voucher[0] != cstr(d.party) or party_account != d.account:
if (
against_voucher[0] != cstr(d.party) or party_account != d.account
) and self.voucher_type != "Exchange Gain Or Loss":
frappe.throw(
_("Row {0}: Party / Account does not match with {1} / {2} in {3} {4}").format(
d.idx,
@@ -756,18 +761,23 @@ class JournalEntry(AccountsController):
)
):
# Modified to include the posting date for which to retreive the exchange rate
d.exchange_rate = get_exchange_rate(
self.posting_date,
d.account,
d.account_currency,
self.company,
d.reference_type,
d.reference_name,
d.debit,
d.credit,
d.exchange_rate,
)
ignore_exchange_rate = False
if self.get("flags") and self.flags.get("ignore_exchange_rate"):
ignore_exchange_rate = True
if not ignore_exchange_rate:
# Modified to include the posting date for which to retreive the exchange rate
d.exchange_rate = get_exchange_rate(
self.posting_date,
d.account,
d.account_currency,
self.company,
d.reference_type,
d.reference_name,
d.debit,
d.credit,
d.exchange_rate,
)
if not d.exchange_rate:
frappe.throw(_("Row {0}: Exchange Rate is mandatory").format(d.idx))
@@ -775,6 +785,9 @@ class JournalEntry(AccountsController):
def create_remarks(self):
r = []
if self.flags.skip_remarks_creation:
return
if self.user_remark:
r.append(_("Note: {0}").format(self.user_remark))
@@ -923,6 +936,8 @@ class JournalEntry(AccountsController):
merge_entries=merge_entries,
update_outstanding=update_outstanding,
)
if cancel:
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
@frappe.whitelist()
def get_balance(self, difference_account=None):

View File

@@ -5,6 +5,7 @@
import unittest
import frappe
from frappe.tests.utils import change_settings
from frappe.utils import flt, nowdate
from erpnext.accounts.doctype.account.test_account import get_inventory_account
@@ -13,6 +14,7 @@ from erpnext.exceptions import InvalidAccountCurrency
class TestJournalEntry(unittest.TestCase):
@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_journal_entry_with_against_jv(self):
jv_invoice = frappe.copy_doc(test_records[2])
base_jv = frappe.copy_doc(test_records[0])

View File

@@ -203,7 +203,7 @@
"fieldtype": "Select",
"label": "Reference Type",
"no_copy": 1,
"options": "\nSales Invoice\nPurchase Invoice\nJournal Entry\nSales Order\nPurchase Order\nExpense Claim\nAsset\nLoan\nPayroll Entry\nEmployee Advance\nExchange Rate Revaluation\nInvoice Discounting\nFees\nFull and Final Statement"
"options": "\nSales Invoice\nPurchase Invoice\nJournal Entry\nSales Order\nPurchase Order\nExpense Claim\nAsset\nLoan\nPayroll Entry\nEmployee Advance\nExchange Rate Revaluation\nInvoice Discounting\nFees\nFull and Final Statement\nPayment Entry"
},
{
"fieldname": "reference_name",
@@ -284,7 +284,7 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2022-10-26 20:03:10.906259",
"modified": "2023-06-16 14:11:13.507807",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry Account",

View File

@@ -7,7 +7,7 @@ cur_frm.cscript.tax_table = "Advance Taxes and Charges";
frappe.ui.form.on('Payment Entry', {
onload: function(frm) {
frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', "Repost Payment Ledger"];
frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', 'Repost Payment Ledger','Repost Accounting Ledger'];
if(frm.doc.__islocal) {
if (!frm.doc.paid_from) frm.set_value("paid_from_account_currency", null);

View File

@@ -24,7 +24,12 @@ from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category
)
from erpnext.accounts.general_ledger import make_gl_entries, process_gl_map
from erpnext.accounts.party import get_party_account
from erpnext.accounts.utils import get_account_currency, get_balance_on, get_outstanding_invoices
from erpnext.accounts.utils import (
cancel_exchange_gain_loss_journal,
get_account_currency,
get_balance_on,
get_outstanding_invoices,
)
from erpnext.controllers.accounts_controller import (
AccountsController,
get_supplier_block_status,
@@ -61,7 +66,7 @@ class PaymentEntry(AccountsController):
def validate(self):
self.setup_party_account_field()
self.set_missing_values()
self.set_missing_ref_details()
self.set_missing_ref_details(force=True)
self.validate_payment_type()
self.validate_party_details()
self.set_exchange_rate()
@@ -100,7 +105,10 @@ class PaymentEntry(AccountsController):
"Payment Ledger Entry",
"Repost Payment Ledger",
"Repost Payment Ledger Items",
"Repost Accounting Ledger",
"Repost Accounting Ledger Items",
)
super(PaymentEntry, self).on_cancel()
self.make_gl_entries(cancel=1)
self.update_outstanding_amounts()
self.update_advance_paid()
@@ -179,84 +187,87 @@ class PaymentEntry(AccountsController):
return False
def validate_allocated_amount_with_latest_data(self):
latest_references = get_outstanding_reference_documents(
{
"posting_date": self.posting_date,
"company": self.company,
"party_type": self.party_type,
"payment_type": self.payment_type,
"party": self.party,
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
"get_outstanding_invoices": True,
"get_orders_to_be_billed": True,
}
)
if self.references:
uniq_vouchers = set([(x.reference_doctype, x.reference_name) for x in self.references])
vouchers = [frappe._dict({"voucher_type": x[0], "voucher_no": x[1]}) for x in uniq_vouchers]
latest_references = get_outstanding_reference_documents(
{
"posting_date": self.posting_date,
"company": self.company,
"party_type": self.party_type,
"payment_type": self.payment_type,
"party": self.party,
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
"get_outstanding_invoices": True,
"get_orders_to_be_billed": True,
"vouchers": vouchers,
}
)
# Group latest_references by (voucher_type, voucher_no)
latest_lookup = {}
for d in latest_references:
d = frappe._dict(d)
latest_lookup.setdefault((d.voucher_type, d.voucher_no), frappe._dict())[d.payment_term] = d
# Group latest_references by (voucher_type, voucher_no)
latest_lookup = {}
for d in latest_references:
d = frappe._dict(d)
latest_lookup.setdefault((d.voucher_type, d.voucher_no), frappe._dict())[d.payment_term] = d
for idx, d in enumerate(self.get("references"), start=1):
latest = latest_lookup.get((d.reference_doctype, d.reference_name)) or frappe._dict()
for idx, d in enumerate(self.get("references"), start=1):
latest = latest_lookup.get((d.reference_doctype, d.reference_name)) or frappe._dict()
# If term based allocation is enabled, throw
if (
d.payment_term is None or d.payment_term == ""
) and self.term_based_allocation_enabled_for_reference(
d.reference_doctype, d.reference_name
):
frappe.throw(
_(
"{0} has Payment Term based allocation enabled. Select a Payment Term for Row #{1} in Payment References section"
).format(frappe.bold(d.reference_name), frappe.bold(idx))
)
# if no payment template is used by invoice and has a custom term(no `payment_term`), then invoice outstanding will be in 'None' key
latest = latest.get(d.payment_term) or latest.get(None)
# The reference has already been fully paid
if not latest:
frappe.throw(
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
)
# The reference has already been partly paid
elif latest.outstanding_amount < latest.invoice_amount and flt(
d.outstanding_amount, d.precision("outstanding_amount")
) != flt(latest.outstanding_amount, d.precision("outstanding_amount")):
frappe.throw(
_(
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts."
).format(_(d.reference_doctype), d.reference_name)
)
fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
if (
d.payment_term
and (
(flt(d.allocated_amount)) > 0
and latest.payment_term_outstanding
and (flt(d.allocated_amount) > flt(latest.payment_term_outstanding))
)
and self.term_based_allocation_enabled_for_reference(d.reference_doctype, d.reference_name)
):
frappe.throw(
_(
"Row #{0}: Allocated amount:{1} is greater than outstanding amount:{2} for Payment Term {3}"
).format(
d.idx, d.allocated_amount, latest.payment_term_outstanding, d.payment_term
# If term based allocation is enabled, throw
if (
d.payment_term is None or d.payment_term == ""
) and self.term_based_allocation_enabled_for_reference(
d.reference_doctype, d.reference_name
):
frappe.throw(
_(
"{0} has Payment Term based allocation enabled. Select a Payment Term for Row #{1} in Payment References section"
).format(frappe.bold(d.reference_name), frappe.bold(idx))
)
)
if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx))
# if no payment template is used by invoice and has a custom term(no `payment_term`), then invoice outstanding will be in 'None' key
latest = latest.get(d.payment_term) or latest.get(None)
# Check for negative outstanding invoices as well
if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx))
# The reference has already been fully paid
if not latest:
frappe.throw(
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
)
# The reference has already been partly paid
elif latest.outstanding_amount < latest.invoice_amount and flt(
d.outstanding_amount, d.precision("outstanding_amount")
) != flt(latest.outstanding_amount, d.precision("outstanding_amount")):
frappe.throw(
_(
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts."
).format(_(d.reference_doctype), d.reference_name)
)
fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
if (
d.payment_term
and (
(flt(d.allocated_amount)) > 0
and latest.payment_term_outstanding
and (flt(d.allocated_amount) > flt(latest.payment_term_outstanding))
)
and self.term_based_allocation_enabled_for_reference(d.reference_doctype, d.reference_name)
):
frappe.throw(
_(
"Row #{0}: Allocated amount:{1} is greater than outstanding amount:{2} for Payment Term {3}"
).format(
d.idx, d.allocated_amount, latest.payment_term_outstanding, d.payment_term
)
)
if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx))
# Check for negative outstanding invoices as well
if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx))
def delink_advance_entry_references(self):
for reference in self.references:
@@ -361,7 +372,7 @@ class PaymentEntry(AccountsController):
else:
if ref_doc:
if self.paid_from_account_currency == ref_doc.currency:
self.source_exchange_rate = ref_doc.get("exchange_rate")
self.source_exchange_rate = ref_doc.get("exchange_rate") or ref_doc.get("conversion_rate")
if not self.source_exchange_rate:
self.source_exchange_rate = get_exchange_rate(
@@ -374,7 +385,7 @@ class PaymentEntry(AccountsController):
elif self.paid_to and not self.target_exchange_rate:
if ref_doc:
if self.paid_to_account_currency == ref_doc.currency:
self.target_exchange_rate = ref_doc.get("exchange_rate")
self.target_exchange_rate = ref_doc.get("exchange_rate") or ref_doc.get("conversion_rate")
if not self.target_exchange_rate:
self.target_exchange_rate = get_exchange_rate(
@@ -783,10 +794,25 @@ class PaymentEntry(AccountsController):
flt(d.allocated_amount) * flt(exchange_rate), self.precision("base_paid_amount")
)
else:
# Use source/target exchange rate, so no difference amount is calculated.
# then update exchange gain/loss amount in reference table
# if there is an exchange gain/loss amount in reference table, submit a JE for that
exchange_rate = 1
if self.payment_type == "Receive":
exchange_rate = self.source_exchange_rate
elif self.payment_type == "Pay":
exchange_rate = self.target_exchange_rate
base_allocated_amount += flt(
flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount")
flt(d.allocated_amount) * flt(exchange_rate), self.precision("base_paid_amount")
)
allocated_amount_in_pe_exchange_rate = flt(
flt(d.allocated_amount) * flt(d.exchange_rate), self.precision("base_paid_amount")
)
d.exchange_gain_loss = base_allocated_amount - allocated_amount_in_pe_exchange_rate
return base_allocated_amount
def set_total_allocated_amount(self):
@@ -977,6 +1003,10 @@ class PaymentEntry(AccountsController):
gl_entries = self.build_gl_map()
gl_entries = process_gl_map(gl_entries)
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
if cancel:
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
else:
self.make_exchange_gain_loss_journal()
def add_party_gl_entries(self, gl_entries):
if self.party_account:
@@ -1438,6 +1468,7 @@ def get_outstanding_reference_documents(args):
min_outstanding=args.get("outstanding_amt_greater_than"),
max_outstanding=args.get("outstanding_amt_less_than"),
accounting_dimensions=accounting_dimensions_filter,
vouchers=args.get("vouchers") or None,
)
outstanding_invoices = split_invoices_based_on_payment_terms(
@@ -1836,10 +1867,15 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
if not total_amount:
if party_account_currency == company_currency:
# for handling cases that don't have multi-currency (base field)
total_amount = ref_doc.get("base_grand_total") or ref_doc.get("grand_total")
total_amount = (
ref_doc.get("base_rounded_total")
or ref_doc.get("rounded_total")
or ref_doc.get("base_grand_total")
or ref_doc.get("grand_total")
)
exchange_rate = 1
else:
total_amount = ref_doc.get("grand_total")
total_amount = ref_doc.get("rounded_total") or ref_doc.get("grand_total")
if not exchange_rate:
# Get the exchange rate from the original ref doc
# or get it based on the posting date of the ref doc.
@@ -1878,7 +1914,6 @@ def get_payment_entry(
payment_type=None,
reference_date=None,
):
reference_doc = None
doc = frappe.get_doc(dt, dn)
over_billing_allowance = frappe.db.get_single_value("Accounts Settings", "over_billing_allowance")
if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) >= (
@@ -2019,7 +2054,7 @@ def get_payment_entry(
update_accounting_dimensions(pe, doc)
if party_account and bank:
pe.set_exchange_rate(ref_doc=reference_doc)
pe.set_exchange_rate(ref_doc=doc)
pe.set_amounts()
if discount_amount:

View File

@@ -31,6 +31,16 @@ class TestPaymentEntry(FrappeTestCase):
def tearDown(self):
frappe.db.rollback()
def get_journals_for(self, voucher_type: str, voucher_no: str) -> list:
journals = []
if voucher_type and voucher_no:
journals = frappe.db.get_all(
"Journal Entry Account",
filters={"reference_type": voucher_type, "reference_name": voucher_no, "docstatus": 1},
fields=["parent"],
)
return journals
def test_payment_entry_against_order(self):
so = make_sales_order()
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Cash - _TC")
@@ -591,21 +601,15 @@ class TestPaymentEntry(FrappeTestCase):
pe.target_exchange_rate = 45.263
pe.reference_no = "1"
pe.reference_date = "2016-01-01"
pe.append(
"deductions",
{
"account": "_Test Exchange Gain/Loss - _TC",
"cost_center": "_Test Cost Center - _TC",
"amount": 94.80,
},
)
pe.save()
self.assertEqual(flt(pe.difference_amount, 2), 0.0)
self.assertEqual(flt(pe.unallocated_amount, 2), 0.0)
# the exchange gain/loss amount is captured in reference table and a separate Journal will be submitted for them
# payment entry will not be generating difference amount
self.assertEqual(flt(pe.references[0].exchange_gain_loss, 2), -94.74)
def test_payment_entry_retrieves_last_exchange_rate(self):
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import (
save_new_records,
@@ -792,33 +796,28 @@ class TestPaymentEntry(FrappeTestCase):
pe.reference_no = "1"
pe.reference_date = "2016-01-01"
pe.source_exchange_rate = 55
pe.append(
"deductions",
{
"account": "_Test Exchange Gain/Loss - _TC",
"cost_center": "_Test Cost Center - _TC",
"amount": -500,
},
)
pe.save()
self.assertEqual(pe.unallocated_amount, 0)
self.assertEqual(pe.difference_amount, 0)
self.assertEqual(pe.references[0].exchange_gain_loss, 500)
pe.submit()
expected_gle = dict(
(d[0], d)
for d in [
["_Test Receivable USD - _TC", 0, 5000, si.name],
["_Test Receivable USD - _TC", 0, 5500, si.name],
["_Test Bank USD - _TC", 5500, 0, None],
["_Test Exchange Gain/Loss - _TC", 0, 500, None],
]
)
self.validate_gl_entries(pe.name, expected_gle)
# Exchange gain/loss should have been posted through a journal
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertEqual(exc_je_for_si, exc_je_for_pe)
outstanding_amount = flt(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"))
self.assertEqual(outstanding_amount, 0)
@@ -1202,6 +1201,24 @@ class TestPaymentEntry(FrappeTestCase):
template.allocate_payment_based_on_payment_terms = 1
template.save()
def test_allocation_validation_for_sales_order(self):
so = make_sales_order(do_not_save=True)
so.items[0].rate = 99.55
so.save().submit()
self.assertGreater(so.rounded_total, 0.0)
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Cash - _TC")
pe.paid_from = "Debtors - _TC"
pe.paid_amount = 45.55
pe.references[0].allocated_amount = 45.55
pe.save().submit()
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Cash - _TC")
pe.paid_from = "Debtors - _TC"
# No validation error should be thrown here.
pe.save().submit()
so.reload()
self.assertEqual(so.advance_paid, so.rounded_total)
def create_payment_entry(**args):
payment_entry = frappe.new_doc("Payment Entry")

View File

@@ -151,6 +151,15 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
this.frm.refresh();
}
invoice_name() {
this.frm.trigger("get_unreconciled_entries");
}
payment_name() {
this.frm.trigger("get_unreconciled_entries");
}
clear_child_tables() {
this.frm.clear_table("invoices");
this.frm.clear_table("payments");

View File

@@ -26,8 +26,10 @@
"bank_cash_account",
"cost_center",
"sec_break1",
"invoice_name",
"invoices",
"column_break_15",
"payment_name",
"payments",
"sec_break2",
"allocation"
@@ -136,6 +138,7 @@
"label": "Minimum Invoice Amount"
},
{
"default": "50",
"description": "System will fetch all the entries if limit value is zero.",
"fieldname": "invoice_limit",
"fieldtype": "Int",
@@ -166,6 +169,7 @@
"label": "Maximum Payment Amount"
},
{
"default": "50",
"description": "System will fetch all the entries if limit value is zero.",
"fieldname": "payment_limit",
"fieldtype": "Int",
@@ -185,13 +189,23 @@
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
},
{
"fieldname": "invoice_name",
"fieldtype": "Data",
"label": "Filter on Invoice"
},
{
"fieldname": "payment_name",
"fieldtype": "Data",
"label": "Filter on Payment"
}
],
"hide_toolbar": 1,
"icon": "icon-resize-horizontal",
"issingle": 1,
"links": [],
"modified": "2022-04-29 15:37:10.246831",
"modified": "2023-08-15 05:35:50.109290",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation",
@@ -218,4 +232,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

View File

@@ -5,8 +5,9 @@
import frappe
from frappe import _, msgprint, qb
from frappe.model.document import Document
from frappe.query_builder import Criterion
from frappe.query_builder.custom import ConstantColumn
from frappe.utils import flt, get_link_to_form, getdate, nowdate, today
from frappe.utils import flt, fmt_money, get_link_to_form, getdate, nowdate, today
import erpnext
from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation import (
@@ -14,6 +15,7 @@ from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_rec
)
from erpnext.accounts.utils import (
QueryPaymentLedger,
create_gain_loss_journal,
get_outstanding_invoices,
reconcile_against_document,
)
@@ -57,6 +59,9 @@ class PaymentReconciliation(Document):
def get_payment_entries(self):
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
condition = self.get_conditions(get_payments=True)
if self.payment_name:
condition += "name like '%%{0}%%'".format(self.payment_name)
payment_entries = get_advance_payment_entries(
self.party_type,
self.party,
@@ -72,6 +77,9 @@ class PaymentReconciliation(Document):
def get_jv_entries(self):
condition = self.get_conditions()
if self.payment_name:
condition += f" and t1.name like '%%{self.payment_name}%%'"
if self.get("cost_center"):
condition += f" and t2.cost_center = '{self.cost_center}' "
@@ -129,6 +137,15 @@ class PaymentReconciliation(Document):
def get_return_invoices(self):
voucher_type = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
doc = qb.DocType(voucher_type)
conditions = []
conditions.append(doc.docstatus == 1)
conditions.append(doc[frappe.scrub(self.party_type)] == self.party)
conditions.append(doc.is_return == 1)
if self.payment_name:
conditions.append(doc.name.like(f"%{self.payment_name}%"))
self.return_invoices = (
qb.from_(doc)
.select(
@@ -136,11 +153,7 @@ class PaymentReconciliation(Document):
doc.name.as_("voucher_no"),
doc.return_against,
)
.where(
(doc.docstatus == 1)
& (doc[frappe.scrub(self.party_type)] == self.party)
& (doc.is_return == 1)
)
.where(Criterion.all(conditions))
.run(as_dict=True)
)
@@ -209,6 +222,8 @@ class PaymentReconciliation(Document):
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,
limit=self.invoice_limit,
voucher_no=self.invoice_name,
)
cr_dr_notes = (
@@ -260,6 +275,11 @@ class PaymentReconciliation(Document):
def calculate_difference_on_allocation_change(self, payment_entry, invoice, allocated_amount):
invoice_exchange_map = self.get_invoice_exchange_map(invoice, payment_entry)
invoice[0]["exchange_rate"] = invoice_exchange_map.get(invoice[0].get("invoice_number"))
if payment_entry[0].get("reference_type") in ["Sales Invoice", "Purchase Invoice"]:
payment_entry[0]["exchange_rate"] = invoice_exchange_map.get(
payment_entry[0].get("reference_name")
)
new_difference_amount = self.get_difference_amount(
payment_entry[0], invoice[0], allocated_amount
)
@@ -347,12 +367,6 @@ class PaymentReconciliation(Document):
payment_details = self.get_payment_details(row, dr_or_cr)
reconciled_entry.append(payment_details)
if payment_details.difference_amount and row.reference_type not in [
"Sales Invoice",
"Purchase Invoice",
]:
self.make_difference_entry(payment_details)
if entry_list:
reconcile_against_document(entry_list, skip_ref_details_update_for_pe)
@@ -385,59 +399,6 @@ class PaymentReconciliation(Document):
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),
reverse_dr_or_cr: flt(row.difference_amount),
}
)
journal_entry.append("accounts", journal_account)
journal_entry.save()
journal_entry.submit()
return journal_entry
def get_payment_details(self, row, dr_or_cr):
return frappe._dict(
{
@@ -603,16 +564,6 @@ class PaymentReconciliation(Document):
def reconcile_dr_cr_note(dr_cr_notes, company):
def get_difference_row(inv):
if inv.difference_amount != 0 and inv.difference_account:
difference_row = {
"account": inv.difference_account,
inv.dr_or_cr: abs(inv.difference_amount) if inv.difference_amount > 0 else 0,
reconcile_dr_or_cr: abs(inv.difference_amount) if inv.difference_amount < 0 else 0,
"cost_center": erpnext.get_default_cost_center(company),
}
return difference_row
for inv in dr_cr_notes:
voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note"
@@ -640,6 +591,8 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
"reference_type": inv.against_voucher_type,
"reference_name": inv.against_voucher,
"cost_center": erpnext.get_default_cost_center(company),
"user_remark": f"{fmt_money(flt(inv.allocated_amount), currency=company_currency)} against {inv.against_voucher}",
"exchange_rate": inv.exchange_rate,
},
{
"account": inv.account,
@@ -653,13 +606,42 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
"reference_type": inv.voucher_type,
"reference_name": inv.voucher_no,
"cost_center": erpnext.get_default_cost_center(company),
"user_remark": f"{fmt_money(flt(inv.allocated_amount), currency=company_currency)} from {inv.voucher_no}",
"exchange_rate": inv.exchange_rate,
},
],
}
)
if difference_entry := get_difference_row(inv):
jv.append("accounts", difference_entry)
jv.flags.ignore_mandatory = True
jv.flags.skip_remarks_creation = True
jv.flags.ignore_exchange_rate = True
jv.is_system_generated = True
jv.remark = None
jv.submit()
if inv.difference_amount != 0:
# make gain/loss journal
if inv.party_type == "Customer":
dr_or_cr = "credit" if inv.difference_amount < 0 else "debit"
else:
dr_or_cr = "debit" if inv.difference_amount < 0 else "credit"
reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
create_gain_loss_journal(
company,
inv.party_type,
inv.party,
inv.account,
inv.difference_account,
inv.difference_amount,
dr_or_cr,
reverse_dr_or_cr,
inv.voucher_type,
inv.voucher_no,
None,
inv.against_voucher_type,
inv.against_voucher,
None,
)

View File

@@ -686,14 +686,24 @@ class TestPaymentReconciliation(FrappeTestCase):
# Check if difference journal entry gets generated for difference amount after reconciliation
pr.reconcile()
total_debit_amount = frappe.db.get_all(
total_credit_amount = frappe.db.get_all(
"Journal Entry Account",
{"account": self.debtors_eur, "docstatus": 1, "reference_name": si.name},
"sum(debit) as amount",
"sum(credit) as amount",
group_by="reference_name",
)[0].amount
self.assertEqual(flt(total_debit_amount, 2), -500)
# total credit includes the exchange gain/loss amount
self.assertEqual(flt(total_credit_amount, 2), 8500)
jea_parent = frappe.db.get_all(
"Journal Entry Account",
filters={"account": self.debtors_eur, "docstatus": 1, "reference_name": si.name, "credit": 500},
fields=["parent"],
)[0]
self.assertEqual(
frappe.db.get_value("Journal Entry", jea_parent.parent, "voucher_type"), "Exchange Gain Or Loss"
)
def test_difference_amount_via_payment_entry(self):
# Make Sale Invoice

View File

@@ -144,8 +144,7 @@ class TestPaymentRequest(unittest.TestCase):
(d[0], d)
for d in [
["_Test Receivable USD - _TC", 0, 5000, si_usd.name],
[pr.payment_account, 6290.0, 0, None],
["_Test Exchange Gain/Loss - _TC", 0, 1290, None],
[pr.payment_account, 5000.0, 0, None],
]
)

View File

@@ -153,7 +153,7 @@ frappe.ui.form.on('POS Closing Entry', {
frappe.ui.form.on('POS Closing Entry Detail', {
closing_amount: (frm, cdt, cdn) => {
const row = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "difference", flt(row.expected_amount - row.closing_amount));
frappe.model.set_value(cdt, cdn, "difference", flt(row.closing_amount - row.expected_amount));
}
})

View File

@@ -130,6 +130,7 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
args: { "pos_profile": frm.pos_profile },
callback: ({ message: profile }) => {
this.update_customer_groups_settings(profile?.customer_groups);
this.frm.set_value("company", profile?.company);
},
});
}

View File

@@ -54,6 +54,7 @@ class POSInvoice(SalesInvoice):
self.validate_pos()
self.validate_payment_amount()
self.validate_loyalty_transaction()
self.validate_company_with_pos_company()
if self.coupon_code:
from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
@@ -370,6 +371,14 @@ class POSInvoice(SalesInvoice):
if total_amount_in_payments and total_amount_in_payments < invoice_total:
frappe.throw(_("Total payments amount can't be greater than {}").format(-invoice_total))
def validate_company_with_pos_company(self):
if self.company != frappe.db.get_value("POS Profile", self.pos_profile, "company"):
frappe.throw(
_("Company {} does not match with POS Profile Company {}").format(
self.company, frappe.db.get_value("POS Profile", self.pos_profile, "company")
)
)
def validate_loyalty_transaction(self):
if self.redeem_loyalty_points and (
not self.loyalty_redemption_account or not self.loyalty_redemption_cost_center
@@ -448,6 +457,7 @@ class POSInvoice(SalesInvoice):
profile = {}
if self.pos_profile:
profile = frappe.get_doc("POS Profile", self.pos_profile)
self.company = profile.get("company")
if not self.get("payments") and not for_validate:
update_multi_mode_option(self, profile)

View File

@@ -146,7 +146,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-04-21 17:19:30.912953",
"modified": "2023-08-11 10:56:51.699137",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Payment Reconciliation",
@@ -154,15 +154,25 @@
"owner": "Administrator",
"permissions": [
{
"amend": 1,
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"role": "Accounts Manager",
"share": 1,
"submit": 1,
"write": 1
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"delete": 1,
"read": 1,
"role": "Accounts User",
"share": 1,
"submit": 1,
"write": 1
}
],

View File

@@ -31,7 +31,7 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
super.onload();
// Ignore linked advances
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry', 'Purchase Invoice', "Repost Payment Ledger"];
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry', 'Purchase Invoice', "Repost Payment Ledger", "Repost Accounting Ledger"];
if(!this.frm.doc.__islocal) {
// show credit_to in print format

View File

@@ -543,6 +543,7 @@ class PurchaseInvoice(BuyingController):
merge_entries=False,
from_repost=from_repost,
)
self.make_exchange_gain_loss_journal()
elif self.docstatus == 2:
provisional_entries = [a for a in gl_entries if a.voucher_type == "Purchase Receipt"]
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
@@ -587,7 +588,6 @@ class PurchaseInvoice(BuyingController):
self.get_asset_gl_entry(gl_entries)
self.make_tax_gl_entries(gl_entries)
self.make_exchange_gain_loss_gl_entries(gl_entries)
self.make_internal_transfer_gl_entries(gl_entries)
gl_entries = make_regional_gl_entries(gl_entries, self)
@@ -768,21 +768,22 @@ class PurchaseInvoice(BuyingController):
# Amount added through landed-cost-voucher
if landed_cost_entries:
for account, amount in landed_cost_entries[(item.item_code, item.name)].items():
gl_entries.append(
self.get_gl_dict(
{
"account": account,
"against": item.expense_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(amount["base_amount"]),
"credit_in_account_currency": flt(amount["amount"]),
"project": item.project or self.project,
},
item=item,
if (item.item_code, item.name) in landed_cost_entries:
for account, amount in landed_cost_entries[(item.item_code, item.name)].items():
gl_entries.append(
self.get_gl_dict(
{
"account": account,
"against": item.expense_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(amount["base_amount"]),
"credit_in_account_currency": flt(amount["amount"]),
"project": item.project or self.project,
},
item=item,
)
)
)
# sub-contracting warehouse
if flt(item.rm_supp_cost):
@@ -1422,6 +1423,8 @@ class PurchaseInvoice(BuyingController):
"Repost Item Valuation",
"Repost Payment Ledger",
"Repost Payment Ledger Items",
"Repost Accounting Ledger",
"Repost Accounting Ledger Items",
"Payment Ledger Entry",
"Tax Withheld Vouchers",
)

View File

@@ -1264,10 +1264,11 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
pi.save()
pi.submit()
creditors_account = pi.credit_to
expected_gle = [
["_Test Account Cost for Goods Sold - _TC", 37500.0],
["_Test Payable USD - _TC", -35000.0],
["Exchange Gain/Loss - _TC", -2500.0],
["_Test Payable USD - _TC", -37500.0],
]
gl_entries = frappe.db.sql(
@@ -1284,6 +1285,31 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
self.assertEqual(expected_gle[i][0], gle.account)
self.assertEqual(expected_gle[i][1], gle.balance)
pi.reload()
self.assertEqual(pi.outstanding_amount, 0)
total_debit_amount = frappe.db.get_all(
"Journal Entry Account",
{"account": creditors_account, "docstatus": 1, "reference_name": pi.name},
"sum(debit) as amount",
group_by="reference_name",
)[0].amount
self.assertEqual(flt(total_debit_amount, 2), 2500)
jea_parent = frappe.db.get_all(
"Journal Entry Account",
filters={
"account": creditors_account,
"docstatus": 1,
"reference_name": pi.name,
"debit": 2500,
"debit_in_account_currency": 0,
},
fields=["parent"],
)[0]
self.assertEqual(
frappe.db.get_value("Journal Entry", jea_parent.parent, "voucher_type"), "Exchange Gain Or Loss"
)
pi_2 = make_purchase_invoice(
supplier="_Test Supplier USD",
currency="USD",
@@ -1308,10 +1334,12 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
pi_2.save()
pi_2.submit()
pi_2.reload()
self.assertEqual(pi_2.outstanding_amount, 0)
expected_gle = [
["_Test Account Cost for Goods Sold - _TC", 36500.0],
["_Test Payable USD - _TC", -35000.0],
["Exchange Gain/Loss - _TC", -1500.0],
["_Test Payable USD - _TC", -36500.0],
]
gl_entries = frappe.db.sql(
@@ -1342,12 +1370,39 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
self.assertEqual(expected_gle[i][0], gle.account)
self.assertEqual(expected_gle[i][1], gle.balance)
total_debit_amount = frappe.db.get_all(
"Journal Entry Account",
{"account": creditors_account, "docstatus": 1, "reference_name": pi_2.name},
"sum(debit) as amount",
group_by="reference_name",
)[0].amount
self.assertEqual(flt(total_debit_amount, 2), 1500)
jea_parent_2 = frappe.db.get_all(
"Journal Entry Account",
filters={
"account": creditors_account,
"docstatus": 1,
"reference_name": pi_2.name,
"debit": 1500,
"debit_in_account_currency": 0,
},
fields=["parent"],
)[0]
self.assertEqual(
frappe.db.get_value("Journal Entry", jea_parent_2.parent, "voucher_type"),
"Exchange Gain Or Loss",
)
pi.reload()
pi.cancel()
self.assertEqual(frappe.db.get_value("Journal Entry", jea_parent.parent, "docstatus"), 2)
pi_2.reload()
pi_2.cancel()
self.assertEqual(frappe.db.get_value("Journal Entry", jea_parent_2.parent, "docstatus"), 2)
pay.reload()
pay.cancel()
@@ -1716,23 +1771,101 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
0,
)
def test_offsetting_entries_for_accounting_dimensions(self):
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.report.trial_balance.test_trial_balance import (
clear_dimension_defaults,
create_accounting_dimension,
disable_dimension,
)
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
gl_entries = frappe.db.sql(
"""select account, debit, credit, posting_date
from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no=%s and posting_date >= %s
order by posting_date asc, account asc""",
(voucher_no, posting_date),
as_dict=1,
create_account(
account_name="Offsetting",
company="_Test Company",
parent_account="Temporary Accounts - _TC",
)
create_accounting_dimension(company="_Test Company", offsetting_account="Offsetting - _TC")
branch1 = frappe.new_doc("Branch")
branch1.branch = "Location 1"
branch1.insert(ignore_if_duplicate=True)
branch2 = frappe.new_doc("Branch")
branch2.branch = "Location 2"
branch2.insert(ignore_if_duplicate=True)
pi = make_purchase_invoice(
company="_Test Company",
customer="_Test Supplier",
do_not_save=True,
do_not_submit=True,
rate=1000,
price_list_rate=1000,
qty=1,
)
pi.branch = branch1.branch
pi.items[0].branch = branch2.branch
pi.save()
pi.submit()
expected_gle = [
["_Test Account Cost for Goods Sold - _TC", 1000, 0.0, nowdate(), branch2.branch],
["Creditors - _TC", 0.0, 1000, nowdate(), branch1.branch],
["Offsetting - _TC", 1000, 0.0, nowdate(), branch1.branch],
["Offsetting - _TC", 0.0, 1000, nowdate(), branch2.branch],
]
check_gl_entries(
self,
pi.name,
expected_gle,
nowdate(),
voucher_type="Purchase Invoice",
additional_columns=["branch"],
)
clear_dimension_defaults("Branch")
disable_dimension()
def check_gl_entries(
doc,
voucher_no,
expected_gle,
posting_date,
voucher_type="Purchase Invoice",
additional_columns=None,
):
gl = frappe.qb.DocType("GL Entry")
query = (
frappe.qb.from_(gl)
.select(gl.account, gl.debit, gl.credit, gl.posting_date)
.where(
(gl.voucher_type == voucher_type)
& (gl.voucher_no == voucher_no)
& (gl.posting_date >= posting_date)
& (gl.is_cancelled == 0)
)
.orderby(gl.posting_date, gl.account, gl.creation)
)
if additional_columns:
for col in additional_columns:
query = query.select(gl[col])
gl_entries = query.run(as_dict=True)
for i, gle in enumerate(gl_entries):
doc.assertEqual(expected_gle[i][0], gle.account)
doc.assertEqual(expected_gle[i][1], gle.debit)
doc.assertEqual(expected_gle[i][2], gle.credit)
doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
if additional_columns:
j = 4
for col in additional_columns:
doc.assertEqual(expected_gle[i][j], gle[col])
j += 1
def create_tax_witholding_category(category_name, company, account):
from erpnext.accounts.utils import get_fiscal_year

View File

@@ -0,0 +1,44 @@
<style>
.print-format {
padding: 4mm;
font-size: 8.0pt !important;
}
.print-format td {
vertical-align:middle !important;
}
.old {
background-color: #FFB3C0;
}
.new {
background-color: #B3FFCC;
}
</style>
<table class="table table-bordered table-condensed">
<colgroup>
{% for col in gl_columns%}
<col style="width: 18mm;">
{% endfor %}
</colgroup>
<thead>
<tr>
{% for col in gl_columns%}
<td>{{ col.label }}</td>
{% endfor %}
</tr>
</thead>
{% for gl in gl_data%}
{% if gl["old"]%}
<tr class="old">
{% else %}
<tr class="new">
{% endif %}
{% for col in gl_columns %}
<td class="text-right">
{{ gl[col.fieldname] }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>

View File

@@ -0,0 +1,50 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on("Repost Accounting Ledger", {
setup: function(frm) {
frm.fields_dict['vouchers'].grid.get_field('voucher_type').get_query = function(doc) {
return {
filters: {
name: ['in', ['Purchase Invoice', 'Sales Invoice', 'Payment Entry', 'Journal Entry']],
}
}
}
frm.fields_dict['vouchers'].grid.get_field('voucher_no').get_query = function(doc) {
if (doc.company) {
return {
filters: {
company: doc.company,
docstatus: 1
}
}
}
}
},
refresh: function(frm) {
frm.add_custom_button(__('Show Preview'), () => {
frm.call({
method: 'generate_preview',
doc: frm.doc,
freeze: true,
freeze_message: __('Generating Preview'),
callback: function(r) {
if (r && r.message) {
let content = r.message;
let opts = {
title: "Preview",
subtitle: "preview",
content: content,
print_settings: {orientation: "landscape"},
columns: [],
data: [],
}
frappe.render_grid(opts);
}
}
});
});
}
});

View File

@@ -0,0 +1,81 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "format:ACC-REPOST-{#####}",
"creation": "2023-07-04 13:07:32.923675",
"default_view": "List",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"company",
"column_break_vpup",
"delete_cancelled_entries",
"section_break_metl",
"vouchers",
"amended_from"
],
"fields": [
{
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Repost Accounting Ledger",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "vouchers",
"fieldtype": "Table",
"label": "Vouchers",
"options": "Repost Accounting Ledger Items"
},
{
"fieldname": "column_break_vpup",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_metl",
"fieldtype": "Section Break"
},
{
"default": "0",
"fieldname": "delete_cancelled_entries",
"fieldtype": "Check",
"label": "Delete Cancelled Ledger Entries"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-07-27 15:47:58.975034",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Repost Accounting Ledger",
"naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}

View File

@@ -0,0 +1,183 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _, qb
from frappe.model.document import Document
from frappe.utils.data import comma_and
class RepostAccountingLedger(Document):
def __init__(self, *args, **kwargs):
super(RepostAccountingLedger, self).__init__(*args, **kwargs)
self._allowed_types = set(
["Purchase Invoice", "Sales Invoice", "Payment Entry", "Journal Entry"]
)
def validate(self):
self.validate_vouchers()
self.validate_for_closed_fiscal_year()
self.validate_for_deferred_accounting()
def validate_for_deferred_accounting(self):
sales_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Sales Invoice"]
docs_with_deferred_revenue = frappe.db.get_all(
"Sales Invoice Item",
filters={"parent": ["in", sales_docs], "docstatus": 1, "enable_deferred_revenue": True},
fields=["parent"],
as_list=1,
)
purchase_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Purchase Invoice"]
docs_with_deferred_expense = frappe.db.get_all(
"Purchase Invoice Item",
filters={"parent": ["in", purchase_docs], "docstatus": 1, "enable_deferred_expense": 1},
fields=["parent"],
as_list=1,
)
if docs_with_deferred_revenue or docs_with_deferred_expense:
frappe.throw(
_("Documents: {0} have deferred revenue/expense enabled for them. Cannot repost.").format(
frappe.bold(
comma_and([x[0] for x in docs_with_deferred_expense + docs_with_deferred_revenue])
)
)
)
def validate_for_closed_fiscal_year(self):
if self.vouchers:
latest_pcv = (
frappe.db.get_all(
"Period Closing Voucher",
filters={"company": self.company},
order_by="posting_date desc",
pluck="posting_date",
limit=1,
)
or None
)
if not latest_pcv:
return
for vtype in self._allowed_types:
if names := [x.voucher_no for x in self.vouchers if x.voucher_type == vtype]:
latest_voucher = frappe.db.get_all(
vtype,
filters={"name": ["in", names]},
pluck="posting_date",
order_by="posting_date desc",
limit=1,
)[0]
if latest_voucher and latest_pcv[0] >= latest_voucher:
frappe.throw(_("Cannot Resubmit Ledger entries for vouchers in Closed fiscal year."))
def validate_vouchers(self):
if self.vouchers:
# Validate voucher types
voucher_types = set([x.voucher_type for x in self.vouchers])
if disallowed_types := voucher_types.difference(self._allowed_types):
frappe.throw(
_("{0} types are not allowed. Only {1} are.").format(
frappe.bold(comma_and(list(disallowed_types))),
frappe.bold(comma_and(list(self._allowed_types))),
)
)
def get_existing_ledger_entries(self):
vouchers = [x.voucher_no for x in self.vouchers]
gl = qb.DocType("GL Entry")
existing_gles = (
qb.from_(gl)
.select(gl.star)
.where((gl.voucher_no.isin(vouchers)) & (gl.is_cancelled == 0))
.run(as_dict=True)
)
self.gles = frappe._dict({})
for gle in existing_gles:
self.gles.setdefault((gle.voucher_type, gle.voucher_no), frappe._dict({})).setdefault(
"existing", []
).append(gle.update({"old": True}))
def generate_preview_data(self):
self.gl_entries = []
self.get_existing_ledger_entries()
for x in self.vouchers:
doc = frappe.get_doc(x.voucher_type, x.voucher_no)
if doc.doctype in ["Payment Entry", "Journal Entry"]:
gle_map = doc.build_gl_map()
else:
gle_map = doc.get_gl_entries()
old_entries = self.gles.get((x.voucher_type, x.voucher_no))
if old_entries:
self.gl_entries.extend(old_entries.existing)
self.gl_entries.extend(gle_map)
@frappe.whitelist()
def generate_preview(self):
from erpnext.accounts.report.general_ledger.general_ledger import get_columns as get_gl_columns
gl_columns = []
gl_data = []
self.generate_preview_data()
if self.gl_entries:
filters = {"company": self.company, "include_dimensions": 1}
for x in get_gl_columns(filters):
if x["fieldname"] == "gl_entry":
x["fieldname"] = "name"
gl_columns.append(x)
gl_data = self.gl_entries
rendered_page = frappe.render_template(
"erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.html",
{"gl_columns": gl_columns, "gl_data": gl_data},
)
return rendered_page
def on_submit(self):
job_name = "repost_accounting_ledger_" + self.name
frappe.enqueue(
method="erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.start_repost",
account_repost_doc=self.name,
is_async=True,
job_name=job_name,
)
frappe.msgprint(_("Repost has started in the background"))
@frappe.whitelist()
def start_repost(account_repost_doc=str) -> None:
if account_repost_doc:
repost_doc = frappe.get_doc("Repost Accounting Ledger", account_repost_doc)
if repost_doc.docstatus == 1:
# Prevent repost on invoices with deferred accounting
repost_doc.validate_for_deferred_accounting()
for x in repost_doc.vouchers:
doc = frappe.get_doc(x.voucher_type, x.voucher_no)
if repost_doc.delete_cancelled_entries:
frappe.db.delete("GL Entry", filters={"voucher_type": doc.doctype, "voucher_no": doc.name})
frappe.db.delete(
"Payment Ledger Entry", filters={"voucher_type": doc.doctype, "voucher_no": doc.name}
)
if doc.doctype in ["Sales Invoice", "Purchase Invoice"]:
if not repost_doc.delete_cancelled_entries:
doc.docstatus = 2
doc.make_gl_entries_on_cancel()
doc.docstatus = 1
doc.make_gl_entries()
elif doc.doctype in ["Payment Entry", "Journal Entry"]:
if not repost_doc.delete_cancelled_entries:
doc.make_gl_entries(1)
doc.make_gl_entries()
frappe.db.commit()

View File

@@ -0,0 +1,202 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from frappe import qb
from frappe.query_builder.functions import Sum
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, nowdate, today
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import start_repost
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.accounts.utils import get_fiscal_year
class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.create_company()
self.create_customer()
self.create_item()
def teadDown(self):
frappe.db.rollback()
def test_01_basic_functions(self):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
)
preq = frappe.get_doc(
make_payment_request(
dt=si.doctype,
dn=si.name,
payment_request_type="Inward",
party_type="Customer",
party=si.customer,
)
)
preq.save().submit()
# Test Validation Error
ral = frappe.new_doc("Repost Accounting Ledger")
ral.company = self.company
ral.delete_cancelled_entries = True
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
ral.append(
"vouchers", {"voucher_type": preq.doctype, "voucher_no": preq.name}
) # this should throw validation error
self.assertRaises(frappe.ValidationError, ral.save)
ral.vouchers.pop()
preq.cancel()
preq.delete()
pe = get_payment_entry(si.doctype, si.name)
pe.save().submit()
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
ral.save()
# manually set an incorrect debit amount in DB
gle = frappe.db.get_all("GL Entry", filters={"voucher_no": si.name, "account": self.debit_to})
frappe.db.set_value("GL Entry", gle[0], "debit", 90)
gl = qb.DocType("GL Entry")
res = (
qb.from_(gl)
.select(gl.voucher_no, Sum(gl.debit).as_("debit"), Sum(gl.credit).as_("credit"))
.where((gl.voucher_no == si.name) & (gl.is_cancelled == 0))
.run()
)
# Assert incorrect ledger balance
self.assertNotEqual(res[0], (si.name, 100, 100))
# Submit repost document
ral.save().submit()
# background jobs don't run on test cases. Manually triggering repost function.
start_repost(ral.name)
res = (
qb.from_(gl)
.select(gl.voucher_no, Sum(gl.debit).as_("debit"), Sum(gl.credit).as_("credit"))
.where((gl.voucher_no == si.name) & (gl.is_cancelled == 0))
.run()
)
# Ledger should reflect correct amount post repost
self.assertEqual(res[0], (si.name, 100, 100))
def test_02_deferred_accounting_valiations(self):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
do_not_submit=True,
)
si.items[0].enable_deferred_revenue = True
si.items[0].deferred_revenue_account = self.deferred_revenue
si.items[0].service_start_date = nowdate()
si.items[0].service_end_date = add_days(nowdate(), 90)
si.save().submit()
ral = frappe.new_doc("Repost Accounting Ledger")
ral.company = self.company
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
self.assertRaises(frappe.ValidationError, ral.save)
@change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1})
def test_04_pcv_validation(self):
# Clear old GL entries so PCV can be submitted.
gl = frappe.qb.DocType("GL Entry")
qb.from_(gl).delete().where(gl.company == self.company).run()
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
)
pcv = frappe.get_doc(
{
"doctype": "Period Closing Voucher",
"transaction_date": today(),
"posting_date": today(),
"company": self.company,
"fiscal_year": get_fiscal_year(today(), company=self.company)[0],
"cost_center": self.cost_center,
"closing_account_head": self.retained_earnings,
"remarks": "test",
}
)
pcv.save().submit()
ral = frappe.new_doc("Repost Accounting Ledger")
ral.company = self.company
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
self.assertRaises(frappe.ValidationError, ral.save)
pcv.reload()
pcv.cancel()
pcv.delete()
def test_03_deletion_flag_and_preview_function(self):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
)
pe = get_payment_entry(si.doctype, si.name)
pe.save().submit()
# without deletion flag set
ral = frappe.new_doc("Repost Accounting Ledger")
ral.company = self.company
ral.delete_cancelled_entries = False
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
ral.save()
# assert preview data is generated
preview = ral.generate_preview()
self.assertIsNotNone(preview)
ral.save().submit()
# background jobs don't run on test cases. Manually triggering repost function.
start_repost(ral.name)
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))
# with deletion flag set
ral = frappe.new_doc("Repost Accounting Ledger")
ral.company = self.company
ral.delete_cancelled_entries = True
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
ral.save().submit()
start_repost(ral.name)
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))

View File

@@ -0,0 +1,40 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-07-04 14:14:01.243848",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"voucher_type",
"voucher_no"
],
"fields": [
{
"fieldname": "voucher_type",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Voucher Type",
"options": "DocType"
},
{
"fieldname": "voucher_no",
"fieldtype": "Dynamic Link",
"in_list_view": 1,
"label": "Voucher No",
"options": "voucher_type"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-07-04 14:15:51.165584",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Repost Accounting Ledger Items",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}

View File

@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
# import frappe
from frappe.model.document import Document
class RepostAccountingLedgerItems(Document):
pass

View File

@@ -34,7 +34,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
super.onload();
this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice', 'Timesheet', 'POS Invoice Merge Log',
'POS Closing Entry', 'Journal Entry', 'Payment Entry', "Repost Payment Ledger"];
'POS Closing Entry', 'Journal Entry', 'Payment Entry', "Repost Payment Ledger", "Repost Accounting Ledger"];
if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
// show debit_to in print format

View File

@@ -714,6 +714,7 @@
"fieldtype": "Table",
"hide_days": 1,
"hide_seconds": 1,
"label": "Items",
"oldfieldname": "entries",
"oldfieldtype": "Table",
"options": "Sales Invoice Item",

View File

@@ -23,7 +23,7 @@ from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category
)
from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center
from erpnext.accounts.party import get_due_date, get_party_account, get_party_details
from erpnext.accounts.utils import get_account_currency
from erpnext.accounts.utils import cancel_exchange_gain_loss_journal, get_account_currency
from erpnext.assets.doctype.asset.depreciation import (
depreciate_asset,
get_disposal_account_and_cost_center,
@@ -399,6 +399,8 @@ class SalesInvoice(SellingController):
"Repost Item Valuation",
"Repost Payment Ledger",
"Repost Payment Ledger Items",
"Repost Accounting Ledger",
"Repost Accounting Ledger Items",
"Payment Ledger Entry",
)
@@ -1046,7 +1048,10 @@ class SalesInvoice(SellingController):
merge_entries=False,
from_repost=from_repost,
)
self.make_exchange_gain_loss_journal()
elif self.docstatus == 2:
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
if update_outstanding == "No":
@@ -1071,7 +1076,6 @@ class SalesInvoice(SellingController):
self.make_customer_gl_entry(gl_entries)
self.make_tax_gl_entries(gl_entries)
self.make_exchange_gain_loss_gl_entries(gl_entries)
self.make_internal_transfer_gl_entries(gl_entries)
self.make_item_gl_entries(gl_entries)
@@ -1665,15 +1669,13 @@ class SalesInvoice(SellingController):
frappe.db.set_value("Customer", self.customer, "loyalty_program_tier", lp_details.tier_name)
def get_returned_amount(self):
from frappe.query_builder.functions import Coalesce, Sum
from frappe.query_builder.functions import Sum
doc = frappe.qb.DocType(self.doctype)
returned_amount = (
frappe.qb.from_(doc)
.select(Sum(doc.grand_total))
.where(
(doc.docstatus == 1) & (doc.is_return == 1) & (Coalesce(doc.return_against, "") == self.name)
)
.where((doc.docstatus == 1) & (doc.is_return == 1) & (doc.return_against == self.name))
).run()
return abs(returned_amount[0][0]) if returned_amount[0][0] else 0

View File

@@ -3213,17 +3213,10 @@ class TestSalesInvoice(unittest.TestCase):
account.disabled = 0
account.save()
@change_settings("Accounts Settings", {"unlink_payment_on_cancellation_of_invoice": 1})
def test_gain_loss_with_advance_entry(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
unlink_enabled = frappe.db.get_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
)
frappe.db.set_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1
)
jv = make_journal_entry("_Test Receivable USD - _TC", "_Test Bank - _TC", -7000, save=False)
jv.accounts[0].exchange_rate = 70
@@ -3256,17 +3249,28 @@ class TestSalesInvoice(unittest.TestCase):
)
si.save()
si.submit()
expected_gle = [
["_Test Receivable USD - _TC", 7500.0, 500],
["Exchange Gain/Loss - _TC", 500.0, 0.0],
["Sales - _TC", 0.0, 7500.0],
["_Test Receivable USD - _TC", 7500.0, 0.0, nowdate()],
["Sales - _TC", 0.0, 7500.0, nowdate()],
]
check_gl_entries(self, si.name, expected_gle, nowdate())
frappe.db.set_value(
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
si.reload()
self.assertEqual(si.outstanding_amount, 0)
journals = frappe.db.get_all(
"Journal Entry Account",
filters={"reference_type": "Sales Invoice", "reference_name": si.name, "docstatus": 1},
pluck="parent",
)
journals = [x for x in journals if x != jv.name]
self.assertEqual(len(journals), 1)
je_type = frappe.get_cached_value("Journal Entry", journals[0], "voucher_type")
self.assertEqual(je_type, "Exchange Gain Or Loss")
ledger_outstanding = frappe.db.get_all(
"Payment Ledger Entry",
filters={"against_voucher_no": si.name, "delinked": 0},
fields=["sum(amount), sum(amount_in_account_currency)"],
as_list=1,
)
def test_batch_expiry_for_sales_invoice_return(self):
@@ -3316,6 +3320,7 @@ class TestSalesInvoice(unittest.TestCase):
)
self.assertRaises(frappe.ValidationError, si.submit)
@change_settings("Selling Settings", {"allow_negative_rates_for_items": 0})
def test_sales_return_negative_rate(self):
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
self.assertRaises(frappe.ValidationError, si.save)

View File

@@ -262,14 +262,20 @@ 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, tax_details, posting_date, net_total)
limit_consumed = get_limit_consumed(ldc, parties)
if is_valid_certificate(ldc, posting_date, limit_consumed):
tax_amount = get_lower_deduction_amount(
net_total, limit_consumed, ldc.certificate_limit, ldc.rate, tax_details
)
else:
tax_amount = net_total * tax_details.rate / 100
else:
tax_amount = net_total * tax_details.rate / 100 if net_total > 0 else 0
tax_amount = net_total * tax_details.rate / 100
# once tds is deducted, not need to add vouchers in the invoice
voucher_wise_amount = {}
else:
tax_amount = get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers)
tax_amount = get_tds_amount(ldc, parties, inv, tax_details, vouchers)
elif party_type == "Customer":
if tax_deducted:
@@ -416,7 +422,7 @@ def get_deducted_tax(taxable_vouchers, tax_details):
return sum(entries)
def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers):
def get_tds_amount(ldc, parties, inv, tax_details, vouchers):
tds_amount = 0
invoice_filters = {"name": ("in", vouchers), "docstatus": 1, "apply_tds": 1}
@@ -496,15 +502,10 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers):
net_total += inv.tax_withholding_net_total
supp_credit_amt = net_total - cumulative_threshold
if ldc and is_valid_certificate(
ldc.valid_from,
ldc.valid_upto,
inv.get("posting_date") or inv.get("transaction_date"),
tax_deducted,
inv.tax_withholding_net_total,
ldc.certificate_limit,
):
tds_amount = get_ltds_amount(supp_credit_amt, 0, ldc.certificate_limit, ldc.rate, tax_details)
if ldc and is_valid_certificate(ldc, inv.get("posting_date") or inv.get("transaction_date"), 0):
tds_amount = get_lower_deduction_amount(
supp_credit_amt, 0, ldc.certificate_limit, ldc.rate, tax_details
)
else:
tds_amount = supp_credit_amt * tax_details.rate / 100 if supp_credit_amt > 0 else 0
@@ -582,8 +583,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, tax_details, posting_date, net_total):
tds_amount = 0
def get_limit_consumed(ldc, parties):
limit_consumed = frappe.db.get_value(
"Purchase Invoice",
{
@@ -597,37 +597,29 @@ def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total):
"sum(tax_withholding_net_total)",
)
if is_valid_certificate(
ldc.valid_from, ldc.valid_upto, posting_date, limit_consumed, net_total, ldc.certificate_limit
):
tds_amount = get_ltds_amount(
net_total, limit_consumed, ldc.certificate_limit, ldc.rate, tax_details
)
return tds_amount
return limit_consumed
def get_ltds_amount(current_amount, deducted_amount, certificate_limit, rate, tax_details):
if certificate_limit - flt(deducted_amount) - flt(current_amount) >= 0:
def get_lower_deduction_amount(
current_amount, limit_consumed, certificate_limit, rate, tax_details
):
if certificate_limit - flt(limit_consumed) - flt(current_amount) >= 0:
return current_amount * rate / 100
else:
ltds_amount = certificate_limit - flt(deducted_amount)
ltds_amount = certificate_limit - flt(limit_consumed)
tds_amount = current_amount - ltds_amount
return ltds_amount * rate / 100 + tds_amount * tax_details.rate / 100
def is_valid_certificate(
valid_from, valid_upto, posting_date, deducted_amount, current_amount, certificate_limit
):
valid = False
def is_valid_certificate(ldc, posting_date, limit_consumed):
available_amount = flt(ldc.certificate_limit) - flt(limit_consumed)
if (
getdate(ldc.valid_from) <= getdate(posting_date) <= getdate(ldc.valid_upto)
) and available_amount > 0:
return True
available_amount = flt(certificate_limit) - flt(deducted_amount)
if (getdate(valid_from) <= getdate(posting_date) <= getdate(valid_upto)) and available_amount > 0:
valid = True
return valid
return False
def normal_round(number):

View File

@@ -4,6 +4,7 @@
import unittest
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from frappe.tests.utils import change_settings
from frappe.utils import today
@@ -18,6 +19,7 @@ class TestTaxWithholdingCategory(unittest.TestCase):
# create relevant supplier, etc
create_records()
create_tax_withholding_category_records()
make_pan_no_field()
def tearDown(self):
cancel_invoices()
@@ -456,6 +458,40 @@ class TestTaxWithholdingCategory(unittest.TestCase):
pe2.cancel()
pe3.cancel()
def test_lower_deduction_certificate_application(self):
frappe.db.set_value(
"Supplier",
"Test LDC Supplier",
{
"tax_withholding_category": "Test Service Category",
"pan": "ABCTY1234D",
},
)
create_lower_deduction_certificate(
supplier="Test LDC Supplier",
certificate_no="1AE0423AAJ",
tax_withholding_category="Test Service Category",
tax_rate=2,
limit=50000,
)
pi1 = create_purchase_invoice(supplier="Test LDC Supplier", rate=35000)
pi1.submit()
self.assertEqual(pi1.taxes[0].tax_amount, 700)
pi2 = create_purchase_invoice(supplier="Test LDC Supplier", rate=35000)
pi2.submit()
self.assertEqual(pi2.taxes[0].tax_amount, 2300)
pi3 = create_purchase_invoice(supplier="Test LDC Supplier", rate=35000)
pi3.submit()
self.assertEqual(pi3.taxes[0].tax_amount, 3500)
pi1.cancel()
pi2.cancel()
pi3.cancel()
def cancel_invoices():
purchase_invoices = frappe.get_all(
@@ -615,6 +651,7 @@ def create_records():
"Test TDS Supplier6",
"Test TDS Supplier7",
"Test TDS Supplier8",
"Test LDC Supplier",
]:
if frappe.db.exists("Supplier", name):
continue
@@ -811,3 +848,39 @@ def create_tax_withholding_category(
"accounts": [{"company": "_Test Company", "account": account}],
}
).insert()
def create_lower_deduction_certificate(
supplier, tax_withholding_category, tax_rate, certificate_no, limit
):
fiscal_year = get_fiscal_year(today(), company="_Test Company")
if not frappe.db.exists("Lower Deduction Certificate", certificate_no):
frappe.get_doc(
{
"doctype": "Lower Deduction Certificate",
"company": "_Test Company",
"supplier": supplier,
"certificate_no": certificate_no,
"tax_withholding_category": tax_withholding_category,
"fiscal_year": fiscal_year[0],
"valid_from": fiscal_year[1],
"valid_upto": fiscal_year[2],
"rate": tax_rate,
"certificate_limit": limit,
}
).insert()
def make_pan_no_field():
pan_field = {
"Supplier": [
{
"fieldname": "pan",
"label": "PAN",
"fieldtype": "Data",
"translatable": 0,
}
]
}
create_custom_fields(pan_field, update=1)

View File

@@ -28,6 +28,7 @@ def make_gl_entries(
):
if gl_map:
if not cancel:
make_acc_dimensions_offsetting_entry(gl_map)
validate_accounting_period(gl_map)
validate_disabled_accounts(gl_map)
gl_map = process_gl_map(gl_map, merge_entries)
@@ -51,6 +52,63 @@ def make_gl_entries(
make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
def make_acc_dimensions_offsetting_entry(gl_map):
accounting_dimensions_to_offset = get_accounting_dimensions_for_offsetting_entry(
gl_map, gl_map[0].company
)
no_of_dimensions = len(accounting_dimensions_to_offset)
if no_of_dimensions == 0:
return
offsetting_entries = []
for gle in gl_map:
for dimension in accounting_dimensions_to_offset:
offsetting_entry = gle.copy()
debit = flt(gle.credit) / no_of_dimensions if gle.credit != 0 else 0
credit = flt(gle.debit) / no_of_dimensions if gle.debit != 0 else 0
offsetting_entry.update(
{
"account": dimension.offsetting_account,
"debit": debit,
"credit": credit,
"debit_in_account_currency": debit,
"credit_in_account_currency": credit,
"remarks": _("Offsetting for Accounting Dimension") + " - {0}".format(dimension.name),
"against_voucher": None,
}
)
offsetting_entry["against_voucher_type"] = None
offsetting_entries.append(offsetting_entry)
gl_map += offsetting_entries
def get_accounting_dimensions_for_offsetting_entry(gl_map, company):
acc_dimension = frappe.qb.DocType("Accounting Dimension")
dimension_detail = frappe.qb.DocType("Accounting Dimension Detail")
acc_dimensions = (
frappe.qb.from_(acc_dimension)
.inner_join(dimension_detail)
.on(acc_dimension.name == dimension_detail.parent)
.select(acc_dimension.fieldname, acc_dimension.name, dimension_detail.offsetting_account)
.where(
(acc_dimension.disabled == 0)
& (dimension_detail.company == company)
& (dimension_detail.automatically_post_balancing_accounting_entry == 1)
)
).run(as_dict=True)
accounting_dimensions_to_offset = []
for acc_dimension in acc_dimensions:
values = set([entry.get(acc_dimension.fieldname) for entry in gl_map])
if len(values) > 1:
accounting_dimensions_to_offset.append(acc_dimension)
return accounting_dimensions_to_offset
def validate_disabled_accounts(gl_map):
accounts = [d.account for d in gl_map if d.account]

View File

@@ -14,7 +14,7 @@ from frappe.contacts.doctype.address.address import (
from frappe.contacts.doctype.contact.contact import get_contact_details
from frappe.core.doctype.user_permission.user_permission import get_permitted_documents
from frappe.model.utils import get_fetch_values
from frappe.query_builder.functions import Date, Sum
from frappe.query_builder.functions import Abs, Date, Sum
from frappe.utils import (
add_days,
add_months,
@@ -884,35 +884,34 @@ def get_party_shipping_address(doctype: str, name: str) -> Optional[str]:
def get_partywise_advanced_payment_amount(
party_type, posting_date=None, future_payment=0, company=None, party=None, account_type=None
party_type, posting_date=None, future_payment=0, company=None, party=None
):
gle = frappe.qb.DocType("GL Entry")
ple = frappe.qb.DocType("Payment Ledger Entry")
query = (
frappe.qb.from_(gle)
.select(gle.party)
frappe.qb.from_(ple)
.select(ple.party, Abs(Sum(ple.amount).as_("amount")))
.where(
(gle.party_type.isin(party_type)) & (gle.against_voucher.isnull()) & (gle.is_cancelled == 0)
(ple.party_type.isin(party_type))
& (ple.amount < 0)
& (ple.against_voucher_no == ple.voucher_no)
& (ple.delinked == 0)
)
.groupby(gle.party)
.groupby(ple.party)
)
if account_type == "Receivable":
query = query.select(Sum(gle.credit).as_("amount"))
else:
query = query.select(Sum(gle.debit).as_("amount"))
if posting_date:
if future_payment:
query = query.where((gle.posting_date <= posting_date) | (Date(gle.creation) <= posting_date))
query = query.where((ple.posting_date <= posting_date) | (Date(ple.creation) <= posting_date))
else:
query = query.where(gle.posting_date <= posting_date)
query = query.where(ple.posting_date <= posting_date)
if company:
query = query.where(gle.company == company)
query = query.where(ple.company == company)
if party:
query = query.where(gle.party == party)
query = query.where(ple.party == party)
data = query.run(as_dict=True)
data = query.run()
if data:
return frappe._dict(data)

View File

@@ -214,8 +214,8 @@ class ReceivablePayableReport(object):
for party_type in self.party_type:
if self.filters.get(scrub(party_type)):
amount = ple.amount_in_account_currency
else:
amount = ple.amount
else:
amount = ple.amount
amount_in_account_currency = ple.amount_in_account_currency
# update voucher
@@ -436,12 +436,11 @@ class ReceivablePayableReport(object):
def allocate_outstanding_based_on_payment_terms(self, row):
self.get_payment_terms(row)
for term in row.payment_terms:
# update "paid" and "oustanding" for this term
# update "paid" and "outstanding" for this term
if not term.paid:
self.allocate_closing_to_term(row, term, "paid")
# update "credit_note" and "oustanding" for this term
# update "credit_note" and "outstanding" for this term
if term.outstanding:
self.allocate_closing_to_term(row, term, "credit_note")
@@ -453,7 +452,8 @@ class ReceivablePayableReport(object):
"""
select
si.name, si.party_account_currency, si.currency, si.conversion_rate,
ps.due_date, ps.payment_term, ps.payment_amount, ps.description, ps.paid_amount, ps.discounted_amount
si.total_advance, ps.due_date, ps.payment_term, ps.payment_amount, ps.base_payment_amount,
ps.description, ps.paid_amount, ps.discounted_amount
from `tab{0}` si, `tabPayment Schedule` ps
where
si.name = ps.parent and
@@ -469,6 +469,10 @@ class ReceivablePayableReport(object):
original_row = frappe._dict(row)
row.payment_terms = []
# Advance allocated during invoicing is not considered in payment terms
# Deduct that from paid amount pre allocation
row.paid -= flt(payment_terms_details[0].total_advance)
# If no or single payment terms, no need to split the row
if len(payment_terms_details) <= 1:
return
@@ -483,7 +487,7 @@ class ReceivablePayableReport(object):
) and d.currency == d.party_account_currency:
invoiced = d.payment_amount
else:
invoiced = flt(flt(d.payment_amount) * flt(d.conversion_rate), self.currency_precision)
invoiced = d.base_payment_amount
row.payment_terms.append(
term.update(
@@ -1086,7 +1090,10 @@ class ReceivablePayableReport(object):
.where(
(je.company == self.filters.company)
& (je.posting_date.lte(self.filters.report_date))
& (je.voucher_type == "Exchange Rate Revaluation")
& (
(je.voucher_type == "Exchange Rate Revaluation")
| (je.voucher_type == "Exchange Gain Or Loss")
)
)
.run()
)

View File

@@ -8,20 +8,17 @@ 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
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
class TestAccountsReceivable(FrappeTestCase):
class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
def setUp(self):
frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company 2'")
frappe.db.sql("delete from `tabSales Order` where company='_Test Company 2'")
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()
self.create_company()
self.create_customer()
self.create_item()
self.create_usd_receivable_account()
self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
@@ -49,29 +46,84 @@ class TestAccountsReceivable(FrappeTestCase):
debtors_usd.account_type = debtors.account_type
self.debtors_usd = debtors_usd.save().name
def create_sales_invoice(self, no_payment_schedule=False, do_not_submit=False):
frappe.set_user("Administrator")
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_save=1,
)
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 = si.save()
if not do_not_submit:
si = si.submit()
return si
def create_payment_entry(self, docname):
pe = get_payment_entry("Sales Invoice", docname, bank_account=self.cash, party_amount=40)
pe.paid_from = self.debit_to
pe.insert()
pe.submit()
def create_credit_note(self, docname):
credit_note = create_sales_invoice(
company=self.company,
customer=self.customer,
item=self.item,
qty=-1,
debit_to=self.debit_to,
cost_center=self.cost_center,
is_return=1,
return_against=docname,
)
return credit_note
def test_accounts_receivable(self):
filters = {
"company": "_Test Company 2",
"company": self.company,
"based_on_payment_terms": 1,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"show_remarks": True,
}
# check invoice grand total and invoiced column's value for 3 payment terms
name = make_sales_invoice().name
si = self.create_sales_invoice()
name = si.name
report = execute(filters)
expected_data = [[100, 30], [100, 50], [100, 20]]
expected_data = [[100, 30, "No Remarks"], [100, 50, "No Remarks"], [100, 20, "No Remarks"]]
for i in range(3):
row = report[1][i - 1]
self.assertEqual(expected_data[i - 1], [row.invoice_grand_total, row.invoiced])
self.assertEqual(expected_data[i - 1], [row.invoice_grand_total, row.invoiced, row.remarks])
# check invoice grand total, invoiced, paid and outstanding column's value after payment
make_payment(name)
self.create_payment_entry(si.name)
report = execute(filters)
expected_data_after_payment = [[100, 50, 10, 40], [100, 20, 0, 20]]
@@ -84,10 +136,10 @@ class TestAccountsReceivable(FrappeTestCase):
)
# check invoice grand total, invoiced, paid and outstanding column's value after credit note
make_credit_note(name)
self.create_credit_note(si.name)
report = execute(filters)
expected_data_after_credit_note = [100, 0, 0, 40, -40, "Debtors - _TC2"]
expected_data_after_credit_note = [100, 0, 0, 40, -40, self.debit_to]
row = report[1][0]
self.assertEqual(
@@ -108,21 +160,20 @@ class TestAccountsReceivable(FrappeTestCase):
"""
so = make_sales_order(
company="_Test Company 2",
customer="_Test Customer 2",
warehouse="Finished Goods - _TC2",
currency="EUR",
debit_to="Debtors - _TC2",
income_account="Sales - _TC2",
expense_account="Cost of Goods Sold - _TC2",
cost_center="Main - _TC2",
company=self.company,
customer=self.customer,
warehouse=self.warehouse,
debit_to=self.debit_to,
income_account=self.income_account,
expense_account=self.expense_account,
cost_center=self.cost_center,
)
pe = get_payment_entry(so.doctype, so.name)
pe = pe.save().submit()
filters = {
"company": "_Test Company 2",
"company": self.company,
"based_on_payment_terms": 0,
"report_date": today(),
"range1": 30,
@@ -147,34 +198,32 @@ class TestAccountsReceivable(FrappeTestCase):
)
@change_settings(
"Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}
"Accounts Settings",
{"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0},
)
def test_exchange_revaluation_for_party(self):
"""
Exchange Revaluation for party on Receivable/Payable shoule be included
Exchange Revaluation for party on Receivable/Payable should be included
"""
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 = frappe.get_doc("Company", self.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 = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
si.currency = "USD"
si.conversion_rate = 0.90
si.conversion_rate = 80
si.debit_to = self.debtors_usd
si = si.save().submit()
# Exchange Revaluation
err = frappe.new_doc("Exchange Rate Revaluation")
err.company = company
err.company = self.company
err.posting_date = today()
accounts = err.get_accounts_data()
err.extend("accounts", accounts)
err.accounts[0].new_exchange_rate = 0.95
err.accounts[0].new_exchange_rate = 85
row = err.accounts[0]
row.new_balance_in_base_currency = flt(
row.new_exchange_rate * flt(row.balance_in_account_currency)
@@ -189,7 +238,7 @@ class TestAccountsReceivable(FrappeTestCase):
je = je.submit()
filters = {
"company": company,
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
@@ -198,7 +247,7 @@ class TestAccountsReceivable(FrappeTestCase):
}
report = execute(filters)
expected_data_for_err = [0, -5, 0, 5]
expected_data_for_err = [0, -500, 0, 500]
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,
@@ -214,46 +263,43 @@ class TestAccountsReceivable(FrappeTestCase):
"""
Payment against credit/debit note should be considered against the parent invoice
"""
company = "_Test Company 2"
customer = "_Test Customer 2"
si1 = make_sales_invoice()
si1 = self.create_sales_invoice()
pe = get_payment_entry("Sales Invoice", si1.name, bank_account="Cash - _TC2")
pe.paid_from = "Debtors - _TC2"
pe = get_payment_entry(si1.doctype, si1.name, bank_account=self.cash)
pe.paid_from = self.debit_to
pe.insert()
pe.submit()
cr_note = make_credit_note(si1.name)
cr_note = self.create_credit_note(si1.name)
si2 = make_sales_invoice()
si2 = self.create_sales_invoice()
# manually link cr_note with si2 using journal entry
je = frappe.new_doc("Journal Entry")
je.company = company
je.company = self.company
je.voucher_type = "Credit Note"
je.posting_date = today()
debit_account = "Debtors - _TC2"
debit_entry = {
"account": debit_account,
"account": self.debit_to,
"party_type": "Customer",
"party": customer,
"party": self.customer,
"debit": 100,
"debit_in_account_currency": 100,
"reference_type": cr_note.doctype,
"reference_name": cr_note.name,
"cost_center": "Main - _TC2",
"cost_center": self.cost_center,
}
credit_entry = {
"account": debit_account,
"account": self.debit_to,
"party_type": "Customer",
"party": customer,
"party": self.customer,
"credit": 100,
"credit_in_account_currency": 100,
"reference_type": si2.doctype,
"reference_name": si2.name,
"cost_center": "Main - _TC2",
"cost_center": self.cost_center,
}
je.append("accounts", debit_entry)
@@ -261,7 +307,7 @@ class TestAccountsReceivable(FrappeTestCase):
je = je.save().submit()
filters = {
"company": company,
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
@@ -271,64 +317,254 @@ class TestAccountsReceivable(FrappeTestCase):
report = execute(filters)
self.assertEqual(report[1], [])
def test_group_by_party(self):
si1 = self.create_sales_invoice(do_not_submit=True)
si1.posting_date = add_days(today(), -1)
si1.save().submit()
si2 = self.create_sales_invoice(do_not_submit=True)
si2.items[0].rate = 85
si2.save().submit()
def make_sales_invoice(no_payment_schedule=False, do_not_submit=False):
frappe.set_user("Administrator")
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"group_by_party": True,
}
report = execute(filters)[1]
self.assertEqual(len(report), 5)
si = create_sales_invoice(
company="_Test Company 2",
customer="_Test Customer 2",
currency="EUR",
warehouse="Finished Goods - _TC2",
debit_to="Debtors - _TC2",
income_account="Sales - _TC2",
expense_account="Cost of Goods Sold - _TC2",
cost_center="Main - _TC2",
do_not_save=1,
)
# assert voucher rows
expected_voucher_rows = [
[100.0, 100.0, 100.0, 100.0],
[85.0, 85.0, 85.0, 85.0],
]
voucher_rows = []
for x in report[0:2]:
voucher_rows.append(
[x.invoiced, x.outstanding, x.invoiced_in_account_currency, x.outstanding_in_account_currency]
)
self.assertEqual(expected_voucher_rows, voucher_rows)
if not no_payment_schedule:
si.append(
"payment_schedule",
dict(due_date=getdate(add_days(today(), 30)), invoice_portion=30.00, payment_amount=30),
# assert total rows
expected_total_rows = [
[self.customer, 185.0, 185.0], # party total
{}, # empty row for padding
["Total", 185.0, 185.0], # grand total
]
party_total_row = report[2]
self.assertEqual(
expected_total_rows[0],
[
party_total_row.get("party"),
party_total_row.get("invoiced"),
party_total_row.get("outstanding"),
],
)
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),
empty_row = report[3]
self.assertEqual(expected_total_rows[1], empty_row)
grand_total_row = report[4]
self.assertEqual(
expected_total_rows[2],
[
grand_total_row.get("party"),
grand_total_row.get("invoiced"),
grand_total_row.get("outstanding"),
],
)
si = si.save()
def test_future_payments(self):
si = self.create_sales_invoice()
pe = get_payment_entry(si.doctype, si.name)
pe.posting_date = add_days(today(), 1)
pe.paid_amount = 90.0
pe.references[0].allocated_amount = 90.0
pe.save().submit()
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"show_future_payments": True,
}
report = execute(filters)[1]
self.assertEqual(len(report), 1)
if not do_not_submit:
si = si.submit()
expected_data = [100.0, 100.0, 10.0, 90.0]
return si
row = report[0]
self.assertEqual(
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
)
pe.cancel()
# full payment in future date
pe = get_payment_entry(si.doctype, si.name)
pe.posting_date = add_days(today(), 1)
pe.save().submit()
report = execute(filters)[1]
self.assertEqual(len(report), 1)
expected_data = [100.0, 100.0, 0.0, 100.0]
row = report[0]
self.assertEqual(
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
)
def make_payment(docname):
pe = get_payment_entry("Sales Invoice", docname, bank_account="Cash - _TC2", party_amount=40)
pe.paid_from = "Debtors - _TC2"
pe.insert()
pe.submit()
pe.cancel()
# over payment in future date
pe = get_payment_entry(si.doctype, si.name)
pe.posting_date = add_days(today(), 1)
pe.paid_amount = 110
pe.save().submit()
report = execute(filters)[1]
self.assertEqual(len(report), 2)
expected_data = [[100.0, 0.0, 100.0, 0.0, 100.0], [0.0, 10.0, -10.0, -10.0, 0.0]]
for idx, row in enumerate(report):
self.assertEqual(
expected_data[idx],
[row.invoiced, row.paid, row.outstanding, row.remaining_balance, row.future_amount],
)
def test_sales_person(self):
sales_person = (
frappe.get_doc({"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True})
.insert()
.submit()
)
si = self.create_sales_invoice(do_not_submit=True)
si.append("sales_team", {"sales_person": sales_person.name, "allocated_percentage": 100})
si.save().submit()
def make_credit_note(docname):
credit_note = create_sales_invoice(
company="_Test Company 2",
customer="_Test Customer 2",
currency="EUR",
qty=-1,
warehouse="Finished Goods - _TC2",
debit_to="Debtors - _TC2",
income_account="Sales - _TC2",
expense_account="Cost of Goods Sold - _TC2",
cost_center="Main - _TC2",
is_return=1,
return_against=docname,
)
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"sales_person": sales_person.name,
"show_sales_person": True,
}
report = execute(filters)[1]
self.assertEqual(len(report), 1)
return credit_note
expected_data = [100.0, 100.0, sales_person.name]
row = report[0]
self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.sales_person])
def test_cost_center_filter(self):
si = self.create_sales_invoice()
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"cost_center": self.cost_center,
}
report = execute(filters)[1]
self.assertEqual(len(report), 1)
expected_data = [100.0, 100.0, self.cost_center]
row = report[0]
self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.cost_center])
def test_customer_group_filter(self):
si = self.create_sales_invoice()
cus_group = frappe.db.get_value("Customer", self.customer, "customer_group")
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"customer_group": cus_group,
}
report = execute(filters)[1]
self.assertEqual(len(report), 1)
expected_data = [100.0, 100.0, cus_group]
row = report[0]
self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.customer_group])
filters.update({"customer_group": "Individual"})
report = execute(filters)[1]
self.assertEqual(len(report), 0)
def test_party_account_filter(self):
si1 = self.create_sales_invoice()
self.customer2 = (
frappe.get_doc(
{
"doctype": "Customer",
"customer_name": "Jane Doe",
"type": "Individual",
"default_currency": "USD",
}
)
.insert()
.submit()
)
si2 = self.create_sales_invoice(do_not_submit=True)
si2.posting_date = add_days(today(), -1)
si2.customer = self.customer2
si2.currency = "USD"
si2.conversion_rate = 80
si2.debit_to = self.debtors_usd
si2.save().submit()
# Filter on company currency receivable account
filters = {
"company": self.company,
"report_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
"party_account": self.debit_to,
}
report = execute(filters)[1]
self.assertEqual(len(report), 1)
expected_data = [100.0, 100.0, self.debit_to, si1.currency]
row = report[0]
self.assertEqual(
expected_data, [row.invoiced, row.outstanding, row.party_account, row.account_currency]
)
# Filter on USD receivable account
filters.update({"party_account": self.debtors_usd})
report = execute(filters)[1]
self.assertEqual(len(report), 1)
expected_data = [8000.0, 8000.0, self.debtors_usd, si2.currency]
row = report[0]
self.assertEqual(
expected_data, [row.invoiced, row.outstanding, row.party_account, row.account_currency]
)
# without filter on party account
filters.pop("party_account")
report = execute(filters)[1]
self.assertEqual(len(report), 2)
expected_data = [
[8000.0, 8000.0, 100.0, 100.0, self.debtors_usd, si2.currency],
[100.0, 100.0, 100.0, 100.0, self.debit_to, si1.currency],
]
for idx, row in enumerate(report):
self.assertEqual(
expected_data[idx],
[
row.invoiced,
row.outstanding,
row.invoiced_in_account_currency,
row.outstanding_in_account_currency,
row.party_account,
row.account_currency,
],
)

View File

@@ -50,13 +50,12 @@ class AccountsReceivableSummary(ReceivablePayableReport):
self.filters.show_future_payments,
self.filters.company,
party=party,
account_type=self.account_type,
)
or {}
)
if self.filters.show_gl_balance:
gl_balance_map = get_gl_balance(self.filters.report_date)
gl_balance_map = get_gl_balance(self.filters.report_date, self.filters.company)
for party, party_dict in self.party_total.items():
if party_dict.outstanding == 0:
@@ -233,12 +232,12 @@ class AccountsReceivableSummary(ReceivablePayableReport):
self.add_column(label="Total Amount Due", fieldname="total_due")
def get_gl_balance(report_date):
def get_gl_balance(report_date, company):
return frappe._dict(
frappe.db.get_all(
"GL Entry",
fields=["party", "sum(debit - credit)"],
filters={"posting_date": ("<=", report_date), "is_cancelled": 0},
filters={"posting_date": ("<=", report_date), "is_cancelled": 0, "company": company},
group_by="party",
as_list=1,
)

View File

@@ -0,0 +1,203 @@
import unittest
import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import today
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_summary.accounts_receivable_summary import execute
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.maxDiff = None
self.create_company()
self.create_customer()
self.create_item()
self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
def test_01_receivable_summary_output(self):
"""
Test for Invoices, Paid, Advance and Outstanding
"""
filters = {
"company": self.company,
"customer": self.customer,
"posting_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
}
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=200,
price_list_rate=200,
)
customer_group, customer_territory = frappe.db.get_all(
"Customer",
filters={"name": self.customer},
fields=["customer_group", "territory"],
as_list=True,
)[0]
report = execute(filters)
rpt_output = report[1]
expected_data = {
"party_type": "Customer",
"advance": 0,
"party": self.customer,
"invoiced": 200.0,
"paid": 0.0,
"credit_note": 0.0,
"outstanding": 200.0,
"range1": 200.0,
"range2": 0.0,
"range3": 0.0,
"range4": 0.0,
"range5": 0.0,
"total_due": 200.0,
"future_amount": 0.0,
"sales_person": [],
"currency": si.currency,
"territory": customer_territory,
"customer_group": customer_group,
}
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
# simulate advance payment
pe = get_payment_entry(si.doctype, si.name)
pe.paid_amount = 50
pe.references[0].allocated_amount = 0 # this essitially removes the reference
pe.save().submit()
# update expected data with advance
expected_data.update(
{
"advance": 50.0,
"outstanding": 150.0,
"range1": 150.0,
"total_due": 150.0,
}
)
report = execute(filters)
rpt_output = report[1]
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
# make partial payment
pe = get_payment_entry(si.doctype, si.name)
pe.paid_amount = 125
pe.references[0].allocated_amount = 125
pe.save().submit()
# update expected data after advance and partial payment
expected_data.update(
{"advance": 50.0, "paid": 125.0, "outstanding": 25.0, "range1": 25.0, "total_due": 25.0}
)
report = execute(filters)
rpt_output = report[1]
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
@change_settings("Selling Settings", {"cust_master_name": "Naming Series"})
def test_02_various_filters_and_output(self):
filters = {
"company": self.company,
"customer": self.customer,
"posting_date": today(),
"range1": 30,
"range2": 60,
"range3": 90,
"range4": 120,
}
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=200,
price_list_rate=200,
)
# make partial payment
pe = get_payment_entry(si.doctype, si.name)
pe.paid_amount = 150
pe.references[0].allocated_amount = 150
pe.save().submit()
customer_group, customer_territory = frappe.db.get_all(
"Customer",
filters={"name": self.customer},
fields=["customer_group", "territory"],
as_list=True,
)[0]
report = execute(filters)
rpt_output = report[1]
expected_data = {
"party_type": "Customer",
"advance": 0,
"party": self.customer,
"party_name": self.customer,
"invoiced": 200.0,
"paid": 150.0,
"credit_note": 0.0,
"outstanding": 50.0,
"range1": 50.0,
"range2": 0.0,
"range3": 0.0,
"range4": 0.0,
"range5": 0.0,
"total_due": 50.0,
"future_amount": 0.0,
"sales_person": [],
"currency": si.currency,
"territory": customer_territory,
"customer_group": customer_group,
}
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
# with gl balance filter
filters.update({"show_gl_balance": True})
expected_data.update({"gl_balance": 50.0, "diff": 0.0})
report = execute(filters)
rpt_output = report[1]
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
# with gl balance and future payments filter
filters.update({"show_future_payments": True})
expected_data.update({"remaining_balance": 50.0})
report = execute(filters)
rpt_output = report[1]
self.assertEqual(len(rpt_output), 1)
self.assertDictEqual(rpt_output[0], expected_data)
# invoice fully paid
pe = get_payment_entry(si.doctype, si.name).save().submit()
report = execute(filters)
rpt_output = report[1]
self.assertEqual(len(rpt_output), 0)

View File

@@ -58,6 +58,9 @@ def get_data(filters):
def get_asset_categories(filters):
condition = ""
if filters.get("asset_category"):
condition += " and asset_category = %(asset_category)s"
return frappe.db.sql(
"""
SELECT asset_category,
@@ -98,15 +101,25 @@ def get_asset_categories(filters):
0
end), 0) as cost_of_scrapped_asset
from `tabAsset`
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {}
group by asset_category
""",
{"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company},
""".format(
condition
),
{
"to_date": filters.to_date,
"from_date": filters.from_date,
"company": filters.company,
"asset_category": filters.get("asset_category"),
},
as_dict=1,
)
def get_assets(filters):
condition = ""
if filters.get("asset_category"):
condition = " and a.asset_category = '{}'".format(filters.get("asset_category"))
return frappe.db.sql(
"""
SELECT results.asset_category,
@@ -138,7 +151,7 @@ def get_assets(filters):
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.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)
where a.docstatus=1 and a.company=%(company)s 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) {0}
group by a.asset_category
union
SELECT a.asset_category,
@@ -154,10 +167,12 @@ def get_assets(filters):
end), 0) as depreciation_eliminated_during_the_period,
0 as depreciation_amount_during_the_period
from `tabAsset` a
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {0}
group by a.asset_category) as results
group by results.asset_category
""",
""".format(
condition
),
{"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company},
as_dict=1,
)

View File

@@ -749,13 +749,18 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters, d):
if from_date:
additional_conditions.append(gle.posting_date >= from_date)
finance_book = filters.get("finance_book")
company_fb = frappe.get_cached_value("Company", d.name, "default_finance_book")
finance_books = []
finance_books.append("")
if filter_fb := filters.get("finance_book"):
finance_books.append(filter_fb)
if filters.get("include_default_book_entries"):
additional_conditions.append((gle.finance_book.isin([finance_book, company_fb, "", None])))
if company_fb := frappe.get_cached_value("Company", d.name, "default_finance_book"):
finance_books.append(company_fb)
additional_conditions.append((gle.finance_book.isin(finance_books)) | gle.finance_book.isnull())
else:
additional_conditions.append((gle.finance_book.isin([finance_book, "", None])))
additional_conditions.append((gle.finance_book.isin(finance_books)) | gle.finance_book.isnull())
return additional_conditions

View File

@@ -335,12 +335,10 @@ def add_total_row(out, root_type, balance_must_be, period_list, company_currency
for period in period_list:
total_row.setdefault(period.key, 0.0)
total_row[period.key] += row.get(period.key, 0.0)
row[period.key] = row.get(period.key, 0.0)
total_row.setdefault("total", 0.0)
total_row["total"] += flt(row["total"])
total_row["opening_balance"] += row["opening_balance"]
row["total"] = ""
if "total" in total_row:
out.append(total_row)
@@ -639,7 +637,13 @@ def get_columns(periodicity, period_list, accumulated_values=1, company=None):
if periodicity != "Yearly":
if not accumulated_values:
columns.append(
{"fieldname": "total", "label": _("Total"), "fieldtype": "Currency", "width": 150}
{
"fieldname": "total",
"label": _("Total"),
"fieldtype": "Currency",
"width": 150,
"options": "currency",
}
)
return columns

View File

@@ -12,17 +12,35 @@ frappe.query_reports["TDS Computation Summary"] = {
"default": frappe.defaults.get_default('company')
},
{
"fieldname":"supplier",
"label": __("Supplier"),
"fieldtype": "Link",
"options": "Supplier",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Select",
"options": ["Supplier", "Customer"],
"reqd": 1,
"default": "Supplier",
"on_change": function(){
frappe.query_report.set_filter_value("party", "");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"get_options": function() {
var party_type = frappe.query_report.get_filter_value('party_type');
var party = frappe.query_report.get_filter_value('party');
if(party && !party_type) {
frappe.throw(__("Please select Party Type first"));
}
return party_type;
},
"get_query": function() {
return {
"filters": {
"tax_withholding_category": ["!=",""],
}
}
}
},
},
{
"fieldname":"from_date",

View File

@@ -9,9 +9,14 @@ from erpnext.accounts.utils import get_fiscal_year
def execute(filters=None):
validate_filters(filters)
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")
filters.naming_series = frappe.db.get_single_value("Buying Settings", "supp_master_name")
filters.update({"naming_series": party_naming_by})
validate_filters(filters)
columns = get_columns(filters)
(
@@ -25,7 +30,7 @@ def execute(filters=None):
res = get_result(
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, invoice_total_map
)
final_result = group_by_supplier_and_category(res)
final_result = group_by_party_and_category(res, filters)
return columns, final_result
@@ -43,60 +48,67 @@ def validate_filters(filters):
filters["fiscal_year"] = from_year
def group_by_supplier_and_category(data):
supplier_category_wise_map = {}
def group_by_party_and_category(data, filters):
party_category_wise_map = {}
for row in data:
supplier_category_wise_map.setdefault(
(row.get("supplier"), row.get("section_code")),
party_category_wise_map.setdefault(
(row.get("party"), row.get("section_code")),
{
"pan": row.get("pan"),
"supplier": row.get("supplier"),
"supplier_name": row.get("supplier_name"),
"tax_id": row.get("tax_id"),
"party": row.get("party"),
"party_name": row.get("party_name"),
"section_code": row.get("section_code"),
"entity_type": row.get("entity_type"),
"tds_rate": row.get("tds_rate"),
"total_amount_credited": 0.0,
"tds_deducted": 0.0,
"rate": row.get("rate"),
"total_amount": 0.0,
"tax_amount": 0.0,
},
)
supplier_category_wise_map.get((row.get("supplier"), row.get("section_code")))[
"total_amount_credited"
] += row.get("total_amount_credited", 0.0)
party_category_wise_map.get((row.get("party"), row.get("section_code")))[
"total_amount"
] += row.get("total_amount", 0.0)
supplier_category_wise_map.get((row.get("supplier"), row.get("section_code")))[
"tds_deducted"
] += row.get("tds_deducted", 0.0)
party_category_wise_map.get((row.get("party"), row.get("section_code")))[
"tax_amount"
] += row.get("tax_amount", 0.0)
final_result = get_final_result(supplier_category_wise_map)
final_result = get_final_result(party_category_wise_map)
return final_result
def get_final_result(supplier_category_wise_map):
def get_final_result(party_category_wise_map):
out = []
for key, value in supplier_category_wise_map.items():
for key, value in party_category_wise_map.items():
out.append(value)
return out
def get_columns(filters):
pan = "pan" if frappe.db.has_column(filters.party_type, "pan") else "tax_id"
columns = [
{"label": _("PAN"), "fieldname": "pan", "fieldtype": "Data", "width": 90},
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 90},
{
"label": _("Supplier"),
"options": "Supplier",
"fieldname": "supplier",
"fieldtype": "Link",
"label": _(filters.get("party_type")),
"fieldname": "party",
"fieldtype": "Dynamic Link",
"options": "party_type",
"width": 180,
},
]
if filters.naming_series == "Naming Series":
columns.append(
{"label": _("Supplier Name"), "fieldname": "supplier_name", "fieldtype": "Data", "width": 180}
{
"label": _(filters.party_type + " Name"),
"fieldname": "party_name",
"fieldtype": "Data",
"width": 180,
}
)
columns.extend(
@@ -109,18 +121,23 @@ def get_columns(filters):
"width": 180,
},
{"label": _("Entity Type"), "fieldname": "entity_type", "fieldtype": "Data", "width": 180},
{"label": _("TDS Rate %"), "fieldname": "tds_rate", "fieldtype": "Percent", "width": 90},
{
"label": _("Total Amount Credited"),
"fieldname": "total_amount_credited",
"fieldtype": "Float",
"width": 90,
"label": _("TDS Rate %") if filters.get("party_type") == "Supplier" else _("TCS Rate %"),
"fieldname": "rate",
"fieldtype": "Percent",
"width": 120,
},
{
"label": _("Amount of TDS Deducted"),
"fieldname": "tds_deducted",
"label": _("Total Amount"),
"fieldname": "total_amount",
"fieldtype": "Float",
"width": 90,
"width": 120,
},
{
"label": _("Tax Amount"),
"fieldname": "tax_amount",
"fieldtype": "Float",
"width": 120,
},
]
)

View File

@@ -33,7 +33,14 @@ frappe.query_reports["TDS Payable Monthly"] = {
frappe.throw(__("Please select Party Type first"));
}
return party_type;
}
},
"get_query": function() {
return {
"filters": {
"tax_withholding_category": ["!=",""],
}
}
},
},
{
"fieldname":"from_date",

View File

@@ -7,19 +7,26 @@ from frappe import _
def execute(filters=None):
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")
filters.update({"naming_series": party_naming_by})
validate_filters(filters)
(
tds_docs,
tds_accounts,
tax_category_map,
journal_entry_party_map,
invoice_net_total_map,
net_total_map,
) = get_tds_docs(filters)
columns = get_columns(filters)
res = get_result(
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, invoice_net_total_map
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, net_total_map
)
return columns, res
@@ -31,7 +38,7 @@ def validate_filters(filters):
def get_result(
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, invoice_net_total_map
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, net_total_map
):
party_map = get_party_pan_map(filters.get("party_type"))
tax_rate_map = get_tax_rate_map(filters)
@@ -39,7 +46,7 @@ def get_result(
out = []
for name, details in gle_map.items():
tax_amount, total_amount = 0, 0
tax_amount, total_amount, grand_total, base_total = 0, 0, 0, 0
tax_withholding_category = tax_category_map.get(name)
rate = tax_rate_map.get(tax_withholding_category)
@@ -60,8 +67,8 @@ def get_result(
if entry.account in tds_accounts:
tax_amount += entry.credit - entry.debit
if invoice_net_total_map.get(name):
total_amount = invoice_net_total_map.get(name)
if net_total_map.get(name):
total_amount, grand_total, base_total = net_total_map.get(name)
else:
total_amount += entry.credit
@@ -69,15 +76,13 @@ def get_result(
if party_map.get(party, {}).get("party_type") == "Supplier":
party_name = "supplier_name"
party_type = "supplier_type"
table_name = "Supplier"
else:
party_name = "customer_name"
party_type = "customer_type"
table_name = "Customer"
row = {
"pan"
if frappe.db.has_column(table_name, "pan")
if frappe.db.has_column(filters.party_type, "pan")
else "tax_id": party_map.get(party, {}).get("pan"),
"party": party_map.get(party, {}).get("name"),
}
@@ -91,6 +96,8 @@ def get_result(
"entity_type": party_map.get(party, {}).get(party_type),
"rate": rate,
"total_amount": total_amount,
"grand_total": grand_total,
"base_total": base_total,
"tax_amount": tax_amount,
"transaction_date": posting_date,
"transaction_type": voucher_type,
@@ -144,9 +151,9 @@ def get_gle_map(documents):
def get_columns(filters):
pan = "pan" if frappe.db.has_column("Supplier", "pan") else "tax_id"
pan = "pan" if frappe.db.has_column(filters.party_type, "pan") else "tax_id"
columns = [
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 90},
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 60},
{
"label": _(filters.get("party_type")),
"fieldname": "party",
@@ -158,25 +165,30 @@ def get_columns(filters):
if filters.naming_series == "Naming Series":
columns.append(
{"label": _("Party Name"), "fieldname": "party_name", "fieldtype": "Data", "width": 180}
{
"label": _(filters.party_type + " Name"),
"fieldname": "party_name",
"fieldtype": "Data",
"width": 180,
}
)
columns.extend(
[
{
"label": _("Date of Transaction"),
"fieldname": "transaction_date",
"fieldtype": "Date",
"width": 100,
},
{
"label": _("Section Code"),
"options": "Tax Withholding Category",
"fieldname": "section_code",
"fieldtype": "Link",
"width": 180,
},
{"label": _("Entity Type"), "fieldname": "entity_type", "fieldtype": "Data", "width": 120},
{
"label": _("TDS Rate %") if filters.get("party_type") == "Supplier" else _("TCS Rate %"),
"fieldname": "rate",
"fieldtype": "Percent",
"width": 90,
},
{"label": _("Entity Type"), "fieldname": "entity_type", "fieldtype": "Data", "width": 100},
{
"label": _("Total Amount"),
"fieldname": "total_amount",
@@ -184,15 +196,27 @@ def get_columns(filters):
"width": 90,
},
{
"label": _("TDS Amount") if filters.get("party_type") == "Supplier" else _("TCS Amount"),
"label": _("TDS Rate %") if filters.get("party_type") == "Supplier" else _("TCS Rate %"),
"fieldname": "rate",
"fieldtype": "Percent",
"width": 90,
},
{
"label": _("Tax Amount"),
"fieldname": "tax_amount",
"fieldtype": "Float",
"width": 90,
},
{
"label": _("Date of Transaction"),
"fieldname": "transaction_date",
"fieldtype": "Date",
"label": _("Grand Total"),
"fieldname": "grand_total",
"fieldtype": "Float",
"width": 90,
},
{
"label": _("Base Total"),
"fieldname": "base_total",
"fieldtype": "Float",
"width": 90,
},
{"label": _("Transaction Type"), "fieldname": "transaction_type", "width": 100},
@@ -216,7 +240,7 @@ def get_tds_docs(filters):
payment_entries = []
journal_entries = []
tax_category_map = frappe._dict()
invoice_net_total_map = frappe._dict()
net_total_map = frappe._dict()
or_filters = frappe._dict()
journal_entry_party_map = frappe._dict()
bank_accounts = frappe.get_all("Account", {"is_group": 0, "account_type": "Bank"}, pluck="name")
@@ -233,7 +257,7 @@ def get_tds_docs(filters):
}
party = frappe.get_all(filters.get("party_type"), pluck="name")
query_filters.update({"against": ("in", party)})
or_filters.update({"against": ("in", party), "voucher_type": "Journal Entry"})
if filters.get("party"):
del query_filters["account"]
@@ -260,24 +284,24 @@ def get_tds_docs(filters):
tds_documents.append(d.voucher_no)
if purchase_invoices:
get_doc_info(purchase_invoices, "Purchase Invoice", tax_category_map, invoice_net_total_map)
get_doc_info(purchase_invoices, "Purchase Invoice", tax_category_map, net_total_map)
if sales_invoices:
get_doc_info(sales_invoices, "Sales Invoice", tax_category_map, invoice_net_total_map)
get_doc_info(sales_invoices, "Sales Invoice", tax_category_map, net_total_map)
if payment_entries:
get_doc_info(payment_entries, "Payment Entry", tax_category_map)
get_doc_info(payment_entries, "Payment Entry", tax_category_map, net_total_map)
if journal_entries:
journal_entry_party_map = get_journal_entry_party_map(journal_entries)
get_doc_info(journal_entries, "Journal Entry", tax_category_map)
get_doc_info(journal_entries, "Journal Entry", tax_category_map, net_total_map)
return (
tds_documents,
tds_accounts,
tax_category_map,
journal_entry_party_map,
invoice_net_total_map,
net_total_map,
)
@@ -285,7 +309,11 @@ def get_journal_entry_party_map(journal_entries):
journal_entry_party_map = {}
for d in frappe.db.get_all(
"Journal Entry Account",
{"parent": ("in", journal_entries), "party_type": "Supplier", "party": ("is", "set")},
{
"parent": ("in", journal_entries),
"party_type": ("in", ("Supplier", "Customer")),
"party": ("is", "set"),
},
["parent", "party"],
):
if d.parent not in journal_entry_party_map:
@@ -295,22 +323,30 @@ def get_journal_entry_party_map(journal_entries):
return journal_entry_party_map
def get_doc_info(vouchers, doctype, tax_category_map, invoice_net_total_map=None):
if doctype == "Purchase Invoice":
fields = ["name", "tax_withholding_category", "base_tax_withholding_net_total"]
if doctype == "Sales Invoice":
fields = ["name", "base_net_total"]
else:
fields = ["name", "tax_withholding_category"]
def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None):
common_fields = ["name", "tax_withholding_category"]
fields_dict = {
"Purchase Invoice": ["base_tax_withholding_net_total", "grand_total", "base_total"],
"Sales Invoice": ["base_net_total", "grand_total", "base_total"],
"Payment Entry": ["paid_amount", "paid_amount_after_tax", "base_paid_amount"],
"Journal Entry": ["total_amount"],
}
entries = frappe.get_all(doctype, filters={"name": ("in", vouchers)}, fields=fields)
entries = frappe.get_all(
doctype, filters={"name": ("in", vouchers)}, fields=common_fields + fields_dict[doctype]
)
for entry in entries:
tax_category_map.update({entry.name: entry.tax_withholding_category})
if doctype == "Purchase Invoice":
invoice_net_total_map.update({entry.name: entry.base_tax_withholding_net_total})
if doctype == "Sales Invoice":
invoice_net_total_map.update({entry.name: entry.base_net_total})
value = [entry.base_tax_withholding_net_total, entry.grand_total, entry.base_total]
elif doctype == "Sales Invoice":
value = [entry.base_net_total, entry.grand_total, entry.base_total]
elif doctype == "Payment Entry":
value = [entry.paid_amount, entry.paid_amount_after_tax, entry.base_paid_amount]
else:
value = [entry.total_amount] * 3
net_total_map.update({entry.name: value})
def get_tax_rate_map(filters):

View File

@@ -0,0 +1,118 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import today
from erpnext.accounts.report.trial_balance.trial_balance import execute
class TestTrialBalance(FrappeTestCase):
def setUp(self):
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
from erpnext.accounts.utils import get_fiscal_year
self.company = create_company()
create_cost_center(
cost_center_name="Test Cost Center",
company="Trial Balance Company",
parent_cost_center="Trial Balance Company - TBC",
)
create_account(
account_name="Offsetting",
company="Trial Balance Company",
parent_account="Temporary Accounts - TBC",
)
self.fiscal_year = get_fiscal_year(today(), company="Trial Balance Company")[0]
create_accounting_dimension()
def test_offsetting_entries_for_accounting_dimensions(self):
"""
Checks if Trial Balance Report is balanced when filtered using a particular Accounting Dimension
"""
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
frappe.db.sql("delete from `tabSales Invoice` where company='Trial Balance Company'")
frappe.db.sql("delete from `tabGL Entry` where company='Trial Balance Company'")
branch1 = frappe.new_doc("Branch")
branch1.branch = "Location 1"
branch1.insert(ignore_if_duplicate=True)
branch2 = frappe.new_doc("Branch")
branch2.branch = "Location 2"
branch2.insert(ignore_if_duplicate=True)
si = create_sales_invoice(
company=self.company,
debit_to="Debtors - TBC",
cost_center="Test Cost Center - TBC",
income_account="Sales - TBC",
do_not_submit=1,
)
si.branch = "Location 1"
si.items[0].branch = "Location 2"
si.save()
si.submit()
filters = frappe._dict(
{"company": self.company, "fiscal_year": self.fiscal_year, "branch": ["Location 1"]}
)
total_row = execute(filters)[1][-1]
self.assertEqual(total_row["debit"], total_row["credit"])
def tearDown(self):
clear_dimension_defaults("Branch")
disable_dimension()
def create_company(**args):
args = frappe._dict(args)
company = frappe.get_doc(
{
"doctype": "Company",
"company_name": args.company_name or "Trial Balance Company",
"country": args.country or "India",
"default_currency": args.currency or "INR",
}
)
company.insert(ignore_if_duplicate=True)
return company.name
def create_accounting_dimension(**args):
args = frappe._dict(args)
document_type = args.document_type or "Branch"
if frappe.db.exists("Accounting Dimension", document_type):
accounting_dimension = frappe.get_doc("Accounting Dimension", document_type)
accounting_dimension.disabled = 0
else:
accounting_dimension = frappe.new_doc("Accounting Dimension")
accounting_dimension.document_type = document_type
accounting_dimension.insert()
accounting_dimension.set("dimension_defaults", [])
accounting_dimension.append(
"dimension_defaults",
{
"company": args.company or "Trial Balance Company",
"automatically_post_balancing_accounting_entry": 1,
"offsetting_account": args.offsetting_account or "Offsetting - TBC",
},
)
accounting_dimension.save()
def disable_dimension(**args):
args = frappe._dict(args)
document_type = args.document_type or "Branch"
dimension = frappe.get_doc("Accounting Dimension", document_type)
dimension.disabled = 1
dimension.save()
def clear_dimension_defaults(dimension_name):
accounting_dimension = frappe.get_doc("Accounting Dimension", dimension_name)
accounting_dimension.dimension_defaults = []
accounting_dimension.save()

View File

@@ -1,10 +1,11 @@
import frappe
from frappe import qb
from erpnext.stock.doctype.item.test_item import create_item
class AccountsTestMixin:
def create_customer(self, customer_name, currency=None):
def create_customer(self, customer_name="_Test Customer", currency=None):
if not frappe.db.exists("Customer", customer_name):
customer = frappe.new_doc("Customer")
customer.customer_name = customer_name
@@ -17,7 +18,7 @@ class AccountsTestMixin:
else:
self.customer = customer_name
def create_supplier(self, supplier_name, currency=None):
def create_supplier(self, supplier_name="_Test Supplier", currency=None):
if not frappe.db.exists("Supplier", supplier_name):
supplier = frappe.new_doc("Supplier")
supplier.supplier_name = supplier_name
@@ -31,7 +32,7 @@ class AccountsTestMixin:
else:
self.supplier = supplier_name
def create_item(self, item_name, is_stock=0, warehouse=None, company=None):
def create_item(self, item_name="_Test Item", is_stock=0, warehouse=None, company=None):
item = create_item(item_name, is_stock_item=is_stock, warehouse=warehouse, company=company)
self.item = item.name
@@ -59,22 +60,82 @@ class AccountsTestMixin:
self.income_account = "Sales - " + abbr
self.expense_account = "Cost of Goods Sold - " + abbr
self.debit_to = "Debtors - " + abbr
self.debit_usd = "Debtors USD - " + abbr
self.cash = "Cash - " + abbr
self.creditors = "Creditors - " + abbr
self.retained_earnings = "Retained Earnings - " + abbr
# create bank account
bank_account = "HDFC - " + abbr
if frappe.db.exists("Account", bank_account):
self.bank = bank_account
else:
bank_acc = frappe.get_doc(
# Deferred revenue, expense and bank accounts
other_accounts = [
frappe._dict(
{
"doctype": "Account",
"attribute_name": "deferred_revenue",
"account_name": "Deferred Revenue",
"parent_account": "Current Liabilities - " + abbr,
}
),
frappe._dict(
{
"attribute_name": "deferred_expense",
"account_name": "Deferred Expense",
"parent_account": "Current Assets - " + abbr,
}
),
frappe._dict(
{
"attribute_name": "bank",
"account_name": "HDFC",
"parent_account": "Bank Accounts - " + abbr,
"company": self.company,
}
),
]
for acc in other_accounts:
acc_name = acc.account_name + " - " + abbr
if frappe.db.exists("Account", acc_name):
setattr(self, acc.attribute_name, acc_name)
else:
new_acc = frappe.get_doc(
{
"doctype": "Account",
"account_name": acc.account_name,
"parent_account": acc.parent_account,
"company": self.company,
}
)
new_acc.save()
setattr(self, acc.attribute_name, new_acc.name)
def create_usd_receivable_account(self):
account_name = "Debtors USD"
if not frappe.db.get_value(
"Account", filters={"account_name": account_name, "company": self.company}
):
acc = frappe.new_doc("Account")
acc.account_name = account_name
acc.parent_account = "Accounts Receivable - " + self.company_abbr
acc.company = self.company
acc.account_currency = "USD"
acc.account_type = "Receivable"
acc.insert()
else:
name = frappe.db.get_value(
"Account",
filters={"account_name": account_name, "company": self.company},
fieldname="name",
pluck=True,
)
bank_acc.save()
self.bank = bank_acc.name
acc = frappe.get_doc("Account", name)
self.debtors_usd = acc.name
def clear_old_entries(self):
doctype_list = [
"GL Entry",
"Payment Ledger Entry",
"Sales Invoice",
"Purchase Invoice",
"Payment Entry",
"Journal Entry",
"Sales Order",
"Exchange Rate Revaluation",
]
for doctype in doctype_list:
qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()

View File

@@ -3,6 +3,8 @@ 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,
@@ -73,6 +75,56 @@ 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, do_not_submit=1
)
purchase_invoice.credit_to = "_Test Payable USD - _TC"
purchase_invoice.submit()
payment_entry = get_payment_entry(purchase_invoice.doctype, purchase_invoice.name)
payment_entry.paid_amount = 15725
payment_entry.deductions = []
payment_entry.save()
# below is the difference between base_received_amount and base_paid_amount
self.assertEqual(payment_entry.difference_amount, -4855.0)
payment_entry.target_exchange_rate = 62.9
payment_entry.save()
# below is due to change in exchange rate
self.assertEqual(payment_entry.references[0].exchange_gain_loss, -4855.0)
payment_entry.references = []
self.assertEqual(payment_entry.difference_amount, 0.0)
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 = [
{

View File

@@ -459,6 +459,9 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
# update ref in advance entry
if voucher_type == "Journal Entry":
update_reference_in_journal_entry(entry, doc, do_not_save=True)
# advance section in sales/purchase invoice and reconciliation tool,both pass on exchange gain/loss
# amount and account in args
doc.make_exchange_gain_loss_journal(args)
else:
update_reference_in_payment_entry(
entry, doc, do_not_save=True, skip_ref_details_update_for_pe=skip_ref_details_update_for_pe
@@ -612,9 +615,7 @@ def update_reference_in_payment_entry(
"total_amount": d.grand_total,
"outstanding_amount": d.outstanding_amount,
"allocated_amount": d.allocated_amount,
"exchange_rate": d.exchange_rate
if not d.exchange_gain_loss
else payment_entry.get_exchange_rate(),
"exchange_rate": d.exchange_rate if d.exchange_gain_loss else payment_entry.get_exchange_rate(),
"exchange_gain_loss": d.exchange_gain_loss, # only populated from invoice in case of advance allocation
}
@@ -635,33 +636,48 @@ def update_reference_in_payment_entry(
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,
"cost_center": payment_entry.cost_center
or frappe.get_cached_value("Company", payment_entry.company, "cost_center"),
}
if d.difference_amount:
account_details["amount"] = d.difference_amount
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()
if not skip_ref_details_update_for_pe:
payment_entry.set_missing_ref_details()
payment_entry.set_amounts()
payment_entry.make_exchange_gain_loss_journal()
if not do_not_save:
payment_entry.save(ignore_permissions=True)
def cancel_exchange_gain_loss_journal(parent_doc: dict | object) -> None:
"""
Cancel Exchange Gain/Loss for Sales/Purchase Invoice, if they have any.
"""
if parent_doc.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
journals = frappe.db.get_all(
"Journal Entry Account",
filters={
"reference_type": parent_doc.doctype,
"reference_name": parent_doc.name,
"docstatus": 1,
},
fields=["parent"],
as_list=1,
)
if journals:
gain_loss_journals = frappe.db.get_all(
"Journal Entry",
filters={
"name": ["in", [x[0] for x in journals]],
"voucher_type": "Exchange Gain Or Loss",
"docstatus": 1,
},
as_list=1,
)
for doc in gain_loss_journals:
frappe.get_doc("Journal Entry", doc[0]).cancel()
def unlink_ref_doc_from_payment_entries(ref_doc):
remove_ref_doc_link_from_jv(ref_doc.doctype, ref_doc.name)
remove_ref_doc_link_from_pe(ref_doc.doctype, ref_doc.name)
@@ -868,6 +884,9 @@ def get_outstanding_invoices(
min_outstanding=None,
max_outstanding=None,
accounting_dimensions=None,
vouchers=None, # list of dicts [{'voucher_type': '', 'voucher_no': ''}] for filtering
limit=None, # passed by reconciliation tool
voucher_no=None, # filter passed by reconciliation tool
):
ple = qb.DocType("Payment Ledger Entry")
@@ -893,12 +912,15 @@ def get_outstanding_invoices(
ple_query = QueryPaymentLedger()
invoice_list = ple_query.get_voucher_outstandings(
vouchers=vouchers,
common_filter=common_filter,
posting_date=posting_date,
min_outstanding=min_outstanding,
max_outstanding=max_outstanding,
get_invoices=True,
accounting_dimensions=accounting_dimensions or [],
limit=limit,
voucher_no=voucher_no,
)
for d in invoice_list:
@@ -1630,12 +1652,13 @@ class QueryPaymentLedger(object):
self.voucher_posting_date = []
self.min_outstanding = None
self.max_outstanding = None
self.limit = self.voucher_no = None
def reset(self):
# clear filters
self.vouchers.clear()
self.common_filter.clear()
self.min_outstanding = self.max_outstanding = None
self.min_outstanding = self.max_outstanding = self.limit = None
# clear result
self.voucher_outstandings.clear()
@@ -1649,6 +1672,7 @@ class QueryPaymentLedger(object):
filter_on_voucher_no = []
filter_on_against_voucher_no = []
if self.vouchers:
voucher_types = set([x.voucher_type for x in self.vouchers])
voucher_nos = set([x.voucher_no for x in self.vouchers])
@@ -1659,6 +1683,10 @@ class QueryPaymentLedger(object):
filter_on_against_voucher_no.append(ple.against_voucher_type.isin(voucher_types))
filter_on_against_voucher_no.append(ple.against_voucher_no.isin(voucher_nos))
if self.voucher_no:
filter_on_voucher_no.append(ple.voucher_no.like(f"%{self.voucher_no}%"))
filter_on_against_voucher_no.append(ple.against_voucher_no.like(f"%{self.voucher_no}%"))
# build outstanding amount filter
filter_on_outstanding_amount = []
if self.min_outstanding:
@@ -1774,6 +1802,11 @@ class QueryPaymentLedger(object):
)
)
if self.limit:
self.cte_query_voucher_amount_and_outstanding = (
self.cte_query_voucher_amount_and_outstanding.limit(self.limit)
)
# execute SQL
self.voucher_outstandings = self.cte_query_voucher_amount_and_outstanding.run(as_dict=True)
@@ -1787,6 +1820,8 @@ class QueryPaymentLedger(object):
get_payments=False,
get_invoices=False,
accounting_dimensions=None,
limit=None,
voucher_no=None,
):
"""
Fetch voucher amount and outstanding amount from Payment Ledger using Database CTE
@@ -1808,6 +1843,79 @@ class QueryPaymentLedger(object):
self.max_outstanding = max_outstanding
self.get_payments = get_payments
self.get_invoices = get_invoices
self.limit = limit
self.voucher_no = voucher_no
self.query_for_outstanding()
return self.voucher_outstandings
def create_gain_loss_journal(
company,
party_type,
party,
party_account,
gain_loss_account,
exc_gain_loss,
dr_or_cr,
reverse_dr_or_cr,
ref1_dt,
ref1_dn,
ref1_detail_no,
ref2_dt,
ref2_dn,
ref2_detail_no,
) -> str:
journal_entry = frappe.new_doc("Journal Entry")
journal_entry.voucher_type = "Exchange Gain Or Loss"
journal_entry.company = company
journal_entry.posting_date = nowdate()
journal_entry.multi_currency = 1
party_account_currency = frappe.get_cached_value("Account", party_account, "account_currency")
if not gain_loss_account:
frappe.throw(_("Please set default Exchange Gain/Loss Account in Company {}").format(company))
gain_loss_account_currency = get_account_currency(gain_loss_account)
company_currency = frappe.get_cached_value("Company", company, "default_currency")
if gain_loss_account_currency != company_currency:
frappe.throw(_("Currency for {0} must be {1}").format(gain_loss_account, company_currency))
journal_account = frappe._dict(
{
"account": party_account,
"party_type": party_type,
"party": party,
"account_currency": party_account_currency,
"exchange_rate": 0,
"cost_center": erpnext.get_default_cost_center(company),
"reference_type": ref1_dt,
"reference_name": ref1_dn,
"reference_detail_no": ref1_detail_no,
dr_or_cr: abs(exc_gain_loss),
dr_or_cr + "_in_account_currency": 0,
}
)
journal_entry.append("accounts", journal_account)
journal_account = frappe._dict(
{
"account": gain_loss_account,
"account_currency": gain_loss_account_currency,
"exchange_rate": 1,
"cost_center": erpnext.get_default_cost_center(company),
"reference_type": ref2_dt,
"reference_name": ref2_dn,
"reference_detail_no": ref2_detail_no,
reverse_dr_or_cr + "_in_account_currency": 0,
reverse_dr_or_cr: abs(exc_gain_loss),
}
)
journal_entry.append("accounts", journal_account)
journal_entry.save()
journal_entry.submit()
return journal_entry.name

View File

@@ -318,6 +318,7 @@
"label": "Depreciation Schedule"
},
{
"depends_on": "schedules",
"fieldname": "schedules",
"fieldtype": "Table",
"label": "Depreciation Schedule",
@@ -537,7 +538,7 @@
"table_fieldname": "accounts"
}
],
"modified": "2023-07-28 15:47:01.137996",
"modified": "2023-08-10 20:25:09.913073",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",

View File

@@ -81,18 +81,27 @@ 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,
date_of_disposal=None,
date_of_return=None,
value_after_depreciation=None,
ignore_booked_entry=False,
):
if self.calculate_depreciation:
self.value_after_depreciation = 0
self.set_depreciation_rate()
if self.should_prepare_depreciation_schedule():
self.make_depreciation_schedule(date_of_disposal)
self.set_accumulated_depreciation(date_of_disposal, date_of_return)
self.make_depreciation_schedule(date_of_disposal, value_after_depreciation)
self.set_accumulated_depreciation(date_of_disposal, date_of_return, ignore_booked_entry)
else:
self.finance_books = []
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(
self.opening_accumulated_depreciation
)
if value_after_depreciation:
self.value_after_depreciation = value_after_depreciation
else:
self.value_after_depreciation = flt(self.gross_purchase_amount) - flt(
self.opening_accumulated_depreciation
)
def should_prepare_depreciation_schedule(self):
if not self.get("schedules"):
@@ -285,7 +294,7 @@ class Asset(AccountsController):
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
)
def make_depreciation_schedule(self, date_of_disposal):
def make_depreciation_schedule(self, date_of_disposal, value_after_depreciation=None):
if not self.get("schedules"):
self.schedules = []
@@ -295,24 +304,30 @@ class Asset(AccountsController):
start = self.clear_depreciation_schedule()
for finance_book in self.get("finance_books"):
self._make_depreciation_schedule(finance_book, start, date_of_disposal)
self._make_depreciation_schedule(
finance_book, start, date_of_disposal, value_after_depreciation
)
if len(self.get("finance_books")) > 1 and any(start):
self.sort_depreciation_schedule()
def _make_depreciation_schedule(self, finance_book, start, date_of_disposal):
def _make_depreciation_schedule(
self, finance_book, start, date_of_disposal, value_after_depreciation=None
):
self.validate_asset_finance_books(finance_book)
value_after_depreciation = self._get_value_after_depreciation_for_making_schedule(finance_book)
if not value_after_depreciation:
value_after_depreciation = self._get_value_after_depreciation_for_making_schedule(finance_book)
finance_book.value_after_depreciation = value_after_depreciation
number_of_pending_depreciations = cint(finance_book.total_number_of_depreciations) - cint(
final_number_of_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
final_number_of_depreciations += 1
has_wdv_or_dd_non_yearly_pro_rata = False
if (
@@ -328,7 +343,9 @@ class Asset(AccountsController):
depreciation_amount = 0
for n in range(start[finance_book.idx - 1], number_of_pending_depreciations):
number_of_pending_depreciations = final_number_of_depreciations - start[finance_book.idx - 1]
for n in range(start[finance_book.idx - 1], final_number_of_depreciations):
# If depreciation is already completed (for double declining balance)
if skip_row:
continue
@@ -345,10 +362,11 @@ class Asset(AccountsController):
n,
prev_depreciation_amount,
has_wdv_or_dd_non_yearly_pro_rata,
number_of_pending_depreciations,
)
if not has_pro_rata or (
n < (cint(number_of_pending_depreciations) - 1) or number_of_pending_depreciations == 2
n < (cint(final_number_of_depreciations) - 1) or final_number_of_depreciations == 2
):
schedule_date = add_months(
finance_book.depreciation_start_date, n * cint(finance_book.frequency_of_depreciation)
@@ -416,7 +434,7 @@ class Asset(AccountsController):
)
# For last row
elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1:
elif has_pro_rata and n == cint(final_number_of_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(
@@ -447,7 +465,7 @@ class Asset(AccountsController):
# 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
n == cint(final_number_of_depreciations) - 1
and value_after_depreciation != finance_book.expected_value_after_useful_life
)
or value_after_depreciation < finance_book.expected_value_after_useful_life
@@ -690,7 +708,10 @@ class Asset(AccountsController):
if s.finance_book_id == d.finance_book_id
and (s.depreciation_method == "Straight Line" or s.depreciation_method == "Manual")
]
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
if i > 0 and self.flags.decrease_in_asset_value_due_to_value_adjustment:
accumulated_depreciation = self.get("schedules")[i - 1].accumulated_depreciation_amount
else:
accumulated_depreciation = flt(self.opening_accumulated_depreciation)
value_after_depreciation = flt(
self.get("finance_books")[cint(d.finance_book_id) - 1].value_after_depreciation
)
@@ -1289,29 +1310,43 @@ def get_total_days(date, frequency):
return date_diff(date, period_start_date)
@erpnext.allow_regional
def get_depreciation_amount(
asset,
depreciable_value,
row,
fb_row,
schedule_idx=0,
prev_depreciation_amount=0,
has_wdv_or_dd_non_yearly_pro_rata=False,
number_of_pending_depreciations=0,
):
if row.depreciation_method in ("Straight Line", "Manual"):
return get_straight_line_or_manual_depr_amount(asset, row)
frappe.flags.company = asset.company
if fb_row.depreciation_method in ("Straight Line", "Manual"):
return get_straight_line_or_manual_depr_amount(
asset, fb_row, schedule_idx, number_of_pending_depreciations
)
else:
rate_of_depreciation = get_updated_rate_of_depreciation_for_wdv_and_dd(
asset, depreciable_value, fb_row
)
return get_wdv_or_dd_depr_amount(
depreciable_value,
row.rate_of_depreciation,
row.frequency_of_depreciation,
rate_of_depreciation,
fb_row.frequency_of_depreciation,
schedule_idx,
prev_depreciation_amount,
has_wdv_or_dd_non_yearly_pro_rata,
)
def get_straight_line_or_manual_depr_amount(asset, row):
@erpnext.allow_regional
def get_updated_rate_of_depreciation_for_wdv_and_dd(asset, depreciable_value, fb_row):
return fb_row.rate_of_depreciation
def get_straight_line_or_manual_depr_amount(
asset, row, schedule_idx, number_of_pending_depreciations
):
# if the Depreciation Schedule is being modified after Asset Repair due to increase in asset life and value
if asset.flags.increase_in_asset_life:
return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / (
@@ -1322,13 +1357,62 @@ def get_straight_line_or_manual_depr_amount(asset, row):
return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / flt(
row.total_number_of_depreciations
)
# if the Depreciation Schedule is being modified after Asset Value Adjustment due to decrease in asset value
elif asset.flags.decrease_in_asset_value_due_to_value_adjustment:
if row.daily_depreciation:
daily_depr_amount = (
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
) / date_diff(
add_months(
row.depreciation_start_date,
flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
* row.frequency_of_depreciation,
),
add_months(
row.depreciation_start_date,
flt(
row.total_number_of_depreciations
- asset.number_of_depreciations_booked
- number_of_pending_depreciations
)
* row.frequency_of_depreciation,
),
)
to_date = add_months(row.depreciation_start_date, schedule_idx * row.frequency_of_depreciation)
from_date = add_months(
row.depreciation_start_date, (schedule_idx - 1) * row.frequency_of_depreciation
)
return daily_depr_amount * date_diff(to_date, from_date)
else:
return (
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
) / number_of_pending_depreciations
# if the Depreciation Schedule is being prepared for the first time
else:
return (
flt(asset.gross_purchase_amount)
- flt(asset.opening_accumulated_depreciation)
- flt(row.expected_value_after_useful_life)
) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
if row.daily_depreciation:
daily_depr_amount = (
flt(asset.gross_purchase_amount)
- flt(asset.opening_accumulated_depreciation)
- flt(row.expected_value_after_useful_life)
) / date_diff(
add_months(
row.depreciation_start_date,
flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
* row.frequency_of_depreciation,
),
row.depreciation_start_date,
)
to_date = add_months(row.depreciation_start_date, schedule_idx * row.frequency_of_depreciation)
from_date = add_months(
row.depreciation_start_date, (schedule_idx - 1) * row.frequency_of_depreciation
)
return daily_depr_amount * date_diff(to_date, from_date)
else:
return (
flt(asset.gross_purchase_amount)
- flt(asset.opening_accumulated_depreciation)
- flt(row.expected_value_after_useful_life)
) / flt(row.total_number_of_depreciations - asset.number_of_depreciations_booked)
def get_wdv_or_dd_depr_amount(

View File

@@ -730,6 +730,40 @@ class TestDepreciationMethods(AssetSetup):
self.assertEqual(schedules, expected_schedules)
def test_schedule_for_straight_line_method_with_daily_depreciation(self):
asset = create_asset(
calculate_depreciation=1,
available_for_use_date="2023-01-01",
purchase_date="2023-01-01",
gross_purchase_amount=12000,
depreciation_start_date="2023-01-31",
total_number_of_depreciations=12,
frequency_of_depreciation=1,
daily_depreciation=1,
)
expected_schedules = [
["2023-01-31", 1019.18, 1019.18],
["2023-02-28", 920.55, 1939.73],
["2023-03-31", 1019.18, 2958.91],
["2023-04-30", 986.3, 3945.21],
["2023-05-31", 1019.18, 4964.39],
["2023-06-30", 986.3, 5950.69],
["2023-07-31", 1019.18, 6969.87],
["2023-08-31", 1019.18, 7989.05],
["2023-09-30", 986.3, 8975.35],
["2023-10-31", 1019.18, 9994.53],
["2023-11-30", 986.3, 10980.83],
["2023-12-31", 1019.17, 12000.0],
]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in asset.get("schedules")
]
self.assertEqual(schedules, expected_schedules)
def test_schedule_for_double_declining_method(self):
asset = create_asset(
calculate_depreciation=1,
@@ -1653,6 +1687,7 @@ def create_asset(**args):
"total_number_of_depreciations": args.total_number_of_depreciations or 5,
"expected_value_after_useful_life": args.expected_value_after_useful_life or 0,
"depreciation_start_date": args.depreciation_start_date,
"daily_depreciation": args.daily_depreciation or 0,
},
)

View File

@@ -33,6 +33,7 @@ frappe.ui.form.on('Asset Category', {
var d = locals[cdt][cdn];
return {
"filters": {
"account_type": "Depreciation",
"root_type": ["in", ["Expense", "Income"]],
"is_group": 0,
"company": d.company_name

View File

@@ -53,7 +53,7 @@ class AssetCategory(Document):
account_type_map = {
"fixed_asset_account": {"account_type": ["Fixed Asset"]},
"accumulated_depreciation_account": {"account_type": ["Accumulated Depreciation"]},
"depreciation_expense_account": {"root_type": ["Expense", "Income"]},
"depreciation_expense_account": {"account_type": ["Depreciation"]},
"capital_work_in_progress_account": {"account_type": ["Capital Work in Progress"]},
}
for d in self.accounts:

View File

@@ -8,6 +8,7 @@
"finance_book",
"depreciation_method",
"total_number_of_depreciations",
"daily_depreciation",
"column_break_5",
"frequency_of_depreciation",
"depreciation_start_date",
@@ -79,12 +80,19 @@
"fieldname": "rate_of_depreciation",
"fieldtype": "Percent",
"label": "Rate of Depreciation"
},
{
"default": "0",
"depends_on": "eval:doc.depreciation_method == \"Straight Line\" || doc.depreciation_method == \"Manual\"",
"fieldname": "daily_depreciation",
"fieldtype": "Check",
"label": "Daily Depreciation"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-06-17 12:59:05.743683",
"modified": "2023-08-10 18:56:09.022246",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Finance Book",
@@ -93,5 +101,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@@ -5,15 +5,12 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cint, date_diff, flt, formatdate, getdate
from frappe.utils import flt, formatdate, getdate
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_checks_for_pl_and_bs_accounts,
)
from erpnext.assets.doctype.asset.asset import (
get_asset_value_after_depreciation,
get_depreciation_amount,
)
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
from erpnext.assets.doctype.asset.depreciation import get_depreciation_accounts
@@ -25,10 +22,10 @@ class AssetValueAdjustment(Document):
def on_submit(self):
self.make_depreciation_entry()
self.reschedule_depreciations(self.new_asset_value)
self.update_asset(self.new_asset_value)
def on_cancel(self):
self.reschedule_depreciations(self.current_asset_value)
self.update_asset(self.current_asset_value)
def validate_date(self):
asset_purchase_date = frappe.db.get_value("Asset", self.asset, "purchase_date")
@@ -71,12 +68,16 @@ class AssetValueAdjustment(Document):
"account": accumulated_depreciation_account,
"credit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center or self.cost_center,
"reference_type": "Asset",
"reference_name": asset.name,
}
debit_entry = {
"account": depreciation_expense_account,
"debit_in_account_currency": self.difference_amount,
"cost_center": depreciation_cost_center or self.cost_center,
"reference_type": "Asset",
"reference_name": asset.name,
}
accounting_dimensions = get_checks_for_pl_and_bs_accounts()
@@ -106,44 +107,11 @@ class AssetValueAdjustment(Document):
self.db_set("journal_entry", je.name)
def reschedule_depreciations(self, asset_value):
def update_asset(self, asset_value):
asset = frappe.get_doc("Asset", self.asset)
country = frappe.get_value("Company", self.company, "country")
for d in asset.finance_books:
d.value_after_depreciation = asset_value
asset.flags.decrease_in_asset_value_due_to_value_adjustment = True
if d.depreciation_method in ("Straight Line", "Manual"):
end_date = max(s.schedule_date for s in asset.schedules if cint(s.finance_book_id) == d.idx)
total_days = date_diff(end_date, self.date)
rate_per_day = flt(d.value_after_depreciation - d.expected_value_after_useful_life) / flt(
total_days
)
from_date = self.date
else:
no_of_depreciations = len(
[
s.name for s in asset.schedules if (cint(s.finance_book_id) == d.idx and not s.journal_entry)
]
)
value_after_depreciation = d.value_after_depreciation
for data in asset.schedules:
if cint(data.finance_book_id) == d.idx and not data.journal_entry:
if d.depreciation_method in ("Straight Line", "Manual"):
days = date_diff(data.schedule_date, from_date)
depreciation_amount = days * rate_per_day
from_date = data.schedule_date
else:
depreciation_amount = get_depreciation_amount(asset, value_after_depreciation, d)
if depreciation_amount:
value_after_depreciation -= flt(depreciation_amount)
data.depreciation_amount = depreciation_amount
d.db_update()
asset.set_accumulated_depreciation(ignore_booked_entry=True)
for asset_data in asset.schedules:
if not asset_data.journal_entry:
asset_data.db_update()
asset.prepare_depreciation_data(value_after_depreciation=asset_value, ignore_booked_entry=True)
asset.flags.ignore_validate_update_after_submit = True
asset.save()

View File

@@ -4,9 +4,10 @@
import unittest
import frappe
from frappe.utils import add_days, get_last_day, nowdate
from frappe.utils import add_days, cstr, get_last_day, getdate, nowdate
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries
from erpnext.assets.doctype.asset.test_asset import create_asset_data
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
@@ -46,40 +47,44 @@ class TestAssetValueAdjustment(unittest.TestCase):
def test_asset_depreciation_value_adjustment(self):
pr = make_purchase_receipt(
item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location"
item_code="Macbook Pro", qty=1, rate=120000.0, location="Test Location"
)
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, "name")
asset_doc = frappe.get_doc("Asset", asset_name)
asset_doc.calculate_depreciation = 1
month_end_date = get_last_day(nowdate())
purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)
asset_doc.available_for_use_date = purchase_date
asset_doc.purchase_date = purchase_date
asset_doc.available_for_use_date = "2023-01-15"
asset_doc.purchase_date = "2023-01-15"
asset_doc.calculate_depreciation = 1
asset_doc.append(
"finance_books",
{
"expected_value_after_useful_life": 200,
"depreciation_method": "Straight Line",
"total_number_of_depreciations": 3,
"frequency_of_depreciation": 10,
"depreciation_start_date": month_end_date,
"total_number_of_depreciations": 12,
"frequency_of_depreciation": 1,
"depreciation_start_date": "2023-01-31",
},
)
asset_doc.submit()
post_depreciation_entries(getdate("2023-08-21"))
current_value = get_asset_value_after_depreciation(asset_doc.name)
adj_doc = make_asset_value_adjustment(
asset=asset_doc.name, current_asset_value=current_value, new_asset_value=50000.0
asset=asset_doc.name,
current_asset_value=current_value,
new_asset_value=50000.0,
date="2023-08-21",
)
adj_doc.submit()
asset_doc.reload()
expected_gle = (
("_Test Accumulated Depreciations - _TC", 0.0, 50000.0),
("_Test Depreciations - _TC", 50000.0, 0.0),
("_Test Accumulated Depreciations - _TC", 0.0, 4625.29),
("_Test Depreciations - _TC", 4625.29, 0.0),
)
gle = frappe.db.sql(
@@ -91,6 +96,29 @@ class TestAssetValueAdjustment(unittest.TestCase):
self.assertSequenceEqual(gle, expected_gle)
expected_schedules = [
["2023-01-31", 5474.73, 5474.73],
["2023-02-28", 9983.33, 15458.06],
["2023-03-31", 9983.33, 25441.39],
["2023-04-30", 9983.33, 35424.72],
["2023-05-31", 9983.33, 45408.05],
["2023-06-30", 9983.33, 55391.38],
["2023-07-31", 9983.33, 65374.71],
["2023-08-31", 8300.0, 73674.71],
["2023-09-30", 8300.0, 81974.71],
["2023-10-31", 8300.0, 90274.71],
["2023-11-30", 8300.0, 98574.71],
["2023-12-31", 8300.0, 106874.71],
["2024-01-15", 8300.0, 115174.71],
]
schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in asset_doc.get("schedules")
]
self.assertEqual(schedules, expected_schedules)
def make_asset_value_adjustment(**args):
args = frappe._dict(args)

View File

@@ -7,13 +7,14 @@ from itertools import chain
import frappe
from frappe import _
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import cstr, flt, formatdate, getdate
from frappe.utils import add_months, cstr, flt, formatdate, getdate, nowdate, today
from erpnext.accounts.report.financial_statements import (
get_fiscal_year_data,
get_period_list,
validate_fiscal_year,
)
from erpnext.accounts.utils import get_fiscal_year
from erpnext.assets.doctype.asset.asset import get_asset_value_after_depreciation
@@ -37,15 +38,26 @@ def get_conditions(filters):
if filters.get("company"):
conditions["company"] = filters.company
if filters.filter_based_on == "Date Range":
if not filters.from_date and not filters.to_date:
filters.from_date = add_months(nowdate(), -12)
filters.to_date = nowdate()
conditions[date_field] = ["between", [filters.from_date, filters.to_date]]
if filters.filter_based_on == "Fiscal Year":
elif filters.filter_based_on == "Fiscal Year":
if not filters.from_fiscal_year and not filters.to_fiscal_year:
default_fiscal_year = get_fiscal_year(today())[0]
filters.from_fiscal_year = default_fiscal_year
filters.to_fiscal_year = default_fiscal_year
fiscal_year = get_fiscal_year_data(filters.from_fiscal_year, filters.to_fiscal_year)
validate_fiscal_year(fiscal_year, filters.from_fiscal_year, filters.to_fiscal_year)
filters.year_start_date = getdate(fiscal_year.year_start_date)
filters.year_end_date = getdate(fiscal_year.year_end_date)
conditions[date_field] = ["between", [filters.year_start_date, filters.year_end_date]]
if filters.get("only_existing_assets"):
conditions["is_existing_asset"] = filters.get("only_existing_assets")
if filters.get("asset_category"):
@@ -144,6 +156,8 @@ def get_data(filters):
def prepare_chart_data(data, filters):
if not data:
return
labels_values_map = {}
if filters.filter_based_on not in ("Date Range", "Fiscal Year"):
filters_filter_based_on = "Date Range"

View File

@@ -245,19 +245,21 @@ frappe.ui.form.on("Request for Quotation",{
]
});
dialog.fields_dict['supplier'].df.onchange = () => {
var supplier = dialog.get_value('supplier');
frm.call('get_supplier_email_preview', {supplier: supplier}).then(result => {
dialog.fields_dict["supplier"].df.onchange = () => {
frm.call("get_supplier_email_preview", {
supplier: dialog.get_value("supplier"),
}).then(({ message }) => {
dialog.fields_dict.email_preview.$wrapper.empty();
dialog.fields_dict.email_preview.$wrapper.append(result.message);
dialog.fields_dict.email_preview.$wrapper.append(
message.message
);
dialog.set_value("subject", message.subject);
});
}
};
dialog.fields_dict.note.$wrapper.append(`<p class="small text-muted">This is a preview of the email to be sent. A PDF of the document will
automatically be attached with the email.</p>`);
dialog.set_value("subject", frm.doc.subject);
dialog.show();
}
})

View File

@@ -20,11 +20,10 @@
"items_section",
"items",
"supplier_response_section",
"salutation",
"subject",
"col_break_email_1",
"email_template",
"preview",
"col_break_email_1",
"html_llwp",
"send_attached_files",
"sec_break_email_2",
"message_for_supplier",
@@ -237,23 +236,6 @@
"print_hide": 1,
"read_only": 1
},
{
"fetch_from": "email_template.subject",
"fetch_if_empty": 1,
"fieldname": "subject",
"fieldtype": "Data",
"label": "Subject",
"print_hide": 1
},
{
"description": "Select a greeting for the receiver. E.g. Mr., Ms., etc.",
"fieldname": "salutation",
"fieldtype": "Link",
"label": "Salutation",
"no_copy": 1,
"options": "Salutation",
"print_hide": 1
},
{
"fieldname": "col_break_email_1",
"fieldtype": "Column Break"
@@ -287,6 +269,14 @@
"fieldtype": "Data",
"label": "Named Place"
},
{
"fieldname": "html_llwp",
"fieldtype": "HTML",
"options": "<p>In your <b>Email Template</b>, you can use the following special variables:\n</p>\n<ul>\n <li>\n <code>{{ update_password_link }}</code>: A link where your supplier can set a new password to log into your portal.\n </li>\n <li>\n <code>{{ portal_link }}</code>: A link to this RFQ in your supplier portal.\n </li>\n <li>\n <code>{{ supplier_name }}</code>: The company name of your supplier.\n </li>\n <li>\n <code>{{ contact.salutation }} {{ contact.last_name }}</code>: The contact person of your supplier.\n </li><li>\n <code>{{ user_fullname }}</code>: Your full name.\n </li>\n </ul>\n<p></p>\n<p>Apart from these, you can access all values in this RFQ, like <code>{{ message_for_supplier }}</code> or <code>{{ terms }}</code>.</p>",
"print_hide": 1,
"read_only": 1,
"report_hide": 1
},
{
"default": "1",
"description": "If enabled, all files attached to this document will be attached to each email",
@@ -299,7 +289,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-07-27 16:41:48.468873",
"modified": "2023-08-08 16:30:10.870429",
"modified_by": "Administrator",
"module": "Buying",
"name": "Request for Quotation",

View File

@@ -116,7 +116,10 @@ class RequestforQuotation(BuyingController):
route = frappe.db.get_value(
"Portal Menu Item", {"reference_doctype": "Request for Quotation"}, ["route"]
)
return get_url("/app/{0}/".format(route) + self.name)
if not route:
frappe.throw(_("Please add Request for Quotation to the sidebar in Portal Settings."))
return get_url(f"{route}/{self.name}")
def update_supplier_part_no(self, supplier):
self.vendor = supplier
@@ -179,35 +182,28 @@ class RequestforQuotation(BuyingController):
if full_name == "Guest":
full_name = "Administrator"
# send document dict and some important data from suppliers row
# to render message_for_supplier from any template
doc_args = self.as_dict()
doc_args.update({"supplier": data.get("supplier"), "supplier_name": data.get("supplier_name")})
# Get Contact Full Name
supplier_name = None
if data.get("contact"):
contact_name = frappe.db.get_value(
"Contact", data.get("contact"), ["first_name", "middle_name", "last_name"]
)
supplier_name = (" ").join(x for x in contact_name if x) # remove any blank values
contact = frappe.get_doc("Contact", data.get("contact"))
doc_args["contact"] = contact.as_dict()
args = {
"update_password_link": update_password_link,
"message": frappe.render_template(self.message_for_supplier, doc_args),
"rfq_link": rfq_link,
"user_fullname": full_name,
"supplier_name": supplier_name or data.get("supplier_name"),
"supplier_salutation": self.salutation or "Dear Mx.",
}
subject = self.subject or _("Request for Quotation")
template = "templates/emails/request_for_quotation.html"
doc_args.update(
{
"supplier": data.get("supplier"),
"supplier_name": data.get("supplier_name"),
"update_password_link": f'<a href="{update_password_link}" class="btn btn-default btn-xs" target="_blank">{_("Set Password")}</a>',
"portal_link": f'<a href="{rfq_link}" class="btn btn-default btn-xs" target="_blank"> {_("Submit your Quotation")} </a>',
"user_fullname": full_name,
}
)
email_template = frappe.get_doc("Email Template", self.email_template)
message = frappe.render_template(email_template.response_, doc_args)
subject = frappe.render_template(email_template.subject, doc_args)
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
message = frappe.get_template(template).render(args)
if preview:
return message
return {"message": message, "subject": subject}
attachments = None
if self.send_attached_files:

View File

@@ -2,11 +2,14 @@
# See license.txt
from urllib.parse import urlparse
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import nowdate
from erpnext.buying.doctype.request_for_quotation.request_for_quotation import (
RequestforQuotation,
create_supplier_quotation,
get_pdf,
make_supplier_quotation_from_rfq,
@@ -125,13 +128,18 @@ class TestRequestforQuotation(FrappeTestCase):
rfq.status = "Draft"
rfq.submit()
def test_get_link(self):
rfq = make_request_for_quotation()
parsed_link = urlparse(rfq.get_link())
self.assertEqual(parsed_link.path, f"/rfq/{rfq.name}")
def test_get_pdf(self):
rfq = make_request_for_quotation()
get_pdf(rfq.name, rfq.get("suppliers")[0].supplier)
self.assertEqual(frappe.local.response.type, "pdf")
def make_request_for_quotation(**args):
def make_request_for_quotation(**args) -> "RequestforQuotation":
"""
:param supplier_data: List containing supplier data
"""

View File

@@ -154,31 +154,35 @@ def get_data(filters):
procurement_record = []
if procurement_record_against_mr:
procurement_record += procurement_record_against_mr
for po in purchase_order_entry:
# fetch material records linked to the purchase order item
mr_record = mr_records.get(po.material_request_item, [{}])[0]
procurement_detail = {
"material_request_date": mr_record.get("transaction_date"),
"cost_center": po.cost_center,
"project": po.project,
"requesting_site": po.warehouse,
"requestor": po.owner,
"material_request_no": po.material_request,
"item_code": po.item_code,
"quantity": flt(po.qty),
"unit_of_measurement": po.stock_uom,
"status": po.status,
"purchase_order_date": po.transaction_date,
"purchase_order": po.parent,
"supplier": po.supplier,
"estimated_cost": flt(mr_record.get("amount")),
"actual_cost": flt(pi_records.get(po.name)),
"purchase_order_amt": flt(po.amount),
"purchase_order_amt_in_company_currency": flt(po.base_amount),
"expected_delivery_date": po.schedule_date,
"actual_delivery_date": pr_records.get(po.name),
}
procurement_record.append(procurement_detail)
material_requests = mr_records.get(po.material_request_item, [{}])
for mr_record in material_requests:
procurement_detail = {
"material_request_date": mr_record.get("transaction_date"),
"cost_center": po.cost_center,
"project": po.project,
"requesting_site": po.warehouse,
"requestor": po.owner,
"material_request_no": po.material_request,
"item_code": po.item_code,
"quantity": flt(po.qty),
"unit_of_measurement": po.stock_uom,
"status": po.status,
"purchase_order_date": po.transaction_date,
"purchase_order": po.parent,
"supplier": po.supplier,
"estimated_cost": flt(mr_record.get("amount")),
"actual_cost": flt(pi_records.get(po.name)),
"purchase_order_amt": flt(po.amount),
"purchase_order_amt_in_company_currency": flt(po.base_amount),
"expected_delivery_date": po.schedule_date,
"actual_delivery_date": pr_records.get(po.name),
}
procurement_record.append(procurement_detail)
return procurement_record
@@ -301,7 +305,7 @@ def get_po_entries(filters):
& (parent.name == child.parent)
& (parent.status.notin(("Closed", "Completed", "Cancelled")))
)
.groupby(parent.name, child.item_code)
.groupby(parent.name, child.material_request_item)
)
query = apply_filters_on_query(filters, parent, child, query)

View File

@@ -5,7 +5,7 @@
import json
import frappe
from frappe import _, bold, throw
from frappe import _, bold, qb, throw
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
from frappe.query_builder.functions import Abs, Sum
from frappe.utils import (
@@ -38,7 +38,12 @@ from erpnext.accounts.party import (
get_party_gle_currency,
validate_party_frozen_disabled,
)
from erpnext.accounts.utils import get_account_currency, get_fiscal_years, validate_fiscal_year
from erpnext.accounts.utils import (
create_gain_loss_journal,
get_account_currency,
get_fiscal_years,
validate_fiscal_year,
)
from erpnext.buying.utils import update_last_purchase_rate
from erpnext.controllers.print_settings import (
set_print_templates_for_item_table,
@@ -195,9 +200,9 @@ class AccountsController(TransactionBase):
# apply tax withholding only if checked and applicable
self.set_tax_withholding()
validate_regional(self)
validate_einvoice_fields(self)
with temporary_flag("company", self.company):
validate_regional(self)
validate_einvoice_fields(self)
if self.doctype != "Material Request" and not self.ignore_pricing_rule:
apply_pricing_rule_on_transaction(self)
@@ -710,7 +715,9 @@ class AccountsController(TransactionBase):
def validate_enabled_taxes_and_charges(self):
taxes_and_charges_doctype = self.meta.get_options("taxes_and_charges")
if frappe.get_cached_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
if self.taxes_and_charges and frappe.get_cached_value(
taxes_and_charges_doctype, self.taxes_and_charges, "disabled"
):
frappe.throw(
_("{0} '{1}' is disabled").format(taxes_and_charges_doctype, self.taxes_and_charges)
)
@@ -962,67 +969,133 @@ class AccountsController(TransactionBase):
d.exchange_gain_loss = difference
def make_exchange_gain_loss_gl_entries(self, gl_entries):
if self.get("doctype") in ["Purchase Invoice", "Sales Invoice"]:
for d in self.get("advances"):
if d.exchange_gain_loss:
is_purchase_invoice = self.get("doctype") == "Purchase Invoice"
party = self.supplier if is_purchase_invoice else self.customer
party_account = self.credit_to if is_purchase_invoice else self.debit_to
party_type = "Supplier" if is_purchase_invoice else "Customer"
def make_exchange_gain_loss_journal(self, args: dict = None) -> None:
"""
Make Exchange Gain/Loss journal for Invoices and Payments
"""
# Cancelling existing exchange gain/loss journals is handled during the `on_cancel` event.
# see accounts/utils.py:cancel_exchange_gain_loss_journal()
if self.docstatus == 1:
if self.get("doctype") == "Journal Entry":
# 'args' is populated with exchange gain/loss account and the amount to be booked.
# These are generated by Sales/Purchase Invoice during reconciliation and advance allocation.
# and below logic is only for such scenarios
if args:
for arg in args:
# Advance section uses `exchange_gain_loss` and reconciliation uses `difference_amount`
if (
arg.get("difference_amount", 0) != 0 or arg.get("exchange_gain_loss", 0) != 0
) and arg.get("difference_account"):
gain_loss_account = frappe.get_cached_value(
"Company", self.company, "exchange_gain_loss_account"
)
if not gain_loss_account:
frappe.throw(
_("Please set default Exchange Gain/Loss Account in Company {}").format(self.get("company"))
)
account_currency = get_account_currency(gain_loss_account)
if account_currency != self.company_currency:
frappe.throw(
_("Currency for {0} must be {1}").format(gain_loss_account, self.company_currency)
)
party_account = arg.get("account")
gain_loss_account = arg.get("difference_account")
difference_amount = arg.get("difference_amount") or arg.get("exchange_gain_loss")
if difference_amount > 0:
dr_or_cr = "debit" if arg.get("party_type") == "Customer" else "credit"
else:
dr_or_cr = "credit" if arg.get("party_type") == "Customer" else "debit"
# for purchase
dr_or_cr = "debit" if d.exchange_gain_loss > 0 else "credit"
if not is_purchase_invoice:
# just reverse for sales?
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
gl_entries.append(
self.get_gl_dict(
{
"account": gain_loss_account,
"account_currency": account_currency,
"against": party,
dr_or_cr + "_in_account_currency": abs(d.exchange_gain_loss),
dr_or_cr: abs(d.exchange_gain_loss),
"cost_center": self.cost_center or erpnext.get_default_cost_center(self.company),
"project": self.project,
},
item=d,
je = create_gain_loss_journal(
self.company,
arg.get("party_type"),
arg.get("party"),
party_account,
gain_loss_account,
difference_amount,
dr_or_cr,
reverse_dr_or_cr,
arg.get("against_voucher_type"),
arg.get("against_voucher"),
arg.get("idx"),
self.doctype,
self.name,
arg.get("idx"),
)
frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format(
get_link_to_form("Journal Entry", je)
)
)
if self.get("doctype") == "Payment Entry":
# For Payment Entry, exchange_gain_loss field in the `references` table is the trigger for journal creation
gain_loss_to_book = [x for x in self.references if x.exchange_gain_loss != 0]
booked = []
if gain_loss_to_book:
vtypes = [x.reference_doctype for x in gain_loss_to_book]
vnames = [x.reference_name for x in gain_loss_to_book]
je = qb.DocType("Journal Entry")
jea = qb.DocType("Journal Entry Account")
parents = (
qb.from_(jea)
.select(jea.parent)
.where(
(jea.reference_type == "Payment Entry")
& (jea.reference_name == self.name)
& (jea.docstatus == 1)
)
.run()
)
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
gl_entries.append(
self.get_gl_dict(
{
"account": party_account,
"party_type": party_type,
"party": party,
"against": gain_loss_account,
dr_or_cr + "_in_account_currency": flt(abs(d.exchange_gain_loss) / self.conversion_rate),
dr_or_cr: abs(d.exchange_gain_loss),
"cost_center": self.cost_center,
"project": self.project,
},
self.party_account_currency,
item=self,
booked = []
if parents:
booked = (
qb.from_(je)
.inner_join(jea)
.on(je.name == jea.parent)
.select(jea.reference_type, jea.reference_name, jea.reference_detail_no)
.where(
(je.docstatus == 1)
& (je.name.isin(parents))
& (je.voucher_type == "Exchange Gain or Loss")
)
.run()
)
for d in gain_loss_to_book:
# Filter out References for which Gain/Loss is already booked
if d.exchange_gain_loss and (
(d.reference_doctype, d.reference_name, str(d.idx)) not in booked
):
if self.payment_type == "Receive":
party_account = self.paid_from
elif self.payment_type == "Pay":
party_account = self.paid_to
dr_or_cr = "debit" if d.exchange_gain_loss > 0 else "credit"
if d.reference_doctype == "Purchase Invoice":
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
reverse_dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
gain_loss_account = frappe.get_cached_value(
"Company", self.company, "exchange_gain_loss_account"
)
je = create_gain_loss_journal(
self.company,
self.party_type,
self.party,
party_account,
gain_loss_account,
d.exchange_gain_loss,
dr_or_cr,
reverse_dr_or_cr,
d.reference_doctype,
d.reference_name,
d.idx,
self.doctype,
self.name,
d.idx,
)
frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format(
get_link_to_form("Journal Entry", je)
)
)
)
def make_precision_loss_gl_entry(self, gl_entries):
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(
@@ -1111,9 +1184,15 @@ class AccountsController(TransactionBase):
reconcile_against_document(lst)
def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
from erpnext.accounts.utils import (
cancel_exchange_gain_loss_journal,
unlink_ref_doc_from_payment_entries,
)
if self.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
# Cancel Exchange Gain/Loss Journal before unlinking
cancel_exchange_gain_loss_journal(self)
if self.doctype in ["Sales Invoice", "Purchase Invoice"]:
if frappe.db.get_single_value("Accounts Settings", "unlink_payment_on_cancellation_of_invoice"):
unlink_ref_doc_from_payment_entries(self)

View File

@@ -13,9 +13,6 @@ def set_print_templates_for_item_table(doc, settings):
}
}
if doc.meta.get_field("items"):
doc.meta.get_field("items").hide_in_print_layout = ["uom", "stock_uom"]
doc.flags.compact_item_fields = ["description", "qty", "rate", "amount"]
if settings.compact_item_print:

View File

@@ -345,6 +345,8 @@ def make_return_doc(doctype: str, source_name: str, target_doc=None):
elif doctype == "Purchase Invoice":
# look for Print Heading "Debit Note"
doc.select_print_heading = frappe.get_cached_value("Print Heading", _("Debit Note"))
if source.tax_withholding_category:
doc.set_onload("supplier_tds", source.tax_withholding_category)
for tax in doc.get("taxes") or []:
if tax.charge_type == "Actual":

View File

@@ -388,7 +388,7 @@ class SellingController(StockController):
for d in self.get("items"):
if d.get(ref_fieldname):
status = frappe.db.get_value("Sales Order", d.get(ref_fieldname), "status")
if status in ("Closed", "On Hold"):
if status in ("Closed", "On Hold") and not self.is_return:
frappe.throw(_("Sales Order {0} is {1}").format(d.get(ref_fieldname), status))
def update_reserved_qty(self):
@@ -404,7 +404,9 @@ class SellingController(StockController):
if so and so_item_rows:
sales_order = frappe.get_doc("Sales Order", so)
if sales_order.status in ["Closed", "Cancelled"]:
if (sales_order.status == "Closed" and not self.is_return) or sales_order.status in [
"Cancelled"
]:
frappe.throw(
_("{0} {1} is cancelled or closed").format(_("Sales Order"), so), frappe.InvalidStatusError
)

View File

@@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import comma_or, flt, getdate, now, nowdate
from frappe.utils import comma_or, flt, get_link_to_form, getdate, now, nowdate
class OverAllowanceError(frappe.ValidationError):
@@ -233,8 +233,17 @@ class StatusUpdater(Document):
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"):
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))
if hasattr(d, "item_code") and hasattr(d, "rate") and d.rate < 0:
frappe.throw(_("For an item {0}, rate must be a positive number").format(d.item_code))
if not frappe.db.get_single_value("Selling Settings", "allow_negative_rates_for_items"):
if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
frappe.throw(
_(
"For item {0}, rate must be a positive number. To Allow negative rates, enable {1} in {2}"
).format(
frappe.bold(d.item_code),
frappe.bold(_("`Allow Negative rates for Items`")),
get_link_to_form("Selling Settings", "Selling Settings"),
),
)
if d.doctype == args["source_dt"] and d.get(args["join_field"]):
args["name"] = d.get(args["join_field"])

View File

@@ -15,7 +15,7 @@ from erpnext.accounts.general_ledger import (
make_reverse_gl_entries,
process_gl_map,
)
from erpnext.accounts.utils import get_fiscal_year
from erpnext.accounts.utils import cancel_exchange_gain_loss_journal, get_fiscal_year
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import (
@@ -513,6 +513,7 @@ class StockController(AccountsController):
make_sl_entries(sl_entries, allow_negative_stock, via_landed_cost_voucher)
def make_gl_entries_on_cancel(self):
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
if frappe.db.sql(
"""select name from `tabGL Entry` where voucher_type=%s
and voucher_no=%s""",

View File

@@ -0,0 +1,999 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import unittest
import frappe
from frappe import qb
from frappe.query_builder.functions import Sum
from frappe.tests.utils import FrappeTestCase, change_settings
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.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.party import get_party_account
from erpnext.stock.doctype.item.test_item import create_item
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.customer_type = "Individual"
if currency:
customer.default_currency = currency
customer.save()
return customer.name
else:
return customer_name
def make_supplier(supplier_name, currency=None):
if not frappe.db.exists("Supplier", supplier_name):
supplier = frappe.new_doc("Supplier")
supplier.supplier_name = supplier_name
supplier.supplier_type = "Individual"
supplier.supplier_group = "All Supplier Groups"
if currency:
supplier.default_currency = currency
supplier.save()
return supplier.name
else:
return supplier_name
class TestAccountsController(FrappeTestCase):
"""
Test Exchange Gain/Loss booking on various scenarios.
Test Cases are numbered for better organization
10 series - Sales Invoice against Payment Entries
20 series - Sales Invoice against Journals
30 series - Sales Invoice against Credit Notes
"""
def setUp(self):
self.create_company()
self.create_account()
self.create_item()
self.create_parties()
self.clear_old_entries()
def tearDown(self):
frappe.db.rollback()
def create_company(self):
company_name = "_Test Company"
self.company_abbr = abbr = "_TC"
if frappe.db.exists("Company", company_name):
company = frappe.get_doc("Company", company_name)
else:
company = frappe.get_doc(
{
"doctype": "Company",
"company_name": company_name,
"country": "India",
"default_currency": "INR",
"create_chart_of_accounts_based_on": "Standard Template",
"chart_of_accounts": "Standard",
}
)
company = company.save()
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
self.debit_usd = "Debtors USD - " + abbr
self.cash = "Cash - " + abbr
self.creditors = "Creditors - " + abbr
def create_item(self):
item = create_item(
item_code="_Test Notebook", is_stock_item=0, company=self.company, warehouse=self.warehouse
)
self.item = item if isinstance(item, str) else item.item_code
def create_parties(self):
self.create_customer()
self.create_supplier()
def create_customer(self):
self.customer = make_customer("_Test MC Customer USD", "USD")
def create_supplier(self):
self.supplier = make_supplier("_Test MC Supplier USD", "USD")
def create_account(self):
account_name = "Debtors USD"
if not frappe.db.get_value(
"Account", filters={"account_name": account_name, "company": self.company}
):
acc = frappe.new_doc("Account")
acc.account_name = account_name
acc.parent_account = "Accounts Receivable - " + self.company_abbr
acc.company = self.company
acc.account_currency = "USD"
acc.account_type = "Receivable"
acc.insert()
else:
name = frappe.db.get_value(
"Account",
filters={"account_name": account_name, "company": self.company},
fieldname="name",
pluck=True,
)
acc = frappe.get_doc("Account", name)
self.debtors_usd = acc.name
def create_sales_invoice(
self,
qty=1,
rate=1,
conversion_rate=80,
posting_date=nowdate(),
do_not_save=False,
do_not_submit=False,
):
"""
Helper function to populate default values in sales invoice
"""
sinv = create_sales_invoice(
qty=qty,
rate=rate,
company=self.company,
customer=self.customer,
item_code=self.item,
item_name=self.item,
cost_center=self.cost_center,
warehouse=self.warehouse,
debit_to=self.debit_usd,
parent_cost_center=self.cost_center,
update_stock=0,
currency="USD",
conversion_rate=conversion_rate,
is_pos=0,
is_return=0,
return_against=None,
income_account=self.income_account,
expense_account=self.expense_account,
do_not_save=do_not_save,
do_not_submit=do_not_submit,
)
return sinv
def create_payment_entry(
self, amount=1, source_exc_rate=75, posting_date=nowdate(), customer=None
):
"""
Helper function to populate default values in payment entry
"""
payment = create_payment_entry(
company=self.company,
payment_type="Receive",
party_type="Customer",
party=customer or self.customer,
paid_from=self.debit_usd,
paid_to=self.cash,
paid_amount=amount,
)
payment.source_exchange_rate = source_exc_rate
payment.received_amount = source_exc_rate * amount
payment.posting_date = posting_date
return payment
def clear_old_entries(self):
doctype_list = [
"GL Entry",
"Payment Ledger Entry",
"Sales Invoice",
"Purchase Invoice",
"Payment Entry",
"Journal Entry",
]
for doctype in doctype_list:
qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()
def create_payment_reconciliation(self):
pr = frappe.new_doc("Payment Reconciliation")
pr.company = self.company
pr.party_type = "Customer"
pr.party = self.customer
pr.receivable_payable_account = get_party_account(pr.party_type, pr.party, pr.company)
pr.from_invoice_date = pr.to_invoice_date = pr.from_payment_date = pr.to_payment_date = nowdate()
return pr
def create_journal_entry(
self,
acc1=None,
acc1_exc_rate=None,
acc2_exc_rate=None,
acc2=None,
acc1_amount=0,
acc2_amount=0,
posting_date=None,
cost_center=None,
):
je = frappe.new_doc("Journal Entry")
je.posting_date = posting_date or nowdate()
je.company = self.company
je.user_remark = "test"
je.multi_currency = True
if not cost_center:
cost_center = self.cost_center
je.set(
"accounts",
[
{
"account": acc1,
"exchange_rate": acc1_exc_rate or 1,
"cost_center": cost_center,
"debit_in_account_currency": acc1_amount if acc1_amount > 0 else 0,
"credit_in_account_currency": abs(acc1_amount) if acc1_amount < 0 else 0,
"debit": acc1_amount * acc1_exc_rate if acc1_amount > 0 else 0,
"credit": abs(acc1_amount * acc1_exc_rate) if acc1_amount < 0 else 0,
},
{
"account": acc2,
"exchange_rate": acc2_exc_rate or 1,
"cost_center": cost_center,
"credit_in_account_currency": acc2_amount if acc2_amount > 0 else 0,
"debit_in_account_currency": abs(acc2_amount) if acc2_amount < 0 else 0,
"credit": acc2_amount * acc2_exc_rate if acc2_amount > 0 else 0,
"debit": abs(acc2_amount * acc2_exc_rate) if acc2_amount < 0 else 0,
},
],
)
return je
def get_journals_for(self, voucher_type: str, voucher_no: str) -> list:
journals = []
if voucher_type and voucher_no:
journals = frappe.db.get_all(
"Journal Entry Account",
filters={"reference_type": voucher_type, "reference_name": voucher_no, "docstatus": 1},
fields=["parent"],
)
return journals
def assert_ledger_outstanding(
self,
voucher_type: str,
voucher_no: str,
outstanding: float,
outstanding_in_account_currency: float,
) -> None:
"""
Assert outstanding amount based on ledger on both company/base currency and account currency
"""
ple = qb.DocType("Payment Ledger Entry")
current_outstanding = (
qb.from_(ple)
.select(
Sum(ple.amount).as_("outstanding"),
Sum(ple.amount_in_account_currency).as_("outstanding_in_account_currency"),
)
.where(
(ple.against_voucher_type == voucher_type)
& (ple.against_voucher_no == voucher_no)
& (ple.delinked == 0)
)
.run(as_dict=True)[0]
)
self.assertEqual(outstanding, current_outstanding.outstanding)
self.assertEqual(
outstanding_in_account_currency, current_outstanding.outstanding_in_account_currency
)
def test_10_payment_against_sales_invoice(self):
# Sales Invoice in Foreign Currency
rate = 80
rate_in_account_currency = 1
si = self.create_sales_invoice(qty=1, rate=rate_in_account_currency)
# Test payments with different exchange rates
for exc_rate in [75.9, 83.1, 80.01]:
with self.subTest(exc_rate=exc_rate):
pe = self.create_payment_entry(amount=1, source_exc_rate=exc_rate).save()
pe.append(
"references",
{"reference_doctype": si.doctype, "reference_name": si.name, "allocated_amount": 1},
)
pe = pe.save().submit()
# Outstanding in both currencies should be '0'
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_si[0], exc_je_for_pe[0])
# Cancel Payment
pe.cancel()
# outstanding should be same as grand total
si.reload()
self.assertEqual(si.outstanding_amount, rate_in_account_currency)
self.assert_ledger_outstanding(si.doctype, si.name, rate, rate_in_account_currency)
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_pe, [])
def test_11_advance_against_sales_invoice(self):
# Advance Payment
adv = self.create_payment_entry(amount=1, source_exc_rate=85).save().submit()
adv.reload()
# Sales Invoices in different exchange rates
for exc_rate in [75.9, 83.1, 80.01]:
with self.subTest(exc_rate=exc_rate):
si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": advances[0].reference_type,
"reference_name": advances[0].reference_name,
"reference_row": advances[0].reference_row,
"advance_amount": 1,
"allocated_amount": 1,
"ref_exchange_rate": advances[0].exchange_rate,
"remarks": advances[0].remarks,
},
)
si = si.save()
si = si.submit()
# Outstanding in both currencies should be '0'
adv.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_adv), 1)
self.assertEqual(exc_je_for_si, exc_je_for_adv)
# Cancel Invoice
si.cancel()
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_adv, [])
def test_12_partial_advance_and_payment_for_sales_invoice(self):
"""
Sales invoice with partial advance payment, and a normal payment reconciled
"""
# Partial Advance
adv = self.create_payment_entry(amount=1, source_exc_rate=85).save().submit()
adv.reload()
# sales invoice with advance(partial amount)
rate = 80
rate_in_account_currency = 1
si = self.create_sales_invoice(
qty=2, conversion_rate=80, rate=rate_in_account_currency, do_not_submit=True
)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": advances[0].reference_type,
"reference_name": advances[0].reference_name,
"advance_amount": 1,
"allocated_amount": 1,
"ref_exchange_rate": advances[0].exchange_rate,
"remarks": advances[0].remarks,
},
)
si = si.save()
si = si.submit()
# Outstanding should be there in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 1) # account currency
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
# Exchange Gain/Loss Journal should've been created for the partial advance
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_adv), 1)
self.assertEqual(exc_je_for_si, exc_je_for_adv)
# Payment for remaining amount
pe = self.create_payment_entry(amount=1, source_exc_rate=75).save()
pe.append(
"references",
{"reference_doctype": si.doctype, "reference_name": si.name, "allocated_amount": 1},
)
pe = pe.save().submit()
# Outstanding in both currencies should be '0'
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created for the payment
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertNotEqual(exc_je_for_si, [])
# There should be 2 JE's now. One for the advance and one for the payment
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_si, exc_je_for_pe + exc_je_for_adv)
# Cancel Invoice
si.reload()
si.cancel()
# Exchange Gain/Loss Journal should been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_pe, [])
self.assertEqual(exc_je_for_adv, [])
def test_13_partial_advance_and_payment_for_invoice_with_cancellation(self):
"""
Invoice with partial advance payment, and a normal payment. Then cancel advance and payment.
"""
# Partial Advance
adv = self.create_payment_entry(amount=1, source_exc_rate=85).save().submit()
adv.reload()
# invoice with advance(partial amount)
si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": advances[0].reference_type,
"reference_name": advances[0].reference_name,
"advance_amount": 1,
"allocated_amount": 1,
"ref_exchange_rate": advances[0].exchange_rate,
"remarks": advances[0].remarks,
},
)
si = si.save()
si = si.submit()
# Outstanding should be there in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 1) # account currency
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
# Exchange Gain/Loss Journal should've been created for the partial advance
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_adv), 1)
self.assertEqual(exc_je_for_si, exc_je_for_adv)
# Payment(remaining amount)
pe = self.create_payment_entry(amount=1, source_exc_rate=75).save()
pe.append(
"references",
{"reference_doctype": si.doctype, "reference_name": si.name, "allocated_amount": 1},
)
pe = pe.save().submit()
# Outstanding should be '0' in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created for the payment
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertNotEqual(exc_je_for_si, [])
# There should be 2 JE's now. One for the advance and one for the payment
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_si, exc_je_for_pe + exc_je_for_adv)
adv.reload()
adv.cancel()
# Outstanding should be there in both currencies, since advance is cancelled.
si.reload()
self.assertEqual(si.outstanding_amount, 1) # account currency
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
# Exchange Gain/Loss Journal for advance should been cancelled
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_adv, [])
def test_14_same_payment_split_against_invoice(self):
# Invoice in Foreign Currency
si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1)
# Payment
pe = self.create_payment_entry(amount=2, source_exc_rate=75).save()
pe.append(
"references",
{"reference_doctype": si.doctype, "reference_name": si.name, "allocated_amount": 1},
)
pe = pe.save().submit()
# There should be outstanding in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 1)
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_si[0], exc_je_for_pe[0])
# Reconcile the remaining amount
pr = frappe.get_doc("Payment Reconciliation")
pr.company = self.company
pr.party_type = "Customer"
pr.party = self.customer
pr.receivable_payable_account = self.debit_usd
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.reconcile()
self.assertEqual(len(pr.invoices), 0)
self.assertEqual(len(pr.payments), 0)
# Exc gain/loss journal should have been creaetd for the reconciled amount
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_pe), 2)
self.assertEqual(exc_je_for_si, exc_je_for_pe)
# There should be no outstanding
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Cancel Payment
pe.reload()
pe.cancel()
si.reload()
self.assertEqual(si.outstanding_amount, 2)
self.assert_ledger_outstanding(si.doctype, si.name, 160.0, 2.0)
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_pe = self.get_journals_for(pe.doctype, pe.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_pe, [])
def test_20_journal_against_sales_invoice(self):
# Invoice in Foreign Currency
si = self.create_sales_invoice(qty=1, conversion_rate=80, rate=1)
# Payment
je = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=75,
acc2=self.cash,
acc1_amount=-1,
acc2_amount=-75,
acc2_exc_rate=1,
)
je.accounts[0].party_type = "Customer"
je.accounts[0].party = self.customer
je = je.save().submit()
# Reconcile the remaining amount
pr = self.create_payment_reconciliation()
# pr.receivable_payable_account = self.debit_usd
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.reconcile()
self.assertEqual(len(pr.invoices), 0)
self.assertEqual(len(pr.payments), 0)
# There should be no outstanding in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_je = self.get_journals_for(je.doctype, je.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(
len(exc_je_for_si), 2
) # payment also has reference. so, there are 2 journals referencing invoice
self.assertEqual(len(exc_je_for_je), 1)
self.assertIn(exc_je_for_je[0], exc_je_for_si)
# Cancel Payment
je.reload()
je.cancel()
si.reload()
self.assertEqual(si.outstanding_amount, 1)
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_je = self.get_journals_for(je.doctype, je.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_je, [])
def test_21_advance_journal_against_sales_invoice(self):
# Advance Payment
adv_exc_rate = 80
adv = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=adv_exc_rate,
acc2=self.cash,
acc1_amount=-1,
acc2_amount=adv_exc_rate * -1,
acc2_exc_rate=1,
)
adv.accounts[0].party_type = "Customer"
adv.accounts[0].party = self.customer
adv.accounts[0].is_advance = "Yes"
adv = adv.save().submit()
adv.reload()
# Sales Invoices in different exchange rates
for exc_rate in [75.9, 83.1]:
with self.subTest(exc_rate=exc_rate):
si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": advances[0].reference_type,
"reference_name": advances[0].reference_name,
"reference_row": advances[0].reference_row,
"advance_amount": 1,
"allocated_amount": 1,
"ref_exchange_rate": advances[0].exchange_rate,
"remarks": advances[0].remarks,
},
)
si = si.save()
si = si.submit()
# Outstanding in both currencies should be '0'
adv.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = [x for x in self.get_journals_for(si.doctype, si.name) if x.parent != adv.name]
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_adv), 1)
self.assertEqual(exc_je_for_si, exc_je_for_adv)
# Cancel Invoice
si.cancel()
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_adv, [])
def test_22_partial_advance_and_payment_for_invoice_with_cancellation(self):
"""
Invoice with partial advance payment as Journal, and a normal payment. Then cancel advance and payment.
"""
# Partial Advance
adv_exc_rate = 75
adv = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=adv_exc_rate,
acc2=self.cash,
acc1_amount=-1,
acc2_amount=adv_exc_rate * -1,
acc2_exc_rate=1,
)
adv.accounts[0].party_type = "Customer"
adv.accounts[0].party = self.customer
adv.accounts[0].is_advance = "Yes"
adv = adv.save().submit()
adv.reload()
# invoice with advance(partial amount)
si = self.create_sales_invoice(qty=3, conversion_rate=80, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append(
"advances",
{
"doctype": "Sales Invoice Advance",
"reference_type": advances[0].reference_type,
"reference_name": advances[0].reference_name,
"reference_row": advances[0].reference_row,
"advance_amount": 1,
"allocated_amount": 1,
"ref_exchange_rate": advances[0].exchange_rate,
"remarks": advances[0].remarks,
},
)
si = si.save()
si = si.submit()
# Outstanding should be there in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 2) # account currency
self.assert_ledger_outstanding(si.doctype, si.name, 160.0, 2.0)
# Exchange Gain/Loss Journal should've been created for the partial advance
exc_je_for_si = [x for x in self.get_journals_for(si.doctype, si.name) if x.parent != adv.name]
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_adv), 1)
self.assertEqual(exc_je_for_si, exc_je_for_adv)
# Payment
adv2_exc_rate = 83
pay = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=adv2_exc_rate,
acc2=self.cash,
acc1_amount=-2,
acc2_amount=adv2_exc_rate * -2,
acc2_exc_rate=1,
)
pay.accounts[0].party_type = "Customer"
pay.accounts[0].party = self.customer
pay.accounts[0].is_advance = "Yes"
pay = pay.save().submit()
pay.reload()
# Reconcile the remaining amount
pr = self.create_payment_reconciliation()
# pr.receivable_payable_account = self.debit_usd
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.reconcile()
self.assertEqual(len(pr.invoices), 0)
self.assertEqual(len(pr.payments), 0)
# Outstanding should be '0' in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Exchange Gain/Loss Journal should've been created for the payment
exc_je_for_si = [
x
for x in self.get_journals_for(si.doctype, si.name)
if x.parent != adv.name and x.parent != pay.name
]
exc_je_for_pe = self.get_journals_for(pay.doctype, pay.name)
self.assertNotEqual(exc_je_for_si, [])
# There should be 2 JE's now. One for the advance and one for the payment
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_si, exc_je_for_pe + exc_je_for_adv)
adv.reload()
adv.cancel()
# Outstanding should be there in both currencies, since advance is cancelled.
si.reload()
self.assertEqual(si.outstanding_amount, 1) # account currency
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
exc_je_for_si = [
x
for x in self.get_journals_for(si.doctype, si.name)
if x.parent != adv.name and x.parent != pay.name
]
exc_je_for_pe = self.get_journals_for(pay.doctype, pay.name)
exc_je_for_adv = self.get_journals_for(adv.doctype, adv.name)
# Exchange Gain/Loss Journal for advance should been cancelled
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_pe), 1)
self.assertEqual(exc_je_for_adv, [])
def test_23_same_journal_split_against_single_invoice(self):
# Invoice in Foreign Currency
si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1)
# Payment
je = self.create_journal_entry(
acc1=self.debit_usd,
acc1_exc_rate=75,
acc2=self.cash,
acc1_amount=-2,
acc2_amount=-150,
acc2_exc_rate=1,
)
je.accounts[0].party_type = "Customer"
je.accounts[0].party = self.customer
je = je.save().submit()
# Reconcile the first half
pr = self.create_payment_reconciliation()
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
difference_amount = pr.calculate_difference_on_allocation_change(
[x.as_dict() for x in pr.payments], [x.as_dict() for x in pr.invoices], 1
)
pr.allocation[0].allocated_amount = 1
pr.allocation[0].difference_amount = difference_amount
pr.reconcile()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
# There should be outstanding in both currencies
si.reload()
self.assertEqual(si.outstanding_amount, 1)
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = [x for x in self.get_journals_for(si.doctype, si.name) if x.parent != je.name]
exc_je_for_je = self.get_journals_for(je.doctype, je.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_je), 1)
self.assertIn(exc_je_for_je[0], exc_je_for_si)
# reconcile remaining half
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
pr.allocation[0].allocated_amount = 1
pr.allocation[0].difference_amount = difference_amount
pr.reconcile()
self.assertEqual(len(pr.invoices), 0)
self.assertEqual(len(pr.payments), 0)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = [x for x in self.get_journals_for(si.doctype, si.name) if x.parent != je.name]
exc_je_for_je = self.get_journals_for(je.doctype, je.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_je), 2)
self.assertIn(exc_je_for_je[0], exc_je_for_si)
si.reload()
self.assertEqual(si.outstanding_amount, 0)
self.assert_ledger_outstanding(si.doctype, si.name, 0.0, 0.0)
# Cancel Payment
je.reload()
je.cancel()
si.reload()
self.assertEqual(si.outstanding_amount, 2)
self.assert_ledger_outstanding(si.doctype, si.name, 160.0, 2.0)
# Exchange Gain/Loss Journal should've been cancelled
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_je = self.get_journals_for(je.doctype, je.name)
self.assertEqual(exc_je_for_si, [])
self.assertEqual(exc_je_for_je, [])
def test_30_cr_note_against_sales_invoice(self):
"""
Reconciling Cr Note against Sales Invoice, both having different exchange rates
"""
# Invoice in Foreign currency
si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1)
# Cr Note in Foreign currency of different exchange rate
cr_note = self.create_sales_invoice(qty=-2, conversion_rate=75, rate=1, do_not_save=True)
cr_note.is_return = 1
cr_note.save().submit()
# Reconcile the first half
pr = self.create_payment_reconciliation()
pr.get_unreconciled_entries()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
invoices = [x.as_dict() for x in pr.invoices]
payments = [x.as_dict() for x in pr.payments]
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
difference_amount = pr.calculate_difference_on_allocation_change(
[x.as_dict() for x in pr.payments], [x.as_dict() for x in pr.invoices], 1
)
pr.allocation[0].allocated_amount = 1
pr.allocation[0].difference_amount = difference_amount
pr.reconcile()
self.assertEqual(len(pr.invoices), 1)
self.assertEqual(len(pr.payments), 1)
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_cr = self.get_journals_for(cr_note.doctype, cr_note.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 2)
self.assertEqual(len(exc_je_for_cr), 2)
self.assertEqual(exc_je_for_cr, exc_je_for_si)
si.reload()
self.assertEqual(si.outstanding_amount, 1)
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)
cr_note.reload()
cr_note.cancel()
# Exchange Gain/Loss Journal should've been created.
exc_je_for_si = self.get_journals_for(si.doctype, si.name)
exc_je_for_cr = self.get_journals_for(cr_note.doctype, cr_note.name)
self.assertNotEqual(exc_je_for_si, [])
self.assertEqual(len(exc_je_for_si), 1)
self.assertEqual(len(exc_je_for_cr), 0)
# The Credit Note JE is still active and is referencing the sales invoice
# So, outstanding stays the same
si.reload()
self.assertEqual(si.outstanding_amount, 1)
self.assert_ledger_outstanding(si.doctype, si.name, 80.0, 1.0)

View File

@@ -1,7 +1,7 @@
{%- macro slide(image, title, subtitle, action, label, index, align="Left", theme="Dark") -%}
{%- set align_class = resolve_class({
'text-right': align == 'Right',
'text-centre': align == 'Centre',
'text-center': align == 'Centre',
'text-left': align == 'Left',
}) -%}

View File

@@ -246,6 +246,9 @@ class LoanRepayment(AccountsController):
)
def check_future_accruals(self):
if self.is_term_loan:
return
future_accrual_date = frappe.db.get_value(
"Loan Interest Accrual",
{"posting_date": (">", self.posting_date), "docstatus": 1, "loan": self.against_loan},

View File

@@ -1,6 +1,6 @@
{
"charts": [],
"content": "[{\"id\":\"_38WStznya\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Your Shortcuts</b></span>\",\"col\":12}},{\"id\":\"t7o_K__1jB\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan Application\",\"col\":3}},{\"id\":\"IRiNDC6w1p\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan\",\"col\":3}},{\"id\":\"xbbo0FYbq0\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Dashboard\",\"col\":3}},{\"id\":\"7ZL4Bro-Vi\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"yhyioTViZ3\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Reports &amp; Masters</b></span>\",\"col\":12}},{\"id\":\"oYFn4b1kSw\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan\",\"col\":4}},{\"id\":\"vZepJF5tl9\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Processes\",\"col\":4}},{\"id\":\"k-393Mjhqe\",\"type\":\"card\",\"data\":{\"card_name\":\"Disbursement and Repayment\",\"col\":4}},{\"id\":\"6crJ0DBiBJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Security\",\"col\":4}},{\"id\":\"Um5YwxVLRJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Reports\",\"col\":4}}]",
"content": "[{\"id\":\"_38WStznya\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Your Shortcuts</b></span>\",\"col\":12}},{\"id\":\"t7o_K__1jB\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan Application\",\"col\":3}},{\"id\":\"IRiNDC6w1p\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Loan\",\"col\":3}},{\"id\":\"xbbo0FYbq0\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Dashboard\",\"col\":3}},{\"id\":\"7ZL4Bro-Vi\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"yhyioTViZ3\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Reports &amp; Masters</b></span>\",\"col\":12}},{\"id\":\"oYFn4b1kSw\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan\",\"col\":4}},{\"id\":\"vZepJF5tl9\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Processes\",\"col\":4}},{\"id\":\"k-393Mjhqe\",\"type\":\"card\",\"data\":{\"card_name\":\"Disbursement and Repayment\",\"col\":4}},{\"id\":\"6crJ0DBiBJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Loan Security\",\"col\":4}},{\"id\":\"Um5YwxVLRJ\",\"type\":\"card\",\"data\":{\"card_name\":\"Reports\",\"col\":4}},{\"id\":\"g2NbPxffmo\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"UKb6Ko91Ju\",\"type\":\"paragraph\",\"data\":{\"text\":\"Loan Management module will be removed from ERPNext in Version 15. Please install the <a href=\\\"https://frappecloud.com/marketplace/apps/lending\\\" draggable=\\\"false\\\">Lending</a> app to continue using it.\",\"col\":12}}]",
"creation": "2020-03-12 16:35:55.299820",
"custom_blocks": [],
"docstatus": 0,
@@ -280,7 +280,7 @@
"type": "Link"
}
],
"modified": "2023-05-24 14:47:24.109945",
"modified": "2023-08-09 19:45:02.748408",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loans",

View File

@@ -53,7 +53,7 @@ class ProductionPlan(Document):
data = sales_order_query(filters={"company": self.company, "sales_orders": sales_orders})
title = _("Production Plan Already Submitted")
if not data:
if not data and sales_orders:
msg = _("No items are available in the sales order {0} for production").format(sales_orders[0])
if len(sales_orders) > 1:
sales_orders = ", ".join(sales_orders)
@@ -347,7 +347,7 @@ class ProductionPlan(Document):
if not data.pending_qty:
continue
item_details = get_item_details(data.item_code)
item_details = get_item_details(data.item_code, throw=False)
if self.combine_items:
if item_details.bom_no in refs:
refs[item_details.bom_no]["so_details"].append(
@@ -795,6 +795,9 @@ class ProductionPlan(Document):
if not row.item_code:
frappe.throw(_("Row #{0}: Please select Item Code in Assembly Items").format(row.idx))
if not row.bom_no:
frappe.throw(_("Row #{0}: Please select the BOM No in Assembly Items").format(row.idx))
bom_data = []
warehouse = row.warehouse if self.skip_available_sub_assembly_item else None

View File

@@ -405,6 +405,8 @@
"read_only": 1
},
{
"fetch_from": "production_item.stock_uom",
"fetch_if_empty": 1,
"fieldname": "stock_uom",
"fieldtype": "Link",
"label": "Stock UOM",
@@ -598,7 +600,7 @@
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2023-06-09 13:20:09.154362",
"modified": "2023-08-11 18:35:49.852069",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",
@@ -618,7 +620,6 @@
"read": 1,
"report": 1,
"role": "Manufacturing User",
"set_user_permissions": 1,
"share": 1,
"submit": 1,
"write": 1

View File

@@ -1075,7 +1075,7 @@ def get_bom_operations(doctype, txt, searchfield, start, page_len, filters):
@frappe.whitelist()
def get_item_details(item, project=None, skip_bom_info=False):
def get_item_details(item, project=None, skip_bom_info=False, throw=True):
res = frappe.db.sql(
"""
select stock_uom, description, item_name, allow_alternative_item,
@@ -1111,12 +1111,15 @@ def get_item_details(item, project=None, skip_bom_info=False):
if not res["bom_no"]:
if project:
res = get_item_details(item)
res = get_item_details(item, throw=throw)
frappe.msgprint(
_("Default BOM not found for Item {0} and Project {1}").format(item, project), alert=1
)
else:
frappe.throw(_("Default BOM for {0} not found").format(item))
msg = _("Default BOM for {0} not found").format(item)
frappe.msgprint(msg, raise_exception=throw, indicator="yellow", alert=(not throw))
return res
bom_data = frappe.db.get_value(
"BOM",

View File

@@ -328,8 +328,7 @@ erpnext.patches.v14_0.set_pick_list_status
erpnext.patches.v13_0.update_docs_link
erpnext.patches.v14_0.enable_all_leads
execute:frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 0)
# below migration patches should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.patches.v14_0.update_reference_type_in_journal_entry_accounts
erpnext.patches.v14_0.update_company_in_ldc
erpnext.patches.v14_0.set_packed_qty_in_draft_delivery_notes
erpnext.patches.v14_0.cleanup_workspaces
@@ -337,4 +336,7 @@ erpnext.patches.v14_0.enable_allow_existing_serial_no
erpnext.patches.v14_0.set_report_in_process_SOA
erpnext.patches.v14_0.create_accounting_dimensions_for_closing_balance
erpnext.patches.v14_0.update_closing_balances #15-07-2023
execute:frappe.defaults.clear_default("fiscal_year")
execute:frappe.defaults.clear_default("fiscal_year")
execute:frappe.db.set_single_value('Selling Settings', 'allow_negative_rates_for_items', 0)
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger

View File

@@ -0,0 +1,22 @@
import frappe
def execute():
"""
Update Propery Setters for Journal Entry with new 'Entry Type'
"""
new_reference_type = "Payment Entry"
prop_setter = frappe.db.get_list(
"Property Setter",
filters={
"doc_type": "Journal Entry Account",
"field_name": "reference_type",
"property": "options",
},
)
if prop_setter:
property_setter_doc = frappe.get_doc("Property Setter", prop_setter[0].get("name"))
if new_reference_type not in property_setter_doc.value.split("\n"):
property_setter_doc.value += "\n" + new_reference_type
property_setter_doc.save()

View File

@@ -98,9 +98,11 @@ def get_timesheets(filters):
record_filters = [
["start_date", "<=", filters.to_date],
["end_date", ">=", filters.from_date],
["docstatus", "=", 1],
]
if not filters.get("include_draft_timesheets"):
record_filters.append(["docstatus", "=", 1])
else:
record_filters.append(["docstatus", "!=", 2])
if "employee" in filters:
record_filters.append(["employee", "=", filters.employee])

View File

@@ -25,5 +25,10 @@ frappe.query_reports["Employee Billing Summary"] = {
default: frappe.datetime.add_days(frappe.datetime.month_start(), -1),
reqd: 1
},
{
fieldname:"include_draft_timesheets",
label: __("Include Timesheets in Draft Status"),
fieldtype: "Check",
},
]
}

View File

@@ -25,5 +25,10 @@ frappe.query_reports["Project Billing Summary"] = {
default: frappe.datetime.add_days(frappe.datetime.month_start(),-1),
reqd: 1
},
{
fieldname:"include_draft_timesheets",
label: __("Include Timesheets in Draft Status"),
fieldtype: "Check",
},
]
}

View File

@@ -117,6 +117,9 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
name: __("Document Name"),
editable: false,
width: 1,
format: (value, row) => {
return frappe.form.formatters.Link(value, {options: row[2].content});
},
},
{
name: __("Reference Date"),

View File

@@ -57,7 +57,8 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
from_date: me.frm.doc.posting_date,
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
company: me.frm.doc.company,
show_cancelled_entries: me.frm.doc.docstatus === 2
show_cancelled_entries: me.frm.doc.docstatus === 2,
ignore_prepared_report: true
};
frappe.set_route("query-report", "Stock Ledger");
}, __("View"));
@@ -75,7 +76,8 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
to_date: moment(me.frm.doc.modified).format('YYYY-MM-DD'),
company: me.frm.doc.company,
group_by: "Group by Voucher (Consolidated)",
show_cancelled_entries: me.frm.doc.docstatus === 2
show_cancelled_entries: me.frm.doc.docstatus === 2,
ignore_prepared_report: true
};
frappe.set_route("query-report", "General Ledger");
}, __("View"));

View File

@@ -24,12 +24,14 @@ erpnext.setup.slides_settings = [
fieldtype: 'Data',
reqd: 1
},
{ fieldtype: "Column Break" },
{
fieldname: 'company_abbr',
label: __('Company Abbreviation'),
fieldtype: 'Data',
hidden: 1
reqd: 1
},
{ fieldtype: "Section Break" },
{
fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
options: "", fieldtype: 'Select'
@@ -134,18 +136,20 @@ erpnext.setup.slides_settings = [
me.charts_modal(slide, chart_template);
});
slide.get_input("company_name").on("change", function () {
slide.get_input("company_name").on("input", function () {
let parts = slide.get_input("company_name").val().split(" ");
let abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase());
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
slide.get_input("company_abbr").on("change", function () {
if (slide.get_input("company_abbr").val().length > 10) {
let abbr = slide.get_input("company_abbr").val();
if (abbr.length > 10) {
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
slide.get_field("company_abbr").set_value("");
abbr = abbr.slice(0, 10);
}
});
slide.get_field("company_abbr").set_value(abbr);
}).val(frappe.boot.sysdefaults.company_abbr || "").trigger("change");
},
charts_modal: function(slide, chart_template) {

View File

@@ -95,18 +95,26 @@ class SalesOrder(SellingController):
and customer = %s",
(self.po_no, self.name, self.customer),
)
if (
so
and so[0][0]
and not cint(
if so and so[0][0]:
if cint(
frappe.db.get_single_value("Selling Settings", "allow_against_multiple_purchase_orders")
)
):
frappe.msgprint(
_("Warning: Sales Order {0} already exists against Customer's Purchase Order {1}").format(
so[0][0], self.po_no
):
frappe.msgprint(
_("Warning: Sales Order {0} already exists against Customer's Purchase Order {1}").format(
frappe.bold(so[0][0]), frappe.bold(self.po_no)
)
)
else:
frappe.throw(
_(
"Sales Order {0} already exists against Customer's Purchase Order {1}. To allow multiple Sales Orders, Enable {2} in {3}"
).format(
frappe.bold(so[0][0]),
frappe.bold(self.po_no),
frappe.bold(_("'Allow Multiple Sales Orders Against a Customer's Purchase Order'")),
get_link_to_form("Selling Settings", "Selling Settings"),
)
)
)
def validate_for_items(self):
for d in self.get("items"):

View File

@@ -2023,7 +2023,7 @@ def make_sales_order(**args):
so.company = args.company or "_Test Company"
so.customer = args.customer or "_Test Customer"
so.currency = args.currency or "INR"
so.po_no = args.po_no or "12345"
so.po_no = args.po_no or ""
if args.selling_price_list:
so.selling_price_list = args.selling_price_list

View File

@@ -20,6 +20,7 @@
"editable_price_list_rate",
"validate_selling_price",
"editable_bundle_item_rates",
"allow_negative_rates_for_items",
"sales_transactions_settings_section",
"so_required",
"dn_required",
@@ -84,7 +85,7 @@
"fieldname": "sales_update_frequency",
"fieldtype": "Select",
"label": "Sales Update Frequency in Company and Project",
"options": "Each Transaction\nDaily\nMonthly",
"options": "Monthly\nEach Transaction\nDaily",
"reqd": 1
},
{
@@ -186,6 +187,12 @@
"fieldname": "over_order_allowance",
"fieldtype": "Float",
"label": "Over Order Allowance (%)"
},
{
"default": "0",
"fieldname": "allow_negative_rates_for_items",
"fieldtype": "Check",
"label": "Allow Negative rates for Items"
}
],
"icon": "fa fa-cog",
@@ -193,7 +200,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-03-03 11:16:54.333615",
"modified": "2023-08-14 20:33:05.693667",
"modified_by": "Administrator",
"module": "Selling",
"name": "Selling Settings",
@@ -222,4 +229,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

View File

@@ -18,6 +18,7 @@ frappe.ui.form.on("Company", {
});
},
setup: function(frm) {
frm.__rename_queue = "long";
erpnext.company.setup_queries(frm);
frm.set_query("parent_company", function() {

View File

@@ -297,7 +297,9 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None):
frappe.msgprint(
_(
"Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement"
).format(frappe.bold(item_code))
).format(frappe.bold(item_code)),
indicator="yellow",
alert=(not throw),
)
if throw:
raise UnableToSelectBatchError

View File

@@ -728,7 +728,7 @@ class TestDeliveryNote(FrappeTestCase):
def test_dn_billing_status_case1(self):
# SO -> DN -> SI
so = make_sales_order()
so = make_sales_order(po_no="12345")
dn = create_dn_against_so(so.name, delivered_qty=2)
self.assertEqual(dn.status, "To Bill")
@@ -755,7 +755,7 @@ class TestDeliveryNote(FrappeTestCase):
make_sales_invoice,
)
so = make_sales_order()
so = make_sales_order(po_no="12345")
si = make_sales_invoice(so.name)
si.get("items")[0].qty = 5
@@ -799,7 +799,7 @@ class TestDeliveryNote(FrappeTestCase):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
so = make_sales_order()
so = make_sales_order(po_no="12345")
dn1 = make_delivery_note(so.name)
dn1.get("items")[0].qty = 2
@@ -845,7 +845,7 @@ class TestDeliveryNote(FrappeTestCase):
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
so = make_sales_order()
so = make_sales_order(po_no="12345")
si = make_sales_invoice(so.name)
si.submit()
@@ -1211,6 +1211,10 @@ class TestDeliveryNote(FrappeTestCase):
self.assertTrue(return_dn.docstatus == 1)
def tearDown(self):
frappe.db.rollback()
frappe.db.set_single_value("Selling Settings", "dont_reserve_sales_order_qty_on_sales_return", 0)
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")

View File

@@ -6,6 +6,7 @@ import frappe
from frappe import _
from frappe.model.document import Document
from frappe.model.meta import get_field_precision
from frappe.query_builder.custom import ConstantColumn
from frappe.utils import flt
import erpnext
@@ -19,19 +20,7 @@ class LandedCostVoucher(Document):
self.set("items", [])
for pr in self.get("purchase_receipts"):
if pr.receipt_document_type and pr.receipt_document:
pr_items = frappe.db.sql(
"""select pr_item.item_code, pr_item.description,
pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name,
pr_item.cost_center, pr_item.is_fixed_asset
from `tab{doctype} Item` pr_item where parent = %s
and exists(select name from tabItem
where name = pr_item.item_code and (is_stock_item = 1 or is_fixed_asset=1))
""".format(
doctype=pr.receipt_document_type
),
pr.receipt_document,
as_dict=True,
)
pr_items = get_pr_items(pr)
for d in pr_items:
item = self.append("items")
@@ -247,3 +236,30 @@ class LandedCostVoucher(Document):
),
tuple([item.valuation_rate] + serial_nos),
)
def get_pr_items(purchase_receipt):
item = frappe.qb.DocType("Item")
pr_item = frappe.qb.DocType(purchase_receipt.receipt_document_type + " Item")
return (
frappe.qb.from_(pr_item)
.inner_join(item)
.on(item.name == pr_item.item_code)
.select(
pr_item.item_code,
pr_item.description,
pr_item.qty,
pr_item.base_rate,
pr_item.base_amount,
pr_item.name,
pr_item.cost_center,
pr_item.is_fixed_asset,
ConstantColumn(purchase_receipt.receipt_document_type).as_("receipt_document_type"),
ConstantColumn(purchase_receipt.receipt_document).as_("receipt_document"),
)
.where(
(pr_item.parent == purchase_receipt.receipt_document)
& ((item.is_stock_item == 1) | (item.is_fixed_asset == 1))
)
.run(as_dict=True)
)

Some files were not shown because too many files have changed in this diff Show More