Compare commits
1 Commits
v13.50.0
...
fix-error-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a3a0a83b7 |
4
.flake8
4
.flake8
@@ -28,10 +28,6 @@ ignore =
|
|||||||
B007,
|
B007,
|
||||||
B950,
|
B950,
|
||||||
W191,
|
W191,
|
||||||
E124, # closing bracket, irritating while writing QB code
|
|
||||||
E131, # continuation line unaligned for hanging indent
|
|
||||||
E123, # closing bracket does not match indentation of opening bracket's line
|
|
||||||
E101, # ensured by use of black
|
|
||||||
|
|
||||||
max-line-length = 200
|
max-line-length = 200
|
||||||
exclude=.github/helper/semgrep_rules
|
exclude=.github/helper/semgrep_rules
|
||||||
|
|||||||
@@ -17,6 +17,3 @@ f0bcb753fb7ebbb64bb0d6906d431d002f0f7d8f
|
|||||||
|
|
||||||
# imports cleanup
|
# imports cleanup
|
||||||
4b2be2999f2203493b49bf74c5b440d49e38b5e3
|
4b2be2999f2203493b49bf74c5b440d49e38b5e3
|
||||||
|
|
||||||
# formatting with black
|
|
||||||
c07713b860505211db2af685e2e950bf5dd7dd3a
|
|
||||||
|
|||||||
2
.github/helper/.flake8_strict
vendored
2
.github/helper/.flake8_strict
vendored
@@ -66,8 +66,6 @@ ignore =
|
|||||||
F841,
|
F841,
|
||||||
E713,
|
E713,
|
||||||
E712,
|
E712,
|
||||||
B023,
|
|
||||||
B028
|
|
||||||
|
|
||||||
|
|
||||||
max-line-length = 200
|
max-line-length = 200
|
||||||
|
|||||||
99
.github/helper/documentation.py
vendored
99
.github/helper/documentation.py
vendored
@@ -3,71 +3,52 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
WEBSITE_REPOS = [
|
docs_repos = [
|
||||||
|
"frappe_docs",
|
||||||
|
"erpnext_documentation",
|
||||||
"erpnext_com",
|
"erpnext_com",
|
||||||
"frappe_io",
|
"frappe_io",
|
||||||
]
|
]
|
||||||
|
|
||||||
DOCUMENTATION_DOMAINS = [
|
|
||||||
"docs.erpnext.com",
|
|
||||||
"frappeframework.com",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
def uri_validator(x):
|
||||||
|
result = urlparse(x)
|
||||||
|
return all([result.scheme, result.netloc, result.path])
|
||||||
|
|
||||||
def is_valid_url(url: str) -> bool:
|
def docs_link_exists(body):
|
||||||
parts = urlparse(url)
|
for line in body.splitlines():
|
||||||
return all((parts.scheme, parts.netloc, parts.path))
|
for word in line.split():
|
||||||
|
if word.startswith('http') and uri_validator(word):
|
||||||
|
parsed_url = urlparse(word)
|
||||||
def is_documentation_link(word: str) -> bool:
|
if parsed_url.netloc == "github.com":
|
||||||
if not word.startswith("http") or not is_valid_url(word):
|
parts = parsed_url.path.split('/')
|
||||||
return False
|
if len(parts) == 5 and parts[1] == "frappe" and parts[2] in docs_repos:
|
||||||
|
return True
|
||||||
parsed_url = urlparse(word)
|
elif parsed_url.netloc == "docs.erpnext.com":
|
||||||
if parsed_url.netloc in DOCUMENTATION_DOMAINS:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
if parsed_url.netloc == "github.com":
|
|
||||||
parts = parsed_url.path.split("/")
|
|
||||||
if len(parts) == 5 and parts[1] == "frappe" and parts[2] in WEBSITE_REPOS:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def contains_documentation_link(body: str) -> bool:
|
|
||||||
return any(
|
|
||||||
is_documentation_link(word)
|
|
||||||
for line in body.splitlines()
|
|
||||||
for word in line.split()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def check_pull_request(number: str) -> "tuple[int, str]":
|
|
||||||
response = requests.get(f"https://api.github.com/repos/frappe/erpnext/pulls/{number}")
|
|
||||||
if not response.ok:
|
|
||||||
return 1, "Pull Request Not Found! ⚠️"
|
|
||||||
|
|
||||||
payload = response.json()
|
|
||||||
title = (payload.get("title") or "").lower().strip()
|
|
||||||
head_sha = (payload.get("head") or {}).get("sha")
|
|
||||||
body = (payload.get("body") or "").lower()
|
|
||||||
|
|
||||||
if (
|
|
||||||
not title.startswith("feat")
|
|
||||||
or not head_sha
|
|
||||||
or "no-docs" in body
|
|
||||||
or "backport" in body
|
|
||||||
):
|
|
||||||
return 0, "Skipping documentation checks... 🏃"
|
|
||||||
|
|
||||||
if contains_documentation_link(body):
|
|
||||||
return 0, "Documentation Link Found. You're Awesome! 🎉"
|
|
||||||
|
|
||||||
return 1, "Documentation Link Not Found! ⚠️"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
exit_code, message = check_pull_request(sys.argv[1])
|
pr = sys.argv[1]
|
||||||
print(message)
|
response = requests.get("https://api.github.com/repos/frappe/erpnext/pulls/{}".format(pr))
|
||||||
sys.exit(exit_code)
|
|
||||||
|
if response.ok:
|
||||||
|
payload = response.json()
|
||||||
|
title = (payload.get("title") or "").lower().strip()
|
||||||
|
head_sha = (payload.get("head") or {}).get("sha")
|
||||||
|
body = (payload.get("body") or "").lower()
|
||||||
|
|
||||||
|
if (title.startswith("feat")
|
||||||
|
and head_sha
|
||||||
|
and "no-docs" not in body
|
||||||
|
and "backport" not in body
|
||||||
|
):
|
||||||
|
if docs_link_exists(body):
|
||||||
|
print("Documentation Link Found. You're Awesome! 🎉")
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Documentation Link Not Found! ⚠️")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("Skipping documentation checks... 🏃")
|
||||||
|
|||||||
9
.github/helper/install.sh
vendored
9
.github/helper/install.sh
vendored
@@ -2,16 +2,9 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Check for merge conflicts before proceeding
|
|
||||||
python -m compileall -f "${GITHUB_WORKSPACE}"
|
|
||||||
if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}"
|
|
||||||
then echo "Found merge conflicts"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd ~ || exit
|
cd ~ || exit
|
||||||
|
|
||||||
sudo apt update && sudo apt install redis-server libcups2-dev
|
sudo apt-get install redis-server libcups2-dev
|
||||||
|
|
||||||
pip install frappe-bench
|
pip install frappe-bench
|
||||||
|
|
||||||
|
|||||||
38
.github/helper/semgrep_rules/README.md
vendored
Normal file
38
.github/helper/semgrep_rules/README.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Semgrep linting
|
||||||
|
|
||||||
|
## What is semgrep?
|
||||||
|
Semgrep or "semantic grep" is language agnostic static analysis tool. In simple terms semgrep is syntax-aware `grep`, so unlike regex it doesn't get confused by different ways of writing same thing or whitespaces or code split in multiple lines etc.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
To check if a translate function is using f-string or not the regex would be `r"_\(\s*f[\"']"` while equivalent rule in semgrep would be `_(f"...")`. As semgrep knows grammer of language it takes care of unnecessary whitespace, type of quotation marks etc.
|
||||||
|
|
||||||
|
You can read more such examples in `.github/helper/semgrep_rules` directory.
|
||||||
|
|
||||||
|
# Why/when to use this?
|
||||||
|
We want to maintain quality of contributions, at the same time remembering all the good practices can be pain to deal with while evaluating contributions. Using semgrep if you can translate "best practice" into a rule then it can automate the task for us.
|
||||||
|
|
||||||
|
## Running locally
|
||||||
|
|
||||||
|
Install semgrep using homebrew `brew install semgrep` or pip `pip install semgrep`.
|
||||||
|
|
||||||
|
To run locally use following command:
|
||||||
|
|
||||||
|
`semgrep --config=.github/helper/semgrep_rules [file/folder names]`
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
semgrep allows testing the tests. Refer to this page: https://semgrep.dev/docs/writing-rules/testing-rules/
|
||||||
|
|
||||||
|
When writing new rules you should write few positive and few negative cases as shown in the guide and current tests.
|
||||||
|
|
||||||
|
To run current tests: `semgrep --test --test-ignore-todo .github/helper/semgrep_rules`
|
||||||
|
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
If you are new to Semgrep read following pages to get started on writing/modifying rules:
|
||||||
|
|
||||||
|
- https://semgrep.dev/docs/getting-started/
|
||||||
|
- https://semgrep.dev/docs/writing-rules/rule-syntax
|
||||||
|
- https://semgrep.dev/docs/writing-rules/pattern-examples/
|
||||||
|
- https://semgrep.dev/docs/writing-rules/rule-ideas/#common-use-cases
|
||||||
34
.github/helper/semgrep_rules/report.yml
vendored
Normal file
34
.github/helper/semgrep_rules/report.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
rules:
|
||||||
|
- id: frappe-missing-translate-function-in-report-python
|
||||||
|
paths:
|
||||||
|
include:
|
||||||
|
- "**/report"
|
||||||
|
exclude:
|
||||||
|
- "**/regional"
|
||||||
|
pattern-either:
|
||||||
|
- patterns:
|
||||||
|
- pattern: |
|
||||||
|
{..., "label": "...", ...}
|
||||||
|
- pattern-not: |
|
||||||
|
{..., "label": _("..."), ...}
|
||||||
|
- patterns:
|
||||||
|
- pattern: dict(..., label="...", ...)
|
||||||
|
- pattern-not: dict(..., label=_("..."), ...)
|
||||||
|
message: |
|
||||||
|
All user facing text must be wrapped in translate function. Please refer to translation documentation. https://frappeframework.com/docs/user/en/guides/basics/translations
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translated-values-in-business-logic
|
||||||
|
paths:
|
||||||
|
include:
|
||||||
|
- "**/report"
|
||||||
|
patterns:
|
||||||
|
- pattern-inside: |
|
||||||
|
{..., filters: [...], ...}
|
||||||
|
- pattern: |
|
||||||
|
{..., options: [..., __("..."), ...], ...}
|
||||||
|
message: |
|
||||||
|
Using translated values in options field will require you to translate the values while comparing in business logic. Instead of passing translated labels provide objects that contain both label and value. e.g. { label: __("Option value"), value: "Option value"}
|
||||||
|
languages: [javascript]
|
||||||
|
severity: ERROR
|
||||||
6
.github/helper/semgrep_rules/security.py
vendored
Normal file
6
.github/helper/semgrep_rules/security.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
def function_name(input):
|
||||||
|
# ruleid: frappe-codeinjection-eval
|
||||||
|
eval(input)
|
||||||
|
|
||||||
|
# ok: frappe-codeinjection-eval
|
||||||
|
eval("1 + 1")
|
||||||
10
.github/helper/semgrep_rules/security.yml
vendored
Normal file
10
.github/helper/semgrep_rules/security.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
rules:
|
||||||
|
- id: frappe-codeinjection-eval
|
||||||
|
patterns:
|
||||||
|
- pattern-not: eval("...")
|
||||||
|
- pattern: eval(...)
|
||||||
|
message: |
|
||||||
|
Detected the use of eval(). eval() can be dangerous if used to evaluate
|
||||||
|
dynamic content. Avoid it or use safe_eval().
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
44
.github/helper/semgrep_rules/translate.js
vendored
Normal file
44
.github/helper/semgrep_rules/translate.js
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// ruleid: frappe-translation-empty-string
|
||||||
|
__("")
|
||||||
|
// ruleid: frappe-translation-empty-string
|
||||||
|
__('')
|
||||||
|
|
||||||
|
// ok: frappe-translation-js-formatting
|
||||||
|
__('Welcome {0}, get started with ERPNext in just a few clicks.', [full_name]);
|
||||||
|
|
||||||
|
// ruleid: frappe-translation-js-formatting
|
||||||
|
__(`Welcome ${full_name}, get started with ERPNext in just a few clicks.`);
|
||||||
|
|
||||||
|
// ok: frappe-translation-js-formatting
|
||||||
|
__('This is fine');
|
||||||
|
|
||||||
|
|
||||||
|
// ok: frappe-translation-trailing-spaces
|
||||||
|
__('This is fine');
|
||||||
|
|
||||||
|
// ruleid: frappe-translation-trailing-spaces
|
||||||
|
__(' this is not ok ');
|
||||||
|
// ruleid: frappe-translation-trailing-spaces
|
||||||
|
__('this is not ok ');
|
||||||
|
// ruleid: frappe-translation-trailing-spaces
|
||||||
|
__(' this is not ok');
|
||||||
|
|
||||||
|
// ok: frappe-translation-js-splitting
|
||||||
|
__('You have {0} subscribers in your mailing list.', [subscribers.length])
|
||||||
|
|
||||||
|
// todoruleid: frappe-translation-js-splitting
|
||||||
|
__('You have') + subscribers.length + __('subscribers in your mailing list.')
|
||||||
|
|
||||||
|
// ruleid: frappe-translation-js-splitting
|
||||||
|
__('You have' + 'subscribers in your mailing list.')
|
||||||
|
|
||||||
|
// ruleid: frappe-translation-js-splitting
|
||||||
|
__('You have {0} subscribers' +
|
||||||
|
'in your mailing list', [subscribers.length])
|
||||||
|
|
||||||
|
// ok: frappe-translation-js-splitting
|
||||||
|
__("Ctrl+Enter to add comment")
|
||||||
|
|
||||||
|
// ruleid: frappe-translation-js-splitting
|
||||||
|
__('You have {0} subscribers \
|
||||||
|
in your mailing list', [subscribers.length])
|
||||||
61
.github/helper/semgrep_rules/translate.py
vendored
Normal file
61
.github/helper/semgrep_rules/translate.py
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Examples taken from https://frappeframework.com/docs/user/en/translations
|
||||||
|
# This file is used for testing the tests.
|
||||||
|
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
|
full_name = "Jon Doe"
|
||||||
|
# ok: frappe-translation-python-formatting
|
||||||
|
_('Welcome {0}, get started with ERPNext in just a few clicks.').format(full_name)
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-python-formatting
|
||||||
|
_('Welcome %s, get started with ERPNext in just a few clicks.' % full_name)
|
||||||
|
# ruleid: frappe-translation-python-formatting
|
||||||
|
_('Welcome %(name)s, get started with ERPNext in just a few clicks.' % {'name': full_name})
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-python-formatting
|
||||||
|
_('Welcome {0}, get started with ERPNext in just a few clicks.'.format(full_name))
|
||||||
|
|
||||||
|
|
||||||
|
subscribers = ["Jon", "Doe"]
|
||||||
|
# ok: frappe-translation-python-formatting
|
||||||
|
_('You have {0} subscribers in your mailing list.').format(len(subscribers))
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-python-splitting
|
||||||
|
_('You have') + len(subscribers) + _('subscribers in your mailing list.')
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-python-splitting
|
||||||
|
_('You have {0} subscribers \
|
||||||
|
in your mailing list').format(len(subscribers))
|
||||||
|
|
||||||
|
# ok: frappe-translation-python-splitting
|
||||||
|
_('You have {0} subscribers') \
|
||||||
|
+ 'in your mailing list'
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-trailing-spaces
|
||||||
|
msg = _(" You have {0} pending invoice ")
|
||||||
|
# ruleid: frappe-translation-trailing-spaces
|
||||||
|
msg = _("You have {0} pending invoice ")
|
||||||
|
# ruleid: frappe-translation-trailing-spaces
|
||||||
|
msg = _(" You have {0} pending invoice")
|
||||||
|
|
||||||
|
# ok: frappe-translation-trailing-spaces
|
||||||
|
msg = ' ' + _("You have {0} pending invoices") + ' '
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-python-formatting
|
||||||
|
_(f"can not format like this - {subscribers}")
|
||||||
|
# ruleid: frappe-translation-python-splitting
|
||||||
|
_(f"what" + f"this is also not cool")
|
||||||
|
|
||||||
|
|
||||||
|
# ruleid: frappe-translation-empty-string
|
||||||
|
_("")
|
||||||
|
# ruleid: frappe-translation-empty-string
|
||||||
|
_('')
|
||||||
|
|
||||||
|
|
||||||
|
class Test:
|
||||||
|
# ok: frappe-translation-python-splitting
|
||||||
|
def __init__(
|
||||||
|
args
|
||||||
|
):
|
||||||
|
pass
|
||||||
64
.github/helper/semgrep_rules/translate.yml
vendored
Normal file
64
.github/helper/semgrep_rules/translate.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
rules:
|
||||||
|
- id: frappe-translation-empty-string
|
||||||
|
pattern-either:
|
||||||
|
- pattern: _("")
|
||||||
|
- pattern: __("")
|
||||||
|
message: |
|
||||||
|
Empty string is useless for translation.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [python, javascript, json]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translation-trailing-spaces
|
||||||
|
pattern-either:
|
||||||
|
- pattern: _("=~/(^[ \t]+|[ \t]+$)/")
|
||||||
|
- pattern: __("=~/(^[ \t]+|[ \t]+$)/")
|
||||||
|
message: |
|
||||||
|
Trailing or leading whitespace not allowed in translate strings.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [python, javascript, json]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translation-python-formatting
|
||||||
|
pattern-either:
|
||||||
|
- pattern: _("..." % ...)
|
||||||
|
- pattern: _("...".format(...))
|
||||||
|
- pattern: _(f"...")
|
||||||
|
message: |
|
||||||
|
Only positional formatters are allowed and formatting should not be done before translating.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translation-js-formatting
|
||||||
|
patterns:
|
||||||
|
- pattern: __(`...`)
|
||||||
|
- pattern-not: __("...")
|
||||||
|
message: |
|
||||||
|
Template strings are not allowed for text formatting.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [javascript, json]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translation-python-splitting
|
||||||
|
pattern-either:
|
||||||
|
- pattern: _(...) + _(...)
|
||||||
|
- pattern: _("..." + "...")
|
||||||
|
- pattern-regex: '[\s\.]_\([^\)]*\\\s*' # lines broken by `\`
|
||||||
|
- pattern-regex: '[\s\.]_\(\s*\n' # line breaks allowed by python for using ( )
|
||||||
|
message: |
|
||||||
|
Do not split strings inside translate function. Do not concatenate using translate functions.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-translation-js-splitting
|
||||||
|
pattern-either:
|
||||||
|
- pattern-regex: '__\([^\)]*[\\]\s+'
|
||||||
|
- pattern: __('...' + '...', ...)
|
||||||
|
- pattern: __('...') + __('...')
|
||||||
|
message: |
|
||||||
|
Do not split strings inside translate function. Do not concatenate using translate functions.
|
||||||
|
Please refer: https://frappeframework.com/docs/user/en/translations
|
||||||
|
languages: [javascript, json]
|
||||||
|
severity: ERROR
|
||||||
9
.github/helper/semgrep_rules/ux.js
vendored
Normal file
9
.github/helper/semgrep_rules/ux.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
// ok: frappe-missing-translate-function-js
|
||||||
|
frappe.msgprint('{{ _("Both login and password required") }}');
|
||||||
|
|
||||||
|
// ruleid: frappe-missing-translate-function-js
|
||||||
|
frappe.msgprint('What');
|
||||||
|
|
||||||
|
// ok: frappe-missing-translate-function-js
|
||||||
|
frappe.throw(' {{ _("Both login and password required") }}. ');
|
||||||
30
.github/helper/semgrep_rules/ux.yml
vendored
Normal file
30
.github/helper/semgrep_rules/ux.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
rules:
|
||||||
|
- id: frappe-missing-translate-function-python
|
||||||
|
pattern-either:
|
||||||
|
- patterns:
|
||||||
|
- pattern: frappe.msgprint("...", ...)
|
||||||
|
- pattern-not: frappe.msgprint(_("..."), ...)
|
||||||
|
- patterns:
|
||||||
|
- pattern: frappe.throw("...", ...)
|
||||||
|
- pattern-not: frappe.throw(_("..."), ...)
|
||||||
|
message: |
|
||||||
|
All user facing text must be wrapped in translate function. Please refer to translation documentation. https://frappeframework.com/docs/user/en/guides/basics/translations
|
||||||
|
languages: [python]
|
||||||
|
severity: ERROR
|
||||||
|
|
||||||
|
- id: frappe-missing-translate-function-js
|
||||||
|
pattern-either:
|
||||||
|
- patterns:
|
||||||
|
- pattern: frappe.msgprint("...", ...)
|
||||||
|
- pattern-not: frappe.msgprint(__("..."), ...)
|
||||||
|
# ignore microtemplating e.g. msgprint("{{ _("server side translation") }}")
|
||||||
|
- pattern-not: frappe.msgprint("=~/\{\{.*\_.*\}\}/i", ...)
|
||||||
|
- patterns:
|
||||||
|
- pattern: frappe.throw("...", ...)
|
||||||
|
- pattern-not: frappe.throw(__("..."), ...)
|
||||||
|
# ignore microtemplating
|
||||||
|
- pattern-not: frappe.throw("=~/\{\{.*\_.*\}\}/i", ...)
|
||||||
|
message: |
|
||||||
|
All user facing text must be wrapped in translate function. Please refer to translation documentation. https://frappeframework.com/docs/user/en/guides/basics/translations
|
||||||
|
languages: [javascript]
|
||||||
|
severity: ERROR
|
||||||
1
.github/workflows/backport.yml
vendored
1
.github/workflows/backport.yml
vendored
@@ -8,7 +8,6 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
main:
|
main:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Actions
|
- name: Checkout Actions
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|||||||
2
.github/workflows/docker-release.yml
vendored
2
.github/workflows/docker-release.yml
vendored
@@ -11,4 +11,4 @@ jobs:
|
|||||||
- name: curl
|
- name: curl
|
||||||
run: |
|
run: |
|
||||||
apk add curl bash
|
apk add curl bash
|
||||||
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.CI_PAT }}" https://api.github.com/repos/frappe/frappe_docker/actions/workflows/build_stable.yml/dispatches -d '{"ref":"main"}'
|
curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token ${{ secrets.TRAVIS_CI_TOKEN }}" -d '{"request":{"branch":"master"}}' https://api.travis-ci.com/repo/frappe%2Ffrappe_docker/requests
|
||||||
|
|||||||
3
.github/workflows/docs-checker.yml
vendored
3
.github/workflows/docs-checker.yml
vendored
@@ -6,13 +6,12 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 'Setup Environment'
|
- name: 'Setup Environment'
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: 3.6
|
||||||
|
|
||||||
- name: 'Clone repo'
|
- name: 'Clone repo'
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|||||||
20
.github/workflows/linters.yml
vendored
20
.github/workflows/linters.yml
vendored
@@ -10,6 +10,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- uses: returntocorp/semgrep-action@v1
|
||||||
|
env:
|
||||||
|
SEMGREP_TIMEOUT: 120
|
||||||
|
with:
|
||||||
|
config: >-
|
||||||
|
r/python.lang.correctness
|
||||||
|
.github/helper/semgrep_rules
|
||||||
|
|
||||||
- name: Set up Python 3.8
|
- name: Set up Python 3.8
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v2
|
||||||
@@ -17,15 +24,4 @@ jobs:
|
|||||||
python-version: 3.8
|
python-version: 3.8
|
||||||
|
|
||||||
- name: Install and Run Pre-commit
|
- name: Install and Run Pre-commit
|
||||||
uses: pre-commit/action@v2.0.3
|
uses: pre-commit/action@v2.0.0
|
||||||
|
|
||||||
- name: Download Semgrep rules
|
|
||||||
run: git clone --depth 1 https://github.com/frappe/semgrep-rules.git frappe-semgrep-rules
|
|
||||||
|
|
||||||
- uses: returntocorp/semgrep-action@v1
|
|
||||||
env:
|
|
||||||
SEMGREP_TIMEOUT: 120
|
|
||||||
with:
|
|
||||||
config: >-
|
|
||||||
r/python.lang.correctness
|
|
||||||
./frappe-semgrep-rules/rules
|
|
||||||
|
|||||||
9
.github/workflows/patch.yml
vendored
9
.github/workflows/patch.yml
vendored
@@ -8,14 +8,9 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: patch-mariadb-v13-${{ github.event.number }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-18.04
|
||||||
timeout-minutes: 60
|
|
||||||
|
|
||||||
name: Patch Test
|
name: Patch Test
|
||||||
|
|
||||||
@@ -35,7 +30,7 @@ jobs:
|
|||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: 3.7
|
python-version: 3.6
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
|
|||||||
31
.github/workflows/release.yml
vendored
31
.github/workflows/release.yml
vendored
@@ -1,31 +0,0 @@
|
|||||||
name: Generate Semantic Release
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- version-13
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
name: Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Entire Repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
- name: Setup dependencies
|
|
||||||
run: |
|
|
||||||
npm install @semantic-release/git @semantic-release/exec --no-save
|
|
||||||
- name: Create Release
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
GIT_AUTHOR_NAME: "Frappe PR Bot"
|
|
||||||
GIT_AUTHOR_EMAIL: "developers@frappe.io"
|
|
||||||
GIT_COMMITTER_NAME: "Frappe PR Bot"
|
|
||||||
GIT_COMMITTER_EMAIL: "developers@frappe.io"
|
|
||||||
run: npx semantic-release
|
|
||||||
42
.github/workflows/server-tests.yml
vendored
42
.github/workflows/server-tests.yml
vendored
@@ -12,20 +12,15 @@ on:
|
|||||||
- '**.js'
|
- '**.js'
|
||||||
- '**.md'
|
- '**.md'
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: server-mariadb-v13-${{ github.event.number }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-18.04
|
||||||
timeout-minutes: 60
|
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
container: [1, 2]
|
container: [1, 2, 3]
|
||||||
|
|
||||||
name: Python Unit Tests
|
name: Python Unit Tests
|
||||||
|
|
||||||
@@ -93,8 +88,39 @@ jobs:
|
|||||||
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: 'cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --total-builds 2 --build-number ${{ matrix.container }}'
|
run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --use-orchestrator --with-coverage
|
||||||
env:
|
env:
|
||||||
TYPE: server
|
TYPE: server
|
||||||
CI_BUILD_ID: ${{ github.run_id }}
|
CI_BUILD_ID: ${{ github.run_id }}
|
||||||
ORCHESTRATOR_URL: http://test-orchestrator.frappe.io
|
ORCHESTRATOR_URL: http://test-orchestrator.frappe.io
|
||||||
|
|
||||||
|
- name: Upload Coverage Data
|
||||||
|
run: |
|
||||||
|
cp ~/frappe-bench/sites/.coverage ${GITHUB_WORKSPACE}
|
||||||
|
cd ${GITHUB_WORKSPACE}
|
||||||
|
pip3 install coverage==5.5
|
||||||
|
pip3 install coveralls==3.0.1
|
||||||
|
coveralls
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
COVERALLS_FLAG_NAME: run-${{ matrix.container }}
|
||||||
|
COVERALLS_SERVICE_NAME: ${{ github.event_name == 'pull_request' && 'github' || 'github-actions' }}
|
||||||
|
COVERALLS_PARALLEL: true
|
||||||
|
|
||||||
|
coveralls:
|
||||||
|
name: Coverage Wrap Up
|
||||||
|
needs: test
|
||||||
|
container: python:3-slim
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Clone
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Coveralls Finished
|
||||||
|
run: |
|
||||||
|
cd ${GITHUB_WORKSPACE}
|
||||||
|
pip3 install coverage==5.5
|
||||||
|
pip3 install coveralls==3.0.1
|
||||||
|
coveralls --finish
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
2
.github/workflows/translation_linter.yml
vendored
2
.github/workflows/translation_linter.yml
vendored
@@ -8,7 +8,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
check_translation:
|
check_translation:
|
||||||
name: Translation Syntax Check
|
name: Translation Syntax Check
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-18.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Setup python3
|
- name: Setup python3
|
||||||
|
|||||||
112
.github/workflows/ui-tests.yml
vendored
Normal file
112
.github/workflows/ui-tests.yml
vendored
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
name: UI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
name: UI Tests (Cypress)
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mariadb:10.3
|
||||||
|
env:
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: YES
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Clone
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Add to Hosts
|
||||||
|
run: |
|
||||||
|
echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
|
||||||
|
|
||||||
|
- name: Cache pip
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pip
|
||||||
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pip-
|
||||||
|
${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Cache node modules
|
||||||
|
uses: actions/cache@v2
|
||||||
|
env:
|
||||||
|
cache-name: cache-node-modules
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
|
${{ runner.os }}-build-
|
||||||
|
${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Get yarn cache directory path
|
||||||
|
id: yarn-cache-dir-path
|
||||||
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
|
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
id: yarn-cache
|
||||||
|
with:
|
||||||
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
|
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-yarn-
|
||||||
|
|
||||||
|
- name: Cache cypress binary
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.cache
|
||||||
|
key: ${{ runner.os }}-cypress-
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cypress-
|
||||||
|
${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
|
||||||
|
env:
|
||||||
|
DB: mariadb
|
||||||
|
TYPE: ui
|
||||||
|
|
||||||
|
- name: Site Setup
|
||||||
|
run: cd ~/frappe-bench/ && bench --site test_site execute erpnext.setup.utils.before_tests
|
||||||
|
|
||||||
|
- name: cypress pre-requisites
|
||||||
|
run: cd ~/frappe-bench/apps/frappe && yarn add cypress-file-upload@^5 @testing-library/cypress@^8 --no-lockfile
|
||||||
|
|
||||||
|
|
||||||
|
- name: Build Assets
|
||||||
|
run: cd ~/frappe-bench/ && bench build
|
||||||
|
env:
|
||||||
|
CI: Yes
|
||||||
|
|
||||||
|
- name: UI Tests
|
||||||
|
run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless
|
||||||
|
env:
|
||||||
|
CYPRESS_RECORD_KEY: 60a8e3bf-08f5-45b1-9269-2b207d7d30cd
|
||||||
|
|
||||||
|
- name: Show bench console if tests failed
|
||||||
|
if: ${{ failure() }}
|
||||||
|
run: cat ~/frappe-bench/bench_run_logs.txt
|
||||||
@@ -16,8 +16,8 @@ repos:
|
|||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- id: check-ast
|
- id: check-ast
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: 5.0.4
|
rev: 3.9.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies: [
|
additional_dependencies: [
|
||||||
@@ -26,19 +26,12 @@ repos:
|
|||||||
args: ['--config', '.github/helper/.flake8_strict']
|
args: ['--config', '.github/helper/.flake8_strict']
|
||||||
exclude: ".*setup.py$"
|
exclude: ".*setup.py$"
|
||||||
|
|
||||||
- repo: https://github.com/adityahase/black
|
- repo: https://github.com/timothycrosley/isort
|
||||||
rev: 9cb0a69f4d0030cdf687eddf314468b39ed54119
|
rev: 5.9.1
|
||||||
hooks:
|
|
||||||
- id: black
|
|
||||||
additional_dependencies: ['click==8.0.4']
|
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/isort
|
|
||||||
rev: 5.12.0
|
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
exclude: ".*setup.py$"
|
exclude: ".*setup.py$"
|
||||||
|
|
||||||
|
|
||||||
ci:
|
ci:
|
||||||
autoupdate_schedule: weekly
|
autoupdate_schedule: weekly
|
||||||
skip: []
|
skip: []
|
||||||
|
|||||||
24
.releaserc
24
.releaserc
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"branches": ["version-13"],
|
|
||||||
"plugins": [
|
|
||||||
"@semantic-release/commit-analyzer", {
|
|
||||||
"preset": "angular",
|
|
||||||
"releaseRules": [
|
|
||||||
{"breaking": true, "release": false}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@semantic-release/release-notes-generator",
|
|
||||||
[
|
|
||||||
"@semantic-release/exec", {
|
|
||||||
"prepareCmd": 'sed -ir -E "s/\"[0-9]+\.[0-9]+\.[0-9]+\"/\"${nextRelease.version}\"/" erpnext/__init__.py'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"@semantic-release/git", {
|
|
||||||
"assets": ["erpnext/__init__.py"],
|
|
||||||
"message": "chore(release): Bumped to Version ${nextRelease.version}\n\n${nextRelease.notes}"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@semantic-release/github"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
43
CODEOWNERS
43
CODEOWNERS
@@ -3,24 +3,33 @@
|
|||||||
# These owners will be the default owners for everything in
|
# These owners will be the default owners for everything in
|
||||||
# the repo. Unless a later match takes precedence,
|
# the repo. Unless a later match takes precedence,
|
||||||
|
|
||||||
erpnext/accounts/ @deepeshgarg007 @ruthra-kumar
|
erpnext/accounts/ @nextchamp-saqib @deepeshgarg007
|
||||||
erpnext/assets/ @anandbaburajan @deepeshgarg007
|
erpnext/assets/ @nextchamp-saqib @deepeshgarg007
|
||||||
erpnext/loan_management/ @deepeshgarg007
|
erpnext/erpnext_integrations/ @nextchamp-saqib
|
||||||
erpnext/regional @deepeshgarg007 @ruthra-kumar
|
erpnext/loan_management/ @nextchamp-saqib @deepeshgarg007
|
||||||
erpnext/selling @deepeshgarg007 @ruthra-kumar
|
erpnext/regional @nextchamp-saqib @deepeshgarg007
|
||||||
erpnext/support/ @deepeshgarg007
|
erpnext/selling @nextchamp-saqib @deepeshgarg007
|
||||||
pos*
|
erpnext/support/ @nextchamp-saqib @deepeshgarg007
|
||||||
|
pos* @nextchamp-saqib
|
||||||
|
|
||||||
erpnext/buying/ @rohitwaghchaure @s-aga-r
|
erpnext/buying/ @marination @rohitwaghchaure @ankush
|
||||||
erpnext/maintenance/ @rohitwaghchaure @s-aga-r
|
erpnext/e_commerce/ @marination
|
||||||
erpnext/manufacturing/ @rohitwaghchaure @s-aga-r
|
erpnext/maintenance/ @marination @rohitwaghchaure
|
||||||
erpnext/quality_management/ @rohitwaghchaure @s-aga-r
|
erpnext/manufacturing/ @marination @rohitwaghchaure @ankush
|
||||||
erpnext/stock/ @rohitwaghchaure @s-aga-r
|
erpnext/portal/ @marination
|
||||||
|
erpnext/quality_management/ @marination @rohitwaghchaure
|
||||||
|
erpnext/shopping_cart/ @marination
|
||||||
|
erpnext/stock/ @marination @rohitwaghchaure @ankush
|
||||||
|
|
||||||
erpnext/controllers @deepeshgarg007 @rohitwaghchaure
|
erpnext/crm/ @ruchamahabal @pateljannat
|
||||||
erpnext/patches/ @deepeshgarg007 @rohitwaghchaure
|
erpnext/education/ @ruchamahabal @pateljannat
|
||||||
requirements.txt @ankush
|
erpnext/healthcare/ @ruchamahabal @pateljannat @chillaranand
|
||||||
|
erpnext/hr/ @ruchamahabal @pateljannat
|
||||||
|
erpnext/non_profit/ @ruchamahabal
|
||||||
|
erpnext/payroll @ruchamahabal @pateljannat
|
||||||
|
erpnext/projects/ @ruchamahabal @pateljannat
|
||||||
|
|
||||||
.github/ @deepeshgarg007
|
erpnext/controllers @deepeshgarg007 @nextchamp-saqib @rohitwaghchaure @marination
|
||||||
pyproject.toml @ankush
|
|
||||||
|
|
||||||
|
.github/ @surajshetty3416 @ankush
|
||||||
|
requirements.txt @gavindsouza
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ GNU/General Public License (see [license.txt](license.txt))
|
|||||||
|
|
||||||
The ERPNext code is licensed as GNU General Public License (v3) and the Documentation is licensed as Creative Commons (CC-BY-SA-3.0) and the copyright is owned by Frappe Technologies Pvt Ltd (Frappe) and Contributors.
|
The ERPNext code is licensed as GNU General Public License (v3) and the Documentation is licensed as Creative Commons (CC-BY-SA-3.0) and the copyright is owned by Frappe Technologies Pvt Ltd (Frappe) and Contributors.
|
||||||
|
|
||||||
By contributing to ERPNext, you agree that your contributions will be licensed under its GNU General Public License (v3).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
@@ -1,60 +1,55 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
from erpnext.hooks import regional_overrides
|
from erpnext.hooks import regional_overrides
|
||||||
|
|
||||||
__version__ = "13.50.0"
|
__version__ = '13.13.0'
|
||||||
|
|
||||||
|
|
||||||
def get_default_company(user=None):
|
def get_default_company(user=None):
|
||||||
"""Get default company for user"""
|
'''Get default company for user'''
|
||||||
from frappe.defaults import get_user_default_as_list
|
from frappe.defaults import get_user_default_as_list
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
|
|
||||||
companies = get_user_default_as_list(user, "company")
|
companies = get_user_default_as_list(user, 'company')
|
||||||
if companies:
|
if companies:
|
||||||
default_company = companies[0]
|
default_company = companies[0]
|
||||||
else:
|
else:
|
||||||
default_company = frappe.db.get_single_value("Global Defaults", "default_company")
|
default_company = frappe.db.get_single_value('Global Defaults', 'default_company')
|
||||||
|
|
||||||
return default_company
|
return default_company
|
||||||
|
|
||||||
|
|
||||||
def get_default_currency():
|
def get_default_currency():
|
||||||
"""Returns the currency of the default company"""
|
'''Returns the currency of the default company'''
|
||||||
company = get_default_company()
|
company = get_default_company()
|
||||||
if company:
|
if company:
|
||||||
return frappe.get_cached_value("Company", company, "default_currency")
|
return frappe.get_cached_value('Company', company, 'default_currency')
|
||||||
|
|
||||||
|
|
||||||
def get_default_cost_center(company):
|
def get_default_cost_center(company):
|
||||||
"""Returns the default cost center of the company"""
|
'''Returns the default cost center of the company'''
|
||||||
if not company:
|
if not company:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not frappe.flags.company_cost_center:
|
if not frappe.flags.company_cost_center:
|
||||||
frappe.flags.company_cost_center = {}
|
frappe.flags.company_cost_center = {}
|
||||||
if not company in frappe.flags.company_cost_center:
|
if not company in frappe.flags.company_cost_center:
|
||||||
frappe.flags.company_cost_center[company] = frappe.get_cached_value(
|
frappe.flags.company_cost_center[company] = frappe.get_cached_value('Company', company, 'cost_center')
|
||||||
"Company", company, "cost_center"
|
|
||||||
)
|
|
||||||
return frappe.flags.company_cost_center[company]
|
return frappe.flags.company_cost_center[company]
|
||||||
|
|
||||||
|
|
||||||
def get_company_currency(company):
|
def get_company_currency(company):
|
||||||
"""Returns the default company currency"""
|
'''Returns the default company currency'''
|
||||||
if not frappe.flags.company_currency:
|
if not frappe.flags.company_currency:
|
||||||
frappe.flags.company_currency = {}
|
frappe.flags.company_currency = {}
|
||||||
if not company in frappe.flags.company_currency:
|
if not company in frappe.flags.company_currency:
|
||||||
frappe.flags.company_currency[company] = frappe.db.get_value(
|
frappe.flags.company_currency[company] = frappe.db.get_value('Company', company, 'default_currency', cache=True)
|
||||||
"Company", company, "default_currency", cache=True
|
|
||||||
)
|
|
||||||
return frappe.flags.company_currency[company]
|
return frappe.flags.company_currency[company]
|
||||||
|
|
||||||
|
|
||||||
def set_perpetual_inventory(enable=1, company=None):
|
def set_perpetual_inventory(enable=1, company=None):
|
||||||
if not company:
|
if not company:
|
||||||
company = "_Test Company" if frappe.flags.in_test else get_default_company()
|
company = "_Test Company" if frappe.flags.in_test else get_default_company()
|
||||||
@@ -63,10 +58,9 @@ def set_perpetual_inventory(enable=1, company=None):
|
|||||||
company.enable_perpetual_inventory = enable
|
company.enable_perpetual_inventory = enable
|
||||||
company.save()
|
company.save()
|
||||||
|
|
||||||
|
def encode_company_abbr(name, company):
|
||||||
def encode_company_abbr(name, company=None, abbr=None):
|
'''Returns name encoded with company abbreviation'''
|
||||||
"""Returns name encoded with company abbreviation"""
|
company_abbr = frappe.get_cached_value('Company', company, "abbr")
|
||||||
company_abbr = abbr or frappe.get_cached_value("Company", company, "abbr")
|
|
||||||
parts = name.rsplit(" - ", 1)
|
parts = name.rsplit(" - ", 1)
|
||||||
|
|
||||||
if parts[-1].lower() != company_abbr.lower():
|
if parts[-1].lower() != company_abbr.lower():
|
||||||
@@ -74,73 +68,65 @@ def encode_company_abbr(name, company=None, abbr=None):
|
|||||||
|
|
||||||
return " - ".join(parts)
|
return " - ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
def is_perpetual_inventory_enabled(company):
|
def is_perpetual_inventory_enabled(company):
|
||||||
if not company:
|
if not company:
|
||||||
company = "_Test Company" if frappe.flags.in_test else get_default_company()
|
company = "_Test Company" if frappe.flags.in_test else get_default_company()
|
||||||
|
|
||||||
if not hasattr(frappe.local, "enable_perpetual_inventory"):
|
if not hasattr(frappe.local, 'enable_perpetual_inventory'):
|
||||||
frappe.local.enable_perpetual_inventory = {}
|
frappe.local.enable_perpetual_inventory = {}
|
||||||
|
|
||||||
if not company in frappe.local.enable_perpetual_inventory:
|
if not company in frappe.local.enable_perpetual_inventory:
|
||||||
frappe.local.enable_perpetual_inventory[company] = (
|
frappe.local.enable_perpetual_inventory[company] = frappe.get_cached_value('Company',
|
||||||
frappe.get_cached_value("Company", company, "enable_perpetual_inventory") or 0
|
company, "enable_perpetual_inventory") or 0
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.local.enable_perpetual_inventory[company]
|
return frappe.local.enable_perpetual_inventory[company]
|
||||||
|
|
||||||
|
|
||||||
def get_default_finance_book(company=None):
|
def get_default_finance_book(company=None):
|
||||||
if not company:
|
if not company:
|
||||||
company = get_default_company()
|
company = get_default_company()
|
||||||
|
|
||||||
if not hasattr(frappe.local, "default_finance_book"):
|
if not hasattr(frappe.local, 'default_finance_book'):
|
||||||
frappe.local.default_finance_book = {}
|
frappe.local.default_finance_book = {}
|
||||||
|
|
||||||
if not company in frappe.local.default_finance_book:
|
if not company in frappe.local.default_finance_book:
|
||||||
frappe.local.default_finance_book[company] = frappe.get_cached_value(
|
frappe.local.default_finance_book[company] = frappe.get_cached_value('Company',
|
||||||
"Company", company, "default_finance_book"
|
company, "default_finance_book")
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.local.default_finance_book[company]
|
return frappe.local.default_finance_book[company]
|
||||||
|
|
||||||
|
|
||||||
def get_party_account_type(party_type):
|
def get_party_account_type(party_type):
|
||||||
if not hasattr(frappe.local, "party_account_types"):
|
if not hasattr(frappe.local, 'party_account_types'):
|
||||||
frappe.local.party_account_types = {}
|
frappe.local.party_account_types = {}
|
||||||
|
|
||||||
if not party_type in frappe.local.party_account_types:
|
if not party_type in frappe.local.party_account_types:
|
||||||
frappe.local.party_account_types[party_type] = (
|
frappe.local.party_account_types[party_type] = frappe.db.get_value("Party Type",
|
||||||
frappe.db.get_value("Party Type", party_type, "account_type") or ""
|
party_type, "account_type") or ''
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.local.party_account_types[party_type]
|
return frappe.local.party_account_types[party_type]
|
||||||
|
|
||||||
|
|
||||||
def get_region(company=None):
|
def get_region(company=None):
|
||||||
"""Return the default country based on flag, company or global settings
|
'''Return the default country based on flag, company or global settings
|
||||||
|
|
||||||
You can also set global company flag in `frappe.flags.company`
|
You can also set global company flag in `frappe.flags.company`
|
||||||
"""
|
'''
|
||||||
if company or frappe.flags.company:
|
if company or frappe.flags.company:
|
||||||
return frappe.get_cached_value("Company", company or frappe.flags.company, "country")
|
return frappe.get_cached_value('Company',
|
||||||
|
company or frappe.flags.company, 'country')
|
||||||
elif frappe.flags.country:
|
elif frappe.flags.country:
|
||||||
return frappe.flags.country
|
return frappe.flags.country
|
||||||
else:
|
else:
|
||||||
return frappe.get_system_settings("country")
|
return frappe.get_system_settings('country')
|
||||||
|
|
||||||
|
|
||||||
def allow_regional(fn):
|
def allow_regional(fn):
|
||||||
"""Decorator to make a function regionally overridable
|
'''Decorator to make a function regionally overridable
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@erpnext.allow_regional
|
@erpnext.allow_regional
|
||||||
def myfunction():
|
def myfunction():
|
||||||
pass"""
|
pass'''
|
||||||
|
|
||||||
def caller(*args, **kwargs):
|
def caller(*args, **kwargs):
|
||||||
region = get_region()
|
region = get_region()
|
||||||
fn_name = inspect.getmodule(fn).__name__ + "." + fn.__name__
|
fn_name = inspect.getmodule(fn).__name__ + '.' + fn.__name__
|
||||||
if region in regional_overrides and fn_name in regional_overrides[region]:
|
if region in regional_overrides and fn_name in regional_overrides[region]:
|
||||||
return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs)
|
return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
@@ -148,17 +134,10 @@ def allow_regional(fn):
|
|||||||
|
|
||||||
return caller
|
return caller
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def get_last_membership(member):
|
def get_last_membership(member):
|
||||||
"""Returns last membership if exists"""
|
'''Returns last membership if exists'''
|
||||||
last_membership = frappe.get_all(
|
last_membership = frappe.get_all('Membership', 'name,to_date,membership_type',
|
||||||
"Membership",
|
dict(member=member, paid=1), order_by='to_date desc', limit=1)
|
||||||
"name,to_date,membership_type",
|
|
||||||
dict(member=member, paid=1),
|
|
||||||
order_by="to_date desc",
|
|
||||||
limit=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
if last_membership:
|
if last_membership:
|
||||||
return last_membership[0]
|
return last_membership[0]
|
||||||
|
|||||||
@@ -23,31 +23,32 @@ class ERPNextAddress(Address):
|
|||||||
if self.is_your_company_address and not [
|
if self.is_your_company_address and not [
|
||||||
row for row in self.links if row.link_doctype == "Company"
|
row for row in self.links if row.link_doctype == "Company"
|
||||||
]:
|
]:
|
||||||
frappe.throw(
|
frappe.throw(_("Address needs to be linked to a Company. Please add a row for Company in the Links table."),
|
||||||
_("Address needs to be linked to a Company. Please add a row for Company in the Links table."),
|
title=_("Company Not Linked"))
|
||||||
title=_("Company Not Linked"),
|
|
||||||
)
|
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
"""
|
"""
|
||||||
After Address is updated, update the related 'Primary Address' on Customer.
|
After Address is updated, update the related 'Primary Address' on Customer.
|
||||||
"""
|
"""
|
||||||
address_display = get_address_display(self.as_dict())
|
address_display = get_address_display(self.as_dict())
|
||||||
filters = {"customer_primary_address": self.name}
|
filters = {
|
||||||
|
"customer_primary_address": self.name
|
||||||
|
}
|
||||||
|
|
||||||
customers = frappe.db.get_all("Customer", filters=filters, as_list=True)
|
customers = frappe.db.get_all("Customer", filters=filters, as_list=True)
|
||||||
for customer_name in customers:
|
for customer_name in customers:
|
||||||
frappe.db.set_value("Customer", customer_name[0], "primary_address", address_display)
|
frappe.db.set_value("Customer", customer_name[0], "primary_address", address_display)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_shipping_address(company, address=None):
|
def get_shipping_address(company, address = None):
|
||||||
filters = [
|
filters = [
|
||||||
["Dynamic Link", "link_doctype", "=", "Company"],
|
["Dynamic Link", "link_doctype", "=", "Company"],
|
||||||
["Dynamic Link", "link_name", "=", company],
|
["Dynamic Link", "link_name", "=", company],
|
||||||
["Address", "is_your_company_address", "=", 1],
|
["Address", "is_your_company_address", "=", 1]
|
||||||
]
|
]
|
||||||
fields = ["*"]
|
fields = ["*"]
|
||||||
if address and frappe.db.get_value("Dynamic Link", {"parent": address, "link_name": company}):
|
if address and frappe.db.get_value('Dynamic Link',
|
||||||
|
{'parent': address, 'link_name': company}):
|
||||||
filters.append(["Address", "name", "=", address])
|
filters.append(["Address", "name", "=", address])
|
||||||
if not address:
|
if not address:
|
||||||
filters.append(["Address", "is_shipping_address", "=", 1])
|
filters.append(["Address", "is_shipping_address", "=", 1])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -12,24 +13,15 @@ from frappe.utils.nestedset import get_descendants_of
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@cache_source
|
@cache_source
|
||||||
def get(
|
def get(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None,
|
||||||
chart_name=None,
|
to_date = None, timespan = None, time_interval = None, heatmap_year = None):
|
||||||
chart=None,
|
|
||||||
no_cache=None,
|
|
||||||
filters=None,
|
|
||||||
from_date=None,
|
|
||||||
to_date=None,
|
|
||||||
timespan=None,
|
|
||||||
time_interval=None,
|
|
||||||
heatmap_year=None,
|
|
||||||
):
|
|
||||||
if chart_name:
|
if chart_name:
|
||||||
chart = frappe.get_doc("Dashboard Chart", chart_name)
|
chart = frappe.get_doc('Dashboard Chart', chart_name)
|
||||||
else:
|
else:
|
||||||
chart = frappe._dict(frappe.parse_json(chart))
|
chart = frappe._dict(frappe.parse_json(chart))
|
||||||
timespan = chart.timespan
|
timespan = chart.timespan
|
||||||
|
|
||||||
if chart.timespan == "Select Date Range":
|
if chart.timespan == 'Select Date Range':
|
||||||
from_date = chart.from_date
|
from_date = chart.from_date
|
||||||
to_date = chart.to_date
|
to_date = chart.to_date
|
||||||
|
|
||||||
@@ -40,23 +32,17 @@ def get(
|
|||||||
company = filters.get("company")
|
company = filters.get("company")
|
||||||
|
|
||||||
if not account and chart_name:
|
if not account and chart_name:
|
||||||
frappe.throw(
|
frappe.throw(_("Account is not set for the dashboard chart {0}")
|
||||||
_("Account is not set for the dashboard chart {0}").format(
|
.format(get_link_to_form("Dashboard Chart", chart_name)))
|
||||||
get_link_to_form("Dashboard Chart", chart_name)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not frappe.db.exists("Account", account) and chart_name:
|
if not frappe.db.exists("Account", account) and chart_name:
|
||||||
frappe.throw(
|
frappe.throw(_("Account {0} does not exists in the dashboard chart {1}")
|
||||||
_("Account {0} does not exists in the dashboard chart {1}").format(
|
.format(account, get_link_to_form("Dashboard Chart", chart_name)))
|
||||||
account, get_link_to_form("Dashboard Chart", chart_name)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not to_date:
|
if not to_date:
|
||||||
to_date = nowdate()
|
to_date = nowdate()
|
||||||
if not from_date:
|
if not from_date:
|
||||||
if timegrain in ("Monthly", "Quarterly"):
|
if timegrain in ('Monthly', 'Quarterly'):
|
||||||
from_date = get_from_date_from_timespan(to_date, timespan)
|
from_date = get_from_date_from_timespan(to_date, timespan)
|
||||||
|
|
||||||
# fetch dates to plot
|
# fetch dates to plot
|
||||||
@@ -69,14 +55,16 @@ def get(
|
|||||||
result = build_result(account, dates, gl_entries)
|
result = build_result(account, dates, gl_entries)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"labels": [formatdate(r[0].strftime("%Y-%m-%d")) for r in result],
|
"labels": [formatdate(r[0].strftime('%Y-%m-%d')) for r in result],
|
||||||
"datasets": [{"name": account, "values": [r[1] for r in result]}],
|
"datasets": [{
|
||||||
|
"name": account,
|
||||||
|
"values": [r[1] for r in result]
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_result(account, dates, gl_entries):
|
def build_result(account, dates, gl_entries):
|
||||||
result = [[getdate(date), 0.0] for date in dates]
|
result = [[getdate(date), 0.0] for date in dates]
|
||||||
root_type = frappe.db.get_value("Account", account, "root_type")
|
root_type = frappe.db.get_value('Account', account, 'root_type')
|
||||||
|
|
||||||
# start with the first date
|
# start with the first date
|
||||||
date_index = 0
|
date_index = 0
|
||||||
@@ -91,34 +79,30 @@ def build_result(account, dates, gl_entries):
|
|||||||
result[date_index][1] += entry.debit - entry.credit
|
result[date_index][1] += entry.debit - entry.credit
|
||||||
|
|
||||||
# if account type is credit, switch balances
|
# if account type is credit, switch balances
|
||||||
if root_type not in ("Asset", "Expense"):
|
if root_type not in ('Asset', 'Expense'):
|
||||||
for r in result:
|
for r in result:
|
||||||
r[1] = -1 * r[1]
|
r[1] = -1 * r[1]
|
||||||
|
|
||||||
# for balance sheet accounts, the totals are cumulative
|
# for balance sheet accounts, the totals are cumulative
|
||||||
if root_type in ("Asset", "Liability", "Equity"):
|
if root_type in ('Asset', 'Liability', 'Equity'):
|
||||||
for i, r in enumerate(result):
|
for i, r in enumerate(result):
|
||||||
if i > 0:
|
if i > 0:
|
||||||
r[1] = r[1] + result[i - 1][1]
|
r[1] = r[1] + result[i-1][1]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_gl_entries(account, to_date):
|
def get_gl_entries(account, to_date):
|
||||||
child_accounts = get_descendants_of("Account", account, ignore_permissions=True)
|
child_accounts = get_descendants_of('Account', account, ignore_permissions=True)
|
||||||
child_accounts.append(account)
|
child_accounts.append(account)
|
||||||
|
|
||||||
return frappe.db.get_all(
|
return frappe.db.get_all('GL Entry',
|
||||||
"GL Entry",
|
fields = ['posting_date', 'debit', 'credit'],
|
||||||
fields=["posting_date", "debit", "credit"],
|
filters = [
|
||||||
filters=[
|
dict(posting_date = ('<', to_date)),
|
||||||
dict(posting_date=("<", to_date)),
|
dict(account = ('in', child_accounts)),
|
||||||
dict(account=("in", child_accounts)),
|
dict(voucher_type = ('!=', 'Period Closing Voucher'))
|
||||||
dict(voucher_type=("!=", "Period Closing Voucher")),
|
|
||||||
],
|
],
|
||||||
order_by="posting_date asc",
|
order_by = 'posting_date asc')
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_dates_from_timegrain(from_date, to_date, timegrain):
|
def get_dates_from_timegrain(from_date, to_date, timegrain):
|
||||||
days = months = years = 0
|
days = months = years = 0
|
||||||
@@ -133,8 +117,6 @@ def get_dates_from_timegrain(from_date, to_date, timegrain):
|
|||||||
|
|
||||||
dates = [get_period_ending(from_date, timegrain)]
|
dates = [get_period_ending(from_date, timegrain)]
|
||||||
while getdate(dates[-1]) < getdate(to_date):
|
while getdate(dates[-1]) < getdate(to_date):
|
||||||
date = get_period_ending(
|
date = get_period_ending(add_to_date(dates[-1], years=years, months=months, days=days), timegrain)
|
||||||
add_to_date(dates[-1], years=years, months=months, days=days), timegrain
|
|
||||||
)
|
|
||||||
dates.append(date)
|
dates.append(date)
|
||||||
return dates
|
return dates
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.email import sendmail_to_system_managers
|
from frappe.email import sendmail_to_system_managers
|
||||||
@@ -22,23 +24,20 @@ from erpnext.accounts.utils import get_account_currency
|
|||||||
|
|
||||||
|
|
||||||
def validate_service_stop_date(doc):
|
def validate_service_stop_date(doc):
|
||||||
"""Validates service_stop_date for Purchase Invoice and Sales Invoice"""
|
''' Validates service_stop_date for Purchase Invoice and Sales Invoice '''
|
||||||
|
|
||||||
enable_check = (
|
enable_check = "enable_deferred_revenue" \
|
||||||
"enable_deferred_revenue" if doc.doctype == "Sales Invoice" else "enable_deferred_expense"
|
if doc.doctype=="Sales Invoice" else "enable_deferred_expense"
|
||||||
)
|
|
||||||
|
|
||||||
old_stop_dates = {}
|
old_stop_dates = {}
|
||||||
old_doc = frappe.db.get_all(
|
old_doc = frappe.db.get_all("{0} Item".format(doc.doctype),
|
||||||
"{0} Item".format(doc.doctype), {"parent": doc.name}, ["name", "service_stop_date"]
|
{"parent": doc.name}, ["name", "service_stop_date"])
|
||||||
)
|
|
||||||
|
|
||||||
for d in old_doc:
|
for d in old_doc:
|
||||||
old_stop_dates[d.name] = d.service_stop_date or ""
|
old_stop_dates[d.name] = d.service_stop_date or ""
|
||||||
|
|
||||||
for item in doc.items:
|
for item in doc.items:
|
||||||
if not item.get(enable_check):
|
if not item.get(enable_check): continue
|
||||||
continue
|
|
||||||
|
|
||||||
if item.service_stop_date:
|
if item.service_stop_date:
|
||||||
if date_diff(item.service_stop_date, item.service_start_date) < 0:
|
if date_diff(item.service_stop_date, item.service_start_date) < 0:
|
||||||
@@ -47,31 +46,21 @@ def validate_service_stop_date(doc):
|
|||||||
if date_diff(item.service_stop_date, item.service_end_date) > 0:
|
if date_diff(item.service_stop_date, item.service_end_date) > 0:
|
||||||
frappe.throw(_("Service Stop Date cannot be after Service End Date"))
|
frappe.throw(_("Service Stop Date cannot be after Service End Date"))
|
||||||
|
|
||||||
if (
|
if old_stop_dates and old_stop_dates.get(item.name) and item.service_stop_date!=old_stop_dates.get(item.name):
|
||||||
old_stop_dates
|
|
||||||
and old_stop_dates.get(item.name)
|
|
||||||
and item.service_stop_date != old_stop_dates.get(item.name)
|
|
||||||
):
|
|
||||||
frappe.throw(_("Cannot change Service Stop Date for item in row {0}").format(item.idx))
|
frappe.throw(_("Cannot change Service Stop Date for item in row {0}").format(item.idx))
|
||||||
|
|
||||||
|
|
||||||
def build_conditions(process_type, account, company):
|
def build_conditions(process_type, account, company):
|
||||||
conditions = ""
|
conditions=''
|
||||||
deferred_account = (
|
deferred_account = "item.deferred_revenue_account" if process_type=="Income" else "item.deferred_expense_account"
|
||||||
"item.deferred_revenue_account" if process_type == "Income" else "item.deferred_expense_account"
|
|
||||||
)
|
|
||||||
|
|
||||||
if account:
|
if account:
|
||||||
conditions += "AND %s='%s'" % (deferred_account, account)
|
conditions += "AND %s='%s'"%(deferred_account, account)
|
||||||
elif company:
|
elif company:
|
||||||
conditions += f"AND p.company = {frappe.db.escape(company)}"
|
conditions += f"AND p.company = {frappe.db.escape(company)}"
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
def convert_deferred_expense_to_expense(deferred_process, start_date=None, end_date=None, conditions=''):
|
||||||
def convert_deferred_expense_to_expense(
|
|
||||||
deferred_process, start_date=None, end_date=None, conditions=""
|
|
||||||
):
|
|
||||||
# book the expense/income on the last day, but it will be trigger on the 1st of month at 12:00 AM
|
# book the expense/income on the last day, but it will be trigger on the 1st of month at 12:00 AM
|
||||||
|
|
||||||
if not start_date:
|
if not start_date:
|
||||||
@@ -80,19 +69,14 @@ def convert_deferred_expense_to_expense(
|
|||||||
end_date = add_days(today(), -1)
|
end_date = add_days(today(), -1)
|
||||||
|
|
||||||
# check for the purchase invoice for which GL entries has to be done
|
# check for the purchase invoice for which GL entries has to be done
|
||||||
invoices = frappe.db.sql_list(
|
invoices = frappe.db.sql_list('''
|
||||||
"""
|
|
||||||
select distinct item.parent
|
select distinct item.parent
|
||||||
from `tabPurchase Invoice Item` item, `tabPurchase Invoice` p
|
from `tabPurchase Invoice Item` item, `tabPurchase Invoice` p
|
||||||
where item.service_start_date<=%s and item.service_end_date>=%s
|
where item.service_start_date<=%s and item.service_end_date>=%s
|
||||||
and item.enable_deferred_expense = 1 and item.parent=p.name
|
and item.enable_deferred_expense = 1 and item.parent=p.name
|
||||||
and item.docstatus = 1 and ifnull(item.amount, 0) > 0
|
and item.docstatus = 1 and ifnull(item.amount, 0) > 0
|
||||||
{0}
|
{0}
|
||||||
""".format(
|
'''.format(conditions), (end_date, start_date)) #nosec
|
||||||
conditions
|
|
||||||
),
|
|
||||||
(end_date, start_date),
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
# For each invoice, book deferred expense
|
# For each invoice, book deferred expense
|
||||||
for invoice in invoices:
|
for invoice in invoices:
|
||||||
@@ -102,10 +86,7 @@ def convert_deferred_expense_to_expense(
|
|||||||
if frappe.flags.deferred_accounting_error:
|
if frappe.flags.deferred_accounting_error:
|
||||||
send_mail(deferred_process)
|
send_mail(deferred_process)
|
||||||
|
|
||||||
|
def convert_deferred_revenue_to_income(deferred_process, start_date=None, end_date=None, conditions=''):
|
||||||
def convert_deferred_revenue_to_income(
|
|
||||||
deferred_process, start_date=None, end_date=None, conditions=""
|
|
||||||
):
|
|
||||||
# book the expense/income on the last day, but it will be trigger on the 1st of month at 12:00 AM
|
# book the expense/income on the last day, but it will be trigger on the 1st of month at 12:00 AM
|
||||||
|
|
||||||
if not start_date:
|
if not start_date:
|
||||||
@@ -114,19 +95,14 @@ def convert_deferred_revenue_to_income(
|
|||||||
end_date = add_days(today(), -1)
|
end_date = add_days(today(), -1)
|
||||||
|
|
||||||
# check for the sales invoice for which GL entries has to be done
|
# check for the sales invoice for which GL entries has to be done
|
||||||
invoices = frappe.db.sql_list(
|
invoices = frappe.db.sql_list('''
|
||||||
"""
|
|
||||||
select distinct item.parent
|
select distinct item.parent
|
||||||
from `tabSales Invoice Item` item, `tabSales Invoice` p
|
from `tabSales Invoice Item` item, `tabSales Invoice` p
|
||||||
where item.service_start_date<=%s and item.service_end_date>=%s
|
where item.service_start_date<=%s and item.service_end_date>=%s
|
||||||
and item.enable_deferred_revenue = 1 and item.parent=p.name
|
and item.enable_deferred_revenue = 1 and item.parent=p.name
|
||||||
and item.docstatus = 1 and ifnull(item.amount, 0) > 0
|
and item.docstatus = 1 and ifnull(item.amount, 0) > 0
|
||||||
{0}
|
{0}
|
||||||
""".format(
|
'''.format(conditions), (end_date, start_date)) #nosec
|
||||||
conditions
|
|
||||||
),
|
|
||||||
(end_date, start_date),
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
for invoice in invoices:
|
for invoice in invoices:
|
||||||
doc = frappe.get_doc("Sales Invoice", invoice)
|
doc = frappe.get_doc("Sales Invoice", invoice)
|
||||||
@@ -135,43 +111,30 @@ def convert_deferred_revenue_to_income(
|
|||||||
if frappe.flags.deferred_accounting_error:
|
if frappe.flags.deferred_accounting_error:
|
||||||
send_mail(deferred_process)
|
send_mail(deferred_process)
|
||||||
|
|
||||||
|
|
||||||
def get_booking_dates(doc, item, posting_date=None):
|
def get_booking_dates(doc, item, posting_date=None):
|
||||||
if not posting_date:
|
if not posting_date:
|
||||||
posting_date = add_days(today(), -1)
|
posting_date = add_days(today(), -1)
|
||||||
|
|
||||||
last_gl_entry = False
|
last_gl_entry = False
|
||||||
|
|
||||||
deferred_account = (
|
deferred_account = "deferred_revenue_account" if doc.doctype=="Sales Invoice" else "deferred_expense_account"
|
||||||
"deferred_revenue_account" if doc.doctype == "Sales Invoice" else "deferred_expense_account"
|
|
||||||
)
|
|
||||||
|
|
||||||
prev_gl_entry = frappe.db.sql(
|
prev_gl_entry = frappe.db.sql('''
|
||||||
"""
|
|
||||||
select name, posting_date from `tabGL Entry` where company=%s and account=%s and
|
select name, posting_date from `tabGL Entry` where company=%s and account=%s and
|
||||||
voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
|
voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
|
||||||
and is_cancelled = 0
|
|
||||||
order by posting_date desc limit 1
|
order by posting_date desc limit 1
|
||||||
""",
|
''', (doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True)
|
||||||
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name),
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
prev_gl_via_je = frappe.db.sql(
|
prev_gl_via_je = frappe.db.sql('''
|
||||||
"""
|
|
||||||
SELECT p.name, p.posting_date FROM `tabJournal Entry` p, `tabJournal Entry Account` c
|
SELECT p.name, p.posting_date FROM `tabJournal Entry` p, `tabJournal Entry Account` c
|
||||||
WHERE p.name = c.parent and p.company=%s and c.account=%s
|
WHERE p.name = c.parent and p.company=%s and c.account=%s
|
||||||
and c.reference_type=%s and c.reference_name=%s
|
and c.reference_type=%s and c.reference_name=%s
|
||||||
and c.reference_detail_no=%s and c.docstatus < 2 order by posting_date desc limit 1
|
and c.reference_detail_no=%s and c.docstatus < 2 order by posting_date desc limit 1
|
||||||
""",
|
''', (doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True)
|
||||||
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name),
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if prev_gl_via_je:
|
if prev_gl_via_je:
|
||||||
if (not prev_gl_entry) or (
|
if (not prev_gl_entry) or (prev_gl_entry and
|
||||||
prev_gl_entry and prev_gl_entry[0].posting_date < prev_gl_via_je[0].posting_date
|
prev_gl_entry[0].posting_date < prev_gl_via_je[0].posting_date):
|
||||||
):
|
|
||||||
prev_gl_entry = prev_gl_via_je
|
prev_gl_entry = prev_gl_via_je
|
||||||
|
|
||||||
if prev_gl_entry:
|
if prev_gl_entry:
|
||||||
@@ -195,94 +158,66 @@ def get_booking_dates(doc, item, posting_date=None):
|
|||||||
else:
|
else:
|
||||||
return None, None, None
|
return None, None, None
|
||||||
|
|
||||||
|
def calculate_monthly_amount(doc, item, last_gl_entry, start_date, end_date, total_days, total_booking_days, account_currency):
|
||||||
def calculate_monthly_amount(
|
|
||||||
doc, item, last_gl_entry, start_date, end_date, total_days, total_booking_days, account_currency
|
|
||||||
):
|
|
||||||
amount, base_amount = 0, 0
|
amount, base_amount = 0, 0
|
||||||
|
|
||||||
if not last_gl_entry:
|
if not last_gl_entry:
|
||||||
total_months = (
|
total_months = (item.service_end_date.year - item.service_start_date.year) * 12 + \
|
||||||
(item.service_end_date.year - item.service_start_date.year) * 12
|
(item.service_end_date.month - item.service_start_date.month) + 1
|
||||||
+ (item.service_end_date.month - item.service_start_date.month)
|
|
||||||
+ 1
|
|
||||||
)
|
|
||||||
|
|
||||||
prorate_factor = flt(date_diff(item.service_end_date, item.service_start_date)) / flt(
|
prorate_factor = flt(date_diff(item.service_end_date, item.service_start_date)) \
|
||||||
date_diff(get_last_day(item.service_end_date), get_first_day(item.service_start_date))
|
/ flt(date_diff(get_last_day(item.service_end_date), get_first_day(item.service_start_date)))
|
||||||
)
|
|
||||||
|
|
||||||
actual_months = rounded(total_months * prorate_factor, 1)
|
actual_months = rounded(total_months * prorate_factor, 1)
|
||||||
|
|
||||||
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(
|
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(doc, item)
|
||||||
doc, item
|
|
||||||
)
|
|
||||||
base_amount = flt(item.base_net_amount / actual_months, item.precision("base_net_amount"))
|
base_amount = flt(item.base_net_amount / actual_months, item.precision("base_net_amount"))
|
||||||
|
|
||||||
if base_amount + already_booked_amount > item.base_net_amount:
|
if base_amount + already_booked_amount > item.base_net_amount:
|
||||||
base_amount = item.base_net_amount - already_booked_amount
|
base_amount = item.base_net_amount - already_booked_amount
|
||||||
|
|
||||||
if account_currency == doc.company_currency:
|
if account_currency==doc.company_currency:
|
||||||
amount = base_amount
|
amount = base_amount
|
||||||
else:
|
else:
|
||||||
amount = flt(item.net_amount / actual_months, item.precision("net_amount"))
|
amount = flt(item.net_amount/actual_months, item.precision("net_amount"))
|
||||||
if amount + already_booked_amount_in_account_currency > item.net_amount:
|
if amount + already_booked_amount_in_account_currency > item.net_amount:
|
||||||
amount = item.net_amount - already_booked_amount_in_account_currency
|
amount = item.net_amount - already_booked_amount_in_account_currency
|
||||||
|
|
||||||
if not (get_first_day(start_date) == start_date and get_last_day(end_date) == end_date):
|
if not (get_first_day(start_date) == start_date and get_last_day(end_date) == end_date):
|
||||||
partial_month = flt(date_diff(end_date, start_date)) / flt(
|
partial_month = flt(date_diff(end_date, start_date)) \
|
||||||
date_diff(get_last_day(end_date), get_first_day(start_date))
|
/ flt(date_diff(get_last_day(end_date), get_first_day(start_date)))
|
||||||
)
|
|
||||||
|
|
||||||
base_amount = rounded(partial_month, 1) * base_amount
|
base_amount = rounded(partial_month, 1) * base_amount
|
||||||
amount = rounded(partial_month, 1) * amount
|
amount = rounded(partial_month, 1) * amount
|
||||||
else:
|
else:
|
||||||
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(
|
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(doc, item)
|
||||||
doc, item
|
base_amount = flt(item.base_net_amount - already_booked_amount, item.precision("base_net_amount"))
|
||||||
)
|
if account_currency==doc.company_currency:
|
||||||
base_amount = flt(
|
|
||||||
item.base_net_amount - already_booked_amount, item.precision("base_net_amount")
|
|
||||||
)
|
|
||||||
if account_currency == doc.company_currency:
|
|
||||||
amount = base_amount
|
amount = base_amount
|
||||||
else:
|
else:
|
||||||
amount = flt(
|
amount = flt(item.net_amount - already_booked_amount_in_account_currency, item.precision("net_amount"))
|
||||||
item.net_amount - already_booked_amount_in_account_currency, item.precision("net_amount")
|
|
||||||
)
|
|
||||||
|
|
||||||
return amount, base_amount
|
return amount, base_amount
|
||||||
|
|
||||||
|
|
||||||
def calculate_amount(doc, item, last_gl_entry, total_days, total_booking_days, account_currency):
|
def calculate_amount(doc, item, last_gl_entry, total_days, total_booking_days, account_currency):
|
||||||
amount, base_amount = 0, 0
|
amount, base_amount = 0, 0
|
||||||
if not last_gl_entry:
|
if not last_gl_entry:
|
||||||
base_amount = flt(
|
base_amount = flt(item.base_net_amount*total_booking_days/flt(total_days), item.precision("base_net_amount"))
|
||||||
item.base_net_amount * total_booking_days / flt(total_days), item.precision("base_net_amount")
|
if account_currency==doc.company_currency:
|
||||||
)
|
|
||||||
if account_currency == doc.company_currency:
|
|
||||||
amount = base_amount
|
amount = base_amount
|
||||||
else:
|
else:
|
||||||
amount = flt(
|
amount = flt(item.net_amount*total_booking_days/flt(total_days), item.precision("net_amount"))
|
||||||
item.net_amount * total_booking_days / flt(total_days), item.precision("net_amount")
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(
|
already_booked_amount, already_booked_amount_in_account_currency = get_already_booked_amount(doc, item)
|
||||||
doc, item
|
|
||||||
)
|
|
||||||
|
|
||||||
base_amount = flt(
|
base_amount = flt(item.base_net_amount - already_booked_amount, item.precision("base_net_amount"))
|
||||||
item.base_net_amount - already_booked_amount, item.precision("base_net_amount")
|
if account_currency==doc.company_currency:
|
||||||
)
|
|
||||||
if account_currency == doc.company_currency:
|
|
||||||
amount = base_amount
|
amount = base_amount
|
||||||
else:
|
else:
|
||||||
amount = flt(
|
amount = flt(item.net_amount - already_booked_amount_in_account_currency, item.precision("net_amount"))
|
||||||
item.net_amount - already_booked_amount_in_account_currency, item.precision("net_amount")
|
|
||||||
)
|
|
||||||
|
|
||||||
return amount, base_amount
|
return amount, base_amount
|
||||||
|
|
||||||
|
|
||||||
def get_already_booked_amount(doc, item):
|
def get_already_booked_amount(doc, item):
|
||||||
if doc.doctype == "Sales Invoice":
|
if doc.doctype == "Sales Invoice":
|
||||||
total_credit_debit, total_credit_debit_currency = "debit", "debit_in_account_currency"
|
total_credit_debit, total_credit_debit_currency = "debit", "debit_in_account_currency"
|
||||||
@@ -291,31 +226,20 @@ def get_already_booked_amount(doc, item):
|
|||||||
total_credit_debit, total_credit_debit_currency = "credit", "credit_in_account_currency"
|
total_credit_debit, total_credit_debit_currency = "credit", "credit_in_account_currency"
|
||||||
deferred_account = "deferred_expense_account"
|
deferred_account = "deferred_expense_account"
|
||||||
|
|
||||||
gl_entries_details = frappe.db.sql(
|
gl_entries_details = frappe.db.sql('''
|
||||||
"""
|
|
||||||
select sum({0}) as total_credit, sum({1}) as total_credit_in_account_currency, voucher_detail_no
|
select sum({0}) as total_credit, sum({1}) as total_credit_in_account_currency, voucher_detail_no
|
||||||
from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
|
from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
|
||||||
and is_cancelled = 0
|
|
||||||
group by voucher_detail_no
|
group by voucher_detail_no
|
||||||
""".format(
|
'''.format(total_credit_debit, total_credit_debit_currency),
|
||||||
total_credit_debit, total_credit_debit_currency
|
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True)
|
||||||
),
|
|
||||||
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name),
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
journal_entry_details = frappe.db.sql(
|
journal_entry_details = frappe.db.sql('''
|
||||||
"""
|
|
||||||
SELECT sum(c.{0}) as total_credit, sum(c.{1}) as total_credit_in_account_currency, reference_detail_no
|
SELECT sum(c.{0}) as total_credit, sum(c.{1}) as total_credit_in_account_currency, reference_detail_no
|
||||||
FROM `tabJournal Entry` p , `tabJournal Entry Account` c WHERE p.name = c.parent and
|
FROM `tabJournal Entry` p , `tabJournal Entry Account` c WHERE p.name = c.parent and
|
||||||
p.company = %s and c.account=%s and c.reference_type=%s and c.reference_name=%s and c.reference_detail_no=%s
|
p.company = %s and c.account=%s and c.reference_type=%s and c.reference_name=%s and c.reference_detail_no=%s
|
||||||
and p.docstatus < 2 group by reference_detail_no
|
and p.docstatus < 2 group by reference_detail_no
|
||||||
""".format(
|
'''.format(total_credit_debit, total_credit_debit_currency),
|
||||||
total_credit_debit, total_credit_debit_currency
|
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True)
|
||||||
),
|
|
||||||
(doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name),
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
already_booked_amount = gl_entries_details[0].total_credit if gl_entries_details else 0
|
already_booked_amount = gl_entries_details[0].total_credit if gl_entries_details else 0
|
||||||
already_booked_amount += journal_entry_details[0].total_credit if journal_entry_details else 0
|
already_booked_amount += journal_entry_details[0].total_credit if journal_entry_details else 0
|
||||||
@@ -323,31 +247,20 @@ def get_already_booked_amount(doc, item):
|
|||||||
if doc.currency == doc.company_currency:
|
if doc.currency == doc.company_currency:
|
||||||
already_booked_amount_in_account_currency = already_booked_amount
|
already_booked_amount_in_account_currency = already_booked_amount
|
||||||
else:
|
else:
|
||||||
already_booked_amount_in_account_currency = (
|
already_booked_amount_in_account_currency = gl_entries_details[0].total_credit_in_account_currency if gl_entries_details else 0
|
||||||
gl_entries_details[0].total_credit_in_account_currency if gl_entries_details else 0
|
already_booked_amount_in_account_currency += journal_entry_details[0].total_credit_in_account_currency if journal_entry_details else 0
|
||||||
)
|
|
||||||
already_booked_amount_in_account_currency += (
|
|
||||||
journal_entry_details[0].total_credit_in_account_currency if journal_entry_details else 0
|
|
||||||
)
|
|
||||||
|
|
||||||
return already_booked_amount, already_booked_amount_in_account_currency
|
return already_booked_amount, already_booked_amount_in_account_currency
|
||||||
|
|
||||||
|
|
||||||
def book_deferred_income_or_expense(doc, deferred_process, posting_date=None):
|
def book_deferred_income_or_expense(doc, deferred_process, posting_date=None):
|
||||||
enable_check = (
|
enable_check = "enable_deferred_revenue" \
|
||||||
"enable_deferred_revenue" if doc.doctype == "Sales Invoice" else "enable_deferred_expense"
|
if doc.doctype=="Sales Invoice" else "enable_deferred_expense"
|
||||||
)
|
|
||||||
|
|
||||||
accounts_frozen_upto = frappe.get_cached_value("Accounts Settings", "None", "acc_frozen_upto")
|
def _book_deferred_revenue_or_expense(item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on):
|
||||||
|
|
||||||
def _book_deferred_revenue_or_expense(
|
|
||||||
item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on
|
|
||||||
):
|
|
||||||
start_date, end_date, last_gl_entry = get_booking_dates(doc, item, posting_date=posting_date)
|
start_date, end_date, last_gl_entry = get_booking_dates(doc, item, posting_date=posting_date)
|
||||||
if not (start_date and end_date):
|
if not (start_date and end_date): return
|
||||||
return
|
|
||||||
|
|
||||||
account_currency = get_account_currency(item.expense_account or item.income_account)
|
account_currency = get_account_currency(item.expense_account)
|
||||||
if doc.doctype == "Sales Invoice":
|
if doc.doctype == "Sales Invoice":
|
||||||
against, project = doc.customer, doc.project
|
against, project = doc.customer, doc.project
|
||||||
credit_account, debit_account = item.income_account, item.deferred_revenue_account
|
credit_account, debit_account = item.income_account, item.deferred_revenue_account
|
||||||
@@ -358,179 +271,103 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None):
|
|||||||
total_days = date_diff(item.service_end_date, item.service_start_date) + 1
|
total_days = date_diff(item.service_end_date, item.service_start_date) + 1
|
||||||
total_booking_days = date_diff(end_date, start_date) + 1
|
total_booking_days = date_diff(end_date, start_date) + 1
|
||||||
|
|
||||||
if book_deferred_entries_based_on == "Months":
|
if book_deferred_entries_based_on == 'Months':
|
||||||
amount, base_amount = calculate_monthly_amount(
|
amount, base_amount = calculate_monthly_amount(doc, item, last_gl_entry,
|
||||||
doc,
|
start_date, end_date, total_days, total_booking_days, account_currency)
|
||||||
item,
|
|
||||||
last_gl_entry,
|
|
||||||
start_date,
|
|
||||||
end_date,
|
|
||||||
total_days,
|
|
||||||
total_booking_days,
|
|
||||||
account_currency,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
amount, base_amount = calculate_amount(
|
amount, base_amount = calculate_amount(doc, item, last_gl_entry,
|
||||||
doc, item, last_gl_entry, total_days, total_booking_days, account_currency
|
total_days, total_booking_days, account_currency)
|
||||||
)
|
|
||||||
|
|
||||||
if not amount:
|
if not amount:
|
||||||
return
|
return
|
||||||
|
|
||||||
# check if books nor frozen till endate:
|
|
||||||
if accounts_frozen_upto and getdate(end_date) <= getdate(accounts_frozen_upto):
|
|
||||||
end_date = get_last_day(add_days(accounts_frozen_upto, 1))
|
|
||||||
|
|
||||||
if via_journal_entry:
|
if via_journal_entry:
|
||||||
book_revenue_via_journal_entry(
|
book_revenue_via_journal_entry(doc, credit_account, debit_account, against, amount,
|
||||||
doc,
|
base_amount, end_date, project, account_currency, item.cost_center, item, deferred_process, submit_journal_entry)
|
||||||
credit_account,
|
|
||||||
debit_account,
|
|
||||||
amount,
|
|
||||||
base_amount,
|
|
||||||
end_date,
|
|
||||||
project,
|
|
||||||
account_currency,
|
|
||||||
item.cost_center,
|
|
||||||
item,
|
|
||||||
deferred_process,
|
|
||||||
submit_journal_entry,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
make_gl_entries(
|
make_gl_entries(doc, credit_account, debit_account, against,
|
||||||
doc,
|
amount, base_amount, end_date, project, account_currency, item.cost_center, item, deferred_process)
|
||||||
credit_account,
|
|
||||||
debit_account,
|
|
||||||
against,
|
|
||||||
amount,
|
|
||||||
base_amount,
|
|
||||||
end_date,
|
|
||||||
project,
|
|
||||||
account_currency,
|
|
||||||
item.cost_center,
|
|
||||||
item,
|
|
||||||
deferred_process,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Returned in case of any errors because it tries to submit the same record again and again in case of errors
|
# Returned in case of any errors because it tries to submit the same record again and again in case of errors
|
||||||
if frappe.flags.deferred_accounting_error:
|
if frappe.flags.deferred_accounting_error:
|
||||||
return
|
return
|
||||||
|
|
||||||
if getdate(end_date) < getdate(posting_date) and not last_gl_entry:
|
if getdate(end_date) < getdate(posting_date) and not last_gl_entry:
|
||||||
_book_deferred_revenue_or_expense(
|
_book_deferred_revenue_or_expense(item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on)
|
||||||
item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on
|
|
||||||
)
|
|
||||||
|
|
||||||
via_journal_entry = cint(
|
via_journal_entry = cint(frappe.db.get_singles_value('Accounts Settings', 'book_deferred_entries_via_journal_entry'))
|
||||||
frappe.db.get_singles_value("Accounts Settings", "book_deferred_entries_via_journal_entry")
|
submit_journal_entry = cint(frappe.db.get_singles_value('Accounts Settings', 'submit_journal_entries'))
|
||||||
)
|
book_deferred_entries_based_on = frappe.db.get_singles_value('Accounts Settings', 'book_deferred_entries_based_on')
|
||||||
submit_journal_entry = cint(
|
|
||||||
frappe.db.get_singles_value("Accounts Settings", "submit_journal_entries")
|
|
||||||
)
|
|
||||||
book_deferred_entries_based_on = frappe.db.get_singles_value(
|
|
||||||
"Accounts Settings", "book_deferred_entries_based_on"
|
|
||||||
)
|
|
||||||
|
|
||||||
for item in doc.get("items"):
|
for item in doc.get('items'):
|
||||||
if item.get(enable_check):
|
if item.get(enable_check):
|
||||||
_book_deferred_revenue_or_expense(
|
_book_deferred_revenue_or_expense(item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on)
|
||||||
item, via_journal_entry, submit_journal_entry, book_deferred_entries_based_on
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def process_deferred_accounting(posting_date=None):
|
def process_deferred_accounting(posting_date=None):
|
||||||
"""Converts deferred income/expense into income/expense
|
''' Converts deferred income/expense into income/expense
|
||||||
Executed via background jobs on every month end"""
|
Executed via background jobs on every month end '''
|
||||||
|
|
||||||
if not posting_date:
|
if not posting_date:
|
||||||
posting_date = today()
|
posting_date = today()
|
||||||
|
|
||||||
if not cint(
|
if not cint(frappe.db.get_singles_value('Accounts Settings', 'automatically_process_deferred_accounting_entry')):
|
||||||
frappe.db.get_singles_value(
|
|
||||||
"Accounts Settings", "automatically_process_deferred_accounting_entry"
|
|
||||||
)
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
start_date = add_months(today(), -1)
|
start_date = add_months(today(), -1)
|
||||||
end_date = add_days(today(), -1)
|
end_date = add_days(today(), -1)
|
||||||
|
|
||||||
companies = frappe.get_all("Company")
|
companies = frappe.get_all('Company')
|
||||||
|
|
||||||
for company in companies:
|
for company in companies:
|
||||||
for record_type in ("Income", "Expense"):
|
for record_type in ('Income', 'Expense'):
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc(dict(
|
||||||
dict(
|
doctype='Process Deferred Accounting',
|
||||||
doctype="Process Deferred Accounting",
|
company=company.name,
|
||||||
company=company.name,
|
posting_date=posting_date,
|
||||||
posting_date=posting_date,
|
start_date=start_date,
|
||||||
start_date=start_date,
|
end_date=end_date,
|
||||||
end_date=end_date,
|
type=record_type
|
||||||
type=record_type,
|
))
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
doc.insert()
|
doc.insert()
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
|
def make_gl_entries(doc, credit_account, debit_account, against,
|
||||||
def make_gl_entries(
|
amount, base_amount, posting_date, project, account_currency, cost_center, item, deferred_process=None):
|
||||||
doc,
|
|
||||||
credit_account,
|
|
||||||
debit_account,
|
|
||||||
against,
|
|
||||||
amount,
|
|
||||||
base_amount,
|
|
||||||
posting_date,
|
|
||||||
project,
|
|
||||||
account_currency,
|
|
||||||
cost_center,
|
|
||||||
item,
|
|
||||||
deferred_process=None,
|
|
||||||
):
|
|
||||||
# GL Entry for crediting the amount in the deferred expense
|
# GL Entry for crediting the amount in the deferred expense
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
|
|
||||||
if amount == 0:
|
if amount == 0: return
|
||||||
return
|
|
||||||
|
|
||||||
gl_entries = []
|
gl_entries = []
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
doc.get_gl_dict(
|
doc.get_gl_dict({
|
||||||
{
|
"account": credit_account,
|
||||||
"account": credit_account,
|
"against": against,
|
||||||
"against": against,
|
"credit": base_amount,
|
||||||
"credit": base_amount,
|
"credit_in_account_currency": amount,
|
||||||
"credit_in_account_currency": amount,
|
"cost_center": cost_center,
|
||||||
"cost_center": cost_center,
|
"voucher_detail_no": item.name,
|
||||||
"voucher_detail_no": item.name,
|
'posting_date': posting_date,
|
||||||
"posting_date": posting_date,
|
'project': project,
|
||||||
"project": project,
|
'against_voucher_type': 'Process Deferred Accounting',
|
||||||
"against_voucher_type": "Process Deferred Accounting",
|
'against_voucher': deferred_process
|
||||||
"against_voucher": deferred_process,
|
}, account_currency, item=item)
|
||||||
},
|
|
||||||
account_currency,
|
|
||||||
item=item,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# GL Entry to debit the amount from the expense
|
# GL Entry to debit the amount from the expense
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
doc.get_gl_dict(
|
doc.get_gl_dict({
|
||||||
{
|
"account": debit_account,
|
||||||
"account": debit_account,
|
"against": against,
|
||||||
"against": against,
|
"debit": base_amount,
|
||||||
"debit": base_amount,
|
"debit_in_account_currency": amount,
|
||||||
"debit_in_account_currency": amount,
|
"cost_center": cost_center,
|
||||||
"cost_center": cost_center,
|
"voucher_detail_no": item.name,
|
||||||
"voucher_detail_no": item.name,
|
'posting_date': posting_date,
|
||||||
"posting_date": posting_date,
|
'project': project,
|
||||||
"project": project,
|
'against_voucher_type': 'Process Deferred Accounting',
|
||||||
"against_voucher_type": "Process Deferred Accounting",
|
'against_voucher': deferred_process
|
||||||
"against_voucher": deferred_process,
|
}, account_currency, item=item)
|
||||||
},
|
|
||||||
account_currency,
|
|
||||||
item=item,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if gl_entries:
|
if gl_entries:
|
||||||
@@ -539,124 +376,95 @@ def make_gl_entries(
|
|||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
traceback = frappe.get_traceback()
|
|
||||||
frappe.log_error(
|
|
||||||
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
|
|
||||||
message=traceback,
|
|
||||||
)
|
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
traceback = frappe.get_traceback()
|
traceback = frappe.get_traceback()
|
||||||
frappe.log_error(
|
frappe.log_error(message=traceback)
|
||||||
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
|
|
||||||
message=traceback,
|
|
||||||
)
|
|
||||||
frappe.flags.deferred_accounting_error = True
|
|
||||||
|
|
||||||
|
frappe.flags.deferred_accounting_error = True
|
||||||
|
|
||||||
def send_mail(deferred_process):
|
def send_mail(deferred_process):
|
||||||
title = _("Error while processing deferred accounting for {0}").format(deferred_process)
|
title = _("Error while processing deferred accounting for {0}").format(deferred_process)
|
||||||
link = get_link_to_form("Process Deferred Accounting", deferred_process)
|
link = get_link_to_form('Process Deferred Accounting', deferred_process)
|
||||||
content = _("Deferred accounting failed for some invoices:") + "\n"
|
content = _("Deferred accounting failed for some invoices:") + "\n"
|
||||||
content += _(
|
content += _("Please check Process Deferred Accounting {0} and submit manually after resolving errors.").format(link)
|
||||||
"Please check Process Deferred Accounting {0} and submit manually after resolving errors."
|
|
||||||
).format(link)
|
|
||||||
sendmail_to_system_managers(title, content)
|
sendmail_to_system_managers(title, content)
|
||||||
|
|
||||||
|
def book_revenue_via_journal_entry(doc, credit_account, debit_account, against,
|
||||||
|
amount, base_amount, posting_date, project, account_currency, cost_center, item,
|
||||||
|
deferred_process=None, submit='No'):
|
||||||
|
|
||||||
def book_revenue_via_journal_entry(
|
if amount == 0: return
|
||||||
doc,
|
|
||||||
credit_account,
|
|
||||||
debit_account,
|
|
||||||
amount,
|
|
||||||
base_amount,
|
|
||||||
posting_date,
|
|
||||||
project,
|
|
||||||
account_currency,
|
|
||||||
cost_center,
|
|
||||||
item,
|
|
||||||
deferred_process=None,
|
|
||||||
submit="No",
|
|
||||||
):
|
|
||||||
|
|
||||||
if amount == 0:
|
journal_entry = frappe.new_doc('Journal Entry')
|
||||||
return
|
|
||||||
|
|
||||||
journal_entry = frappe.new_doc("Journal Entry")
|
|
||||||
journal_entry.posting_date = posting_date
|
journal_entry.posting_date = posting_date
|
||||||
journal_entry.company = doc.company
|
journal_entry.company = doc.company
|
||||||
journal_entry.voucher_type = (
|
journal_entry.voucher_type = 'Deferred Revenue' if doc.doctype == 'Sales Invoice' \
|
||||||
"Deferred Revenue" if doc.doctype == "Sales Invoice" else "Deferred Expense"
|
else 'Deferred Expense'
|
||||||
)
|
|
||||||
journal_entry.process_deferred_accounting = deferred_process
|
|
||||||
|
|
||||||
debit_entry = {
|
debit_entry = {
|
||||||
"account": credit_account,
|
'account': credit_account,
|
||||||
"credit": base_amount,
|
'credit': base_amount,
|
||||||
"credit_in_account_currency": amount,
|
'credit_in_account_currency': amount,
|
||||||
"account_currency": account_currency,
|
'party_type': 'Customer' if doc.doctype == 'Sales Invoice' else 'Supplier',
|
||||||
"reference_name": doc.name,
|
'party': against,
|
||||||
"reference_type": doc.doctype,
|
'account_currency': account_currency,
|
||||||
"reference_detail_no": item.name,
|
'reference_name': doc.name,
|
||||||
"cost_center": cost_center,
|
'reference_type': doc.doctype,
|
||||||
"project": project,
|
'reference_detail_no': item.name,
|
||||||
|
'cost_center': cost_center,
|
||||||
|
'project': project,
|
||||||
}
|
}
|
||||||
|
|
||||||
credit_entry = {
|
credit_entry = {
|
||||||
"account": debit_account,
|
'account': debit_account,
|
||||||
"debit": base_amount,
|
'debit': base_amount,
|
||||||
"debit_in_account_currency": amount,
|
'debit_in_account_currency': amount,
|
||||||
"account_currency": account_currency,
|
'party_type': 'Customer' if doc.doctype == 'Sales Invoice' else 'Supplier',
|
||||||
"reference_name": doc.name,
|
'party': against,
|
||||||
"reference_type": doc.doctype,
|
'account_currency': account_currency,
|
||||||
"reference_detail_no": item.name,
|
'reference_name': doc.name,
|
||||||
"cost_center": cost_center,
|
'reference_type': doc.doctype,
|
||||||
"project": project,
|
'reference_detail_no': item.name,
|
||||||
|
'cost_center': cost_center,
|
||||||
|
'project': project,
|
||||||
}
|
}
|
||||||
|
|
||||||
for dimension in get_accounting_dimensions():
|
for dimension in get_accounting_dimensions():
|
||||||
debit_entry.update({dimension: item.get(dimension)})
|
debit_entry.update({
|
||||||
|
dimension: item.get(dimension)
|
||||||
|
})
|
||||||
|
|
||||||
credit_entry.update({dimension: item.get(dimension)})
|
credit_entry.update({
|
||||||
|
dimension: item.get(dimension)
|
||||||
|
})
|
||||||
|
|
||||||
journal_entry.append("accounts", debit_entry)
|
journal_entry.append('accounts', debit_entry)
|
||||||
journal_entry.append("accounts", credit_entry)
|
journal_entry.append('accounts', credit_entry)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
journal_entry.save()
|
journal_entry.save()
|
||||||
|
|
||||||
if submit:
|
if submit:
|
||||||
journal_entry.submit()
|
journal_entry.submit()
|
||||||
|
|
||||||
frappe.db.commit()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
traceback = frappe.get_traceback()
|
traceback = frappe.get_traceback()
|
||||||
frappe.log_error(
|
frappe.log_error(message=traceback)
|
||||||
title=_("Error while processing deferred accounting for Invoice {0}").format(doc.name),
|
|
||||||
message=traceback,
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.flags.deferred_accounting_error = True
|
frappe.flags.deferred_accounting_error = True
|
||||||
|
|
||||||
|
|
||||||
def get_deferred_booking_accounts(doctype, voucher_detail_no, dr_or_cr):
|
def get_deferred_booking_accounts(doctype, voucher_detail_no, dr_or_cr):
|
||||||
|
|
||||||
if doctype == "Sales Invoice":
|
if doctype == 'Sales Invoice':
|
||||||
credit_account, debit_account = frappe.db.get_value(
|
credit_account, debit_account = frappe.db.get_value('Sales Invoice Item', {'name': voucher_detail_no},
|
||||||
"Sales Invoice Item",
|
['income_account', 'deferred_revenue_account'])
|
||||||
{"name": voucher_detail_no},
|
|
||||||
["income_account", "deferred_revenue_account"],
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
credit_account, debit_account = frappe.db.get_value(
|
credit_account, debit_account = frappe.db.get_value('Purchase Invoice Item', {'name': voucher_detail_no},
|
||||||
"Purchase Invoice Item",
|
['deferred_expense_account', 'expense_account'])
|
||||||
{"name": voucher_detail_no},
|
|
||||||
["deferred_expense_account", "expense_account"],
|
|
||||||
)
|
|
||||||
|
|
||||||
if dr_or_cr == "Debit":
|
if dr_or_cr == 'Debit':
|
||||||
return debit_account
|
return debit_account
|
||||||
else:
|
else:
|
||||||
return credit_account
|
return credit_account
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ frappe.ui.form.on('Account', {
|
|||||||
frm.trigger('add_toolbar_buttons');
|
frm.trigger('add_toolbar_buttons');
|
||||||
}
|
}
|
||||||
if (frm.has_perm('write')) {
|
if (frm.has_perm('write')) {
|
||||||
frm.add_custom_button(__('Merge Account'), function () {
|
|
||||||
frm.trigger("merge_account");
|
|
||||||
}, __('Actions'));
|
|
||||||
frm.add_custom_button(__('Update Account Name / Number'), function () {
|
frm.add_custom_button(__('Update Account Name / Number'), function () {
|
||||||
frm.trigger("update_account_number");
|
frm.trigger("update_account_number");
|
||||||
}, __('Actions'));
|
});
|
||||||
|
frm.add_custom_button(__('Merge Account'), function () {
|
||||||
|
frm.trigger("merge_account");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -59,12 +59,11 @@ frappe.ui.form.on('Account', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
add_toolbar_buttons: function(frm) {
|
add_toolbar_buttons: function(frm) {
|
||||||
frm.add_custom_button(__('Chart of Accounts'), () => {
|
frm.add_custom_button(__('Chart of Accounts'),
|
||||||
frappe.set_route("Tree", "Account");
|
function () { frappe.set_route("Tree", "Account"); });
|
||||||
}, __('View'));
|
|
||||||
|
|
||||||
if (frm.doc.is_group == 1) {
|
if (frm.doc.is_group == 1) {
|
||||||
frm.add_custom_button(__('Convert to Non-Group'), function () {
|
frm.add_custom_button(__('Group to Non-Group'), function () {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
doc: frm.doc,
|
doc: frm.doc,
|
||||||
method: 'convert_group_to_ledger',
|
method: 'convert_group_to_ledger',
|
||||||
@@ -72,11 +71,10 @@ frappe.ui.form.on('Account', {
|
|||||||
frm.refresh();
|
frm.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, __('Actions'));
|
});
|
||||||
|
|
||||||
} else if (cint(frm.doc.is_group) == 0
|
} else if (cint(frm.doc.is_group) == 0
|
||||||
&& frappe.boot.user.can_read.indexOf("GL Entry") !== -1) {
|
&& frappe.boot.user.can_read.indexOf("GL Entry") !== -1) {
|
||||||
frm.add_custom_button(__('General Ledger'), function () {
|
frm.add_custom_button(__('Ledger'), function () {
|
||||||
frappe.route_options = {
|
frappe.route_options = {
|
||||||
"account": frm.doc.name,
|
"account": frm.doc.name,
|
||||||
"from_date": frappe.sys_defaults.year_start_date,
|
"from_date": frappe.sys_defaults.year_start_date,
|
||||||
@@ -84,9 +82,9 @@ frappe.ui.form.on('Account', {
|
|||||||
"company": frm.doc.company
|
"company": frm.doc.company
|
||||||
};
|
};
|
||||||
frappe.set_route("query-report", "General Ledger");
|
frappe.set_route("query-report", "General Ledger");
|
||||||
}, __('View'));
|
});
|
||||||
|
|
||||||
frm.add_custom_button(__('Convert to Group'), function () {
|
frm.add_custom_button(__('Non-Group to Group'), function () {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
doc: frm.doc,
|
doc: frm.doc,
|
||||||
method: 'convert_ledger_to_group',
|
method: 'convert_ledger_to_group',
|
||||||
@@ -94,7 +92,7 @@ frappe.ui.form.on('Account', {
|
|||||||
frm.refresh();
|
frm.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, __('Actions'));
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, throw
|
from frappe import _, throw
|
||||||
@@ -10,17 +11,11 @@ from frappe.utils.nestedset import NestedSet, get_ancestors_of, get_descendants_
|
|||||||
import erpnext
|
import erpnext
|
||||||
|
|
||||||
|
|
||||||
class RootNotEditable(frappe.ValidationError):
|
class RootNotEditable(frappe.ValidationError): pass
|
||||||
pass
|
class BalanceMismatchError(frappe.ValidationError): pass
|
||||||
|
|
||||||
|
|
||||||
class BalanceMismatchError(frappe.ValidationError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Account(NestedSet):
|
class Account(NestedSet):
|
||||||
nsm_parent_field = "parent_account"
|
nsm_parent_field = 'parent_account'
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
if frappe.local.flags.ignore_update_nsm:
|
if frappe.local.flags.ignore_update_nsm:
|
||||||
return
|
return
|
||||||
@@ -28,20 +23,17 @@ class Account(NestedSet):
|
|||||||
super(Account, self).on_update()
|
super(Account, self).on_update()
|
||||||
|
|
||||||
def onload(self):
|
def onload(self):
|
||||||
frozen_accounts_modifier = frappe.db.get_value(
|
frozen_accounts_modifier = frappe.db.get_value("Accounts Settings", "Accounts Settings",
|
||||||
"Accounts Settings", "Accounts Settings", "frozen_accounts_modifier"
|
"frozen_accounts_modifier")
|
||||||
)
|
|
||||||
if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles():
|
if not frozen_accounts_modifier or frozen_accounts_modifier in frappe.get_roles():
|
||||||
self.set_onload("can_freeze_account", True)
|
self.set_onload("can_freeze_account", True)
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
from erpnext.accounts.utils import get_autoname_with_number
|
from erpnext.accounts.utils import get_autoname_with_number
|
||||||
|
|
||||||
self.name = get_autoname_with_number(self.account_number, self.account_name, None, self.company)
|
self.name = get_autoname_with_number(self.account_number, self.account_name, None, self.company)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
from erpnext.accounts.utils import validate_field_number
|
from erpnext.accounts.utils import validate_field_number
|
||||||
|
|
||||||
if frappe.local.flags.allow_unverified_charts:
|
if frappe.local.flags.allow_unverified_charts:
|
||||||
return
|
return
|
||||||
self.validate_parent()
|
self.validate_parent()
|
||||||
@@ -58,33 +50,22 @@ class Account(NestedSet):
|
|||||||
def validate_parent(self):
|
def validate_parent(self):
|
||||||
"""Fetch Parent Details and validate parent account"""
|
"""Fetch Parent Details and validate parent account"""
|
||||||
if self.parent_account:
|
if self.parent_account:
|
||||||
par = frappe.db.get_value(
|
par = frappe.db.get_value("Account", self.parent_account,
|
||||||
"Account", self.parent_account, ["name", "is_group", "company"], as_dict=1
|
["name", "is_group", "company"], as_dict=1)
|
||||||
)
|
|
||||||
if not par:
|
if not par:
|
||||||
throw(
|
throw(_("Account {0}: Parent account {1} does not exist").format(self.name, self.parent_account))
|
||||||
_("Account {0}: Parent account {1} does not exist").format(self.name, self.parent_account)
|
|
||||||
)
|
|
||||||
elif par.name == self.name:
|
elif par.name == self.name:
|
||||||
throw(_("Account {0}: You can not assign itself as parent account").format(self.name))
|
throw(_("Account {0}: You can not assign itself as parent account").format(self.name))
|
||||||
elif not par.is_group:
|
elif not par.is_group:
|
||||||
throw(
|
throw(_("Account {0}: Parent account {1} can not be a ledger").format(self.name, self.parent_account))
|
||||||
_("Account {0}: Parent account {1} can not be a ledger").format(
|
|
||||||
self.name, self.parent_account
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif par.company != self.company:
|
elif par.company != self.company:
|
||||||
throw(
|
throw(_("Account {0}: Parent account {1} does not belong to company: {2}")
|
||||||
_("Account {0}: Parent account {1} does not belong to company: {2}").format(
|
.format(self.name, self.parent_account, self.company))
|
||||||
self.name, self.parent_account, self.company
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def set_root_and_report_type(self):
|
def set_root_and_report_type(self):
|
||||||
if self.parent_account:
|
if self.parent_account:
|
||||||
par = frappe.db.get_value(
|
par = frappe.db.get_value("Account", self.parent_account,
|
||||||
"Account", self.parent_account, ["report_type", "root_type"], as_dict=1
|
["report_type", "root_type"], as_dict=1)
|
||||||
)
|
|
||||||
|
|
||||||
if par.report_type:
|
if par.report_type:
|
||||||
self.report_type = par.report_type
|
self.report_type = par.report_type
|
||||||
@@ -95,20 +76,15 @@ class Account(NestedSet):
|
|||||||
db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1)
|
db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1)
|
||||||
if db_value:
|
if db_value:
|
||||||
if self.report_type != db_value.report_type:
|
if self.report_type != db_value.report_type:
|
||||||
frappe.db.sql(
|
frappe.db.sql("update `tabAccount` set report_type=%s where lft > %s and rgt < %s",
|
||||||
"update `tabAccount` set report_type=%s where lft > %s and rgt < %s",
|
(self.report_type, self.lft, self.rgt))
|
||||||
(self.report_type, self.lft, self.rgt),
|
|
||||||
)
|
|
||||||
if self.root_type != db_value.root_type:
|
if self.root_type != db_value.root_type:
|
||||||
frappe.db.sql(
|
frappe.db.sql("update `tabAccount` set root_type=%s where lft > %s and rgt < %s",
|
||||||
"update `tabAccount` set root_type=%s where lft > %s and rgt < %s",
|
(self.root_type, self.lft, self.rgt))
|
||||||
(self.root_type, self.lft, self.rgt),
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.root_type and not self.report_type:
|
if self.root_type and not self.report_type:
|
||||||
self.report_type = (
|
self.report_type = "Balance Sheet" \
|
||||||
"Balance Sheet" if self.root_type in ("Asset", "Liability", "Equity") else "Profit and Loss"
|
if self.root_type in ("Asset", "Liability", "Equity") else "Profit and Loss"
|
||||||
)
|
|
||||||
|
|
||||||
def validate_root_details(self):
|
def validate_root_details(self):
|
||||||
# does not exists parent
|
# does not exists parent
|
||||||
@@ -121,26 +97,21 @@ class Account(NestedSet):
|
|||||||
|
|
||||||
def validate_root_company_and_sync_account_to_children(self):
|
def validate_root_company_and_sync_account_to_children(self):
|
||||||
# ignore validation while creating new compnay or while syncing to child companies
|
# ignore validation while creating new compnay or while syncing to child companies
|
||||||
if (
|
if frappe.local.flags.ignore_root_company_validation or self.flags.ignore_root_company_validation:
|
||||||
frappe.local.flags.ignore_root_company_validation or self.flags.ignore_root_company_validation
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
ancestors = get_root_company(self.company)
|
ancestors = get_root_company(self.company)
|
||||||
if ancestors:
|
if ancestors:
|
||||||
if frappe.get_value("Company", self.company, "allow_account_creation_against_child_company"):
|
if frappe.get_value("Company", self.company, "allow_account_creation_against_child_company"):
|
||||||
return
|
return
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value("Account",
|
||||||
"Account", {"account_name": self.account_name, "company": ancestors[0]}, "name"
|
{'account_name': self.account_name, 'company': ancestors[0]}, 'name'):
|
||||||
):
|
|
||||||
frappe.throw(_("Please add the account to root level Company - {}").format(ancestors[0]))
|
frappe.throw(_("Please add the account to root level Company - {}").format(ancestors[0]))
|
||||||
elif self.parent_account:
|
elif self.parent_account:
|
||||||
descendants = get_descendants_of("Company", self.company)
|
descendants = get_descendants_of('Company', self.company)
|
||||||
if not descendants:
|
if not descendants: return
|
||||||
return
|
|
||||||
parent_acc_name_map = {}
|
parent_acc_name_map = {}
|
||||||
parent_acc_name, parent_acc_number = frappe.db.get_value(
|
parent_acc_name, parent_acc_number = frappe.db.get_value('Account', self.parent_account, \
|
||||||
"Account", self.parent_account, ["account_name", "account_number"]
|
["account_name", "account_number"])
|
||||||
)
|
|
||||||
filters = {
|
filters = {
|
||||||
"company": ["in", descendants],
|
"company": ["in", descendants],
|
||||||
"account_name": parent_acc_name,
|
"account_name": parent_acc_name,
|
||||||
@@ -148,13 +119,10 @@ class Account(NestedSet):
|
|||||||
if parent_acc_number:
|
if parent_acc_number:
|
||||||
filters["account_number"] = parent_acc_number
|
filters["account_number"] = parent_acc_number
|
||||||
|
|
||||||
for d in frappe.db.get_values(
|
for d in frappe.db.get_values('Account', filters=filters, fieldname=["company", "name"], as_dict=True):
|
||||||
"Account", filters=filters, fieldname=["company", "name"], as_dict=True
|
|
||||||
):
|
|
||||||
parent_acc_name_map[d["company"]] = d["name"]
|
parent_acc_name_map[d["company"]] = d["name"]
|
||||||
|
|
||||||
if not parent_acc_name_map:
|
if not parent_acc_name_map: return
|
||||||
return
|
|
||||||
|
|
||||||
self.create_account_for_child_company(parent_acc_name_map, descendants, parent_acc_name)
|
self.create_account_for_child_company(parent_acc_name_map, descendants, parent_acc_name)
|
||||||
|
|
||||||
@@ -175,38 +143,26 @@ class Account(NestedSet):
|
|||||||
def validate_frozen_accounts_modifier(self):
|
def validate_frozen_accounts_modifier(self):
|
||||||
old_value = frappe.db.get_value("Account", self.name, "freeze_account")
|
old_value = frappe.db.get_value("Account", self.name, "freeze_account")
|
||||||
if old_value and old_value != self.freeze_account:
|
if old_value and old_value != self.freeze_account:
|
||||||
frozen_accounts_modifier = frappe.db.get_value(
|
frozen_accounts_modifier = frappe.db.get_value('Accounts Settings', None, 'frozen_accounts_modifier')
|
||||||
"Accounts Settings", None, "frozen_accounts_modifier"
|
if not frozen_accounts_modifier or \
|
||||||
)
|
frozen_accounts_modifier not in frappe.get_roles():
|
||||||
if not frozen_accounts_modifier or frozen_accounts_modifier not in frappe.get_roles():
|
throw(_("You are not authorized to set Frozen value"))
|
||||||
throw(_("You are not authorized to set Frozen value"))
|
|
||||||
|
|
||||||
def validate_balance_must_be_debit_or_credit(self):
|
def validate_balance_must_be_debit_or_credit(self):
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
|
|
||||||
if not self.get("__islocal") and self.balance_must_be:
|
if not self.get("__islocal") and self.balance_must_be:
|
||||||
account_balance = get_balance_on(self.name)
|
account_balance = get_balance_on(self.name)
|
||||||
|
|
||||||
if account_balance > 0 and self.balance_must_be == "Credit":
|
if account_balance > 0 and self.balance_must_be == "Credit":
|
||||||
frappe.throw(
|
frappe.throw(_("Account balance already in Debit, you are not allowed to set 'Balance Must Be' as 'Credit'"))
|
||||||
_(
|
|
||||||
"Account balance already in Debit, you are not allowed to set 'Balance Must Be' as 'Credit'"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif account_balance < 0 and self.balance_must_be == "Debit":
|
elif account_balance < 0 and self.balance_must_be == "Debit":
|
||||||
frappe.throw(
|
frappe.throw(_("Account balance already in Credit, you are not allowed to set 'Balance Must Be' as 'Debit'"))
|
||||||
_(
|
|
||||||
"Account balance already in Credit, you are not allowed to set 'Balance Must Be' as 'Debit'"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_account_currency(self):
|
def validate_account_currency(self):
|
||||||
if not self.account_currency:
|
if not self.account_currency:
|
||||||
self.account_currency = frappe.get_cached_value("Company", self.company, "default_currency")
|
self.account_currency = frappe.get_cached_value('Company', self.company, "default_currency")
|
||||||
|
|
||||||
gl_currency = frappe.db.get_value("GL Entry", {"account": self.name}, "account_currency")
|
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
|
||||||
|
|
||||||
if gl_currency and self.account_currency != gl_currency:
|
|
||||||
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
||||||
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
||||||
|
|
||||||
@@ -215,52 +171,45 @@ class Account(NestedSet):
|
|||||||
company_bold = frappe.bold(company)
|
company_bold = frappe.bold(company)
|
||||||
parent_acc_name_bold = frappe.bold(parent_acc_name)
|
parent_acc_name_bold = frappe.bold(parent_acc_name)
|
||||||
if not parent_acc_name_map.get(company):
|
if not parent_acc_name_map.get(company):
|
||||||
frappe.throw(
|
frappe.throw(_("While creating account for Child Company {0}, parent account {1} not found. Please create the parent account in corresponding COA")
|
||||||
_(
|
.format(company_bold, parent_acc_name_bold), title=_("Account Not Found"))
|
||||||
"While creating account for Child Company {0}, parent account {1} not found. Please create the parent account in corresponding COA"
|
|
||||||
).format(company_bold, parent_acc_name_bold),
|
|
||||||
title=_("Account Not Found"),
|
|
||||||
)
|
|
||||||
|
|
||||||
# validate if parent of child company account to be added is a group
|
# validate if parent of child company account to be added is a group
|
||||||
if frappe.db.get_value("Account", self.parent_account, "is_group") and not frappe.db.get_value(
|
if (frappe.db.get_value("Account", self.parent_account, "is_group")
|
||||||
"Account", parent_acc_name_map[company], "is_group"
|
and not frappe.db.get_value("Account", parent_acc_name_map[company], "is_group")):
|
||||||
):
|
msg = _("While creating account for Child Company {0}, parent account {1} found as a ledger account.").format(company_bold, parent_acc_name_bold)
|
||||||
msg = _(
|
|
||||||
"While creating account for Child Company {0}, parent account {1} found as a ledger account."
|
|
||||||
).format(company_bold, parent_acc_name_bold)
|
|
||||||
msg += "<br><br>"
|
msg += "<br><br>"
|
||||||
msg += _(
|
msg += _("Please convert the parent account in corresponding child company to a group account.")
|
||||||
"Please convert the parent account in corresponding child company to a group account."
|
|
||||||
)
|
|
||||||
frappe.throw(msg, title=_("Invalid Parent Account"))
|
frappe.throw(msg, title=_("Invalid Parent Account"))
|
||||||
|
|
||||||
filters = {"account_name": self.account_name, "company": company}
|
filters = {
|
||||||
|
"account_name": self.account_name,
|
||||||
|
"company": company
|
||||||
|
}
|
||||||
|
|
||||||
if self.account_number:
|
if self.account_number:
|
||||||
filters["account_number"] = self.account_number
|
filters["account_number"] = self.account_number
|
||||||
|
|
||||||
child_account = frappe.db.get_value("Account", filters, "name")
|
child_account = frappe.db.get_value("Account", filters, 'name')
|
||||||
if not child_account:
|
if not child_account:
|
||||||
doc = frappe.copy_doc(self)
|
doc = frappe.copy_doc(self)
|
||||||
doc.flags.ignore_root_company_validation = True
|
doc.flags.ignore_root_company_validation = True
|
||||||
doc.update(
|
doc.update({
|
||||||
{
|
"company": company,
|
||||||
"company": company,
|
# parent account's currency should be passed down to child account's curreny
|
||||||
# parent account's currency should be passed down to child account's curreny
|
# if it is None, it picks it up from default company currency, which might be unintended
|
||||||
# if it is None, it picks it up from default company currency, which might be unintended
|
"account_currency": erpnext.get_company_currency(company),
|
||||||
"account_currency": erpnext.get_company_currency(company),
|
"parent_account": parent_acc_name_map[company]
|
||||||
"parent_account": parent_acc_name_map[company],
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
doc.save()
|
doc.save()
|
||||||
frappe.msgprint(_("Account {0} is added in the child company {1}").format(doc.name, company))
|
frappe.msgprint(_("Account {0} is added in the child company {1}")
|
||||||
|
.format(doc.name, company))
|
||||||
elif child_account:
|
elif child_account:
|
||||||
# update the parent company's value in child companies
|
# update the parent company's value in child companies
|
||||||
doc = frappe.get_doc("Account", child_account)
|
doc = frappe.get_doc("Account", child_account)
|
||||||
parent_value_changed = False
|
parent_value_changed = False
|
||||||
for field in ["account_type", "freeze_account", "balance_must_be"]:
|
for field in ['account_type', 'freeze_account', 'balance_must_be']:
|
||||||
if doc.get(field) != self.get(field):
|
if doc.get(field) != self.get(field):
|
||||||
parent_value_changed = True
|
parent_value_changed = True
|
||||||
doc.set(field, self.get(field))
|
doc.set(field, self.get(field))
|
||||||
@@ -295,11 +244,8 @@ class Account(NestedSet):
|
|||||||
return frappe.db.get_value("GL Entry", {"account": self.name})
|
return frappe.db.get_value("GL Entry", {"account": self.name})
|
||||||
|
|
||||||
def check_if_child_exists(self):
|
def check_if_child_exists(self):
|
||||||
return frappe.db.sql(
|
return frappe.db.sql("""select name from `tabAccount` where parent_account = %s
|
||||||
"""select name from `tabAccount` where parent_account = %s
|
and docstatus != 2""", self.name)
|
||||||
and docstatus != 2""",
|
|
||||||
self.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_mandatory(self):
|
def validate_mandatory(self):
|
||||||
if not self.root_type:
|
if not self.root_type:
|
||||||
@@ -315,99 +261,73 @@ class Account(NestedSet):
|
|||||||
|
|
||||||
super(Account, self).on_trash(True)
|
super(Account, self).on_trash(True)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
|
def get_parent_account(doctype, txt, searchfield, start, page_len, filters):
|
||||||
return frappe.db.sql(
|
return frappe.db.sql("""select name from tabAccount
|
||||||
"""select name from tabAccount
|
|
||||||
where is_group = 1 and docstatus != 2 and company = %s
|
where is_group = 1 and docstatus != 2 and company = %s
|
||||||
and %s like %s order by name limit %s, %s"""
|
and %s like %s order by name limit %s, %s""" %
|
||||||
% ("%s", searchfield, "%s", "%s", "%s"),
|
("%s", searchfield, "%s", "%s", "%s"),
|
||||||
(filters["company"], "%%%s%%" % txt, start, page_len),
|
(filters["company"], "%%%s%%" % txt, start, page_len), as_list=1)
|
||||||
as_list=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_account_currency(account):
|
def get_account_currency(account):
|
||||||
"""Helper function to get account currency"""
|
"""Helper function to get account currency"""
|
||||||
if not account:
|
if not account:
|
||||||
return
|
return
|
||||||
|
|
||||||
def generator():
|
def generator():
|
||||||
account_currency, company = frappe.get_cached_value(
|
account_currency, company = frappe.get_cached_value("Account", account, ["account_currency", "company"])
|
||||||
"Account", account, ["account_currency", "company"]
|
|
||||||
)
|
|
||||||
if not account_currency:
|
if not account_currency:
|
||||||
account_currency = frappe.get_cached_value("Company", company, "default_currency")
|
account_currency = frappe.get_cached_value('Company', company, "default_currency")
|
||||||
|
|
||||||
return account_currency
|
return account_currency
|
||||||
|
|
||||||
return frappe.local_cache("account_currency", account, generator)
|
return frappe.local_cache("account_currency", account, generator)
|
||||||
|
|
||||||
|
|
||||||
def on_doctype_update():
|
def on_doctype_update():
|
||||||
frappe.db.add_index("Account", ["lft", "rgt"])
|
frappe.db.add_index("Account", ["lft", "rgt"])
|
||||||
|
|
||||||
|
|
||||||
def get_account_autoname(account_number, account_name, company):
|
def get_account_autoname(account_number, account_name, company):
|
||||||
# first validate if company exists
|
# first validate if company exists
|
||||||
company = frappe.get_cached_value("Company", company, ["abbr", "name"], as_dict=True)
|
company = frappe.get_cached_value('Company', company, ["abbr", "name"], as_dict=True)
|
||||||
if not company:
|
if not company:
|
||||||
frappe.throw(_("Company {0} does not exist").format(company))
|
frappe.throw(_('Company {0} does not exist').format(company))
|
||||||
|
|
||||||
parts = [account_name.strip(), company.abbr]
|
parts = [account_name.strip(), company.abbr]
|
||||||
if cstr(account_number).strip():
|
if cstr(account_number).strip():
|
||||||
parts.insert(0, cstr(account_number).strip())
|
parts.insert(0, cstr(account_number).strip())
|
||||||
return " - ".join(parts)
|
return ' - '.join(parts)
|
||||||
|
|
||||||
|
|
||||||
def validate_account_number(name, account_number, company):
|
def validate_account_number(name, account_number, company):
|
||||||
if account_number:
|
if account_number:
|
||||||
account_with_same_number = frappe.db.get_value(
|
account_with_same_number = frappe.db.get_value("Account",
|
||||||
"Account", {"account_number": account_number, "company": company, "name": ["!=", name]}
|
{"account_number": account_number, "company": company, "name": ["!=", name]})
|
||||||
)
|
|
||||||
if account_with_same_number:
|
if account_with_same_number:
|
||||||
frappe.throw(
|
frappe.throw(_("Account Number {0} already used in account {1}")
|
||||||
_("Account Number {0} already used in account {1}").format(
|
.format(account_number, account_with_same_number))
|
||||||
account_number, account_with_same_number
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
||||||
account = frappe.db.get_value("Account", name, "company", as_dict=True)
|
account = frappe.db.get_value("Account", name, "company", as_dict=True)
|
||||||
if not account:
|
if not account: return
|
||||||
return
|
|
||||||
|
|
||||||
old_acc_name, old_acc_number = frappe.db.get_value(
|
old_acc_name, old_acc_number = frappe.db.get_value('Account', name, \
|
||||||
"Account", name, ["account_name", "account_number"]
|
["account_name", "account_number"])
|
||||||
)
|
|
||||||
|
|
||||||
# check if account exists in parent company
|
# check if account exists in parent company
|
||||||
ancestors = get_ancestors_of("Company", account.company)
|
ancestors = get_ancestors_of("Company", account.company)
|
||||||
allow_independent_account_creation = frappe.get_value(
|
allow_independent_account_creation = frappe.get_value("Company", account.company, "allow_account_creation_against_child_company")
|
||||||
"Company", account.company, "allow_account_creation_against_child_company"
|
|
||||||
)
|
|
||||||
|
|
||||||
if ancestors and not allow_independent_account_creation:
|
if ancestors and not allow_independent_account_creation:
|
||||||
for ancestor in ancestors:
|
for ancestor in ancestors:
|
||||||
if frappe.db.get_value("Account", {"account_name": old_acc_name, "company": ancestor}, "name"):
|
if frappe.db.get_value("Account", {'account_name': old_acc_name, 'company': ancestor}, 'name'):
|
||||||
# same account in parent company exists
|
# same account in parent company exists
|
||||||
allow_child_account_creation = _("Allow Account Creation Against Child Company")
|
allow_child_account_creation = _("Allow Account Creation Against Child Company")
|
||||||
|
|
||||||
message = _("Account {0} exists in parent company {1}.").format(
|
message = _("Account {0} exists in parent company {1}.").format(frappe.bold(old_acc_name), frappe.bold(ancestor))
|
||||||
frappe.bold(old_acc_name), frappe.bold(ancestor)
|
|
||||||
)
|
|
||||||
message += "<br>"
|
message += "<br>"
|
||||||
message += _("Renaming it is only allowed via parent company {0}, to avoid mismatch.").format(
|
message += _("Renaming it is only allowed via parent company {0}, to avoid mismatch.").format(frappe.bold(ancestor))
|
||||||
frappe.bold(ancestor)
|
|
||||||
)
|
|
||||||
message += "<br><br>"
|
message += "<br><br>"
|
||||||
message += _("To overrule this, enable '{0}' in company {1}").format(
|
message += _("To overrule this, enable '{0}' in company {1}").format(allow_child_account_creation, frappe.bold(account.company))
|
||||||
allow_child_account_creation, frappe.bold(account.company)
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.throw(message, title=_("Rename Not Allowed"))
|
frappe.throw(message, title=_("Rename Not Allowed"))
|
||||||
|
|
||||||
@@ -420,53 +340,42 @@ def update_account_number(name, account_name, account_number=None, from_descenda
|
|||||||
|
|
||||||
if not from_descendant:
|
if not from_descendant:
|
||||||
# Update and rename in child company accounts as well
|
# Update and rename in child company accounts as well
|
||||||
descendants = get_descendants_of("Company", account.company)
|
descendants = get_descendants_of('Company', account.company)
|
||||||
if descendants:
|
if descendants:
|
||||||
sync_update_account_number_in_child(
|
sync_update_account_number_in_child(descendants, old_acc_name, account_name, account_number, old_acc_number)
|
||||||
descendants, old_acc_name, account_name, account_number, old_acc_number
|
|
||||||
)
|
|
||||||
|
|
||||||
new_name = get_account_autoname(account_number, account_name, account.company)
|
new_name = get_account_autoname(account_number, account_name, account.company)
|
||||||
if name != new_name:
|
if name != new_name:
|
||||||
frappe.rename_doc("Account", name, new_name, force=1)
|
frappe.rename_doc("Account", name, new_name, force=1)
|
||||||
return new_name
|
return new_name
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def merge_account(old, new, is_group, root_type, company):
|
def merge_account(old, new, is_group, root_type, company):
|
||||||
# Validate properties before merging
|
# Validate properties before merging
|
||||||
if not frappe.db.exists("Account", new):
|
if not frappe.db.exists("Account", new):
|
||||||
throw(_("Account {0} does not exist").format(new))
|
throw(_("Account {0} does not exist").format(new))
|
||||||
|
|
||||||
val = list(frappe.db.get_value("Account", new, ["is_group", "root_type", "company"]))
|
val = list(frappe.db.get_value("Account", new,
|
||||||
|
["is_group", "root_type", "company"]))
|
||||||
|
|
||||||
if val != [cint(is_group), root_type, company]:
|
if val != [cint(is_group), root_type, company]:
|
||||||
throw(
|
throw(_("""Merging is only possible if following properties are same in both records. Is Group, Root Type, Company"""))
|
||||||
_(
|
|
||||||
"""Merging is only possible if following properties are same in both records. Is Group, Root Type, Company"""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if is_group and frappe.db.get_value("Account", new, "parent_account") == old:
|
if is_group and frappe.db.get_value("Account", new, "parent_account") == old:
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Account", new, "parent_account",
|
||||||
"Account", new, "parent_account", frappe.db.get_value("Account", old, "parent_account")
|
frappe.db.get_value("Account", old, "parent_account"))
|
||||||
)
|
|
||||||
|
|
||||||
frappe.rename_doc("Account", old, new, merge=1, force=1)
|
frappe.rename_doc("Account", old, new, merge=1, force=1)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_root_company(company):
|
def get_root_company(company):
|
||||||
# return the topmost company in the hierarchy
|
# return the topmost company in the hierarchy
|
||||||
ancestors = get_ancestors_of("Company", company, "lft asc")
|
ancestors = get_ancestors_of('Company', company, "lft asc")
|
||||||
return [ancestors[0]] if ancestors else []
|
return [ancestors[0]] if ancestors else []
|
||||||
|
|
||||||
|
def sync_update_account_number_in_child(descendants, old_acc_name, account_name, account_number=None, old_acc_number=None):
|
||||||
def sync_update_account_number_in_child(
|
|
||||||
descendants, old_acc_name, account_name, account_number=None, old_acc_number=None
|
|
||||||
):
|
|
||||||
filters = {
|
filters = {
|
||||||
"company": ["in", descendants],
|
"company": ["in", descendants],
|
||||||
"account_name": old_acc_name,
|
"account_name": old_acc_name,
|
||||||
@@ -474,7 +383,5 @@ def sync_update_account_number_in_child(
|
|||||||
if old_acc_number:
|
if old_acc_number:
|
||||||
filters["account_number"] = old_acc_number
|
filters["account_number"] = old_acc_number
|
||||||
|
|
||||||
for d in frappe.db.get_values(
|
for d in frappe.db.get_values('Account', filters=filters, fieldname=["company", "name"], as_dict=True):
|
||||||
"Account", filters=filters, fieldname=["company", "name"], as_dict=True
|
update_account_number(d["name"], account_name, account_number, from_descendant=True)
|
||||||
):
|
|
||||||
update_account_number(d["name"], account_name, account_number, from_descendant=True)
|
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ frappe.treeview_settings["Account"] = {
|
|||||||
const format = (value, currency) => format_currency(Math.abs(value), currency);
|
const format = (value, currency) => format_currency(Math.abs(value), currency);
|
||||||
|
|
||||||
if (account.balance!==undefined) {
|
if (account.balance!==undefined) {
|
||||||
node.parent && node.parent.find('.balance-area').remove();
|
|
||||||
$('<span class="balance-area pull-right">'
|
$('<span class="balance-area pull-right">'
|
||||||
+ (account.balance_in_account_currency ?
|
+ (account.balance_in_account_currency ?
|
||||||
(format(account.balance_in_account_currency, account.account_currency) + " / ") : "")
|
(format(account.balance_in_account_currency, account.account_currency) + " / ") : "")
|
||||||
@@ -176,7 +175,7 @@ frappe.treeview_settings["Account"] = {
|
|||||||
&& node.expandable && !node.hide_add;
|
&& node.expandable && !node.hide_add;
|
||||||
},
|
},
|
||||||
click: function() {
|
click: function() {
|
||||||
var me = frappe.views.trees['Account'];
|
var me = frappe.treeview_settings['Account'].treeview;
|
||||||
me.new_node();
|
me.new_node();
|
||||||
},
|
},
|
||||||
btnClass: "hidden-xs"
|
btnClass: "hidden-xs"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -11,9 +12,7 @@ from six import iteritems
|
|||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
|
||||||
def create_charts(
|
def create_charts(company, chart_template=None, existing_company=None, custom_chart=None, from_coa_importer=None):
|
||||||
company, chart_template=None, existing_company=None, custom_chart=None, from_coa_importer=None
|
|
||||||
):
|
|
||||||
chart = custom_chart or get_chart(chart_template, existing_company)
|
chart = custom_chart or get_chart(chart_template, existing_company)
|
||||||
if chart:
|
if chart:
|
||||||
accounts = []
|
accounts = []
|
||||||
@@ -23,41 +22,30 @@ def create_charts(
|
|||||||
if root_account:
|
if root_account:
|
||||||
root_type = child.get("root_type")
|
root_type = child.get("root_type")
|
||||||
|
|
||||||
if account_name not in [
|
if account_name not in ["account_name", "account_number", "account_type",
|
||||||
"account_name",
|
"root_type", "is_group", "tax_rate"]:
|
||||||
"account_number",
|
|
||||||
"account_type",
|
|
||||||
"root_type",
|
|
||||||
"is_group",
|
|
||||||
"tax_rate",
|
|
||||||
]:
|
|
||||||
|
|
||||||
account_number = cstr(child.get("account_number")).strip()
|
account_number = cstr(child.get("account_number")).strip()
|
||||||
account_name, account_name_in_db = add_suffix_if_duplicate(
|
account_name, account_name_in_db = add_suffix_if_duplicate(account_name,
|
||||||
account_name, account_number, accounts
|
account_number, accounts)
|
||||||
)
|
|
||||||
|
|
||||||
is_group = identify_is_group(child)
|
is_group = identify_is_group(child)
|
||||||
report_type = (
|
report_type = "Balance Sheet" if root_type in ["Asset", "Liability", "Equity"] \
|
||||||
"Balance Sheet" if root_type in ["Asset", "Liability", "Equity"] else "Profit and Loss"
|
else "Profit and Loss"
|
||||||
)
|
|
||||||
|
|
||||||
account = frappe.get_doc(
|
account = frappe.get_doc({
|
||||||
{
|
"doctype": "Account",
|
||||||
"doctype": "Account",
|
"account_name": child.get('account_name') if from_coa_importer else account_name,
|
||||||
"account_name": child.get("account_name") if from_coa_importer else account_name,
|
"company": company,
|
||||||
"company": company,
|
"parent_account": parent,
|
||||||
"parent_account": parent,
|
"is_group": is_group,
|
||||||
"is_group": is_group,
|
"root_type": root_type,
|
||||||
"root_type": root_type,
|
"report_type": report_type,
|
||||||
"report_type": report_type,
|
"account_number": account_number,
|
||||||
"account_number": account_number,
|
"account_type": child.get("account_type"),
|
||||||
"account_type": child.get("account_type"),
|
"account_currency": child.get('account_currency') or frappe.db.get_value('Company', company, "default_currency"),
|
||||||
"account_currency": child.get("account_currency")
|
"tax_rate": child.get("tax_rate")
|
||||||
or frappe.db.get_value("Company", company, "default_currency"),
|
})
|
||||||
"tax_rate": child.get("tax_rate"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if root_account or frappe.local.flags.allow_unverified_charts:
|
if root_account or frappe.local.flags.allow_unverified_charts:
|
||||||
account.flags.ignore_mandatory = True
|
account.flags.ignore_mandatory = True
|
||||||
@@ -77,10 +65,10 @@ def create_charts(
|
|||||||
rebuild_tree("Account", "parent_account")
|
rebuild_tree("Account", "parent_account")
|
||||||
frappe.local.flags.ignore_update_nsm = False
|
frappe.local.flags.ignore_update_nsm = False
|
||||||
|
|
||||||
|
|
||||||
def add_suffix_if_duplicate(account_name, account_number, accounts):
|
def add_suffix_if_duplicate(account_name, account_number, accounts):
|
||||||
if account_number:
|
if account_number:
|
||||||
account_name_in_db = unidecode(" - ".join([account_number, account_name.strip().lower()]))
|
account_name_in_db = unidecode(" - ".join([account_number,
|
||||||
|
account_name.strip().lower()]))
|
||||||
else:
|
else:
|
||||||
account_name_in_db = unidecode(account_name.strip().lower())
|
account_name_in_db = unidecode(account_name.strip().lower())
|
||||||
|
|
||||||
@@ -90,21 +78,16 @@ def add_suffix_if_duplicate(account_name, account_number, accounts):
|
|||||||
|
|
||||||
return account_name, account_name_in_db
|
return account_name, account_name_in_db
|
||||||
|
|
||||||
|
|
||||||
def identify_is_group(child):
|
def identify_is_group(child):
|
||||||
if child.get("is_group"):
|
if child.get("is_group"):
|
||||||
is_group = child.get("is_group")
|
is_group = child.get("is_group")
|
||||||
elif len(
|
elif len(set(child.keys()) - set(["account_type", "root_type", "is_group", "tax_rate", "account_number"])):
|
||||||
set(child.keys())
|
|
||||||
- set(["account_name", "account_type", "root_type", "is_group", "tax_rate", "account_number"])
|
|
||||||
):
|
|
||||||
is_group = 1
|
is_group = 1
|
||||||
else:
|
else:
|
||||||
is_group = 0
|
is_group = 0
|
||||||
|
|
||||||
return is_group
|
return is_group
|
||||||
|
|
||||||
|
|
||||||
def get_chart(chart_template, existing_company=None):
|
def get_chart(chart_template, existing_company=None):
|
||||||
chart = {}
|
chart = {}
|
||||||
if existing_company:
|
if existing_company:
|
||||||
@@ -114,13 +97,11 @@ def get_chart(chart_template, existing_company=None):
|
|||||||
from erpnext.accounts.doctype.account.chart_of_accounts.verified import (
|
from erpnext.accounts.doctype.account.chart_of_accounts.verified import (
|
||||||
standard_chart_of_accounts,
|
standard_chart_of_accounts,
|
||||||
)
|
)
|
||||||
|
|
||||||
return standard_chart_of_accounts.get()
|
return standard_chart_of_accounts.get()
|
||||||
elif chart_template == "Standard with Numbers":
|
elif chart_template == "Standard with Numbers":
|
||||||
from erpnext.accounts.doctype.account.chart_of_accounts.verified import (
|
from erpnext.accounts.doctype.account.chart_of_accounts.verified import (
|
||||||
standard_chart_of_accounts_with_account_number,
|
standard_chart_of_accounts_with_account_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
return standard_chart_of_accounts_with_account_number.get()
|
return standard_chart_of_accounts_with_account_number.get()
|
||||||
else:
|
else:
|
||||||
folders = ("verified",)
|
folders = ("verified",)
|
||||||
@@ -136,7 +117,6 @@ def get_chart(chart_template, existing_company=None):
|
|||||||
if chart and json.loads(chart).get("name") == chart_template:
|
if chart and json.loads(chart).get("name") == chart_template:
|
||||||
return json.loads(chart).get("tree")
|
return json.loads(chart).get("tree")
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_charts_for_country(country, with_standard=False):
|
def get_charts_for_country(country, with_standard=False):
|
||||||
charts = []
|
charts = []
|
||||||
@@ -144,10 +124,9 @@ def get_charts_for_country(country, with_standard=False):
|
|||||||
def _get_chart_name(content):
|
def _get_chart_name(content):
|
||||||
if content:
|
if content:
|
||||||
content = json.loads(content)
|
content = json.loads(content)
|
||||||
if (
|
if (content and content.get("disabled", "No") == "No") \
|
||||||
content and content.get("disabled", "No") == "No"
|
or frappe.local.flags.allow_unverified_charts:
|
||||||
) or frappe.local.flags.allow_unverified_charts:
|
charts.append(content["name"])
|
||||||
charts.append(content["name"])
|
|
||||||
|
|
||||||
country_code = frappe.db.get_value("Country", country, "code")
|
country_code = frappe.db.get_value("Country", country, "code")
|
||||||
if country_code:
|
if country_code:
|
||||||
@@ -174,21 +153,11 @@ def get_charts_for_country(country, with_standard=False):
|
|||||||
|
|
||||||
|
|
||||||
def get_account_tree_from_existing_company(existing_company):
|
def get_account_tree_from_existing_company(existing_company):
|
||||||
all_accounts = frappe.get_all(
|
all_accounts = frappe.get_all('Account',
|
||||||
"Account",
|
filters={'company': existing_company},
|
||||||
filters={"company": existing_company},
|
fields = ["name", "account_name", "parent_account", "account_type",
|
||||||
fields=[
|
"is_group", "root_type", "tax_rate", "account_number"],
|
||||||
"name",
|
order_by="lft, rgt")
|
||||||
"account_name",
|
|
||||||
"parent_account",
|
|
||||||
"account_type",
|
|
||||||
"is_group",
|
|
||||||
"root_type",
|
|
||||||
"tax_rate",
|
|
||||||
"account_number",
|
|
||||||
],
|
|
||||||
order_by="lft, rgt",
|
|
||||||
)
|
|
||||||
|
|
||||||
account_tree = {}
|
account_tree = {}
|
||||||
|
|
||||||
@@ -197,7 +166,6 @@ def get_account_tree_from_existing_company(existing_company):
|
|||||||
build_account_tree(account_tree, None, all_accounts)
|
build_account_tree(account_tree, None, all_accounts)
|
||||||
return account_tree
|
return account_tree
|
||||||
|
|
||||||
|
|
||||||
def build_account_tree(tree, parent, all_accounts):
|
def build_account_tree(tree, parent, all_accounts):
|
||||||
# find children
|
# find children
|
||||||
parent_account = parent.name if parent else ""
|
parent_account = parent.name if parent else ""
|
||||||
@@ -226,29 +194,27 @@ def build_account_tree(tree, parent, all_accounts):
|
|||||||
# call recursively to build a subtree for current account
|
# call recursively to build a subtree for current account
|
||||||
build_account_tree(tree[child.account_name], child, all_accounts)
|
build_account_tree(tree[child.account_name], child, all_accounts)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def validate_bank_account(coa, bank_account):
|
def validate_bank_account(coa, bank_account):
|
||||||
accounts = []
|
accounts = []
|
||||||
chart = get_chart(coa)
|
chart = get_chart(coa)
|
||||||
|
|
||||||
if chart:
|
if chart:
|
||||||
|
|
||||||
def _get_account_names(account_master):
|
def _get_account_names(account_master):
|
||||||
for account_name, child in iteritems(account_master):
|
for account_name, child in iteritems(account_master):
|
||||||
if account_name not in ["account_number", "account_type", "root_type", "is_group", "tax_rate"]:
|
if account_name not in ["account_number", "account_type",
|
||||||
|
"root_type", "is_group", "tax_rate"]:
|
||||||
accounts.append(account_name)
|
accounts.append(account_name)
|
||||||
|
|
||||||
_get_account_names(child)
|
_get_account_names(child)
|
||||||
|
|
||||||
_get_account_names(chart)
|
_get_account_names(chart)
|
||||||
|
|
||||||
return bank_account in accounts
|
return (bank_account in accounts)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=False):
|
def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=False):
|
||||||
"""get chart template from its folder and parse the json to be rendered as tree"""
|
''' get chart template from its folder and parse the json to be rendered as tree '''
|
||||||
chart = chart_data or get_chart(chart_template)
|
chart = chart_data or get_chart(chart_template)
|
||||||
|
|
||||||
# if no template selected, return as it is
|
# if no template selected, return as it is
|
||||||
@@ -256,33 +222,22 @@ def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=Fals
|
|||||||
return
|
return
|
||||||
|
|
||||||
accounts = []
|
accounts = []
|
||||||
|
|
||||||
def _import_accounts(children, parent):
|
def _import_accounts(children, parent):
|
||||||
"""recursively called to form a parent-child based list of dict from chart template"""
|
''' recursively called to form a parent-child based list of dict from chart template '''
|
||||||
for account_name, child in iteritems(children):
|
for account_name, child in iteritems(children):
|
||||||
account = {}
|
account = {}
|
||||||
if account_name in [
|
if account_name in ["account_name", "account_number", "account_type",\
|
||||||
"account_name",
|
"root_type", "is_group", "tax_rate"]: continue
|
||||||
"account_number",
|
|
||||||
"account_type",
|
|
||||||
"root_type",
|
|
||||||
"is_group",
|
|
||||||
"tax_rate",
|
|
||||||
]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if from_coa_importer:
|
if from_coa_importer:
|
||||||
account_name = child["account_name"]
|
account_name = child['account_name']
|
||||||
|
|
||||||
account["parent_account"] = parent
|
account['parent_account'] = parent
|
||||||
account["expandable"] = True if identify_is_group(child) else False
|
account['expandable'] = True if identify_is_group(child) else False
|
||||||
account["value"] = (
|
account['value'] = (cstr(child.get('account_number')).strip() + ' - ' + account_name) \
|
||||||
(cstr(child.get("account_number")).strip() + " - " + account_name)
|
if child.get('account_number') else account_name
|
||||||
if child.get("account_number")
|
|
||||||
else account_name
|
|
||||||
)
|
|
||||||
accounts.append(account)
|
accounts.append(account)
|
||||||
_import_accounts(child, account["value"])
|
_import_accounts(child, account['value'])
|
||||||
|
|
||||||
_import_accounts(chart, None)
|
_import_accounts(chart, None)
|
||||||
return accounts
|
return accounts
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"""
|
"""
|
||||||
Import chart of accounts from OpenERP sources
|
Import chart of accounts from OpenERP sources
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
import json
|
import json
|
||||||
@@ -21,7 +22,6 @@ charts = {}
|
|||||||
all_account_types = []
|
all_account_types = []
|
||||||
all_roots = {}
|
all_roots = {}
|
||||||
|
|
||||||
|
|
||||||
def go():
|
def go():
|
||||||
global accounts, charts
|
global accounts, charts
|
||||||
default_account_types = get_default_account_types()
|
default_account_types = get_default_account_types()
|
||||||
@@ -36,16 +36,14 @@ def go():
|
|||||||
accounts, charts = {}, {}
|
accounts, charts = {}, {}
|
||||||
country_path = os.path.join(path, country_dir)
|
country_path = os.path.join(path, country_dir)
|
||||||
manifest = ast.literal_eval(open(os.path.join(country_path, "__openerp__.py")).read())
|
manifest = ast.literal_eval(open(os.path.join(country_path, "__openerp__.py")).read())
|
||||||
data_files = (
|
data_files = manifest.get("data", []) + manifest.get("init_xml", []) + \
|
||||||
manifest.get("data", []) + manifest.get("init_xml", []) + manifest.get("update_xml", [])
|
manifest.get("update_xml", [])
|
||||||
)
|
|
||||||
files_path = [os.path.join(country_path, d) for d in data_files]
|
files_path = [os.path.join(country_path, d) for d in data_files]
|
||||||
xml_roots = get_xml_roots(files_path)
|
xml_roots = get_xml_roots(files_path)
|
||||||
csv_content = get_csv_contents(files_path)
|
csv_content = get_csv_contents(files_path)
|
||||||
prefix = country_dir if csv_content else None
|
prefix = country_dir if csv_content else None
|
||||||
account_types = get_account_types(
|
account_types = get_account_types(xml_roots.get("account.account.type", []),
|
||||||
xml_roots.get("account.account.type", []), csv_content.get("account.account.type", []), prefix
|
csv_content.get("account.account.type", []), prefix)
|
||||||
)
|
|
||||||
account_types.update(default_account_types)
|
account_types.update(default_account_types)
|
||||||
|
|
||||||
if xml_roots:
|
if xml_roots:
|
||||||
@@ -58,15 +56,12 @@ def go():
|
|||||||
|
|
||||||
create_all_roots_file()
|
create_all_roots_file()
|
||||||
|
|
||||||
|
|
||||||
def get_default_account_types():
|
def get_default_account_types():
|
||||||
default_types_root = []
|
default_types_root = []
|
||||||
default_types_root.append(
|
default_types_root.append(ET.parse(os.path.join(path, "account", "data",
|
||||||
ET.parse(os.path.join(path, "account", "data", "data_account_type.xml")).getroot()
|
"data_account_type.xml")).getroot())
|
||||||
)
|
|
||||||
return get_account_types(default_types_root, None, prefix="account")
|
return get_account_types(default_types_root, None, prefix="account")
|
||||||
|
|
||||||
|
|
||||||
def get_xml_roots(files_path):
|
def get_xml_roots(files_path):
|
||||||
xml_roots = frappe._dict()
|
xml_roots = frappe._dict()
|
||||||
for filepath in files_path:
|
for filepath in files_path:
|
||||||
@@ -75,69 +70,64 @@ def get_xml_roots(files_path):
|
|||||||
tree = ET.parse(filepath)
|
tree = ET.parse(filepath)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
for node in root[0].findall("record"):
|
for node in root[0].findall("record"):
|
||||||
if node.get("model") in [
|
if node.get("model") in ["account.account.template",
|
||||||
"account.account.template",
|
"account.chart.template", "account.account.type"]:
|
||||||
"account.chart.template",
|
|
||||||
"account.account.type",
|
|
||||||
]:
|
|
||||||
xml_roots.setdefault(node.get("model"), []).append(root)
|
xml_roots.setdefault(node.get("model"), []).append(root)
|
||||||
break
|
break
|
||||||
return xml_roots
|
return xml_roots
|
||||||
|
|
||||||
|
|
||||||
def get_csv_contents(files_path):
|
def get_csv_contents(files_path):
|
||||||
csv_content = {}
|
csv_content = {}
|
||||||
for filepath in files_path:
|
for filepath in files_path:
|
||||||
fname = os.path.basename(filepath)
|
fname = os.path.basename(filepath)
|
||||||
for file_type in ["account.account.template", "account.account.type", "account.chart.template"]:
|
for file_type in ["account.account.template", "account.account.type",
|
||||||
|
"account.chart.template"]:
|
||||||
if fname.startswith(file_type) and fname.endswith(".csv"):
|
if fname.startswith(file_type) and fname.endswith(".csv"):
|
||||||
with open(filepath, "r") as csvfile:
|
with open(filepath, "r") as csvfile:
|
||||||
try:
|
try:
|
||||||
csv_content.setdefault(file_type, []).append(read_csv_content(csvfile.read()))
|
csv_content.setdefault(file_type, [])\
|
||||||
|
.append(read_csv_content(csvfile.read()))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
continue
|
continue
|
||||||
return csv_content
|
return csv_content
|
||||||
|
|
||||||
|
|
||||||
def get_account_types(root_list, csv_content, prefix=None):
|
def get_account_types(root_list, csv_content, prefix=None):
|
||||||
types = {}
|
types = {}
|
||||||
account_type_map = {
|
account_type_map = {
|
||||||
"cash": "Cash",
|
'cash': 'Cash',
|
||||||
"bank": "Bank",
|
'bank': 'Bank',
|
||||||
"tr_cash": "Cash",
|
'tr_cash': 'Cash',
|
||||||
"tr_bank": "Bank",
|
'tr_bank': 'Bank',
|
||||||
"receivable": "Receivable",
|
'receivable': 'Receivable',
|
||||||
"tr_receivable": "Receivable",
|
'tr_receivable': 'Receivable',
|
||||||
"account rec": "Receivable",
|
'account rec': 'Receivable',
|
||||||
"payable": "Payable",
|
'payable': 'Payable',
|
||||||
"tr_payable": "Payable",
|
'tr_payable': 'Payable',
|
||||||
"equity": "Equity",
|
'equity': 'Equity',
|
||||||
"stocks": "Stock",
|
'stocks': 'Stock',
|
||||||
"stock": "Stock",
|
'stock': 'Stock',
|
||||||
"tax": "Tax",
|
'tax': 'Tax',
|
||||||
"tr_tax": "Tax",
|
'tr_tax': 'Tax',
|
||||||
"tax-out": "Tax",
|
'tax-out': 'Tax',
|
||||||
"tax-in": "Tax",
|
'tax-in': 'Tax',
|
||||||
"charges_personnel": "Chargeable",
|
'charges_personnel': 'Chargeable',
|
||||||
"fixed asset": "Fixed Asset",
|
'fixed asset': 'Fixed Asset',
|
||||||
"cogs": "Cost of Goods Sold",
|
'cogs': 'Cost of Goods Sold',
|
||||||
|
|
||||||
}
|
}
|
||||||
for root in root_list:
|
for root in root_list:
|
||||||
for node in root[0].findall("record"):
|
for node in root[0].findall("record"):
|
||||||
if node.get("model") == "account.account.type":
|
if node.get("model")=="account.account.type":
|
||||||
data = {}
|
data = {}
|
||||||
for field in node.findall("field"):
|
for field in node.findall("field"):
|
||||||
if (
|
if field.get("name")=="code" and field.text.lower() != "none" \
|
||||||
field.get("name") == "code"
|
and account_type_map.get(field.text):
|
||||||
and field.text.lower() != "none"
|
data["account_type"] = account_type_map[field.text]
|
||||||
and account_type_map.get(field.text)
|
|
||||||
):
|
|
||||||
data["account_type"] = account_type_map[field.text]
|
|
||||||
|
|
||||||
node_id = prefix + "." + node.get("id") if prefix else node.get("id")
|
node_id = prefix + "." + node.get("id") if prefix else node.get("id")
|
||||||
types[node_id] = data
|
types[node_id] = data
|
||||||
|
|
||||||
if csv_content and csv_content[0][0] == "id":
|
if csv_content and csv_content[0][0]=="id":
|
||||||
for row in csv_content[1:]:
|
for row in csv_content[1:]:
|
||||||
row_dict = dict(zip(csv_content[0], row))
|
row_dict = dict(zip(csv_content[0], row))
|
||||||
data = {}
|
data = {}
|
||||||
@@ -148,22 +138,21 @@ def get_account_types(root_list, csv_content, prefix=None):
|
|||||||
types[node_id] = data
|
types[node_id] = data
|
||||||
return types
|
return types
|
||||||
|
|
||||||
|
|
||||||
def make_maps_for_xml(xml_roots, account_types, country_dir):
|
def make_maps_for_xml(xml_roots, account_types, country_dir):
|
||||||
"""make maps for `charts` and `accounts`"""
|
"""make maps for `charts` and `accounts`"""
|
||||||
for model, root_list in iteritems(xml_roots):
|
for model, root_list in iteritems(xml_roots):
|
||||||
for root in root_list:
|
for root in root_list:
|
||||||
for node in root[0].findall("record"):
|
for node in root[0].findall("record"):
|
||||||
if node.get("model") == "account.account.template":
|
if node.get("model")=="account.account.template":
|
||||||
data = {}
|
data = {}
|
||||||
for field in node.findall("field"):
|
for field in node.findall("field"):
|
||||||
if field.get("name") == "name":
|
if field.get("name")=="name":
|
||||||
data["name"] = field.text
|
data["name"] = field.text
|
||||||
if field.get("name") == "parent_id":
|
if field.get("name")=="parent_id":
|
||||||
parent_id = field.get("ref") or field.get("eval")
|
parent_id = field.get("ref") or field.get("eval")
|
||||||
data["parent_id"] = parent_id
|
data["parent_id"] = parent_id
|
||||||
|
|
||||||
if field.get("name") == "user_type":
|
if field.get("name")=="user_type":
|
||||||
value = field.get("ref")
|
value = field.get("ref")
|
||||||
if account_types.get(value, {}).get("account_type"):
|
if account_types.get(value, {}).get("account_type"):
|
||||||
data["account_type"] = account_types[value]["account_type"]
|
data["account_type"] = account_types[value]["account_type"]
|
||||||
@@ -173,17 +162,16 @@ def make_maps_for_xml(xml_roots, account_types, country_dir):
|
|||||||
data["children"] = []
|
data["children"] = []
|
||||||
accounts[node.get("id")] = data
|
accounts[node.get("id")] = data
|
||||||
|
|
||||||
if node.get("model") == "account.chart.template":
|
if node.get("model")=="account.chart.template":
|
||||||
data = {}
|
data = {}
|
||||||
for field in node.findall("field"):
|
for field in node.findall("field"):
|
||||||
if field.get("name") == "name":
|
if field.get("name")=="name":
|
||||||
data["name"] = field.text
|
data["name"] = field.text
|
||||||
if field.get("name") == "account_root_id":
|
if field.get("name")=="account_root_id":
|
||||||
data["account_root_id"] = field.get("ref")
|
data["account_root_id"] = field.get("ref")
|
||||||
data["id"] = country_dir
|
data["id"] = country_dir
|
||||||
charts.setdefault(node.get("id"), {}).update(data)
|
charts.setdefault(node.get("id"), {}).update(data)
|
||||||
|
|
||||||
|
|
||||||
def make_maps_for_csv(csv_content, account_types, country_dir):
|
def make_maps_for_csv(csv_content, account_types, country_dir):
|
||||||
for content in csv_content.get("account.account.template", []):
|
for content in csv_content.get("account.account.template", []):
|
||||||
for row in content[1:]:
|
for row in content[1:]:
|
||||||
@@ -191,7 +179,7 @@ def make_maps_for_csv(csv_content, account_types, country_dir):
|
|||||||
account = {
|
account = {
|
||||||
"name": data.get("name"),
|
"name": data.get("name"),
|
||||||
"parent_id": data.get("parent_id:id") or data.get("parent_id/id"),
|
"parent_id": data.get("parent_id:id") or data.get("parent_id/id"),
|
||||||
"children": [],
|
"children": []
|
||||||
}
|
}
|
||||||
user_type = data.get("user_type/id") or data.get("user_type:id")
|
user_type = data.get("user_type/id") or data.get("user_type:id")
|
||||||
if account_types.get(user_type, {}).get("account_type"):
|
if account_types.get(user_type, {}).get("account_type"):
|
||||||
@@ -208,14 +196,12 @@ def make_maps_for_csv(csv_content, account_types, country_dir):
|
|||||||
for row in content[1:]:
|
for row in content[1:]:
|
||||||
if row:
|
if row:
|
||||||
data = dict(zip(content[0], row))
|
data = dict(zip(content[0], row))
|
||||||
charts.setdefault(data.get("id"), {}).update(
|
charts.setdefault(data.get("id"), {}).update({
|
||||||
{
|
"account_root_id": data.get("account_root_id:id") or \
|
||||||
"account_root_id": data.get("account_root_id:id") or data.get("account_root_id/id"),
|
data.get("account_root_id/id"),
|
||||||
"name": data.get("name"),
|
"name": data.get("name"),
|
||||||
"id": country_dir,
|
"id": country_dir
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def make_account_trees():
|
def make_account_trees():
|
||||||
"""build tree hierarchy"""
|
"""build tree hierarchy"""
|
||||||
@@ -234,7 +220,6 @@ def make_account_trees():
|
|||||||
if "children" in accounts[id] and not accounts[id].get("children"):
|
if "children" in accounts[id] and not accounts[id].get("children"):
|
||||||
del accounts[id]["children"]
|
del accounts[id]["children"]
|
||||||
|
|
||||||
|
|
||||||
def make_charts():
|
def make_charts():
|
||||||
"""write chart files in app/setup/doctype/company/charts"""
|
"""write chart files in app/setup/doctype/company/charts"""
|
||||||
for chart_id in charts:
|
for chart_id in charts:
|
||||||
@@ -253,38 +238,34 @@ def make_charts():
|
|||||||
chart["country_code"] = src["id"][5:]
|
chart["country_code"] = src["id"][5:]
|
||||||
chart["tree"] = accounts[src["account_root_id"]]
|
chart["tree"] = accounts[src["account_root_id"]]
|
||||||
|
|
||||||
|
|
||||||
for key, val in chart["tree"].items():
|
for key, val in chart["tree"].items():
|
||||||
if key in ["name", "parent_id"]:
|
if key in ["name", "parent_id"]:
|
||||||
chart["tree"].pop(key)
|
chart["tree"].pop(key)
|
||||||
if type(val) == dict:
|
if type(val) == dict:
|
||||||
val["root_type"] = ""
|
val["root_type"] = ""
|
||||||
if chart:
|
if chart:
|
||||||
fpath = os.path.join(
|
fpath = os.path.join("erpnext", "erpnext", "accounts", "doctype", "account",
|
||||||
"erpnext", "erpnext", "accounts", "doctype", "account", "chart_of_accounts", filename + ".json"
|
"chart_of_accounts", filename + ".json")
|
||||||
)
|
|
||||||
|
|
||||||
with open(fpath, "r") as chartfile:
|
with open(fpath, "r") as chartfile:
|
||||||
old_content = chartfile.read()
|
old_content = chartfile.read()
|
||||||
if not old_content or (
|
if not old_content or (json.loads(old_content).get("is_active", "No") == "No" \
|
||||||
json.loads(old_content).get("is_active", "No") == "No"
|
and json.loads(old_content).get("disabled", "No") == "No"):
|
||||||
and json.loads(old_content).get("disabled", "No") == "No"
|
|
||||||
):
|
|
||||||
with open(fpath, "w") as chartfile:
|
with open(fpath, "w") as chartfile:
|
||||||
chartfile.write(json.dumps(chart, indent=4, sort_keys=True))
|
chartfile.write(json.dumps(chart, indent=4, sort_keys=True))
|
||||||
|
|
||||||
all_roots.setdefault(filename, chart["tree"].keys())
|
all_roots.setdefault(filename, chart["tree"].keys())
|
||||||
|
|
||||||
|
|
||||||
def create_all_roots_file():
|
def create_all_roots_file():
|
||||||
with open("all_roots.txt", "w") as f:
|
with open('all_roots.txt', 'w') as f:
|
||||||
for filename, roots in sorted(all_roots.items()):
|
for filename, roots in sorted(all_roots.items()):
|
||||||
f.write(filename)
|
f.write(filename)
|
||||||
f.write("\n----------------------\n")
|
f.write('\n----------------------\n')
|
||||||
for r in sorted(roots):
|
for r in sorted(roots):
|
||||||
f.write(r.encode("utf-8"))
|
f.write(r.encode('utf-8'))
|
||||||
f.write("\n")
|
f.write('\n')
|
||||||
f.write("\n\n\n")
|
f.write('\n\n\n')
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
if __name__ == "__main__":
|
|
||||||
go()
|
go()
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
{
|
{
|
||||||
"country_code": "de",
|
"country_code": "de",
|
||||||
"name": "SKR03 mit Kontonummern",
|
"name": "SKR03 mit Kontonummern",
|
||||||
"tree": {
|
"tree": {
|
||||||
"Aktiva": {
|
"Aktiva": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Asset",
|
"root_type": "Asset",
|
||||||
"A - Anlagevermögen": {
|
"A - Anlagevermögen": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"EDV-Software": {
|
"EDV-Software": {
|
||||||
"account_number": "0027",
|
"account_number": "0027",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Geschäftsausstattung": {
|
"Gesch\u00e4ftsausstattung": {
|
||||||
"account_number": "0410",
|
"account_number": "0410",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Büroeinrichtung": {
|
"B\u00fcroeinrichtung": {
|
||||||
"account_number": "0420",
|
"account_number": "0420",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Darlehen": {
|
"Darlehen": {
|
||||||
"account_number": "0565"
|
"account_number": "0565"
|
||||||
},
|
},
|
||||||
"Maschinen": {
|
"Maschinen": {
|
||||||
"account_number": "0210",
|
"account_number": "0210",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Betriebsausstattung": {
|
"Betriebsausstattung": {
|
||||||
"account_number": "0400",
|
"account_number": "0400",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Ladeneinrichtung": {
|
"Ladeneinrichtung": {
|
||||||
"account_number": "0430",
|
"account_number": "0430",
|
||||||
"account_type": "Fixed Asset"
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
"Accumulated Depreciation": {
|
"Accumulated Depreciation": {
|
||||||
"account_type": "Accumulated Depreciation"
|
"account_type": "Accumulated Depreciation"
|
||||||
@@ -60,46 +60,36 @@
|
|||||||
"Durchlaufende Posten": {
|
"Durchlaufende Posten": {
|
||||||
"account_number": "1590"
|
"account_number": "1590"
|
||||||
},
|
},
|
||||||
"Verrechnungskonto Gewinnermittlung § 4 Abs. 3 EStG, nicht ergebniswirksam": {
|
"Gewinnermittlung \u00a74/3 nicht Ergebniswirksam": {
|
||||||
"account_number": "1371"
|
"account_number": "1371"
|
||||||
},
|
},
|
||||||
"Abziehbare Vorsteuer": {
|
"Abziehbare Vorsteuer": {
|
||||||
|
"account_type": "Tax",
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Abziehbare Vorsteuer 7 %": {
|
"Abziehbare Vorsteuer 7%": {
|
||||||
"account_number": "1571",
|
"account_number": "1571"
|
||||||
"account_type": "Tax",
|
|
||||||
"tax_rate": 7.0
|
|
||||||
},
|
},
|
||||||
"Abziehbare Vorsteuer 19 %": {
|
"Abziehbare Vorsteuer 19%": {
|
||||||
"account_number": "1576",
|
"account_number": "1576"
|
||||||
"account_type": "Tax",
|
|
||||||
"tax_rate": 19.0
|
|
||||||
},
|
},
|
||||||
"Abziehbare Vorsteuer nach § 13b UStG 19 %": {
|
"Abziehbare Vorsteuer nach \u00a713b UStG 19%": {
|
||||||
"account_number": "1577",
|
"account_number": "1577"
|
||||||
"account_type": "Tax",
|
},
|
||||||
"tax_rate": 19.0
|
"Leistungen \u00a713b UStG 19% Vorsteuer, 19% Umsatzsteuer": {
|
||||||
|
"account_number": "3120"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"III. Wertpapiere": {
|
"III. Wertpapiere": {
|
||||||
"is_group": 1,
|
"is_group": 1
|
||||||
"Anteile an verbundenen Unternehmen (Umlaufvermögen)": {
|
|
||||||
"account_number": "1340"
|
|
||||||
},
|
|
||||||
"Anteile an herrschender oder mit Mehrheit beteiligter Gesellschaft": {
|
|
||||||
"account_number": "1344"
|
|
||||||
},
|
|
||||||
"Sonstige Wertpapiere": {
|
|
||||||
"account_number": "1348"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"IV. Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks.": {
|
"IV. Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks.": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Kasse": {
|
"Kasse": {
|
||||||
"is_group": 1,
|
|
||||||
"account_type": "Cash",
|
"account_type": "Cash",
|
||||||
|
"is_group": 1,
|
||||||
"Kasse": {
|
"Kasse": {
|
||||||
|
"is_group": 1,
|
||||||
"account_number": "1000",
|
"account_number": "1000",
|
||||||
"account_type": "Cash"
|
"account_type": "Cash"
|
||||||
}
|
}
|
||||||
@@ -121,21 +111,21 @@
|
|||||||
"C - Rechnungsabgrenzungsposten": {
|
"C - Rechnungsabgrenzungsposten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Aktive Rechnungsabgrenzung": {
|
"Aktive Rechnungsabgrenzung": {
|
||||||
"account_number": "0980"
|
"account_number": "0980"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"D - Aktive latente Steuern": {
|
"D - Aktive latente Steuern": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Aktive latente Steuern": {
|
"Aktive latente Steuern": {
|
||||||
"account_number": "0983"
|
"account_number": "0983"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"E - Aktiver Unterschiedsbetrag aus der Vermögensverrechnung": {
|
"E - Aktiver Unterschiedsbetrag aus der Vermögensverrechnung": {
|
||||||
"is_group": 1
|
"is_group": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Passiva": {
|
"Passiva": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Liability",
|
"root_type": "Liability",
|
||||||
"A. Eigenkapital": {
|
"A. Eigenkapital": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
@@ -210,32 +200,26 @@
|
|||||||
},
|
},
|
||||||
"Umsatzsteuer": {
|
"Umsatzsteuer": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Umsatzsteuer 7 %": {
|
"account_type": "Tax",
|
||||||
"account_number": "1771",
|
"Umsatzsteuer 7%": {
|
||||||
"account_type": "Tax",
|
"account_number": "1771"
|
||||||
"tax_rate": 7.0
|
|
||||||
},
|
},
|
||||||
"Umsatzsteuer 19 %": {
|
"Umsatzsteuer 19%": {
|
||||||
"account_number": "1776",
|
"account_number": "1776"
|
||||||
"account_type": "Tax",
|
|
||||||
"tax_rate": 19.0
|
|
||||||
},
|
},
|
||||||
"Umsatzsteuer-Vorauszahlung": {
|
"Umsatzsteuer-Vorauszahlung": {
|
||||||
"account_number": "1780",
|
"account_number": "1780"
|
||||||
"account_type": "Tax"
|
|
||||||
},
|
},
|
||||||
"Umsatzsteuer-Vorauszahlung 1/11": {
|
"Umsatzsteuer-Vorauszahlung 1/11": {
|
||||||
"account_number": "1781"
|
"account_number": "1781"
|
||||||
},
|
},
|
||||||
"Umsatzsteuer nach § 13b UStG 19 %": {
|
"Umsatzsteuer \u00a7 13b UStG 19%": {
|
||||||
"account_number": "1787",
|
"account_number": "1787"
|
||||||
"account_type": "Tax",
|
|
||||||
"tax_rate": 19.0
|
|
||||||
},
|
},
|
||||||
"Umsatzsteuer Vorjahr": {
|
"Umsatzsteuer Vorjahr": {
|
||||||
"account_number": "1790"
|
"account_number": "1790"
|
||||||
},
|
},
|
||||||
"Umsatzsteuer frühere Jahre": {
|
"Umsatzsteuer fr\u00fchere Jahre": {
|
||||||
"account_number": "1791"
|
"account_number": "1791"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,56 +234,44 @@
|
|||||||
"E. Passive latente Steuern": {
|
"E. Passive latente Steuern": {
|
||||||
"is_group": 1
|
"is_group": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Erlöse u. Erträge 2/8": {
|
"Erl\u00f6se u. Ertr\u00e4ge 2/8": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Income",
|
"root_type": "Income",
|
||||||
"Erlöskonten 8": {
|
"Erl\u00f6skonten 8": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Erlöse": {
|
"Erl\u00f6se": {
|
||||||
"account_number": "8200",
|
"account_number": "8200",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
},
|
},
|
||||||
"Erlöse USt. 19 %": {
|
"Erl\u00f6se USt. 19%": {
|
||||||
"account_number": "8400",
|
"account_number": "8400",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
},
|
},
|
||||||
"Erlöse USt. 7 %": {
|
"Erl\u00f6se USt. 7%": {
|
||||||
"account_number": "8300",
|
"account_number": "8300",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Ertragskonten 2": {
|
"Ertragskonten 2": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"sonstige Zinsen und ähnliche Erträge": {
|
"sonstige Zinsen und \u00e4hnliche Ertr\u00e4ge": {
|
||||||
"account_number": "2650",
|
"account_number": "2650",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
},
|
},
|
||||||
"Außerordentliche Erträge": {
|
"Au\u00dferordentliche Ertr\u00e4ge": {
|
||||||
"account_number": "2500",
|
"account_number": "2500",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
},
|
},
|
||||||
"Sonstige Erträge": {
|
"Sonstige Ertr\u00e4ge": {
|
||||||
"account_number": "2700",
|
"account_number": "2700",
|
||||||
"account_type": "Income Account"
|
"account_type": "Income Account"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Aufwendungen 2/4": {
|
"Aufwendungen 2/4": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Expense",
|
"root_type": "Expense",
|
||||||
"Fremdleistungen": {
|
|
||||||
"account_number": "3100",
|
|
||||||
"account_type": "Expense Account"
|
|
||||||
},
|
|
||||||
"Fremdleistungen ohne Vorsteuer": {
|
|
||||||
"account_number": "3109",
|
|
||||||
"account_type": "Expense Account"
|
|
||||||
},
|
|
||||||
"Bauleistungen eines im Inland ansässigen Unternehmers 19 % Vorsteuer und 19 % Umsatzsteuer": {
|
|
||||||
"account_number": "3120",
|
|
||||||
"account_type": "Expense Account"
|
|
||||||
},
|
|
||||||
"Wareneingang": {
|
"Wareneingang": {
|
||||||
"account_number": "3200"
|
"account_number": "3200"
|
||||||
},
|
},
|
||||||
@@ -326,234 +298,234 @@
|
|||||||
"Gegenkonto 4996-4998": {
|
"Gegenkonto 4996-4998": {
|
||||||
"account_number": "4999"
|
"account_number": "4999"
|
||||||
},
|
},
|
||||||
"Abschreibungen": {
|
"Abschreibungen": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Abschreibungen auf Sachanlagen (ohne AfA auf Kfz und Gebäude)": {
|
"Abschreibungen auf Sachanlagen (ohne AfA auf Kfz und Gebäude)": {
|
||||||
"account_number": "4830",
|
"account_number": "4830",
|
||||||
"account_type": "Accumulated Depreciation"
|
"account_type": "Accumulated Depreciation"
|
||||||
},
|
},
|
||||||
"Abschreibungen auf Gebäude": {
|
"Abschreibungen auf Gebäude": {
|
||||||
"account_number": "4831",
|
"account_number": "4831",
|
||||||
"account_type": "Depreciation"
|
"account_type": "Depreciation"
|
||||||
},
|
},
|
||||||
"Abschreibungen auf Kfz": {
|
"Abschreibungen auf Kfz": {
|
||||||
"account_number": "4832",
|
"account_number": "4832",
|
||||||
"account_type": "Depreciation"
|
"account_type": "Depreciation"
|
||||||
},
|
},
|
||||||
"Sofortabschreibung GWG": {
|
"Sofortabschreibung GWG": {
|
||||||
"account_number": "4855",
|
"account_number": "4855",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Kfz-Kosten": {
|
"Kfz-Kosten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Kfz-Steuer": {
|
"Kfz-Steuer": {
|
||||||
"account_number": "4510",
|
"account_number": "4510",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Kfz-Versicherungen": {
|
"Kfz-Versicherungen": {
|
||||||
"account_number": "4520",
|
"account_number": "4520",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"laufende Kfz-Betriebskosten": {
|
"laufende Kfz-Betriebskosten": {
|
||||||
"account_number": "4530",
|
"account_number": "4530",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Kfz-Reparaturen": {
|
"Kfz-Reparaturen": {
|
||||||
"account_number": "4540",
|
"account_number": "4540",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Fremdfahrzeuge": {
|
"Fremdfahrzeuge": {
|
||||||
"account_number": "4570",
|
"account_number": "4570",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"sonstige Kfz-Kosten": {
|
"sonstige Kfz-Kosten": {
|
||||||
"account_number": "4580",
|
"account_number": "4580",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Personalkosten": {
|
"Personalkosten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Gehälter": {
|
"Geh\u00e4lter": {
|
||||||
"account_number": "4120",
|
"account_number": "4120",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"gesetzliche soziale Aufwendungen": {
|
"gesetzliche soziale Aufwendungen": {
|
||||||
"account_number": "4130",
|
"account_number": "4130",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Aufwendungen für Altersvorsorge": {
|
"Aufwendungen f\u00fcr Altersvorsorge": {
|
||||||
"account_number": "4165",
|
"account_number": "4165",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Vermögenswirksame Leistungen": {
|
"Verm\u00f6genswirksame Leistungen": {
|
||||||
"account_number": "4170",
|
"account_number": "4170",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Aushilfslöhne": {
|
"Aushilfsl\u00f6hne": {
|
||||||
"account_number": "4190",
|
"account_number": "4190",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Raumkosten": {
|
"Raumkosten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Miete und Nebenkosten": {
|
"Miete und Nebenkosten": {
|
||||||
"account_number": "4210",
|
"account_number": "4210",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Gas, Wasser, Strom (Verwaltung, Vertrieb)": {
|
"Gas, Wasser, Strom (Verwaltung, Vertrieb)": {
|
||||||
"account_number": "4240",
|
"account_number": "4240",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Reinigung": {
|
"Reinigung": {
|
||||||
"account_number": "4250",
|
"account_number": "4250",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Reparatur/Instandhaltung": {
|
"Reparatur/Instandhaltung": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Reparaturen und Instandhaltungen von anderen Anlagen und Betriebs- und Geschäftsausstattung": {
|
"Reparatur u. Instandh. von Anlagen/Maschinen u. Betriebs- u. Gesch\u00e4ftsausst.": {
|
||||||
"account_number": "4805",
|
"account_number": "4805",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Versicherungsbeiträge": {
|
"Versicherungsbeitr\u00e4ge": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Versicherungen": {
|
"Versicherungen": {
|
||||||
"account_number": "4360",
|
"account_number": "4360",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Beiträge": {
|
"Beitr\u00e4ge": {
|
||||||
"account_number": "4380",
|
"account_number": "4380",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"sonstige Ausgaben": {
|
"sonstige Ausgaben": {
|
||||||
"account_number": "4390",
|
"account_number": "4390",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"steuerlich abzugsfähige Verspätungszuschläge und Zwangsgelder": {
|
"steuerlich abzugsf\u00e4hige Versp\u00e4tungszuschl\u00e4ge und Zwangsgelder": {
|
||||||
"account_number": "4396",
|
"account_number": "4396",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Werbe-/Reisekosten": {
|
"Werbe-/Reisekosten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Werbekosten": {
|
"Werbekosten": {
|
||||||
"account_number": "4610",
|
"account_number": "4610",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Aufmerksamkeiten": {
|
"Aufmerksamkeiten": {
|
||||||
"account_number": "4653",
|
"account_number": "4653",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"nicht abzugsfähige Betriebsausg. aus Werbe-, Repräs.- u. Reisekosten": {
|
"nicht abzugsf\u00e4hige Betriebsausg. aus Werbe-, Repr\u00e4s.- u. Reisekosten": {
|
||||||
"account_number": "4665",
|
"account_number": "4665",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Reisekosten Unternehmer": {
|
"Reisekosten Unternehmer": {
|
||||||
"account_number": "4670",
|
"account_number": "4670",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"verschiedene Kosten": {
|
"verschiedene Kosten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Porto": {
|
"Porto": {
|
||||||
"account_number": "4910",
|
"account_number": "4910",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Telekom": {
|
"Telekom": {
|
||||||
"account_number": "4920",
|
"account_number": "4920",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Mobilfunk D2": {
|
"Mobilfunk D2": {
|
||||||
"account_number": "4921",
|
"account_number": "4921",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Internet": {
|
"Internet": {
|
||||||
"account_number": "4922",
|
"account_number": "4922",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Bürobedarf": {
|
"B\u00fcrobedarf": {
|
||||||
"account_number": "4930",
|
"account_number": "4930",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Zeitschriften, Bücher": {
|
"Zeitschriften, B\u00fccher": {
|
||||||
"account_number": "4940",
|
"account_number": "4940",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Fortbildungskosten": {
|
"Fortbildungskosten": {
|
||||||
"account_number": "4945",
|
"account_number": "4945",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Buchführungskosten": {
|
"Buchf\u00fchrungskosten": {
|
||||||
"account_number": "4955",
|
"account_number": "4955",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Abschluß- u. Prüfungskosten": {
|
"Abschlu\u00df- u. Pr\u00fcfungskosten": {
|
||||||
"account_number": "4957",
|
"account_number": "4957",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Nebenkosten des Geldverkehrs": {
|
"Nebenkosten des Geldverkehrs": {
|
||||||
"account_number": "4970",
|
"account_number": "4970",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Werkzeuge und Kleingeräte": {
|
"Werkzeuge und Kleinger\u00e4te": {
|
||||||
"account_number": "4985",
|
"account_number": "4985",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Zinsaufwendungen": {
|
"Zinsaufwendungen": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Zinsaufwendungen für kurzfristige Verbindlichkeiten": {
|
"Zinsaufwendungen f\u00fcr kurzfristige Verbindlichkeiten": {
|
||||||
"account_number": "2110",
|
"account_number": "2110",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
},
|
},
|
||||||
"Zinsaufwendungen für KFZ Finanzierung": {
|
"Zinsaufwendungen f\u00fcr KFZ Finanzierung": {
|
||||||
"account_number": "2121",
|
"account_number": "2121",
|
||||||
"account_type": "Expense Account"
|
"account_type": "Expense Account"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Anfangsbestand 9": {
|
"Anfangsbestand 9": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Equity",
|
"root_type": "Equity",
|
||||||
"Saldenvortragskonten": {
|
"Saldenvortragskonten": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Saldenvortrag Sachkonten": {
|
"Saldenvortrag Sachkonten": {
|
||||||
"account_number": "9000"
|
"account_number": "9000"
|
||||||
},
|
},
|
||||||
"Saldenvorträge Debitoren": {
|
"Saldenvortr\u00e4ge Debitoren": {
|
||||||
"account_number": "9008"
|
"account_number": "9008"
|
||||||
},
|
},
|
||||||
"Saldenvorträge Kreditoren": {
|
"Saldenvortr\u00e4ge Kreditoren": {
|
||||||
"account_number": "9009"
|
"account_number": "9009"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Privatkonten 1": {
|
"Privatkonten 1": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"root_type": "Equity",
|
"root_type": "Equity",
|
||||||
"Privatentnahmen/-einlagen": {
|
"Privatentnahmen/-einlagen": {
|
||||||
"is_group": 1,
|
"is_group": 1,
|
||||||
"Privatentnahme allgemein": {
|
"Privatentnahme allgemein": {
|
||||||
"account_number": "1800"
|
"account_number": "1800"
|
||||||
},
|
},
|
||||||
"Privatsteuern": {
|
"Privatsteuern": {
|
||||||
"account_number": "1810"
|
"account_number": "1810"
|
||||||
},
|
},
|
||||||
"Sonderausgaben beschränkt abzugsfähig": {
|
"Sonderausgaben beschr\u00e4nkt abzugsf\u00e4hig": {
|
||||||
"account_number": "1820"
|
"account_number": "1820"
|
||||||
},
|
},
|
||||||
"Sonderausgaben unbeschränkt abzugsfähig": {
|
"Sonderausgaben unbeschr\u00e4nkt abzugsf\u00e4hig": {
|
||||||
"account_number": "1830"
|
"account_number": "1830"
|
||||||
},
|
},
|
||||||
"Außergewöhnliche Belastungen": {
|
"Au\u00dfergew\u00f6hnliche Belastungen": {
|
||||||
"account_number": "1850"
|
"account_number": "1850"
|
||||||
},
|
},
|
||||||
"Privateinlagen": {
|
"Privateinlagen": {
|
||||||
"account_number": "1890"
|
"account_number": "1890"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +1,189 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
return {
|
return {
|
||||||
_("Application of Funds (Assets)"): {
|
_("Application of Funds (Assets)"): {
|
||||||
_("Current Assets"): {
|
_("Current Assets"): {
|
||||||
_("Accounts Receivable"): {_("Debtors"): {"account_type": "Receivable"}},
|
_("Accounts Receivable"): {
|
||||||
_("Bank Accounts"): {"account_type": "Bank", "is_group": 1},
|
_("Debtors"): {
|
||||||
_("Cash In Hand"): {_("Cash"): {"account_type": "Cash"}, "account_type": "Cash"},
|
"account_type": "Receivable"
|
||||||
_("Loans and Advances (Assets)"): {
|
}
|
||||||
_("Employee Advances"): {},
|
},
|
||||||
|
_("Bank Accounts"): {
|
||||||
|
"account_type": "Bank",
|
||||||
|
"is_group": 1
|
||||||
|
},
|
||||||
|
_("Cash In Hand"): {
|
||||||
|
_("Cash"): {
|
||||||
|
"account_type": "Cash"
|
||||||
|
},
|
||||||
|
"account_type": "Cash"
|
||||||
|
},
|
||||||
|
_("Loans and Advances (Assets)"): {
|
||||||
|
_("Employee Advances"): {
|
||||||
|
},
|
||||||
|
},
|
||||||
|
_("Securities and Deposits"): {
|
||||||
|
_("Earnest Money"): {}
|
||||||
|
},
|
||||||
|
_("Stock Assets"): {
|
||||||
|
_("Stock In Hand"): {
|
||||||
|
"account_type": "Stock"
|
||||||
|
},
|
||||||
|
"account_type": "Stock",
|
||||||
|
},
|
||||||
|
_("Tax Assets"): {
|
||||||
|
"is_group": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_("Fixed Assets"): {
|
||||||
|
_("Capital Equipments"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
|
},
|
||||||
|
_("Electronic Equipments"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
|
},
|
||||||
|
_("Furnitures and Fixtures"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
|
},
|
||||||
|
_("Office Equipments"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
|
},
|
||||||
|
_("Plants and Machineries"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
|
},
|
||||||
|
_("Buildings"): {
|
||||||
|
"account_type": "Fixed Asset"
|
||||||
},
|
},
|
||||||
_("Securities and Deposits"): {_("Earnest Money"): {}},
|
_("Softwares"): {
|
||||||
_("Stock Assets"): {
|
"account_type": "Fixed Asset"
|
||||||
_("Stock In Hand"): {"account_type": "Stock"},
|
|
||||||
"account_type": "Stock",
|
|
||||||
},
|
},
|
||||||
_("Tax Assets"): {"is_group": 1},
|
_("Accumulated Depreciation"): {
|
||||||
},
|
"account_type": "Accumulated Depreciation"
|
||||||
_("Fixed Assets"): {
|
},
|
||||||
_("Capital Equipments"): {"account_type": "Fixed Asset"},
|
_("CWIP Account"): {
|
||||||
_("Electronic Equipments"): {"account_type": "Fixed Asset"},
|
"account_type": "Capital Work in Progress",
|
||||||
_("Furnitures and Fixtures"): {"account_type": "Fixed Asset"},
|
}
|
||||||
_("Office Equipments"): {"account_type": "Fixed Asset"},
|
},
|
||||||
_("Plants and Machineries"): {"account_type": "Fixed Asset"},
|
_("Investments"): {
|
||||||
_("Buildings"): {"account_type": "Fixed Asset"},
|
"is_group": 1
|
||||||
_("Softwares"): {"account_type": "Fixed Asset"},
|
},
|
||||||
_("Accumulated Depreciation"): {"account_type": "Accumulated Depreciation"},
|
_("Temporary Accounts"): {
|
||||||
_("CWIP Account"): {
|
_("Temporary Opening"): {
|
||||||
"account_type": "Capital Work in Progress",
|
"account_type": "Temporary"
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
_("Investments"): {"is_group": 1},
|
"root_type": "Asset"
|
||||||
_("Temporary Accounts"): {_("Temporary Opening"): {"account_type": "Temporary"}},
|
},
|
||||||
"root_type": "Asset",
|
_("Expenses"): {
|
||||||
},
|
_("Direct Expenses"): {
|
||||||
_("Expenses"): {
|
_("Stock Expenses"): {
|
||||||
_("Direct Expenses"): {
|
_("Cost of Goods Sold"): {
|
||||||
_("Stock Expenses"): {
|
"account_type": "Cost of Goods Sold"
|
||||||
_("Cost of Goods Sold"): {"account_type": "Cost of Goods Sold"},
|
},
|
||||||
_("Expenses Included In Asset Valuation"): {
|
_("Expenses Included In Asset Valuation"): {
|
||||||
"account_type": "Expenses Included In Asset Valuation"
|
"account_type": "Expenses Included In Asset Valuation"
|
||||||
},
|
},
|
||||||
_("Expenses Included In Valuation"): {"account_type": "Expenses Included In Valuation"},
|
_("Expenses Included In Valuation"): {
|
||||||
_("Stock Adjustment"): {"account_type": "Stock Adjustment"},
|
"account_type": "Expenses Included In Valuation"
|
||||||
},
|
},
|
||||||
},
|
_("Stock Adjustment"): {
|
||||||
_("Indirect Expenses"): {
|
"account_type": "Stock Adjustment"
|
||||||
_("Administrative Expenses"): {},
|
}
|
||||||
_("Commission on Sales"): {},
|
},
|
||||||
_("Depreciation"): {"account_type": "Depreciation"},
|
},
|
||||||
_("Entertainment Expenses"): {},
|
_("Indirect Expenses"): {
|
||||||
_("Freight and Forwarding Charges"): {"account_type": "Chargeable"},
|
_("Administrative Expenses"): {},
|
||||||
_("Legal Expenses"): {},
|
_("Commission on Sales"): {},
|
||||||
_("Marketing Expenses"): {"account_type": "Chargeable"},
|
_("Depreciation"): {
|
||||||
_("Miscellaneous Expenses"): {"account_type": "Chargeable"},
|
"account_type": "Depreciation"
|
||||||
_("Office Maintenance Expenses"): {},
|
},
|
||||||
_("Office Rent"): {},
|
_("Entertainment Expenses"): {},
|
||||||
_("Postal Expenses"): {},
|
_("Freight and Forwarding Charges"): {
|
||||||
_("Print and Stationery"): {},
|
"account_type": "Chargeable"
|
||||||
_("Round Off"): {"account_type": "Round Off"},
|
},
|
||||||
_("Salary"): {},
|
_("Legal Expenses"): {},
|
||||||
_("Sales Expenses"): {},
|
_("Marketing Expenses"): {
|
||||||
_("Telephone Expenses"): {},
|
"account_type": "Chargeable"
|
||||||
_("Travel Expenses"): {},
|
},
|
||||||
_("Utility Expenses"): {},
|
_("Miscellaneous Expenses"): {
|
||||||
|
"account_type": "Chargeable"
|
||||||
|
},
|
||||||
|
_("Office Maintenance Expenses"): {},
|
||||||
|
_("Office Rent"): {},
|
||||||
|
_("Postal Expenses"): {},
|
||||||
|
_("Print and Stationery"): {},
|
||||||
|
_("Round Off"): {
|
||||||
|
"account_type": "Round Off"
|
||||||
|
},
|
||||||
|
_("Salary"): {},
|
||||||
|
_("Sales Expenses"): {},
|
||||||
|
_("Telephone Expenses"): {},
|
||||||
|
_("Travel Expenses"): {},
|
||||||
|
_("Utility Expenses"): {},
|
||||||
_("Write Off"): {},
|
_("Write Off"): {},
|
||||||
_("Exchange Gain/Loss"): {},
|
_("Exchange Gain/Loss"): {},
|
||||||
_("Gain/Loss on Asset Disposal"): {},
|
_("Gain/Loss on Asset Disposal"): {}
|
||||||
},
|
},
|
||||||
"root_type": "Expense",
|
"root_type": "Expense"
|
||||||
},
|
},
|
||||||
_("Income"): {
|
_("Income"): {
|
||||||
_("Direct Income"): {_("Sales"): {}, _("Service"): {}},
|
_("Direct Income"): {
|
||||||
_("Indirect Income"): {"is_group": 1},
|
_("Sales"): {},
|
||||||
"root_type": "Income",
|
_("Service"): {}
|
||||||
},
|
},
|
||||||
_("Source of Funds (Liabilities)"): {
|
_("Indirect Income"): {
|
||||||
_("Current Liabilities"): {
|
"is_group": 1
|
||||||
_("Accounts Payable"): {
|
},
|
||||||
_("Creditors"): {"account_type": "Payable"},
|
"root_type": "Income"
|
||||||
_("Payroll Payable"): {},
|
},
|
||||||
|
_("Source of Funds (Liabilities)"): {
|
||||||
|
_("Current Liabilities"): {
|
||||||
|
_("Accounts Payable"): {
|
||||||
|
_("Creditors"): {
|
||||||
|
"account_type": "Payable"
|
||||||
|
},
|
||||||
|
_("Payroll Payable"): {},
|
||||||
|
},
|
||||||
|
_("Stock Liabilities"): {
|
||||||
|
_("Stock Received But Not Billed"): {
|
||||||
|
"account_type": "Stock Received But Not Billed"
|
||||||
|
},
|
||||||
|
_("Asset Received But Not Billed"): {
|
||||||
|
"account_type": "Asset Received But Not Billed"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_("Duties and Taxes"): {
|
||||||
|
"account_type": "Tax",
|
||||||
|
"is_group": 1
|
||||||
},
|
},
|
||||||
_("Stock Liabilities"): {
|
|
||||||
_("Stock Received But Not Billed"): {"account_type": "Stock Received But Not Billed"},
|
|
||||||
_("Asset Received But Not Billed"): {"account_type": "Asset Received But Not Billed"},
|
|
||||||
},
|
|
||||||
_("Duties and Taxes"): {"account_type": "Tax", "is_group": 1},
|
|
||||||
_("Loans (Liabilities)"): {
|
_("Loans (Liabilities)"): {
|
||||||
_("Secured Loans"): {},
|
_("Secured Loans"): {},
|
||||||
_("Unsecured Loans"): {},
|
_("Unsecured Loans"): {},
|
||||||
_("Bank Overdraft Account"): {},
|
_("Bank Overdraft Account"): {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"root_type": "Liability",
|
"root_type": "Liability"
|
||||||
},
|
},
|
||||||
_("Equity"): {
|
_("Equity"): {
|
||||||
_("Capital Stock"): {"account_type": "Equity"},
|
_("Capital Stock"): {
|
||||||
_("Dividends Paid"): {"account_type": "Equity"},
|
"account_type": "Equity"
|
||||||
_("Opening Balance Equity"): {"account_type": "Equity"},
|
},
|
||||||
_("Retained Earnings"): {"account_type": "Equity"},
|
_("Dividends Paid"): {
|
||||||
"root_type": "Equity",
|
"account_type": "Equity"
|
||||||
},
|
},
|
||||||
|
_("Opening Balance Equity"): {
|
||||||
|
"account_type": "Equity"
|
||||||
|
},
|
||||||
|
_("Retained Earnings"): {
|
||||||
|
"account_type": "Equity"
|
||||||
|
},
|
||||||
|
"root_type": "Equity"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,158 +1,294 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
return {
|
return {
|
||||||
_("Application of Funds (Assets)"): {
|
_("Application of Funds (Assets)"): {
|
||||||
_("Current Assets"): {
|
_("Current Assets"): {
|
||||||
_("Accounts Receivable"): {
|
_("Accounts Receivable"): {
|
||||||
_("Debtors"): {"account_type": "Receivable", "account_number": "1310"},
|
_("Debtors"): {
|
||||||
"account_number": "1300",
|
"account_type": "Receivable",
|
||||||
},
|
"account_number": "1310"
|
||||||
_("Bank Accounts"): {"account_type": "Bank", "is_group": 1, "account_number": "1200"},
|
},
|
||||||
_("Cash In Hand"): {
|
"account_number": "1300"
|
||||||
_("Cash"): {"account_type": "Cash", "account_number": "1110"},
|
},
|
||||||
"account_type": "Cash",
|
_("Bank Accounts"): {
|
||||||
"account_number": "1100",
|
"account_type": "Bank",
|
||||||
},
|
"is_group": 1,
|
||||||
_("Loans and Advances (Assets)"): {
|
"account_number": "1200"
|
||||||
_("Employee Advances"): {"account_number": "1610"},
|
},
|
||||||
"account_number": "1600",
|
_("Cash In Hand"): {
|
||||||
},
|
_("Cash"): {
|
||||||
_("Securities and Deposits"): {
|
"account_type": "Cash",
|
||||||
_("Earnest Money"): {"account_number": "1651"},
|
"account_number": "1110"
|
||||||
"account_number": "1650",
|
},
|
||||||
},
|
"account_type": "Cash",
|
||||||
_("Stock Assets"): {
|
"account_number": "1100"
|
||||||
_("Stock In Hand"): {"account_type": "Stock", "account_number": "1410"},
|
},
|
||||||
"account_type": "Stock",
|
_("Loans and Advances (Assets)"): {
|
||||||
"account_number": "1400",
|
_("Employee Advances"): {
|
||||||
},
|
"account_number": "1610"
|
||||||
_("Tax Assets"): {"is_group": 1, "account_number": "1500"},
|
},
|
||||||
"account_number": "1100-1600",
|
"account_number": "1600"
|
||||||
},
|
},
|
||||||
_("Fixed Assets"): {
|
_("Securities and Deposits"): {
|
||||||
_("Capital Equipments"): {"account_type": "Fixed Asset", "account_number": "1710"},
|
_("Earnest Money"): {
|
||||||
_("Electronic Equipments"): {"account_type": "Fixed Asset", "account_number": "1720"},
|
"account_number": "1651"
|
||||||
_("Furnitures and Fixtures"): {"account_type": "Fixed Asset", "account_number": "1730"},
|
},
|
||||||
_("Office Equipments"): {"account_type": "Fixed Asset", "account_number": "1740"},
|
"account_number": "1650"
|
||||||
_("Plants and Machineries"): {"account_type": "Fixed Asset", "account_number": "1750"},
|
},
|
||||||
_("Buildings"): {"account_type": "Fixed Asset", "account_number": "1760"},
|
_("Stock Assets"): {
|
||||||
_("Softwares"): {"account_type": "Fixed Asset", "account_number": "1770"},
|
_("Stock In Hand"): {
|
||||||
_("Accumulated Depreciation"): {
|
"account_type": "Stock",
|
||||||
"account_type": "Accumulated Depreciation",
|
"account_number": "1410"
|
||||||
"account_number": "1780",
|
},
|
||||||
},
|
"account_type": "Stock",
|
||||||
_("CWIP Account"): {"account_type": "Capital Work in Progress", "account_number": "1790"},
|
"account_number": "1400"
|
||||||
"account_number": "1700",
|
},
|
||||||
},
|
_("Tax Assets"): {
|
||||||
_("Investments"): {"is_group": 1, "account_number": "1800"},
|
"is_group": 1,
|
||||||
_("Temporary Accounts"): {
|
"account_number": "1500"
|
||||||
_("Temporary Opening"): {"account_type": "Temporary", "account_number": "1910"},
|
},
|
||||||
"account_number": "1900",
|
"account_number": "1100-1600"
|
||||||
},
|
},
|
||||||
"root_type": "Asset",
|
_("Fixed Assets"): {
|
||||||
"account_number": "1000",
|
_("Capital Equipments"): {
|
||||||
},
|
"account_type": "Fixed Asset",
|
||||||
_("Expenses"): {
|
"account_number": "1710"
|
||||||
_("Direct Expenses"): {
|
},
|
||||||
_("Stock Expenses"): {
|
_("Electronic Equipments"): {
|
||||||
_("Cost of Goods Sold"): {"account_type": "Cost of Goods Sold", "account_number": "5111"},
|
"account_type": "Fixed Asset",
|
||||||
_("Expenses Included In Asset Valuation"): {
|
"account_number": "1720"
|
||||||
"account_type": "Expenses Included In Asset Valuation",
|
},
|
||||||
"account_number": "5112",
|
_("Furnitures and Fixtures"): {
|
||||||
},
|
"account_type": "Fixed Asset",
|
||||||
_("Expenses Included In Valuation"): {
|
"account_number": "1730"
|
||||||
"account_type": "Expenses Included In Valuation",
|
},
|
||||||
"account_number": "5118",
|
_("Office Equipments"): {
|
||||||
},
|
"account_type": "Fixed Asset",
|
||||||
_("Stock Adjustment"): {"account_type": "Stock Adjustment", "account_number": "5119"},
|
"account_number": "1740"
|
||||||
"account_number": "5110",
|
},
|
||||||
},
|
_("Plants and Machineries"): {
|
||||||
"account_number": "5100",
|
"account_type": "Fixed Asset",
|
||||||
},
|
"account_number": "1750"
|
||||||
_("Indirect Expenses"): {
|
},
|
||||||
_("Administrative Expenses"): {"account_number": "5201"},
|
_("Buildings"): {
|
||||||
_("Commission on Sales"): {"account_number": "5202"},
|
"account_type": "Fixed Asset",
|
||||||
_("Depreciation"): {"account_type": "Depreciation", "account_number": "5203"},
|
"account_number": "1760"
|
||||||
_("Entertainment Expenses"): {"account_number": "5204"},
|
},
|
||||||
_("Freight and Forwarding Charges"): {"account_type": "Chargeable", "account_number": "5205"},
|
_("Softwares"): {
|
||||||
_("Legal Expenses"): {"account_number": "5206"},
|
"account_type": "Fixed Asset",
|
||||||
_("Marketing Expenses"): {"account_type": "Chargeable", "account_number": "5207"},
|
"account_number": "1770"
|
||||||
_("Office Maintenance Expenses"): {"account_number": "5208"},
|
},
|
||||||
_("Office Rent"): {"account_number": "5209"},
|
_("Accumulated Depreciation"): {
|
||||||
_("Postal Expenses"): {"account_number": "5210"},
|
"account_type": "Accumulated Depreciation",
|
||||||
_("Print and Stationery"): {"account_number": "5211"},
|
"account_number": "1780"
|
||||||
_("Round Off"): {"account_type": "Round Off", "account_number": "5212"},
|
},
|
||||||
_("Salary"): {"account_number": "5213"},
|
_("CWIP Account"): {
|
||||||
_("Sales Expenses"): {"account_number": "5214"},
|
"account_type": "Capital Work in Progress",
|
||||||
_("Telephone Expenses"): {"account_number": "5215"},
|
"account_number": "1790"
|
||||||
_("Travel Expenses"): {"account_number": "5216"},
|
},
|
||||||
_("Utility Expenses"): {"account_number": "5217"},
|
"account_number": "1700"
|
||||||
_("Write Off"): {"account_number": "5218"},
|
},
|
||||||
_("Exchange Gain/Loss"): {"account_number": "5219"},
|
_("Investments"): {
|
||||||
_("Gain/Loss on Asset Disposal"): {"account_number": "5220"},
|
"is_group": 1,
|
||||||
_("Miscellaneous Expenses"): {"account_type": "Chargeable", "account_number": "5221"},
|
"account_number": "1800"
|
||||||
"account_number": "5200",
|
},
|
||||||
},
|
_("Temporary Accounts"): {
|
||||||
"root_type": "Expense",
|
_("Temporary Opening"): {
|
||||||
"account_number": "5000",
|
"account_type": "Temporary",
|
||||||
},
|
"account_number": "1910"
|
||||||
_("Income"): {
|
},
|
||||||
_("Direct Income"): {
|
"account_number": "1900"
|
||||||
_("Sales"): {"account_number": "4110"},
|
},
|
||||||
_("Service"): {"account_number": "4120"},
|
"root_type": "Asset",
|
||||||
"account_number": "4100",
|
"account_number": "1000"
|
||||||
},
|
},
|
||||||
_("Indirect Income"): {"is_group": 1, "account_number": "4200"},
|
_("Expenses"): {
|
||||||
"root_type": "Income",
|
_("Direct Expenses"): {
|
||||||
"account_number": "4000",
|
_("Stock Expenses"): {
|
||||||
},
|
_("Cost of Goods Sold"): {
|
||||||
_("Source of Funds (Liabilities)"): {
|
"account_type": "Cost of Goods Sold",
|
||||||
_("Current Liabilities"): {
|
"account_number": "5111"
|
||||||
_("Accounts Payable"): {
|
},
|
||||||
_("Creditors"): {"account_type": "Payable", "account_number": "2110"},
|
_("Expenses Included In Asset Valuation"): {
|
||||||
_("Payroll Payable"): {"account_number": "2120"},
|
"account_type": "Expenses Included In Asset Valuation",
|
||||||
"account_number": "2100",
|
"account_number": "5112"
|
||||||
},
|
},
|
||||||
_("Stock Liabilities"): {
|
_("Expenses Included In Valuation"): {
|
||||||
_("Stock Received But Not Billed"): {
|
"account_type": "Expenses Included In Valuation",
|
||||||
"account_type": "Stock Received But Not Billed",
|
"account_number": "5118"
|
||||||
"account_number": "2210",
|
},
|
||||||
},
|
_("Stock Adjustment"): {
|
||||||
_("Asset Received But Not Billed"): {
|
"account_type": "Stock Adjustment",
|
||||||
"account_type": "Asset Received But Not Billed",
|
"account_number": "5119"
|
||||||
"account_number": "2211",
|
},
|
||||||
},
|
"account_number": "5110"
|
||||||
"account_number": "2200",
|
},
|
||||||
},
|
"account_number": "5100"
|
||||||
_("Duties and Taxes"): {
|
},
|
||||||
_("TDS Payable"): {"account_number": "2310"},
|
_("Indirect Expenses"): {
|
||||||
"account_type": "Tax",
|
_("Administrative Expenses"): {
|
||||||
"is_group": 1,
|
"account_number": "5201"
|
||||||
"account_number": "2300",
|
},
|
||||||
},
|
_("Commission on Sales"): {
|
||||||
_("Loans (Liabilities)"): {
|
"account_number": "5202"
|
||||||
_("Secured Loans"): {"account_number": "2410"},
|
},
|
||||||
_("Unsecured Loans"): {"account_number": "2420"},
|
_("Depreciation"): {
|
||||||
_("Bank Overdraft Account"): {"account_number": "2430"},
|
"account_type": "Depreciation",
|
||||||
"account_number": "2400",
|
"account_number": "5203"
|
||||||
},
|
},
|
||||||
"account_number": "2100-2400",
|
_("Entertainment Expenses"): {
|
||||||
},
|
"account_number": "5204"
|
||||||
"root_type": "Liability",
|
},
|
||||||
"account_number": "2000",
|
_("Freight and Forwarding Charges"): {
|
||||||
},
|
"account_type": "Chargeable",
|
||||||
_("Equity"): {
|
"account_number": "5205"
|
||||||
_("Capital Stock"): {"account_type": "Equity", "account_number": "3100"},
|
},
|
||||||
_("Dividends Paid"): {"account_type": "Equity", "account_number": "3200"},
|
_("Legal Expenses"): {
|
||||||
_("Opening Balance Equity"): {"account_type": "Equity", "account_number": "3300"},
|
"account_number": "5206"
|
||||||
_("Retained Earnings"): {"account_type": "Equity", "account_number": "3400"},
|
},
|
||||||
"root_type": "Equity",
|
_("Marketing Expenses"): {
|
||||||
"account_number": "3000",
|
"account_type": "Chargeable",
|
||||||
},
|
"account_number": "5207"
|
||||||
}
|
},
|
||||||
|
_("Office Maintenance Expenses"): {
|
||||||
|
"account_number": "5208"
|
||||||
|
},
|
||||||
|
_("Office Rent"): {
|
||||||
|
"account_number": "5209"
|
||||||
|
},
|
||||||
|
_("Postal Expenses"): {
|
||||||
|
"account_number": "5210"
|
||||||
|
},
|
||||||
|
_("Print and Stationery"): {
|
||||||
|
"account_number": "5211"
|
||||||
|
},
|
||||||
|
_("Round Off"): {
|
||||||
|
"account_type": "Round Off",
|
||||||
|
"account_number": "5212"
|
||||||
|
},
|
||||||
|
_("Salary"): {
|
||||||
|
"account_number": "5213"
|
||||||
|
},
|
||||||
|
_("Sales Expenses"): {
|
||||||
|
"account_number": "5214"
|
||||||
|
},
|
||||||
|
_("Telephone Expenses"): {
|
||||||
|
"account_number": "5215"
|
||||||
|
},
|
||||||
|
_("Travel Expenses"): {
|
||||||
|
"account_number": "5216"
|
||||||
|
},
|
||||||
|
_("Utility Expenses"): {
|
||||||
|
"account_number": "5217"
|
||||||
|
},
|
||||||
|
_("Write Off"): {
|
||||||
|
"account_number": "5218"
|
||||||
|
},
|
||||||
|
_("Exchange Gain/Loss"): {
|
||||||
|
"account_number": "5219"
|
||||||
|
},
|
||||||
|
_("Gain/Loss on Asset Disposal"): {
|
||||||
|
"account_number": "5220"
|
||||||
|
},
|
||||||
|
_("Miscellaneous Expenses"): {
|
||||||
|
"account_type": "Chargeable",
|
||||||
|
"account_number": "5221"
|
||||||
|
},
|
||||||
|
"account_number": "5200"
|
||||||
|
},
|
||||||
|
"root_type": "Expense",
|
||||||
|
"account_number": "5000"
|
||||||
|
},
|
||||||
|
_("Income"): {
|
||||||
|
_("Direct Income"): {
|
||||||
|
_("Sales"): {
|
||||||
|
"account_number": "4110"
|
||||||
|
},
|
||||||
|
_("Service"): {
|
||||||
|
"account_number": "4120"
|
||||||
|
},
|
||||||
|
"account_number": "4100"
|
||||||
|
},
|
||||||
|
_("Indirect Income"): {
|
||||||
|
"is_group": 1,
|
||||||
|
"account_number": "4200"
|
||||||
|
},
|
||||||
|
"root_type": "Income",
|
||||||
|
"account_number": "4000"
|
||||||
|
},
|
||||||
|
_("Source of Funds (Liabilities)"): {
|
||||||
|
_("Current Liabilities"): {
|
||||||
|
_("Accounts Payable"): {
|
||||||
|
_("Creditors"): {
|
||||||
|
"account_type": "Payable",
|
||||||
|
"account_number": "2110"
|
||||||
|
},
|
||||||
|
_("Payroll Payable"): {
|
||||||
|
"account_number": "2120"
|
||||||
|
},
|
||||||
|
"account_number": "2100"
|
||||||
|
},
|
||||||
|
_("Stock Liabilities"): {
|
||||||
|
_("Stock Received But Not Billed"): {
|
||||||
|
"account_type": "Stock Received But Not Billed",
|
||||||
|
"account_number": "2210"
|
||||||
|
},
|
||||||
|
_("Asset Received But Not Billed"): {
|
||||||
|
"account_type": "Asset Received But Not Billed",
|
||||||
|
"account_number": "2211"
|
||||||
|
},
|
||||||
|
"account_number": "2200"
|
||||||
|
},
|
||||||
|
_("Duties and Taxes"): {
|
||||||
|
_("TDS Payable"): {
|
||||||
|
"account_number": "2310"
|
||||||
|
},
|
||||||
|
"account_type": "Tax",
|
||||||
|
"is_group": 1,
|
||||||
|
"account_number": "2300"
|
||||||
|
},
|
||||||
|
_("Loans (Liabilities)"): {
|
||||||
|
_("Secured Loans"): {
|
||||||
|
"account_number": "2410"
|
||||||
|
},
|
||||||
|
_("Unsecured Loans"): {
|
||||||
|
"account_number": "2420"
|
||||||
|
},
|
||||||
|
_("Bank Overdraft Account"): {
|
||||||
|
"account_number": "2430"
|
||||||
|
},
|
||||||
|
"account_number": "2400"
|
||||||
|
},
|
||||||
|
"account_number": "2100-2400"
|
||||||
|
},
|
||||||
|
"root_type": "Liability",
|
||||||
|
"account_number": "2000"
|
||||||
|
},
|
||||||
|
_("Equity"): {
|
||||||
|
_("Capital Stock"): {
|
||||||
|
"account_type": "Equity",
|
||||||
|
"account_number": "3100"
|
||||||
|
},
|
||||||
|
_("Dividends Paid"): {
|
||||||
|
"account_type": "Equity",
|
||||||
|
"account_number": "3200"
|
||||||
|
},
|
||||||
|
_("Opening Balance Equity"): {
|
||||||
|
"account_type": "Equity",
|
||||||
|
"account_number": "3300"
|
||||||
|
},
|
||||||
|
_("Retained Earnings"): {
|
||||||
|
"account_type": "Equity",
|
||||||
|
"account_number": "3400"
|
||||||
|
},
|
||||||
|
"root_type": "Equity",
|
||||||
|
"account_number": "3000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -20,9 +21,8 @@ class TestAccount(unittest.TestCase):
|
|||||||
acc.company = "_Test Company"
|
acc.company = "_Test Company"
|
||||||
acc.insert()
|
acc.insert()
|
||||||
|
|
||||||
account_number, account_name = frappe.db.get_value(
|
account_number, account_name = frappe.db.get_value("Account", "1210 - Debtors - _TC",
|
||||||
"Account", "1210 - Debtors - _TC", ["account_number", "account_name"]
|
["account_number", "account_name"])
|
||||||
)
|
|
||||||
self.assertEqual(account_number, "1210")
|
self.assertEqual(account_number, "1210")
|
||||||
self.assertEqual(account_name, "Debtors")
|
self.assertEqual(account_name, "Debtors")
|
||||||
|
|
||||||
@@ -31,12 +31,8 @@ class TestAccount(unittest.TestCase):
|
|||||||
|
|
||||||
update_account_number("1210 - Debtors - _TC", new_account_name, new_account_number)
|
update_account_number("1210 - Debtors - _TC", new_account_name, new_account_number)
|
||||||
|
|
||||||
new_acc = frappe.db.get_value(
|
new_acc = frappe.db.get_value("Account", "1211-11-4 - 6 - - Debtors 1 - Test - - _TC",
|
||||||
"Account",
|
["account_name", "account_number"], as_dict=1)
|
||||||
"1211-11-4 - 6 - - Debtors 1 - Test - - _TC",
|
|
||||||
["account_name", "account_number"],
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(new_acc.account_name, "Debtors 1 - Test -")
|
self.assertEqual(new_acc.account_name, "Debtors 1 - Test -")
|
||||||
self.assertEqual(new_acc.account_number, "1211-11-4 - 6 -")
|
self.assertEqual(new_acc.account_number, "1211-11-4 - 6 -")
|
||||||
@@ -84,9 +80,7 @@ class TestAccount(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(parent, "Securities and Deposits - _TC")
|
self.assertEqual(parent, "Securities and Deposits - _TC")
|
||||||
|
|
||||||
merge_account(
|
merge_account("Securities and Deposits - _TC", "Cash In Hand - _TC", doc.is_group, doc.root_type, doc.company)
|
||||||
"Securities and Deposits - _TC", "Cash In Hand - _TC", doc.is_group, doc.root_type, doc.company
|
|
||||||
)
|
|
||||||
parent = frappe.db.get_value("Account", "Earnest Money - _TC", "parent_account")
|
parent = frappe.db.get_value("Account", "Earnest Money - _TC", "parent_account")
|
||||||
|
|
||||||
# Parent account of the child account changes after merging
|
# Parent account of the child account changes after merging
|
||||||
@@ -98,28 +92,14 @@ class TestAccount(unittest.TestCase):
|
|||||||
doc = frappe.get_doc("Account", "Current Assets - _TC")
|
doc = frappe.get_doc("Account", "Current Assets - _TC")
|
||||||
|
|
||||||
# Raise error as is_group property doesn't match
|
# Raise error as is_group property doesn't match
|
||||||
self.assertRaises(
|
self.assertRaises(frappe.ValidationError, merge_account, "Current Assets - _TC",\
|
||||||
frappe.ValidationError,
|
"Accumulated Depreciation - _TC", doc.is_group, doc.root_type, doc.company)
|
||||||
merge_account,
|
|
||||||
"Current Assets - _TC",
|
|
||||||
"Accumulated Depreciation - _TC",
|
|
||||||
doc.is_group,
|
|
||||||
doc.root_type,
|
|
||||||
doc.company,
|
|
||||||
)
|
|
||||||
|
|
||||||
doc = frappe.get_doc("Account", "Capital Stock - _TC")
|
doc = frappe.get_doc("Account", "Capital Stock - _TC")
|
||||||
|
|
||||||
# Raise error as root_type property doesn't match
|
# Raise error as root_type property doesn't match
|
||||||
self.assertRaises(
|
self.assertRaises(frappe.ValidationError, merge_account, "Capital Stock - _TC",\
|
||||||
frappe.ValidationError,
|
"Softwares - _TC", doc.is_group, doc.root_type, doc.company)
|
||||||
merge_account,
|
|
||||||
"Capital Stock - _TC",
|
|
||||||
"Softwares - _TC",
|
|
||||||
doc.is_group,
|
|
||||||
doc.root_type,
|
|
||||||
doc.company,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_account_sync(self):
|
def test_account_sync(self):
|
||||||
frappe.local.flags.pop("ignore_root_company_validation", None)
|
frappe.local.flags.pop("ignore_root_company_validation", None)
|
||||||
@@ -130,12 +110,8 @@ class TestAccount(unittest.TestCase):
|
|||||||
acc.company = "_Test Company 3"
|
acc.company = "_Test Company 3"
|
||||||
acc.insert()
|
acc.insert()
|
||||||
|
|
||||||
acc_tc_4 = frappe.db.get_value(
|
acc_tc_4 = frappe.db.get_value('Account', {'account_name': "Test Sync Account", "company": "_Test Company 4"})
|
||||||
"Account", {"account_name": "Test Sync Account", "company": "_Test Company 4"}
|
acc_tc_5 = frappe.db.get_value('Account', {'account_name': "Test Sync Account", "company": "_Test Company 5"})
|
||||||
)
|
|
||||||
acc_tc_5 = frappe.db.get_value(
|
|
||||||
"Account", {"account_name": "Test Sync Account", "company": "_Test Company 5"}
|
|
||||||
)
|
|
||||||
self.assertEqual(acc_tc_4, "Test Sync Account - _TC4")
|
self.assertEqual(acc_tc_4, "Test Sync Account - _TC4")
|
||||||
self.assertEqual(acc_tc_5, "Test Sync Account - _TC5")
|
self.assertEqual(acc_tc_5, "Test Sync Account - _TC5")
|
||||||
|
|
||||||
@@ -163,26 +139,8 @@ class TestAccount(unittest.TestCase):
|
|||||||
update_account_number(acc.name, "Test Rename Sync Account", "1234")
|
update_account_number(acc.name, "Test Rename Sync Account", "1234")
|
||||||
|
|
||||||
# Check if renamed in children
|
# Check if renamed in children
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.exists("Account", {'account_name': "Test Rename Sync Account", "company": "_Test Company 4", "account_number": "1234"}))
|
||||||
frappe.db.exists(
|
self.assertTrue(frappe.db.exists("Account", {'account_name': "Test Rename Sync Account", "company": "_Test Company 5", "account_number": "1234"}))
|
||||||
"Account",
|
|
||||||
{
|
|
||||||
"account_name": "Test Rename Sync Account",
|
|
||||||
"company": "_Test Company 4",
|
|
||||||
"account_number": "1234",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
frappe.db.exists(
|
|
||||||
"Account",
|
|
||||||
{
|
|
||||||
"account_name": "Test Rename Sync Account",
|
|
||||||
"company": "_Test Company 5",
|
|
||||||
"account_number": "1234",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC3")
|
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC3")
|
||||||
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC4")
|
frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC4")
|
||||||
@@ -198,71 +156,25 @@ class TestAccount(unittest.TestCase):
|
|||||||
acc.company = "_Test Company 3"
|
acc.company = "_Test Company 3"
|
||||||
acc.insert()
|
acc.insert()
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.exists("Account", {'account_name': "Test Group Account", "company": "_Test Company 4"}))
|
||||||
frappe.db.exists(
|
self.assertTrue(frappe.db.exists("Account", {'account_name': "Test Group Account", "company": "_Test Company 5"}))
|
||||||
"Account", {"account_name": "Test Group Account", "company": "_Test Company 4"}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
frappe.db.exists(
|
|
||||||
"Account", {"account_name": "Test Group Account", "company": "_Test Company 5"}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Try renaming child company account
|
# Try renaming child company account
|
||||||
acc_tc_5 = frappe.db.get_value(
|
acc_tc_5 = frappe.db.get_value('Account', {'account_name': "Test Group Account", "company": "_Test Company 5"})
|
||||||
"Account", {"account_name": "Test Group Account", "company": "_Test Company 5"}
|
self.assertRaises(frappe.ValidationError, update_account_number, acc_tc_5, "Test Modified Account")
|
||||||
)
|
|
||||||
self.assertRaises(
|
|
||||||
frappe.ValidationError, update_account_number, acc_tc_5, "Test Modified Account"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Rename child company account with allow_account_creation_against_child_company enabled
|
# Rename child company account with allow_account_creation_against_child_company enabled
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Company", "_Test Company 5", "allow_account_creation_against_child_company", 1)
|
||||||
"Company", "_Test Company 5", "allow_account_creation_against_child_company", 1
|
|
||||||
)
|
|
||||||
|
|
||||||
update_account_number(acc_tc_5, "Test Modified Account")
|
update_account_number(acc_tc_5, "Test Modified Account")
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.exists("Account", {'name': "Test Modified Account - _TC5", "company": "_Test Company 5"}))
|
||||||
frappe.db.exists(
|
|
||||||
"Account", {"name": "Test Modified Account - _TC5", "company": "_Test Company 5"}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Company", "_Test Company 5", "allow_account_creation_against_child_company", 0)
|
||||||
"Company", "_Test Company 5", "allow_account_creation_against_child_company", 0
|
|
||||||
)
|
|
||||||
|
|
||||||
to_delete = [
|
to_delete = ["Test Group Account - _TC3", "Test Group Account - _TC4", "Test Modified Account - _TC5"]
|
||||||
"Test Group Account - _TC3",
|
|
||||||
"Test Group Account - _TC4",
|
|
||||||
"Test Modified Account - _TC5",
|
|
||||||
]
|
|
||||||
for doc in to_delete:
|
for doc in to_delete:
|
||||||
frappe.delete_doc("Account", doc)
|
frappe.delete_doc("Account", doc)
|
||||||
|
|
||||||
def test_validate_account_currency(self):
|
|
||||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
|
||||||
|
|
||||||
if not frappe.db.get_value("Account", "Test Currency Account - _TC"):
|
|
||||||
acc = frappe.new_doc("Account")
|
|
||||||
acc.account_name = "Test Currency Account"
|
|
||||||
acc.parent_account = "Tax Assets - _TC"
|
|
||||||
acc.company = "_Test Company"
|
|
||||||
acc.insert()
|
|
||||||
else:
|
|
||||||
acc = frappe.get_doc("Account", "Test Currency Account - _TC")
|
|
||||||
|
|
||||||
self.assertEqual(acc.account_currency, "INR")
|
|
||||||
|
|
||||||
# Make a JV against this account
|
|
||||||
make_journal_entry(
|
|
||||||
"Test Currency Account - _TC", "Miscellaneous Expenses - _TC", 100, submit=True
|
|
||||||
)
|
|
||||||
|
|
||||||
acc.account_currency = "USD"
|
|
||||||
self.assertRaises(frappe.ValidationError, acc.save)
|
|
||||||
|
|
||||||
|
|
||||||
def _make_test_records(verbose=None):
|
def _make_test_records(verbose=None):
|
||||||
from frappe.test_runner import make_test_objects
|
from frappe.test_runner import make_test_objects
|
||||||
@@ -273,16 +185,20 @@ def _make_test_records(verbose=None):
|
|||||||
["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"],
|
["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"],
|
||||||
["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"],
|
["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"],
|
||||||
["_Test Cash", "Cash In Hand", 0, "Cash", None],
|
["_Test Cash", "Cash In Hand", 0, "Cash", None],
|
||||||
|
|
||||||
["_Test Account Stock Expenses", "Direct Expenses", 1, None, None],
|
["_Test Account Stock Expenses", "Direct Expenses", 1, None, None],
|
||||||
["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
|
["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
|
||||||
["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None],
|
["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None],
|
||||||
["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
|
["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None],
|
||||||
["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None],
|
["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None],
|
||||||
["_Test Employee Advance", "Current Liabilities", 0, None, None],
|
["_Test Employee Advance", "Current Liabilities", 0, None, None],
|
||||||
|
|
||||||
["_Test Account Tax Assets", "Current Assets", 1, None, None],
|
["_Test Account Tax Assets", "Current Assets", 1, None, None],
|
||||||
["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None],
|
["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None],
|
||||||
["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None],
|
["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None],
|
||||||
|
|
||||||
["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None],
|
["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None],
|
||||||
|
|
||||||
["_Test Account Cost for Goods Sold", "Expenses", 0, None, None],
|
["_Test Account Cost for Goods Sold", "Expenses", 0, None, None],
|
||||||
["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None],
|
["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None],
|
||||||
["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None],
|
["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None],
|
||||||
@@ -291,45 +207,38 @@ def _make_test_records(verbose=None):
|
|||||||
["_Test Account Discount", "Direct Expenses", 0, None, None],
|
["_Test Account Discount", "Direct Expenses", 0, None, None],
|
||||||
["_Test Write Off", "Indirect Expenses", 0, None, None],
|
["_Test Write Off", "Indirect Expenses", 0, None, None],
|
||||||
["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None],
|
["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None],
|
||||||
|
|
||||||
["_Test Account Sales", "Direct Income", 0, None, None],
|
["_Test Account Sales", "Direct Income", 0, None, None],
|
||||||
|
|
||||||
# related to Account Inventory Integration
|
# related to Account Inventory Integration
|
||||||
["_Test Account Stock In Hand", "Current Assets", 0, None, None],
|
["_Test Account Stock In Hand", "Current Assets", 0, None, None],
|
||||||
|
|
||||||
# fixed asset depreciation
|
# fixed asset depreciation
|
||||||
["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None],
|
["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None],
|
||||||
["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None],
|
["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None],
|
||||||
["_Test Depreciations", "Expenses", 0, "Depreciation", None],
|
["_Test Depreciations", "Expenses", 0, None, None],
|
||||||
["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None],
|
["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None],
|
||||||
|
|
||||||
# Receivable / Payable Account
|
# Receivable / Payable Account
|
||||||
["_Test Receivable", "Current Assets", 0, "Receivable", None],
|
["_Test Receivable", "Current Assets", 0, "Receivable", None],
|
||||||
["_Test Payable", "Current Liabilities", 0, "Payable", None],
|
["_Test Payable", "Current Liabilities", 0, "Payable", None],
|
||||||
["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"],
|
["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"],
|
||||||
["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"],
|
["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"]
|
||||||
]
|
]
|
||||||
|
|
||||||
for company, abbr in [
|
for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"], ["_Test Company with perpetual inventory", "TCP1"]]:
|
||||||
["_Test Company", "_TC"],
|
test_objects = make_test_objects("Account", [{
|
||||||
["_Test Company 1", "_TC1"],
|
"doctype": "Account",
|
||||||
["_Test Company with perpetual inventory", "TCP1"],
|
"account_name": account_name,
|
||||||
]:
|
"parent_account": parent_account + " - " + abbr,
|
||||||
test_objects = make_test_objects(
|
"company": company,
|
||||||
"Account",
|
"is_group": is_group,
|
||||||
[
|
"account_type": account_type,
|
||||||
{
|
"account_currency": currency
|
||||||
"doctype": "Account",
|
} for account_name, parent_account, is_group, account_type, currency in accounts])
|
||||||
"account_name": account_name,
|
|
||||||
"parent_account": parent_account + " - " + abbr,
|
|
||||||
"company": company,
|
|
||||||
"is_group": is_group,
|
|
||||||
"account_type": account_type,
|
|
||||||
"account_currency": currency,
|
|
||||||
}
|
|
||||||
for account_name, parent_account, is_group, account_type, currency in accounts
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
return test_objects
|
return test_objects
|
||||||
|
|
||||||
|
|
||||||
def get_inventory_account(company, warehouse=None):
|
def get_inventory_account(company, warehouse=None):
|
||||||
account = None
|
account = None
|
||||||
if warehouse:
|
if warehouse:
|
||||||
@@ -339,24 +248,19 @@ def get_inventory_account(company, warehouse=None):
|
|||||||
|
|
||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
def create_account(**kwargs):
|
def create_account(**kwargs):
|
||||||
account = frappe.db.get_value(
|
account = frappe.db.get_value("Account", filters={"account_name": kwargs.get("account_name"), "company": kwargs.get("company")})
|
||||||
"Account", filters={"account_name": kwargs.get("account_name"), "company": kwargs.get("company")}
|
|
||||||
)
|
|
||||||
if account:
|
if account:
|
||||||
return account
|
return account
|
||||||
else:
|
else:
|
||||||
account = frappe.get_doc(
|
account = frappe.get_doc(dict(
|
||||||
dict(
|
doctype = "Account",
|
||||||
doctype="Account",
|
account_name = kwargs.get('account_name'),
|
||||||
account_name=kwargs.get("account_name"),
|
account_type = kwargs.get('account_type'),
|
||||||
account_type=kwargs.get("account_type"),
|
parent_account = kwargs.get('parent_account'),
|
||||||
parent_account=kwargs.get("parent_account"),
|
company = kwargs.get('company'),
|
||||||
company=kwargs.get("company"),
|
account_currency = kwargs.get('account_currency')
|
||||||
account_currency=kwargs.get("account_currency"),
|
))
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
account.save()
|
account.save()
|
||||||
return account.name
|
return account.name
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -17,21 +19,13 @@ class AccountingDimension(Document):
|
|||||||
self.set_fieldname_and_label()
|
self.set_fieldname_and_label()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if self.document_type in core_doctypes_list + (
|
if self.document_type in core_doctypes_list + ('Accounting Dimension', 'Project',
|
||||||
"Accounting Dimension",
|
'Cost Center', 'Accounting Dimension Detail', 'Company', 'Account') :
|
||||||
"Project",
|
|
||||||
"Cost Center",
|
|
||||||
"Accounting Dimension Detail",
|
|
||||||
"Company",
|
|
||||||
"Account",
|
|
||||||
):
|
|
||||||
|
|
||||||
msg = _("Not allowed to create accounting dimension for {0}").format(self.document_type)
|
msg = _("Not allowed to create accounting dimension for {0}").format(self.document_type)
|
||||||
frappe.throw(msg)
|
frappe.throw(msg)
|
||||||
|
|
||||||
exists = frappe.db.get_value(
|
exists = frappe.db.get_value("Accounting Dimension", {'document_type': self.document_type}, ['name'])
|
||||||
"Accounting Dimension", {"document_type": self.document_type}, ["name"]
|
|
||||||
)
|
|
||||||
|
|
||||||
if exists and self.is_new():
|
if exists and self.is_new():
|
||||||
frappe.throw(_("Document Type already used as a dimension"))
|
frappe.throw(_("Document Type already used as a dimension"))
|
||||||
@@ -50,13 +44,13 @@ class AccountingDimension(Document):
|
|||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
make_dimension_in_accounting_doctypes(doc=self)
|
make_dimension_in_accounting_doctypes(doc=self)
|
||||||
else:
|
else:
|
||||||
frappe.enqueue(make_dimension_in_accounting_doctypes, doc=self, queue="long")
|
frappe.enqueue(make_dimension_in_accounting_doctypes, doc=self, queue='long')
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
delete_accounting_dimension(doc=self)
|
delete_accounting_dimension(doc=self)
|
||||||
else:
|
else:
|
||||||
frappe.enqueue(delete_accounting_dimension, doc=self, queue="long")
|
frappe.enqueue(delete_accounting_dimension, doc=self, queue='long')
|
||||||
|
|
||||||
def set_fieldname_and_label(self):
|
def set_fieldname_and_label(self):
|
||||||
if not self.label:
|
if not self.label:
|
||||||
@@ -68,7 +62,6 @@ class AccountingDimension(Document):
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
frappe.flags.accounting_dimensions = None
|
frappe.flags.accounting_dimensions = None
|
||||||
|
|
||||||
|
|
||||||
def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
||||||
if not doclist:
|
if not doclist:
|
||||||
doclist = get_doctypes_with_dimensions()
|
doclist = get_doctypes_with_dimensions()
|
||||||
@@ -79,9 +72,9 @@ def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
|||||||
for doctype in doclist:
|
for doctype in doclist:
|
||||||
|
|
||||||
if (doc_count + 1) % 2 == 0:
|
if (doc_count + 1) % 2 == 0:
|
||||||
insert_after_field = "dimension_col_break"
|
insert_after_field = 'dimension_col_break'
|
||||||
else:
|
else:
|
||||||
insert_after_field = "accounting_dimensions_section"
|
insert_after_field = 'accounting_dimensions_section'
|
||||||
|
|
||||||
df = {
|
df = {
|
||||||
"fieldname": doc.fieldname,
|
"fieldname": doc.fieldname,
|
||||||
@@ -89,33 +82,30 @@ def make_dimension_in_accounting_doctypes(doc, doclist=None):
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": doc.document_type,
|
"options": doc.document_type,
|
||||||
"insert_after": insert_after_field,
|
"insert_after": insert_after_field,
|
||||||
"owner": "Administrator",
|
"owner": "Administrator"
|
||||||
}
|
}
|
||||||
|
|
||||||
meta = frappe.get_meta(doctype, cached=False)
|
meta = frappe.get_meta(doctype, cached=False)
|
||||||
fieldnames = [d.fieldname for d in meta.get("fields")]
|
fieldnames = [d.fieldname for d in meta.get("fields")]
|
||||||
|
|
||||||
if df["fieldname"] not in fieldnames:
|
if df['fieldname'] not in fieldnames:
|
||||||
if doctype == "Budget":
|
if doctype == "Budget":
|
||||||
add_dimension_to_budget_doctype(df.copy(), doc)
|
add_dimension_to_budget_doctype(df.copy(), doc)
|
||||||
else:
|
else:
|
||||||
create_custom_field(doctype, df, ignore_validate=True)
|
create_custom_field(doctype, df)
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
frappe.publish_progress(count * 100 / len(doclist), title=_("Creating Dimensions..."))
|
frappe.publish_progress(count*100/len(doclist), title = _("Creating Dimensions..."))
|
||||||
frappe.clear_cache(doctype=doctype)
|
frappe.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
|
|
||||||
def add_dimension_to_budget_doctype(df, doc):
|
def add_dimension_to_budget_doctype(df, doc):
|
||||||
df.update(
|
df.update({
|
||||||
{
|
"insert_after": "cost_center",
|
||||||
"insert_after": "cost_center",
|
"depends_on": "eval:doc.budget_against == '{0}'".format(doc.document_type)
|
||||||
"depends_on": "eval:doc.budget_against == '{0}'".format(doc.document_type),
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
create_custom_field("Budget", df, ignore_validate=True)
|
create_custom_field("Budget", df)
|
||||||
|
|
||||||
property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options")
|
property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options")
|
||||||
|
|
||||||
@@ -124,44 +114,36 @@ def add_dimension_to_budget_doctype(df, doc):
|
|||||||
property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
|
property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
|
||||||
property_setter_doc.save()
|
property_setter_doc.save()
|
||||||
|
|
||||||
frappe.clear_cache(doctype="Budget")
|
frappe.clear_cache(doctype='Budget')
|
||||||
else:
|
else:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Property Setter",
|
||||||
"doctype": "Property Setter",
|
"doctype_or_field": "DocField",
|
||||||
"doctype_or_field": "DocField",
|
"doc_type": "Budget",
|
||||||
"doc_type": "Budget",
|
"field_name": "budget_against",
|
||||||
"field_name": "budget_against",
|
"property": "options",
|
||||||
"property": "options",
|
"property_type": "Text",
|
||||||
"property_type": "Text",
|
"value": "\nCost Center\nProject\n" + doc.document_type
|
||||||
"value": "\nCost Center\nProject\n" + doc.document_type,
|
}).insert(ignore_permissions=True)
|
||||||
}
|
|
||||||
).insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
|
|
||||||
def delete_accounting_dimension(doc):
|
def delete_accounting_dimension(doc):
|
||||||
doclist = get_doctypes_with_dimensions()
|
doclist = get_doctypes_with_dimensions()
|
||||||
|
|
||||||
frappe.db.sql(
|
frappe.db.sql("""
|
||||||
"""
|
|
||||||
DELETE FROM `tabCustom Field`
|
DELETE FROM `tabCustom Field`
|
||||||
WHERE fieldname = %s
|
WHERE fieldname = %s
|
||||||
AND dt IN (%s)"""
|
AND dt IN (%s)""" % #nosec
|
||||||
% ("%s", ", ".join(["%s"] * len(doclist))), # nosec
|
('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist))
|
||||||
tuple([doc.fieldname] + doclist),
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.sql(
|
frappe.db.sql("""
|
||||||
"""
|
|
||||||
DELETE FROM `tabProperty Setter`
|
DELETE FROM `tabProperty Setter`
|
||||||
WHERE field_name = %s
|
WHERE field_name = %s
|
||||||
AND doc_type IN (%s)"""
|
AND doc_type IN (%s)""" % #nosec
|
||||||
% ("%s", ", ".join(["%s"] * len(doclist))), # nosec
|
('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist))
|
||||||
tuple([doc.fieldname] + doclist),
|
|
||||||
)
|
|
||||||
|
|
||||||
budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options")
|
budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options")
|
||||||
value_list = budget_against_property.value.split("\n")[3:]
|
value_list = budget_against_property.value.split('\n')[3:]
|
||||||
|
|
||||||
if doc.document_type in value_list:
|
if doc.document_type in value_list:
|
||||||
value_list.remove(doc.document_type)
|
value_list.remove(doc.document_type)
|
||||||
@@ -172,7 +154,6 @@ def delete_accounting_dimension(doc):
|
|||||||
for doctype in doclist:
|
for doctype in doclist:
|
||||||
frappe.clear_cache(doctype=doctype)
|
frappe.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def disable_dimension(doc):
|
def disable_dimension(doc):
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
@@ -180,11 +161,10 @@ def disable_dimension(doc):
|
|||||||
else:
|
else:
|
||||||
frappe.enqueue(toggle_disabling, doc=doc)
|
frappe.enqueue(toggle_disabling, doc=doc)
|
||||||
|
|
||||||
|
|
||||||
def toggle_disabling(doc):
|
def toggle_disabling(doc):
|
||||||
doc = json.loads(doc)
|
doc = json.loads(doc)
|
||||||
|
|
||||||
if doc.get("disabled"):
|
if doc.get('disabled'):
|
||||||
df = {"read_only": 1}
|
df = {"read_only": 1}
|
||||||
else:
|
else:
|
||||||
df = {"read_only": 0}
|
df = {"read_only": 0}
|
||||||
@@ -192,7 +172,7 @@ def toggle_disabling(doc):
|
|||||||
doclist = get_doctypes_with_dimensions()
|
doclist = get_doctypes_with_dimensions()
|
||||||
|
|
||||||
for doctype in doclist:
|
for doctype in doclist:
|
||||||
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": doc.get("fieldname")})
|
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": doc.get('fieldname')})
|
||||||
if field:
|
if field:
|
||||||
custom_field = frappe.get_doc("Custom Field", field)
|
custom_field = frappe.get_doc("Custom Field", field)
|
||||||
custom_field.update(df)
|
custom_field.update(df)
|
||||||
@@ -200,82 +180,61 @@ def toggle_disabling(doc):
|
|||||||
|
|
||||||
frappe.clear_cache(doctype=doctype)
|
frappe.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
|
|
||||||
def get_doctypes_with_dimensions():
|
def get_doctypes_with_dimensions():
|
||||||
return frappe.get_hooks("accounting_dimension_doctypes")
|
return frappe.get_hooks("accounting_dimension_doctypes")
|
||||||
|
|
||||||
|
def get_accounting_dimensions(as_list=True):
|
||||||
def get_accounting_dimensions(as_list=True, filters=None):
|
|
||||||
|
|
||||||
if not filters:
|
|
||||||
filters = {"disabled": 0}
|
|
||||||
|
|
||||||
if frappe.flags.accounting_dimensions is None:
|
if frappe.flags.accounting_dimensions is None:
|
||||||
frappe.flags.accounting_dimensions = frappe.get_all(
|
frappe.flags.accounting_dimensions = frappe.get_all("Accounting Dimension",
|
||||||
"Accounting Dimension",
|
fields=["label", "fieldname", "disabled", "document_type"])
|
||||||
fields=["label", "fieldname", "disabled", "document_type"],
|
|
||||||
filters=filters,
|
|
||||||
)
|
|
||||||
|
|
||||||
if as_list:
|
if as_list:
|
||||||
return [d.fieldname for d in frappe.flags.accounting_dimensions]
|
return [d.fieldname for d in frappe.flags.accounting_dimensions]
|
||||||
else:
|
else:
|
||||||
return frappe.flags.accounting_dimensions
|
return frappe.flags.accounting_dimensions
|
||||||
|
|
||||||
|
|
||||||
def get_checks_for_pl_and_bs_accounts():
|
def get_checks_for_pl_and_bs_accounts():
|
||||||
dimensions = frappe.db.sql(
|
dimensions = frappe.db.sql("""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
|
||||||
"""SELECT p.label, p.disabled, p.fieldname, c.default_dimension, c.company, c.mandatory_for_pl, c.mandatory_for_bs
|
|
||||||
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
|
FROM `tabAccounting Dimension`p ,`tabAccounting Dimension Detail` c
|
||||||
WHERE p.name = c.parent""",
|
WHERE p.name = c.parent""", as_dict=1)
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
return dimensions
|
return dimensions
|
||||||
|
|
||||||
|
def get_dimension_with_children(doctype, dimension):
|
||||||
|
|
||||||
def get_dimension_with_children(doctype, dimensions):
|
if isinstance(dimension, list):
|
||||||
|
dimension = dimension[0]
|
||||||
if isinstance(dimensions, str):
|
|
||||||
dimensions = [dimensions]
|
|
||||||
|
|
||||||
all_dimensions = []
|
all_dimensions = []
|
||||||
|
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
|
||||||
for dimension in dimensions:
|
children = frappe.get_all(doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft")
|
||||||
lft, rgt = frappe.db.get_value(doctype, dimension, ["lft", "rgt"])
|
all_dimensions += [c.name for c in children]
|
||||||
children = frappe.get_all(
|
|
||||||
doctype, filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, order_by="lft"
|
|
||||||
)
|
|
||||||
all_dimensions += [c.name for c in children]
|
|
||||||
|
|
||||||
return all_dimensions
|
return all_dimensions
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dimensions(with_cost_center_and_project=False):
|
def get_dimensions(with_cost_center_and_project=False):
|
||||||
dimension_filters = frappe.db.sql(
|
dimension_filters = frappe.db.sql("""
|
||||||
"""
|
|
||||||
SELECT label, fieldname, document_type
|
SELECT label, fieldname, document_type
|
||||||
FROM `tabAccounting Dimension`
|
FROM `tabAccounting Dimension`
|
||||||
WHERE disabled = 0
|
WHERE disabled = 0
|
||||||
""",
|
""", as_dict=1)
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
default_dimensions = frappe.db.sql(
|
default_dimensions = frappe.db.sql("""SELECT p.fieldname, c.company, c.default_dimension
|
||||||
"""SELECT p.fieldname, c.company, c.default_dimension
|
|
||||||
FROM `tabAccounting Dimension Detail` c, `tabAccounting Dimension` p
|
FROM `tabAccounting Dimension Detail` c, `tabAccounting Dimension` p
|
||||||
WHERE c.parent = p.name""",
|
WHERE c.parent = p.name""", as_dict=1)
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
if with_cost_center_and_project:
|
if with_cost_center_and_project:
|
||||||
dimension_filters.extend(
|
dimension_filters.extend([
|
||||||
[
|
{
|
||||||
{"fieldname": "cost_center", "document_type": "Cost Center"},
|
'fieldname': 'cost_center',
|
||||||
{"fieldname": "project", "document_type": "Project"},
|
'document_type': 'Cost Center'
|
||||||
]
|
},
|
||||||
)
|
{
|
||||||
|
'fieldname': 'project',
|
||||||
|
'document_type': 'Project'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
default_dimensions_map = {}
|
default_dimensions_map = {}
|
||||||
for dimension in default_dimensions:
|
for dimension in default_dimensions:
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -8,8 +10,7 @@ import frappe
|
|||||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
|
|
||||||
test_dependencies = ["Cost Center", "Location", "Warehouse", "Department"]
|
test_dependencies = ['Cost Center', 'Location', 'Warehouse', 'Department']
|
||||||
|
|
||||||
|
|
||||||
class TestAccountingDimension(unittest.TestCase):
|
class TestAccountingDimension(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -19,27 +20,24 @@ class TestAccountingDimension(unittest.TestCase):
|
|||||||
si = create_sales_invoice(do_not_save=1)
|
si = create_sales_invoice(do_not_save=1)
|
||||||
|
|
||||||
si.location = "Block 1"
|
si.location = "Block 1"
|
||||||
si.append(
|
si.append("items", {
|
||||||
"items",
|
"item_code": "_Test Item",
|
||||||
{
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
"item_code": "_Test Item",
|
"qty": 1,
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
"rate": 100,
|
||||||
"qty": 1,
|
"income_account": "Sales - _TC",
|
||||||
"rate": 100,
|
"expense_account": "Cost of Goods Sold - _TC",
|
||||||
"income_account": "Sales - _TC",
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
"expense_account": "Cost of Goods Sold - _TC",
|
"department": "_Test Department - _TC",
|
||||||
"cost_center": "_Test Cost Center - _TC",
|
"location": "Block 1"
|
||||||
"department": "_Test Department - _TC",
|
})
|
||||||
"location": "Block 1",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
si.save()
|
si.save()
|
||||||
si.submit()
|
si.submit()
|
||||||
|
|
||||||
gle = frappe.get_doc("GL Entry", {"voucher_no": si.name, "account": "Sales - _TC"})
|
gle = frappe.get_doc("GL Entry", {"voucher_no": si.name, "account": "Sales - _TC"})
|
||||||
|
|
||||||
self.assertEqual(gle.get("department"), "_Test Department - _TC")
|
self.assertEqual(gle.get('department'), "_Test Department - _TC")
|
||||||
|
|
||||||
def test_dimension_against_journal_entry(self):
|
def test_dimension_against_journal_entry(self):
|
||||||
je = make_journal_entry("Sales - _TC", "Sales Expenses - _TC", 500, save=False)
|
je = make_journal_entry("Sales - _TC", "Sales Expenses - _TC", 500, save=False)
|
||||||
@@ -54,24 +52,21 @@ class TestAccountingDimension(unittest.TestCase):
|
|||||||
|
|
||||||
gle = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales - _TC"})
|
gle = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales - _TC"})
|
||||||
gle1 = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales Expenses - _TC"})
|
gle1 = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales Expenses - _TC"})
|
||||||
self.assertEqual(gle.get("department"), "_Test Department - _TC")
|
self.assertEqual(gle.get('department'), "_Test Department - _TC")
|
||||||
self.assertEqual(gle1.get("department"), "_Test Department - _TC")
|
self.assertEqual(gle1.get('department'), "_Test Department - _TC")
|
||||||
|
|
||||||
def test_mandatory(self):
|
def test_mandatory(self):
|
||||||
si = create_sales_invoice(do_not_save=1)
|
si = create_sales_invoice(do_not_save=1)
|
||||||
si.append(
|
si.append("items", {
|
||||||
"items",
|
"item_code": "_Test Item",
|
||||||
{
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
"item_code": "_Test Item",
|
"qty": 1,
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
"rate": 100,
|
||||||
"qty": 1,
|
"income_account": "Sales - _TC",
|
||||||
"rate": 100,
|
"expense_account": "Cost of Goods Sold - _TC",
|
||||||
"income_account": "Sales - _TC",
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
"expense_account": "Cost of Goods Sold - _TC",
|
"location": ""
|
||||||
"cost_center": "_Test Cost Center - _TC",
|
})
|
||||||
"location": "",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
si.save()
|
si.save()
|
||||||
self.assertRaises(frappe.ValidationError, si.submit)
|
self.assertRaises(frappe.ValidationError, si.submit)
|
||||||
@@ -79,39 +74,31 @@ class TestAccountingDimension(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
disable_dimension()
|
disable_dimension()
|
||||||
|
|
||||||
|
|
||||||
def create_dimension():
|
def create_dimension():
|
||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
|
|
||||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Accounting Dimension",
|
||||||
"doctype": "Accounting Dimension",
|
"document_type": "Department",
|
||||||
"document_type": "Department",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
else:
|
else:
|
||||||
dimension = frappe.get_doc("Accounting Dimension", "Department")
|
dimension = frappe.get_doc("Accounting Dimension", "Department")
|
||||||
dimension.disabled = 0
|
dimension.disabled = 0
|
||||||
dimension.save()
|
dimension.save()
|
||||||
|
|
||||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
||||||
dimension1 = frappe.get_doc(
|
dimension1 = frappe.get_doc({
|
||||||
{
|
"doctype": "Accounting Dimension",
|
||||||
"doctype": "Accounting Dimension",
|
"document_type": "Location",
|
||||||
"document_type": "Location",
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
dimension1.append(
|
dimension1.append("dimension_defaults", {
|
||||||
"dimension_defaults",
|
"company": "_Test Company",
|
||||||
{
|
"reference_document": "Location",
|
||||||
"company": "_Test Company",
|
"default_dimension": "Block 1",
|
||||||
"reference_document": "Location",
|
"mandatory_for_bs": 1
|
||||||
"default_dimension": "Block 1",
|
})
|
||||||
"mandatory_for_bs": 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
dimension1.insert()
|
dimension1.insert()
|
||||||
dimension1.save()
|
dimension1.save()
|
||||||
@@ -120,7 +107,6 @@ def create_dimension():
|
|||||||
dimension1.disabled = 0
|
dimension1.disabled = 0
|
||||||
dimension1.save()
|
dimension1.save()
|
||||||
|
|
||||||
|
|
||||||
def disable_dimension():
|
def disable_dimension():
|
||||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
||||||
dimension1.disabled = 1
|
dimension1.disabled = 1
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
frappe.ui.form.on('Accounting Dimension Filter', {
|
frappe.ui.form.on('Accounting Dimension Filter', {
|
||||||
refresh: function(frm, cdt, cdn) {
|
refresh: function(frm, cdt, cdn) {
|
||||||
|
if (frm.doc.accounting_dimension) {
|
||||||
|
frm.set_df_property('dimensions', 'label', frm.doc.accounting_dimension, cdn, 'dimension_value');
|
||||||
|
}
|
||||||
|
|
||||||
let help_content =
|
let help_content =
|
||||||
`<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
|
`<table class="table table-bordered" style="background-color: #f9f9f9;">
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<p>
|
<p>
|
||||||
<i class="fa fa-hand-right"></i>
|
<i class="fa fa-hand-right"></i>
|
||||||
@@ -64,7 +68,6 @@ frappe.ui.form.on('Accounting Dimension Filter', {
|
|||||||
frm.clear_table("dimensions");
|
frm.clear_table("dimensions");
|
||||||
let row = frm.add_child("dimensions");
|
let row = frm.add_child("dimensions");
|
||||||
row.accounting_dimension = frm.doc.accounting_dimension;
|
row.accounting_dimension = frm.doc.accounting_dimension;
|
||||||
frm.fields_dict["dimensions"].grid.update_docfield_property("dimension_value", "label", frm.doc.accounting_dimension);
|
|
||||||
frm.refresh_field("dimensions");
|
frm.refresh_field("dimensions");
|
||||||
frm.trigger('setup_filters');
|
frm.trigger('setup_filters');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright, (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright, (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, scrub
|
from frappe import _, scrub
|
||||||
@@ -19,27 +21,17 @@ class AccountingDimensionFilter(Document):
|
|||||||
WHERE d.name = a.parent
|
WHERE d.name = a.parent
|
||||||
and d.name != %s
|
and d.name != %s
|
||||||
and d.accounting_dimension = %s
|
and d.accounting_dimension = %s
|
||||||
""",
|
""", (self.name, self.accounting_dimension), as_dict=1)
|
||||||
(self.name, self.accounting_dimension),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
account_list = [d.account for d in accounts]
|
account_list = [d.account for d in accounts]
|
||||||
|
|
||||||
for account in self.get("accounts"):
|
for account in self.get('accounts'):
|
||||||
if account.applicable_on_account in account_list:
|
if account.applicable_on_account in account_list:
|
||||||
frappe.throw(
|
frappe.throw(_("Row {0}: {1} account already applied for Accounting Dimension {2}").format(
|
||||||
_("Row {0}: {1} account already applied for Accounting Dimension {2}").format(
|
account.idx, frappe.bold(account.applicable_on_account), frappe.bold(self.accounting_dimension)))
|
||||||
account.idx,
|
|
||||||
frappe.bold(account.applicable_on_account),
|
|
||||||
frappe.bold(self.accounting_dimension),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_dimension_filter_map():
|
def get_dimension_filter_map():
|
||||||
filters = frappe.db.sql(
|
filters = frappe.db.sql("""
|
||||||
"""
|
|
||||||
SELECT
|
SELECT
|
||||||
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
||||||
p.allow_or_restrict, a.is_mandatory
|
p.allow_or_restrict, a.is_mandatory
|
||||||
@@ -50,30 +42,22 @@ def get_dimension_filter_map():
|
|||||||
p.name = a.parent
|
p.name = a.parent
|
||||||
AND p.disabled = 0
|
AND p.disabled = 0
|
||||||
AND p.name = d.parent
|
AND p.name = d.parent
|
||||||
""",
|
""", as_dict=1)
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
dimension_filter_map = {}
|
dimension_filter_map = {}
|
||||||
|
|
||||||
for f in filters:
|
for f in filters:
|
||||||
f.fieldname = scrub(f.accounting_dimension)
|
f.fieldname = scrub(f.accounting_dimension)
|
||||||
|
|
||||||
build_map(
|
build_map(dimension_filter_map, f.fieldname, f.applicable_on_account, f.dimension_value,
|
||||||
dimension_filter_map,
|
f.allow_or_restrict, f.is_mandatory)
|
||||||
f.fieldname,
|
|
||||||
f.applicable_on_account,
|
|
||||||
f.dimension_value,
|
|
||||||
f.allow_or_restrict,
|
|
||||||
f.is_mandatory,
|
|
||||||
)
|
|
||||||
|
|
||||||
return dimension_filter_map
|
return dimension_filter_map
|
||||||
|
|
||||||
|
|
||||||
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):
|
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):
|
||||||
map_object.setdefault(
|
map_object.setdefault((dimension, account), {
|
||||||
(dimension, account),
|
'allowed_dimensions': [],
|
||||||
{"allowed_dimensions": [], "is_mandatory": is_mandatory, "allow_or_restrict": allow_or_restrict},
|
'is_mandatory': is_mandatory,
|
||||||
)
|
'allow_or_restrict': allow_or_restrict
|
||||||
map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)
|
})
|
||||||
|
map_object[(dimension, account)]['allowed_dimensions'].append(filter_value)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -12,8 +14,7 @@ from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension imp
|
|||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
|
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
|
||||||
|
|
||||||
test_dependencies = ["Location", "Cost Center", "Department"]
|
test_dependencies = ['Location', 'Cost Center', 'Department']
|
||||||
|
|
||||||
|
|
||||||
class TestAccountingDimensionFilter(unittest.TestCase):
|
class TestAccountingDimensionFilter(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -23,9 +24,9 @@ class TestAccountingDimensionFilter(unittest.TestCase):
|
|||||||
|
|
||||||
def test_allowed_dimension_validation(self):
|
def test_allowed_dimension_validation(self):
|
||||||
si = create_sales_invoice(do_not_save=1)
|
si = create_sales_invoice(do_not_save=1)
|
||||||
si.items[0].cost_center = "Main - _TC"
|
si.items[0].cost_center = 'Main - _TC'
|
||||||
si.department = "Accounts - _TC"
|
si.department = 'Accounts - _TC'
|
||||||
si.location = "Block 1"
|
si.location = 'Block 1'
|
||||||
si.save()
|
si.save()
|
||||||
|
|
||||||
self.assertRaises(InvalidAccountDimensionError, si.submit)
|
self.assertRaises(InvalidAccountDimensionError, si.submit)
|
||||||
@@ -33,12 +34,12 @@ class TestAccountingDimensionFilter(unittest.TestCase):
|
|||||||
|
|
||||||
def test_mandatory_dimension_validation(self):
|
def test_mandatory_dimension_validation(self):
|
||||||
si = create_sales_invoice(do_not_save=1)
|
si = create_sales_invoice(do_not_save=1)
|
||||||
si.department = ""
|
si.department = ''
|
||||||
si.location = "Block 1"
|
si.location = 'Block 1'
|
||||||
|
|
||||||
# Test with no department for Sales Account
|
# Test with no department for Sales Account
|
||||||
si.items[0].department = ""
|
si.items[0].department = ''
|
||||||
si.items[0].cost_center = "_Test Cost Center 2 - _TC"
|
si.items[0].cost_center = '_Test Cost Center 2 - _TC'
|
||||||
si.save()
|
si.save()
|
||||||
|
|
||||||
self.assertRaises(MandatoryAccountDimensionError, si.submit)
|
self.assertRaises(MandatoryAccountDimensionError, si.submit)
|
||||||
@@ -53,54 +54,53 @@ class TestAccountingDimensionFilter(unittest.TestCase):
|
|||||||
if si.docstatus == 1:
|
if si.docstatus == 1:
|
||||||
si.cancel()
|
si.cancel()
|
||||||
|
|
||||||
|
|
||||||
def create_accounting_dimension_filter():
|
def create_accounting_dimension_filter():
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||||
"Accounting Dimension Filter", {"accounting_dimension": "Cost Center"}
|
{'accounting_dimension': 'Cost Center'}):
|
||||||
):
|
frappe.get_doc({
|
||||||
frappe.get_doc(
|
'doctype': 'Accounting Dimension Filter',
|
||||||
{
|
'accounting_dimension': 'Cost Center',
|
||||||
"doctype": "Accounting Dimension Filter",
|
'allow_or_restrict': 'Allow',
|
||||||
"accounting_dimension": "Cost Center",
|
'company': '_Test Company',
|
||||||
"allow_or_restrict": "Allow",
|
'accounts': [{
|
||||||
"company": "_Test Company",
|
'applicable_on_account': 'Sales - _TC',
|
||||||
"accounts": [
|
}],
|
||||||
{
|
'dimensions': [{
|
||||||
"applicable_on_account": "Sales - _TC",
|
'accounting_dimension': 'Cost Center',
|
||||||
}
|
'dimension_value': '_Test Cost Center 2 - _TC'
|
||||||
],
|
}]
|
||||||
"dimensions": [
|
}).insert()
|
||||||
{"accounting_dimension": "Cost Center", "dimension_value": "_Test Cost Center 2 - _TC"}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
else:
|
else:
|
||||||
doc = frappe.get_doc("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"})
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||||
doc.disabled = 0
|
doc.disabled = 0
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
if not frappe.db.get_value("Accounting Dimension Filter", {"accounting_dimension": "Department"}):
|
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||||
frappe.get_doc(
|
{'accounting_dimension': 'Department'}):
|
||||||
{
|
frappe.get_doc({
|
||||||
"doctype": "Accounting Dimension Filter",
|
'doctype': 'Accounting Dimension Filter',
|
||||||
"accounting_dimension": "Department",
|
'accounting_dimension': 'Department',
|
||||||
"allow_or_restrict": "Allow",
|
'allow_or_restrict': 'Allow',
|
||||||
"company": "_Test Company",
|
'company': '_Test Company',
|
||||||
"accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}],
|
'accounts': [{
|
||||||
"dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}],
|
'applicable_on_account': 'Sales - _TC',
|
||||||
}
|
'is_mandatory': 1
|
||||||
).insert()
|
}],
|
||||||
|
'dimensions': [{
|
||||||
|
'accounting_dimension': 'Department',
|
||||||
|
'dimension_value': 'Accounts - _TC'
|
||||||
|
}]
|
||||||
|
}).insert()
|
||||||
else:
|
else:
|
||||||
doc = frappe.get_doc("Accounting Dimension Filter", {"accounting_dimension": "Department"})
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Department'})
|
||||||
doc.disabled = 0
|
doc.disabled = 0
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
|
|
||||||
def disable_dimension_filter():
|
def disable_dimension_filter():
|
||||||
doc = frappe.get_doc("Accounting Dimension Filter", {"accounting_dimension": "Cost Center"})
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||||
doc.disabled = 1
|
doc.disabled = 1
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
doc = frappe.get_doc("Accounting Dimension Filter", {"accounting_dimension": "Department"})
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Department'})
|
||||||
doc.disabled = 1
|
doc.disabled = 1
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class OverlapError(frappe.ValidationError):
|
class OverlapError(frappe.ValidationError): pass
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AccountingPeriod(Document):
|
class AccountingPeriod(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
@@ -19,12 +19,11 @@ class AccountingPeriod(Document):
|
|||||||
self.bootstrap_doctypes_for_closing()
|
self.bootstrap_doctypes_for_closing()
|
||||||
|
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
company_abbr = frappe.get_cached_value("Company", self.company, "abbr")
|
company_abbr = frappe.get_cached_value('Company', self.company, "abbr")
|
||||||
self.name = " - ".join([self.period_name, company_abbr])
|
self.name = " - ".join([self.period_name, company_abbr])
|
||||||
|
|
||||||
def validate_overlap(self):
|
def validate_overlap(self):
|
||||||
existing_accounting_period = frappe.db.sql(
|
existing_accounting_period = frappe.db.sql("""select name from `tabAccounting Period`
|
||||||
"""select name from `tabAccounting Period`
|
|
||||||
where (
|
where (
|
||||||
(%(start_date)s between start_date and end_date)
|
(%(start_date)s between start_date and end_date)
|
||||||
or (%(end_date)s between start_date and end_date)
|
or (%(end_date)s between start_date and end_date)
|
||||||
@@ -35,29 +34,18 @@ class AccountingPeriod(Document):
|
|||||||
"start_date": self.start_date,
|
"start_date": self.start_date,
|
||||||
"end_date": self.end_date,
|
"end_date": self.end_date,
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"company": self.company,
|
"company": self.company
|
||||||
},
|
}, as_dict=True)
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(existing_accounting_period) > 0:
|
if len(existing_accounting_period) > 0:
|
||||||
frappe.throw(
|
frappe.throw(_("Accounting Period overlaps with {0}")
|
||||||
_("Accounting Period overlaps with {0}").format(existing_accounting_period[0].get("name")),
|
.format(existing_accounting_period[0].get("name")), OverlapError)
|
||||||
OverlapError,
|
|
||||||
)
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_doctypes_for_closing(self):
|
def get_doctypes_for_closing(self):
|
||||||
docs_for_closing = []
|
docs_for_closing = []
|
||||||
doctypes = [
|
doctypes = ["Sales Invoice", "Purchase Invoice", "Journal Entry", "Payroll Entry", \
|
||||||
"Sales Invoice",
|
"Bank Clearance", "Asset", "Stock Entry"]
|
||||||
"Purchase Invoice",
|
|
||||||
"Journal Entry",
|
|
||||||
"Payroll Entry",
|
|
||||||
"Bank Clearance",
|
|
||||||
"Asset",
|
|
||||||
"Stock Entry",
|
|
||||||
]
|
|
||||||
closed_doctypes = [{"document_type": doctype, "closed": 1} for doctype in doctypes]
|
closed_doctypes = [{"document_type": doctype, "closed": 1} for doctype in doctypes]
|
||||||
for closed_doctype in closed_doctypes:
|
for closed_doctype in closed_doctypes:
|
||||||
docs_for_closing.append(closed_doctype)
|
docs_for_closing.append(closed_doctype)
|
||||||
@@ -67,7 +55,7 @@ class AccountingPeriod(Document):
|
|||||||
def bootstrap_doctypes_for_closing(self):
|
def bootstrap_doctypes_for_closing(self):
|
||||||
if len(self.closed_documents) == 0:
|
if len(self.closed_documents) == 0:
|
||||||
for doctype_for_closing in self.get_doctypes_for_closing():
|
for doctype_for_closing in self.get_doctypes_for_closing():
|
||||||
self.append(
|
self.append('closed_documents', {
|
||||||
"closed_documents",
|
"document_type": doctype_for_closing.document_type,
|
||||||
{"document_type": doctype_for_closing.document_type, "closed": doctype_for_closing.closed},
|
"closed": doctype_for_closing.closed
|
||||||
)
|
})
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -10,38 +12,29 @@ from erpnext.accounts.doctype.accounting_period.accounting_period import Overlap
|
|||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
from erpnext.accounts.general_ledger import ClosedAccountingPeriod
|
from erpnext.accounts.general_ledger import ClosedAccountingPeriod
|
||||||
|
|
||||||
test_dependencies = ["Item"]
|
test_dependencies = ['Item']
|
||||||
|
|
||||||
|
|
||||||
class TestAccountingPeriod(unittest.TestCase):
|
class TestAccountingPeriod(unittest.TestCase):
|
||||||
def test_overlap(self):
|
def test_overlap(self):
|
||||||
ap1 = create_accounting_period(
|
ap1 = create_accounting_period(start_date = "2018-04-01",
|
||||||
start_date="2018-04-01", end_date="2018-06-30", company="Wind Power LLC"
|
end_date = "2018-06-30", company = "Wind Power LLC")
|
||||||
)
|
|
||||||
ap1.save()
|
ap1.save()
|
||||||
|
|
||||||
ap2 = create_accounting_period(
|
ap2 = create_accounting_period(start_date = "2018-06-30",
|
||||||
start_date="2018-06-30",
|
end_date = "2018-07-10", company = "Wind Power LLC", period_name = "Test Accounting Period 1")
|
||||||
end_date="2018-07-10",
|
|
||||||
company="Wind Power LLC",
|
|
||||||
period_name="Test Accounting Period 1",
|
|
||||||
)
|
|
||||||
self.assertRaises(OverlapError, ap2.save)
|
self.assertRaises(OverlapError, ap2.save)
|
||||||
|
|
||||||
def test_accounting_period(self):
|
def test_accounting_period(self):
|
||||||
ap1 = create_accounting_period(period_name="Test Accounting Period 2")
|
ap1 = create_accounting_period(period_name = "Test Accounting Period 2")
|
||||||
ap1.save()
|
ap1.save()
|
||||||
|
|
||||||
doc = create_sales_invoice(
|
doc = create_sales_invoice(do_not_submit=1, cost_center="_Test Company - _TC", warehouse="Stores - _TC")
|
||||||
do_not_submit=1, cost_center="_Test Company - _TC", warehouse="Stores - _TC"
|
|
||||||
)
|
|
||||||
self.assertRaises(ClosedAccountingPeriod, doc.submit)
|
self.assertRaises(ClosedAccountingPeriod, doc.submit)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for d in frappe.get_all("Accounting Period"):
|
for d in frappe.get_all("Accounting Period"):
|
||||||
frappe.delete_doc("Accounting Period", d.name)
|
frappe.delete_doc("Accounting Period", d.name)
|
||||||
|
|
||||||
|
|
||||||
def create_accounting_period(**args):
|
def create_accounting_period(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|
||||||
@@ -50,6 +43,8 @@ def create_accounting_period(**args):
|
|||||||
accounting_period.end_date = args.end_date or add_months(nowdate(), 1)
|
accounting_period.end_date = args.end_date or add_months(nowdate(), 1)
|
||||||
accounting_period.company = args.company or "_Test Company"
|
accounting_period.company = args.company or "_Test Company"
|
||||||
accounting_period.period_name = args.period_name or "_Test_Period_Name_1"
|
accounting_period.period_name = args.period_name or "_Test_Period_Name_1"
|
||||||
accounting_period.append("closed_documents", {"document_type": "Sales Invoice", "closed": 1})
|
accounting_period.append("closed_documents", {
|
||||||
|
"document_type": 'Sales Invoice', "closed": 1
|
||||||
|
})
|
||||||
|
|
||||||
return accounting_period
|
return accounting_period
|
||||||
|
|||||||
@@ -19,14 +19,12 @@
|
|||||||
"book_asset_depreciation_entry_automatically",
|
"book_asset_depreciation_entry_automatically",
|
||||||
"unlink_advance_payment_on_cancelation_of_order",
|
"unlink_advance_payment_on_cancelation_of_order",
|
||||||
"enable_common_party_accounting",
|
"enable_common_party_accounting",
|
||||||
"allow_multi_currency_invoices_against_single_party_account",
|
|
||||||
"post_change_gl_entries",
|
"post_change_gl_entries",
|
||||||
"enable_discount_accounting",
|
"enable_discount_accounting",
|
||||||
"tax_settings_section",
|
"tax_settings_section",
|
||||||
"determine_address_tax_category_from",
|
"determine_address_tax_category_from",
|
||||||
"column_break_19",
|
"column_break_19",
|
||||||
"add_taxes_from_item_tax_template",
|
"add_taxes_from_item_tax_template",
|
||||||
"book_tax_discount_loss",
|
|
||||||
"period_closing_settings_section",
|
"period_closing_settings_section",
|
||||||
"acc_frozen_upto",
|
"acc_frozen_upto",
|
||||||
"frozen_accounts_modifier",
|
"frozen_accounts_modifier",
|
||||||
@@ -175,7 +173,6 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
"description": "Payment Terms from orders will be fetched into the invoices as is",
|
|
||||||
"fieldname": "automatically_fetch_payment_terms",
|
"fieldname": "automatically_fetch_payment_terms",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Automatically Fetch Payment Terms from Order"
|
"label": "Automatically Fetch Payment Terms from Order"
|
||||||
@@ -279,28 +276,14 @@
|
|||||||
"fieldname": "enable_common_party_accounting",
|
"fieldname": "enable_common_party_accounting",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Enable Common Party Accounting"
|
"label": "Enable Common Party Accounting"
|
||||||
},
|
}
|
||||||
{
|
|
||||||
"default": "0",
|
|
||||||
"description": "Enabling this will allow creation of multi-currency invoices against single party account in company currency",
|
|
||||||
"fieldname": "allow_multi_currency_invoices_against_single_party_account",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"label": "Allow multi-currency invoices against single party account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"default": "0",
|
|
||||||
"description": "Split Early Payment Discount Loss into Income and Tax Loss",
|
|
||||||
"fieldname": "book_tax_discount_loss",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"label": "Book Tax Loss on Early Payment Discount"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"icon": "icon-cog",
|
"icon": "icon-cog",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-04-14 17:22:03.680886",
|
"modified": "2021-10-11 17:42:36.427699",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Accounts Settings",
|
"name": "Accounts Settings",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -10,116 +11,46 @@ from frappe.custom.doctype.property_setter.property_setter import make_property_
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cint
|
from frappe.utils import cint
|
||||||
|
|
||||||
from erpnext.stock.utils import check_pending_reposting
|
|
||||||
|
|
||||||
|
|
||||||
class AccountsSettings(Document):
|
class AccountsSettings(Document):
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
frappe.clear_cache()
|
frappe.clear_cache()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
frappe.db.set_default(
|
frappe.db.set_default("add_taxes_from_item_tax_template",
|
||||||
"add_taxes_from_item_tax_template", self.get("add_taxes_from_item_tax_template", 0)
|
self.get("add_taxes_from_item_tax_template", 0))
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.set_default(
|
|
||||||
"enable_common_party_accounting", self.get("enable_common_party_accounting", 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.validate_stale_days()
|
self.validate_stale_days()
|
||||||
self.enable_payment_schedule_in_print()
|
self.enable_payment_schedule_in_print()
|
||||||
self.toggle_discount_accounting_fields()
|
self.toggle_discount_accounting_fields()
|
||||||
self.validate_pending_reposts()
|
|
||||||
|
|
||||||
def validate_stale_days(self):
|
def validate_stale_days(self):
|
||||||
if not self.allow_stale and cint(self.stale_days) <= 0:
|
if not self.allow_stale and cint(self.stale_days) <= 0:
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
_("Stale Days should start from 1."), title="Error", indicator="red", raise_exception=1
|
_("Stale Days should start from 1."), title='Error', indicator='red',
|
||||||
)
|
raise_exception=1)
|
||||||
|
|
||||||
def enable_payment_schedule_in_print(self):
|
def enable_payment_schedule_in_print(self):
|
||||||
show_in_print = cint(self.show_payment_schedule_in_print)
|
show_in_print = cint(self.show_payment_schedule_in_print)
|
||||||
for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
|
for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
|
||||||
make_property_setter(
|
make_property_setter(doctype, "due_date", "print_hide", show_in_print, "Check", validate_fields_for_doctype=False)
|
||||||
doctype, "due_date", "print_hide", show_in_print, "Check", validate_fields_for_doctype=False
|
make_property_setter(doctype, "payment_schedule", "print_hide", 0 if show_in_print else 1, "Check", validate_fields_for_doctype=False)
|
||||||
)
|
|
||||||
make_property_setter(
|
|
||||||
doctype,
|
|
||||||
"payment_schedule",
|
|
||||||
"print_hide",
|
|
||||||
0 if show_in_print else 1,
|
|
||||||
"Check",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def toggle_discount_accounting_fields(self):
|
def toggle_discount_accounting_fields(self):
|
||||||
enable_discount_accounting = cint(self.enable_discount_accounting)
|
enable_discount_accounting = cint(self.enable_discount_accounting)
|
||||||
|
|
||||||
for doctype in ["Sales Invoice Item", "Purchase Invoice Item"]:
|
for doctype in ["Sales Invoice Item", "Purchase Invoice Item"]:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"discount_account",
|
|
||||||
"hidden",
|
|
||||||
not (enable_discount_accounting),
|
|
||||||
"Check",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
if enable_discount_accounting:
|
if enable_discount_accounting:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "discount_account", "mandatory_depends_on", "eval: doc.discount_amount", "Code", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"discount_account",
|
|
||||||
"mandatory_depends_on",
|
|
||||||
"eval: doc.discount_amount",
|
|
||||||
"Code",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "discount_account", "mandatory_depends_on", "", "Code", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"discount_account",
|
|
||||||
"mandatory_depends_on",
|
|
||||||
"",
|
|
||||||
"Code",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for doctype in ["Sales Invoice", "Purchase Invoice"]:
|
for doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "additional_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"additional_discount_account",
|
|
||||||
"hidden",
|
|
||||||
not (enable_discount_accounting),
|
|
||||||
"Check",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
if enable_discount_accounting:
|
if enable_discount_accounting:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "additional_discount_account", "mandatory_depends_on", "eval: doc.discount_amount", "Code", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"additional_discount_account",
|
|
||||||
"mandatory_depends_on",
|
|
||||||
"eval: doc.discount_amount",
|
|
||||||
"Code",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
make_property_setter(
|
make_property_setter(doctype, "additional_discount_account", "mandatory_depends_on", "", "Code", validate_fields_for_doctype=False)
|
||||||
doctype,
|
|
||||||
"additional_discount_account",
|
|
||||||
"mandatory_depends_on",
|
|
||||||
"",
|
|
||||||
"Code",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
make_property_setter(
|
make_property_setter("Item", "default_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
||||||
"Item",
|
|
||||||
"default_discount_account",
|
|
||||||
"hidden",
|
|
||||||
not (enable_discount_accounting),
|
|
||||||
"Check",
|
|
||||||
validate_fields_for_doctype=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_pending_reposts(self):
|
|
||||||
if self.acc_frozen_upto:
|
|
||||||
check_pending_reposting(self.acc_frozen_upto)
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
@@ -7,12 +9,12 @@ class TestAccountsSettings(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Just in case `save` method succeeds, we need to take things back to default so that other tests
|
# Just in case `save` method succeeds, we need to take things back to default so that other tests
|
||||||
# don't break
|
# don't break
|
||||||
cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings")
|
cur_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
|
||||||
cur_settings.allow_stale = 1
|
cur_settings.allow_stale = 1
|
||||||
cur_settings.save()
|
cur_settings.save()
|
||||||
|
|
||||||
def test_stale_days(self):
|
def test_stale_days(self):
|
||||||
cur_settings = frappe.get_doc("Accounts Settings", "Accounts Settings")
|
cur_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
|
||||||
cur_settings.allow_stale = 0
|
cur_settings.allow_stale = 0
|
||||||
cur_settings.stale_days = 0
|
cur_settings.stale_days = 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
{
|
|
||||||
"actions": [],
|
|
||||||
"allow_rename": 1,
|
|
||||||
"creation": "2021-11-25 10:24:39.836195",
|
|
||||||
"doctype": "DocType",
|
|
||||||
"engine": "InnoDB",
|
|
||||||
"field_order": [
|
|
||||||
"reference_type",
|
|
||||||
"reference_name",
|
|
||||||
"reference_detail",
|
|
||||||
"account_head",
|
|
||||||
"allocated_amount"
|
|
||||||
],
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldname": "reference_type",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Reference Type",
|
|
||||||
"options": "DocType"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "reference_name",
|
|
||||||
"fieldtype": "Dynamic Link",
|
|
||||||
"label": "Reference Name",
|
|
||||||
"options": "reference_type"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "reference_detail",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"label": "Reference Detail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "account_head",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Account Head",
|
|
||||||
"options": "Account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "allocated_amount",
|
|
||||||
"fieldtype": "Currency",
|
|
||||||
"label": "Allocated Amount",
|
|
||||||
"options": "party_account_currency"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"index_web_pages_for_search": 1,
|
|
||||||
"istable": 1,
|
|
||||||
"links": [],
|
|
||||||
"modified": "2021-11-25 10:27:51.712286",
|
|
||||||
"modified_by": "Administrator",
|
|
||||||
"module": "Accounts",
|
|
||||||
"name": "Advance Tax",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"permissions": [],
|
|
||||||
"sort_field": "modified",
|
|
||||||
"sort_order": "DESC"
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
|
||||||
# For license information, please see license.txt
|
|
||||||
|
|
||||||
# import frappe
|
|
||||||
from frappe.model.document import Document
|
|
||||||
|
|
||||||
|
|
||||||
class AdvanceTax(Document):
|
|
||||||
pass
|
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
"allocated_amount",
|
"allocated_amount",
|
||||||
"column_break_13",
|
"column_break_13",
|
||||||
"base_tax_amount",
|
"base_tax_amount",
|
||||||
"base_total"
|
"base_total",
|
||||||
|
"base_allocated_amount"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -167,6 +168,12 @@
|
|||||||
"label": "Allocated Amount",
|
"label": "Allocated Amount",
|
||||||
"options": "currency"
|
"options": "currency"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "base_allocated_amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Allocated Amount (Company Currency)",
|
||||||
|
"options": "Company:company:default_currency"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fetch_from": "account_head.account_currency",
|
"fetch_from": "account_head.account_currency",
|
||||||
"fieldname": "currency",
|
"fieldname": "currency",
|
||||||
@@ -179,7 +186,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-11-25 11:10:10.945027",
|
"modified": "2021-06-09 11:46:58.373170",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Advance Taxes and Charges",
|
"name": "Advance Taxes and Charges",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.contacts.address_and_contact import (
|
from frappe.contacts.address_and_contact import (
|
||||||
delete_contact_and_address,
|
delete_contact_and_address,
|
||||||
@@ -15,4 +17,4 @@ class Bank(Document):
|
|||||||
load_address_and_contact(self)
|
load_address_and_contact(self)
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
delete_contact_and_address("Bank", self.name)
|
delete_contact_and_address('Bank', self.name)
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
|
||||||
def get_data():
|
def get_data():
|
||||||
return {
|
return {
|
||||||
"fieldname": "bank",
|
'fieldname': 'bank',
|
||||||
"transactions": [{"label": _("Bank Details"), "items": ["Bank Account", "Bank Guarantee"]}],
|
'transactions': [
|
||||||
|
{
|
||||||
|
'label': _('Bank Details'),
|
||||||
|
'items': ['Bank Account', 'Bank Guarantee']
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -20,7 +22,7 @@ class BankAccount(Document):
|
|||||||
self.name = self.account_name + " - " + self.bank
|
self.name = self.account_name + " - " + self.bank
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
delete_contact_and_address("BankAccount", self.name)
|
delete_contact_and_address('BankAccount', self.name)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_company()
|
self.validate_company()
|
||||||
@@ -31,9 +33,9 @@ class BankAccount(Document):
|
|||||||
frappe.throw(_("Company is manadatory for company account"))
|
frappe.throw(_("Company is manadatory for company account"))
|
||||||
|
|
||||||
def validate_iban(self):
|
def validate_iban(self):
|
||||||
"""
|
'''
|
||||||
Algorithm: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
|
Algorithm: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
|
||||||
"""
|
'''
|
||||||
# IBAN field is optional
|
# IBAN field is optional
|
||||||
if not self.iban:
|
if not self.iban:
|
||||||
return
|
return
|
||||||
@@ -43,7 +45,7 @@ class BankAccount(Document):
|
|||||||
return str(9 + ord(c) - 64)
|
return str(9 + ord(c) - 64)
|
||||||
|
|
||||||
# remove whitespaces, upper case to get the right number from ord()
|
# remove whitespaces, upper case to get the right number from ord()
|
||||||
iban = "".join(self.iban.split(" ")).upper()
|
iban = ''.join(self.iban.split(' ')).upper()
|
||||||
|
|
||||||
# Move country code and checksum from the start to the end
|
# Move country code and checksum from the start to the end
|
||||||
flipped = iban[4:] + iban[:4]
|
flipped = iban[4:] + iban[:4]
|
||||||
@@ -52,12 +54,12 @@ class BankAccount(Document):
|
|||||||
encoded = [encode_char(c) if ord(c) >= 65 and ord(c) <= 90 else c for c in flipped]
|
encoded = [encode_char(c) if ord(c) >= 65 and ord(c) <= 90 else c for c in flipped]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
to_check = int("".join(encoded))
|
to_check = int(''.join(encoded))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
frappe.throw(_("IBAN is not valid"))
|
frappe.throw(_('IBAN is not valid'))
|
||||||
|
|
||||||
if to_check % 97 != 1:
|
if to_check % 97 != 1:
|
||||||
frappe.throw(_("IBAN is not valid"))
|
frappe.throw(_('IBAN is not valid'))
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@@ -69,14 +71,12 @@ def make_bank_account(doctype, docname):
|
|||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_party_bank_account(party_type, party):
|
def get_party_bank_account(party_type, party):
|
||||||
return frappe.db.get_value(party_type, party, "default_bank_account")
|
return frappe.db.get_value(party_type,
|
||||||
|
party, 'default_bank_account')
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_bank_account_details(bank_account):
|
def get_bank_account_details(bank_account):
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value("Bank Account",
|
||||||
"Bank Account", bank_account, ["account", "bank", "bank_account_no"], as_dict=1
|
bank_account, ['account', 'bank', 'bank_account_no'], as_dict=1)
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,20 +1,29 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
|
||||||
def get_data():
|
def get_data():
|
||||||
return {
|
return {
|
||||||
"fieldname": "bank_account",
|
'fieldname': 'bank_account',
|
||||||
"non_standard_fieldnames": {
|
'non_standard_fieldnames': {
|
||||||
"Customer": "default_bank_account",
|
'Customer': 'default_bank_account',
|
||||||
"Supplier": "default_bank_account",
|
'Supplier': 'default_bank_account',
|
||||||
},
|
},
|
||||||
"transactions": [
|
'transactions': [
|
||||||
{
|
{
|
||||||
"label": _("Payments"),
|
'label': _('Payments'),
|
||||||
"items": ["Payment Entry", "Payment Request", "Payment Order", "Payroll Entry"],
|
'items': ['Payment Entry', 'Payment Request', 'Payment Order', 'Payroll Entry']
|
||||||
},
|
},
|
||||||
{"label": _("Party"), "items": ["Customer", "Supplier"]},
|
{
|
||||||
{"items": ["Bank Guarantee"]},
|
'label': _('Party'),
|
||||||
{"items": ["Journal Entry"]},
|
'items': ['Customer', 'Supplier']
|
||||||
],
|
},
|
||||||
|
{
|
||||||
|
'items': ['Bank Guarantee']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'items': ['Journal Entry']
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -8,28 +10,28 @@ from frappe import ValidationError
|
|||||||
|
|
||||||
# test_records = frappe.get_test_records('Bank Account')
|
# test_records = frappe.get_test_records('Bank Account')
|
||||||
|
|
||||||
|
|
||||||
class TestBankAccount(unittest.TestCase):
|
class TestBankAccount(unittest.TestCase):
|
||||||
|
|
||||||
def test_validate_iban(self):
|
def test_validate_iban(self):
|
||||||
valid_ibans = [
|
valid_ibans = [
|
||||||
"GB82 WEST 1234 5698 7654 32",
|
'GB82 WEST 1234 5698 7654 32',
|
||||||
"DE91 1000 0000 0123 4567 89",
|
'DE91 1000 0000 0123 4567 89',
|
||||||
"FR76 3000 6000 0112 3456 7890 189",
|
'FR76 3000 6000 0112 3456 7890 189'
|
||||||
]
|
]
|
||||||
|
|
||||||
invalid_ibans = [
|
invalid_ibans = [
|
||||||
# wrong checksum (3rd place)
|
# wrong checksum (3rd place)
|
||||||
"GB72 WEST 1234 5698 7654 32",
|
'GB72 WEST 1234 5698 7654 32',
|
||||||
"DE81 1000 0000 0123 4567 89",
|
'DE81 1000 0000 0123 4567 89',
|
||||||
"FR66 3000 6000 0112 3456 7890 189",
|
'FR66 3000 6000 0112 3456 7890 189'
|
||||||
]
|
]
|
||||||
|
|
||||||
bank_account = frappe.get_doc({"doctype": "Bank Account"})
|
bank_account = frappe.get_doc({'doctype':'Bank Account'})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bank_account.validate_iban()
|
bank_account.validate_iban()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
msg = "BankAccount.validate_iban() failed for empty IBAN"
|
msg = 'BankAccount.validate_iban() failed for empty IBAN'
|
||||||
self.fail(msg=msg)
|
self.fail(msg=msg)
|
||||||
|
|
||||||
for iban in valid_ibans:
|
for iban in valid_ibans:
|
||||||
@@ -37,11 +39,11 @@ class TestBankAccount(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
bank_account.validate_iban()
|
bank_account.validate_iban()
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
msg = "BankAccount.validate_iban() failed for valid IBAN {}".format(iban)
|
msg = 'BankAccount.validate_iban() failed for valid IBAN {}'.format(iban)
|
||||||
self.fail(msg=msg)
|
self.fail(msg=msg)
|
||||||
|
|
||||||
for not_iban in invalid_ibans:
|
for not_iban in invalid_ibans:
|
||||||
bank_account.iban = not_iban
|
bank_account.iban = not_iban
|
||||||
msg = "BankAccount.validate_iban() accepted invalid IBAN {}".format(not_iban)
|
msg = 'BankAccount.validate_iban() accepted invalid IBAN {}'.format(not_iban)
|
||||||
with self.assertRaises(ValidationError, msg=msg):
|
with self.assertRaises(ValidationError, msg=msg):
|
||||||
bank_account.validate_iban()
|
bank_account.validate_iban()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, msgprint
|
from frappe import _, msgprint
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.query_builder.custom import ConstantColumn
|
from frappe.utils import flt, fmt_money, getdate, nowdate
|
||||||
from frappe.utils import flt, fmt_money, getdate
|
|
||||||
|
|
||||||
import erpnext
|
|
||||||
|
|
||||||
form_grid_templates = {"journal_entries": "templates/form_grid/bank_reconciliation_grid.html"}
|
|
||||||
|
|
||||||
|
form_grid_templates = {
|
||||||
|
"journal_entries": "templates/form_grid/bank_reconciliation_grid.html"
|
||||||
|
}
|
||||||
|
|
||||||
class BankClearance(Document):
|
class BankClearance(Document):
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@@ -26,8 +25,7 @@ class BankClearance(Document):
|
|||||||
if not self.include_reconciled_entries:
|
if not self.include_reconciled_entries:
|
||||||
condition = "and (clearance_date IS NULL or clearance_date='0000-00-00')"
|
condition = "and (clearance_date IS NULL or clearance_date='0000-00-00')"
|
||||||
|
|
||||||
journal_entries = frappe.db.sql(
|
journal_entries = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
"Journal Entry" as payment_document, t1.name as payment_entry,
|
"Journal Entry" as payment_document, t1.name as payment_entry,
|
||||||
t1.cheque_no as cheque_number, t1.cheque_date,
|
t1.cheque_no as cheque_number, t1.cheque_date,
|
||||||
@@ -41,22 +39,16 @@ class BankClearance(Document):
|
|||||||
and ifnull(t1.is_opening, 'No') = 'No' {condition}
|
and ifnull(t1.is_opening, 'No') = 'No' {condition}
|
||||||
group by t2.account, t1.name
|
group by t2.account, t1.name
|
||||||
order by t1.posting_date ASC, t1.name DESC
|
order by t1.posting_date ASC, t1.name DESC
|
||||||
""".format(
|
""".format(condition=condition), {"account": self.account, "from": self.from_date, "to": self.to_date}, as_dict=1)
|
||||||
condition=condition
|
|
||||||
),
|
|
||||||
{"account": self.account, "from": self.from_date, "to": self.to_date},
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.bank_account:
|
if self.bank_account:
|
||||||
condition += "and bank_account = %(bank_account)s"
|
condition += 'and bank_account = %(bank_account)s'
|
||||||
|
|
||||||
payment_entries = frappe.db.sql(
|
payment_entries = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
"Payment Entry" as payment_document, name as payment_entry,
|
"Payment Entry" as payment_document, name as payment_entry,
|
||||||
reference_no as cheque_number, reference_date as cheque_date,
|
reference_no as cheque_number, reference_date as cheque_date,
|
||||||
if(paid_from=%(account)s, paid_amount + total_taxes_and_charges, 0) as credit,
|
if(paid_from=%(account)s, paid_amount, 0) as credit,
|
||||||
if(paid_from=%(account)s, 0, received_amount) as debit,
|
if(paid_from=%(account)s, 0, received_amount) as debit,
|
||||||
posting_date, ifnull(party,if(paid_from=%(account)s,paid_to,paid_from)) as against_account, clearance_date,
|
posting_date, ifnull(party,if(paid_from=%(account)s,paid_to,paid_from)) as against_account, clearance_date,
|
||||||
if(paid_to=%(account)s, paid_to_account_currency, paid_from_account_currency) as account_currency
|
if(paid_to=%(account)s, paid_to_account_currency, paid_from_account_currency) as account_currency
|
||||||
@@ -67,69 +59,12 @@ class BankClearance(Document):
|
|||||||
{condition}
|
{condition}
|
||||||
order by
|
order by
|
||||||
posting_date ASC, name DESC
|
posting_date ASC, name DESC
|
||||||
""".format(
|
""".format(condition=condition), {"account": self.account, "from":self.from_date,
|
||||||
condition=condition
|
"to": self.to_date, "bank_account": self.bank_account}, as_dict=1)
|
||||||
),
|
|
||||||
{
|
|
||||||
"account": self.account,
|
|
||||||
"from": self.from_date,
|
|
||||||
"to": self.to_date,
|
|
||||||
"bank_account": self.bank_account,
|
|
||||||
},
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
loan_disbursement = frappe.qb.DocType("Loan Disbursement")
|
|
||||||
|
|
||||||
loan_disbursements = (
|
|
||||||
frappe.qb.from_(loan_disbursement)
|
|
||||||
.select(
|
|
||||||
ConstantColumn("Loan Disbursement").as_("payment_document"),
|
|
||||||
loan_disbursement.name.as_("payment_entry"),
|
|
||||||
loan_disbursement.disbursed_amount.as_("credit"),
|
|
||||||
ConstantColumn(0).as_("debit"),
|
|
||||||
loan_disbursement.reference_number.as_("cheque_number"),
|
|
||||||
loan_disbursement.reference_date.as_("cheque_date"),
|
|
||||||
loan_disbursement.disbursement_date.as_("posting_date"),
|
|
||||||
loan_disbursement.applicant.as_("against_account"),
|
|
||||||
)
|
|
||||||
.where(loan_disbursement.docstatus == 1)
|
|
||||||
.where(loan_disbursement.disbursement_date >= self.from_date)
|
|
||||||
.where(loan_disbursement.disbursement_date <= self.to_date)
|
|
||||||
.where(loan_disbursement.clearance_date.isnull())
|
|
||||||
.where(loan_disbursement.disbursement_account.isin([self.bank_account, self.account]))
|
|
||||||
.orderby(loan_disbursement.disbursement_date)
|
|
||||||
.orderby(loan_disbursement.name, frappe.qb.desc)
|
|
||||||
).run(as_dict=1)
|
|
||||||
|
|
||||||
loan_repayment = frappe.qb.DocType("Loan Repayment")
|
|
||||||
|
|
||||||
loan_repayments = (
|
|
||||||
frappe.qb.from_(loan_repayment)
|
|
||||||
.select(
|
|
||||||
ConstantColumn("Loan Repayment").as_("payment_document"),
|
|
||||||
loan_repayment.name.as_("payment_entry"),
|
|
||||||
loan_repayment.amount_paid.as_("debit"),
|
|
||||||
ConstantColumn(0).as_("credit"),
|
|
||||||
loan_repayment.reference_number.as_("cheque_number"),
|
|
||||||
loan_repayment.reference_date.as_("cheque_date"),
|
|
||||||
loan_repayment.applicant.as_("against_account"),
|
|
||||||
loan_repayment.posting_date,
|
|
||||||
)
|
|
||||||
.where(loan_repayment.docstatus == 1)
|
|
||||||
.where(loan_repayment.clearance_date.isnull())
|
|
||||||
.where(loan_repayment.repay_from_salary == 0)
|
|
||||||
.where(loan_repayment.posting_date >= self.from_date)
|
|
||||||
.where(loan_repayment.posting_date <= self.to_date)
|
|
||||||
.where(loan_repayment.payment_account.isin([self.bank_account, self.account]))
|
|
||||||
.orderby(loan_repayment.posting_date)
|
|
||||||
.orderby(loan_repayment.name, frappe.qb.desc)
|
|
||||||
).run(as_dict=1)
|
|
||||||
|
|
||||||
pos_sales_invoices, pos_purchase_invoices = [], []
|
pos_sales_invoices, pos_purchase_invoices = [], []
|
||||||
if self.include_pos_transactions:
|
if self.include_pos_transactions:
|
||||||
pos_sales_invoices = frappe.db.sql(
|
pos_sales_invoices = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
"Sales Invoice Payment" as payment_document, sip.name as payment_entry, sip.amount as debit,
|
"Sales Invoice Payment" as payment_document, sip.name as payment_entry, sip.amount as debit,
|
||||||
si.posting_date, si.customer as against_account, sip.clearance_date,
|
si.posting_date, si.customer as against_account, sip.clearance_date,
|
||||||
@@ -140,13 +75,9 @@ class BankClearance(Document):
|
|||||||
and account.name = sip.account and si.posting_date >= %(from)s and si.posting_date <= %(to)s
|
and account.name = sip.account and si.posting_date >= %(from)s and si.posting_date <= %(to)s
|
||||||
order by
|
order by
|
||||||
si.posting_date ASC, si.name DESC
|
si.posting_date ASC, si.name DESC
|
||||||
""",
|
""", {"account":self.account, "from":self.from_date, "to":self.to_date}, as_dict=1)
|
||||||
{"account": self.account, "from": self.from_date, "to": self.to_date},
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
pos_purchase_invoices = frappe.db.sql(
|
pos_purchase_invoices = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
"Purchase Invoice" as payment_document, pi.name as payment_entry, pi.paid_amount as credit,
|
"Purchase Invoice" as payment_document, pi.name as payment_entry, pi.paid_amount as credit,
|
||||||
pi.posting_date, pi.supplier as against_account, pi.clearance_date,
|
pi.posting_date, pi.supplier as against_account, pi.clearance_date,
|
||||||
@@ -157,36 +88,21 @@ class BankClearance(Document):
|
|||||||
and pi.posting_date >= %(from)s and pi.posting_date <= %(to)s
|
and pi.posting_date >= %(from)s and pi.posting_date <= %(to)s
|
||||||
order by
|
order by
|
||||||
pi.posting_date ASC, pi.name DESC
|
pi.posting_date ASC, pi.name DESC
|
||||||
""",
|
""", {"account": self.account, "from": self.from_date, "to": self.to_date}, as_dict=1)
|
||||||
{"account": self.account, "from": self.from_date, "to": self.to_date},
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
entries = sorted(
|
entries = sorted(list(payment_entries) + list(journal_entries + list(pos_sales_invoices) + list(pos_purchase_invoices)),
|
||||||
list(payment_entries)
|
key=lambda k: k['posting_date'] or getdate(nowdate()))
|
||||||
+ list(journal_entries)
|
|
||||||
+ list(pos_sales_invoices)
|
|
||||||
+ list(pos_purchase_invoices)
|
|
||||||
+ list(loan_disbursements)
|
|
||||||
+ list(loan_repayments),
|
|
||||||
key=lambda k: getdate(k["posting_date"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.set("payment_entries", [])
|
self.set('payment_entries', [])
|
||||||
self.total_amount = 0.0
|
self.total_amount = 0.0
|
||||||
default_currency = erpnext.get_default_currency()
|
|
||||||
|
|
||||||
for d in entries:
|
for d in entries:
|
||||||
row = self.append("payment_entries", {})
|
row = self.append('payment_entries', {})
|
||||||
|
|
||||||
amount = flt(d.get("debit", 0)) - flt(d.get("credit", 0))
|
amount = flt(d.get('debit', 0)) - flt(d.get('credit', 0))
|
||||||
|
|
||||||
if not d.get("account_currency"):
|
|
||||||
d.account_currency = default_currency
|
|
||||||
|
|
||||||
formatted_amount = fmt_money(abs(amount), 2, d.account_currency)
|
formatted_amount = fmt_money(abs(amount), 2, d.account_currency)
|
||||||
d.amount = formatted_amount + " " + (_("Dr") if amount > 0 else _("Cr"))
|
d.amount = formatted_amount + " " + (_("Dr") if amount > 0 else _("Cr"))
|
||||||
d.posting_date = getdate(d.posting_date)
|
|
||||||
|
|
||||||
d.pop("credit")
|
d.pop("credit")
|
||||||
d.pop("debit")
|
d.pop("debit")
|
||||||
@@ -197,24 +113,21 @@ class BankClearance(Document):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def update_clearance_date(self):
|
def update_clearance_date(self):
|
||||||
clearance_date_updated = False
|
clearance_date_updated = False
|
||||||
for d in self.get("payment_entries"):
|
for d in self.get('payment_entries'):
|
||||||
if d.clearance_date:
|
if d.clearance_date:
|
||||||
if not d.payment_document:
|
if not d.payment_document:
|
||||||
frappe.throw(_("Row #{0}: Payment document is required to complete the transaction"))
|
frappe.throw(_("Row #{0}: Payment document is required to complete the transaction"))
|
||||||
|
|
||||||
if d.cheque_date and getdate(d.clearance_date) < getdate(d.cheque_date):
|
if d.cheque_date and getdate(d.clearance_date) < getdate(d.cheque_date):
|
||||||
frappe.throw(
|
frappe.throw(_("Row #{0}: Clearance date {1} cannot be before Cheque Date {2}")
|
||||||
_("Row #{0}: Clearance date {1} cannot be before Cheque Date {2}").format(
|
.format(d.idx, d.clearance_date, d.cheque_date))
|
||||||
d.idx, d.clearance_date, d.cheque_date
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if d.clearance_date or self.include_reconciled_entries:
|
if d.clearance_date or self.include_reconciled_entries:
|
||||||
if not d.clearance_date:
|
if not d.clearance_date:
|
||||||
d.clearance_date = None
|
d.clearance_date = None
|
||||||
|
|
||||||
payment_entry = frappe.get_doc(d.payment_document, d.payment_entry)
|
payment_entry = frappe.get_doc(d.payment_document, d.payment_entry)
|
||||||
payment_entry.db_set("clearance_date", d.clearance_date)
|
payment_entry.db_set('clearance_date', d.clearance_date)
|
||||||
|
|
||||||
clearance_date_updated = True
|
clearance_date_updated = True
|
||||||
|
|
||||||
|
|||||||
@@ -1,96 +1,11 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
|
||||||
from frappe.utils import add_months, getdate
|
|
||||||
|
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
|
||||||
from erpnext.loan_management.doctype.loan.test_loan import (
|
|
||||||
create_loan,
|
|
||||||
create_loan_accounts,
|
|
||||||
create_loan_type,
|
|
||||||
create_repayment_entry,
|
|
||||||
make_loan_disbursement_entry,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestBankClearance(unittest.TestCase):
|
class TestBankClearance(unittest.TestCase):
|
||||||
@classmethod
|
pass
|
||||||
def setUpClass(cls):
|
|
||||||
make_bank_account()
|
|
||||||
create_loan_accounts()
|
|
||||||
create_loan_masters()
|
|
||||||
add_transactions()
|
|
||||||
|
|
||||||
# Basic test case to test if bank clearance tool doesn't break
|
|
||||||
# Detailed test can be added later
|
|
||||||
def test_bank_clearance(self):
|
|
||||||
bank_clearance = frappe.get_doc("Bank Clearance")
|
|
||||||
bank_clearance.account = "_Test Bank Clearance - _TC"
|
|
||||||
bank_clearance.from_date = add_months(getdate(), -1)
|
|
||||||
bank_clearance.to_date = getdate()
|
|
||||||
bank_clearance.get_payment_entries()
|
|
||||||
self.assertEqual(len(bank_clearance.payment_entries), 3)
|
|
||||||
|
|
||||||
|
|
||||||
def make_bank_account():
|
|
||||||
if not frappe.db.get_value("Account", "_Test Bank Clearance - _TC"):
|
|
||||||
frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "Account",
|
|
||||||
"account_type": "Bank",
|
|
||||||
"account_name": "_Test Bank Clearance",
|
|
||||||
"company": "_Test Company",
|
|
||||||
"parent_account": "Bank Accounts - _TC",
|
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
|
|
||||||
|
|
||||||
def create_loan_masters():
|
|
||||||
create_loan_type(
|
|
||||||
"Clearance Loan",
|
|
||||||
2000000,
|
|
||||||
13.5,
|
|
||||||
25,
|
|
||||||
0,
|
|
||||||
5,
|
|
||||||
"Cash",
|
|
||||||
"_Test Bank Clearance - _TC",
|
|
||||||
"_Test Bank Clearance - _TC",
|
|
||||||
"Loan Account - _TC",
|
|
||||||
"Interest Income Account - _TC",
|
|
||||||
"Penalty Income Account - _TC",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def add_transactions():
|
|
||||||
make_payment_entry()
|
|
||||||
make_loan()
|
|
||||||
|
|
||||||
|
|
||||||
def make_loan():
|
|
||||||
loan = create_loan(
|
|
||||||
"_Test Customer",
|
|
||||||
"Clearance Loan",
|
|
||||||
280000,
|
|
||||||
"Repay Over Number of Periods",
|
|
||||||
20,
|
|
||||||
applicant_type="Customer",
|
|
||||||
)
|
|
||||||
loan.submit()
|
|
||||||
make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=getdate())
|
|
||||||
repayment_entry = create_repayment_entry(loan.name, "_Test Customer", getdate(), loan.loan_amount)
|
|
||||||
repayment_entry.save()
|
|
||||||
repayment_entry.submit()
|
|
||||||
|
|
||||||
|
|
||||||
def make_payment_entry():
|
|
||||||
pi = make_purchase_invoice(supplier="_Test Supplier", qty=1, rate=690)
|
|
||||||
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank Clearance - _TC")
|
|
||||||
pe.reference_no = "Conrad Oct 18"
|
|
||||||
pe.reference_date = "2018-10-24"
|
|
||||||
pe.insert()
|
|
||||||
pe.submit()
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,20 @@ frappe.ui.form.on('Bank Guarantee', {
|
|||||||
|
|
||||||
reference_docname: function(frm) {
|
reference_docname: function(frm) {
|
||||||
if (frm.doc.reference_docname && frm.doc.reference_doctype) {
|
if (frm.doc.reference_docname && frm.doc.reference_doctype) {
|
||||||
|
let fields_to_fetch = ["grand_total"];
|
||||||
let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier";
|
let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier";
|
||||||
|
|
||||||
|
if (frm.doc.reference_doctype == "Sales Order") {
|
||||||
|
fields_to_fetch.push("project");
|
||||||
|
}
|
||||||
|
|
||||||
|
fields_to_fetch.push(party_field);
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details",
|
method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_vouchar_detials",
|
||||||
args: {
|
args: {
|
||||||
"bank_guarantee_type": frm.doc.bg_type,
|
"column_list": fields_to_fetch,
|
||||||
"reference_name": frm.doc.reference_docname
|
"doctype": frm.doc.reference_doctype,
|
||||||
|
"docname": frm.doc.reference_docname
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.desk.search import sanitize_searchfield
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
@@ -20,20 +25,10 @@ class BankGuarantee(Document):
|
|||||||
if not self.bank:
|
if not self.bank:
|
||||||
frappe.throw(_("Enter the name of the bank or lending institution before submittting."))
|
frappe.throw(_("Enter the name of the bank or lending institution before submittting."))
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_voucher_details(bank_guarantee_type: str, reference_name: str):
|
def get_vouchar_detials(column_list, doctype, docname):
|
||||||
if not isinstance(reference_name, str):
|
column_list = json.loads(column_list)
|
||||||
raise TypeError("reference_name must be a string")
|
for col in column_list:
|
||||||
|
sanitize_searchfield(col)
|
||||||
fields_to_fetch = ["grand_total"]
|
return frappe.db.sql(''' select {columns} from `tab{doctype}` where name=%s'''
|
||||||
|
.format(columns=", ".join(column_list), doctype=doctype), docname, as_dict=1)[0]
|
||||||
if bank_guarantee_type == "Receiving":
|
|
||||||
doctype = "Sales Order"
|
|
||||||
fields_to_fetch.append("customer")
|
|
||||||
fields_to_fetch.append("project")
|
|
||||||
else:
|
|
||||||
doctype = "Purchase Order"
|
|
||||||
fields_to_fetch.append("supplier")
|
|
||||||
|
|
||||||
return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,13 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
frm.set_query("bank_account", function () {
|
frm.set_query("bank_account", function () {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
company: frm.doc.company,
|
company: ["in", frm.doc.company],
|
||||||
'is_company_account': 1
|
'is_company_account': 1
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onload: function (frm) {
|
|
||||||
frm.trigger('bank_account');
|
|
||||||
},
|
|
||||||
|
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
frappe.require("assets/js/bank-reconciliation-tool.min.js", () =>
|
frappe.require("assets/js/bank-reconciliation-tool.min.js", () =>
|
||||||
frm.trigger("make_reconciliation_tool")
|
frm.trigger("make_reconciliation_tool")
|
||||||
@@ -55,7 +51,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
bank_account: function (frm) {
|
bank_account: function (frm) {
|
||||||
frappe.db.get_value(
|
frappe.db.get_value(
|
||||||
"Bank Account",
|
"Bank Account",
|
||||||
frm.doc.bank_account,
|
frm.bank_account,
|
||||||
"account",
|
"account",
|
||||||
(r) => {
|
(r) => {
|
||||||
frappe.db.get_value(
|
frappe.db.get_value(
|
||||||
@@ -64,7 +60,6 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
"account_currency",
|
"account_currency",
|
||||||
(r) => {
|
(r) => {
|
||||||
frm.currency = r.account_currency;
|
frm.currency = r.account_currency;
|
||||||
frm.trigger("render_chart");
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -129,7 +124,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render_chart: frappe.utils.debounce((frm) => {
|
render_chart(frm) {
|
||||||
frm.cards_manager = new erpnext.accounts.bank_reconciliation.NumberCardManager(
|
frm.cards_manager = new erpnext.accounts.bank_reconciliation.NumberCardManager(
|
||||||
{
|
{
|
||||||
$reconciliation_tool_cards: frm.get_field(
|
$reconciliation_tool_cards: frm.get_field(
|
||||||
@@ -141,7 +136,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
currency: frm.currency,
|
currency: frm.currency,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, 500),
|
},
|
||||||
|
|
||||||
render(frm) {
|
render(frm) {
|
||||||
if (frm.doc.bank_account) {
|
if (frm.doc.bank_account) {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.query_builder.custom import ConstantColumn
|
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
|
||||||
from erpnext import get_company_currency
|
from erpnext import get_company_currency
|
||||||
@@ -22,63 +23,48 @@ from erpnext.accounts.utils import get_balance_on
|
|||||||
class BankReconciliationTool(Document):
|
class BankReconciliationTool(Document):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_bank_transactions(bank_account, from_date=None, to_date=None):
|
def get_bank_transactions(bank_account, from_date = None, to_date = None):
|
||||||
# returns bank transactions for a bank account
|
# returns bank transactions for a bank account
|
||||||
filters = []
|
filters = []
|
||||||
filters.append(["bank_account", "=", bank_account])
|
filters.append(['bank_account', '=', bank_account])
|
||||||
filters.append(["docstatus", "=", 1])
|
filters.append(['docstatus', '=', 1])
|
||||||
filters.append(["unallocated_amount", ">", 0])
|
filters.append(['unallocated_amount', '>', 0])
|
||||||
if to_date:
|
if to_date:
|
||||||
filters.append(["date", "<=", to_date])
|
filters.append(['date', '<=', to_date])
|
||||||
if from_date:
|
if from_date:
|
||||||
filters.append(["date", ">=", from_date])
|
filters.append(['date', '>=', from_date])
|
||||||
transactions = frappe.get_all(
|
transactions = frappe.get_all(
|
||||||
"Bank Transaction",
|
'Bank Transaction',
|
||||||
fields=[
|
fields = ['date', 'deposit', 'withdrawal', 'currency',
|
||||||
"date",
|
'description', 'name', 'bank_account', 'company',
|
||||||
"deposit",
|
'unallocated_amount', 'reference_number', 'party_type', 'party'],
|
||||||
"withdrawal",
|
filters = filters
|
||||||
"currency",
|
|
||||||
"description",
|
|
||||||
"name",
|
|
||||||
"bank_account",
|
|
||||||
"company",
|
|
||||||
"unallocated_amount",
|
|
||||||
"reference_number",
|
|
||||||
"party_type",
|
|
||||||
"party",
|
|
||||||
],
|
|
||||||
filters=filters,
|
|
||||||
)
|
)
|
||||||
return transactions
|
return transactions
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_account_balance(bank_account, till_date):
|
def get_account_balance(bank_account, till_date):
|
||||||
# returns account balance till the specified date
|
# returns account balance till the specified date
|
||||||
account = frappe.db.get_value("Bank Account", bank_account, "account")
|
account = frappe.db.get_value('Bank Account', bank_account, 'account')
|
||||||
filters = frappe._dict(
|
filters = frappe._dict({
|
||||||
{"account": account, "report_date": till_date, "include_pos_transactions": 1}
|
"account": account,
|
||||||
)
|
"report_date": till_date,
|
||||||
|
"include_pos_transactions": 1
|
||||||
|
})
|
||||||
data = get_entries(filters)
|
data = get_entries(filters)
|
||||||
|
|
||||||
balance_as_per_system = get_balance_on(filters["account"], filters["report_date"])
|
balance_as_per_system = get_balance_on(filters["account"], filters["report_date"])
|
||||||
|
|
||||||
total_debit, total_credit = 0, 0
|
total_debit, total_credit = 0,0
|
||||||
for d in data:
|
for d in data:
|
||||||
total_debit += flt(d.debit)
|
total_debit += flt(d.debit)
|
||||||
total_credit += flt(d.credit)
|
total_credit += flt(d.credit)
|
||||||
|
|
||||||
amounts_not_reflected_in_system = get_amounts_not_reflected_in_system(filters)
|
amounts_not_reflected_in_system = get_amounts_not_reflected_in_system(filters)
|
||||||
|
|
||||||
bank_bal = (
|
bank_bal = flt(balance_as_per_system) - flt(total_debit) + flt(total_credit) \
|
||||||
flt(balance_as_per_system)
|
|
||||||
- flt(total_debit)
|
|
||||||
+ flt(total_credit)
|
|
||||||
+ amounts_not_reflected_in_system
|
+ amounts_not_reflected_in_system
|
||||||
)
|
|
||||||
|
|
||||||
return bank_bal
|
return bank_bal
|
||||||
|
|
||||||
@@ -91,94 +77,71 @@ def update_bank_transaction(bank_transaction_name, reference_number, party_type=
|
|||||||
bank_transaction.party_type = party_type
|
bank_transaction.party_type = party_type
|
||||||
bank_transaction.party = party
|
bank_transaction.party = party
|
||||||
bank_transaction.save()
|
bank_transaction.save()
|
||||||
return frappe.db.get_all(
|
return frappe.db.get_all('Bank Transaction',
|
||||||
"Bank Transaction",
|
filters={
|
||||||
filters={"name": bank_transaction_name},
|
'name': bank_transaction_name
|
||||||
fields=[
|
},
|
||||||
"date",
|
fields=['date', 'deposit', 'withdrawal', 'currency',
|
||||||
"deposit",
|
'description', 'name', 'bank_account', 'company',
|
||||||
"withdrawal",
|
'unallocated_amount', 'reference_number',
|
||||||
"currency",
|
'party_type', 'party'],
|
||||||
"description",
|
|
||||||
"name",
|
|
||||||
"bank_account",
|
|
||||||
"company",
|
|
||||||
"unallocated_amount",
|
|
||||||
"reference_number",
|
|
||||||
"party_type",
|
|
||||||
"party",
|
|
||||||
],
|
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_journal_entry_bts(
|
def create_journal_entry_bts( bank_transaction_name, reference_number=None, reference_date=None, posting_date=None, entry_type=None,
|
||||||
bank_transaction_name,
|
second_account=None, mode_of_payment=None, party_type=None, party=None, allow_edit=None):
|
||||||
reference_number=None,
|
|
||||||
reference_date=None,
|
|
||||||
posting_date=None,
|
|
||||||
entry_type=None,
|
|
||||||
second_account=None,
|
|
||||||
mode_of_payment=None,
|
|
||||||
party_type=None,
|
|
||||||
party=None,
|
|
||||||
allow_edit=None,
|
|
||||||
):
|
|
||||||
# Create a new journal entry based on the bank transaction
|
# Create a new journal entry based on the bank transaction
|
||||||
bank_transaction = frappe.db.get_values(
|
bank_transaction = frappe.db.get_values(
|
||||||
"Bank Transaction",
|
"Bank Transaction", bank_transaction_name,
|
||||||
bank_transaction_name,
|
fieldname=["name", "deposit", "withdrawal", "bank_account"] ,
|
||||||
fieldname=["name", "deposit", "withdrawal", "bank_account"],
|
as_dict=True
|
||||||
as_dict=True,
|
|
||||||
)[0]
|
)[0]
|
||||||
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account")
|
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account")
|
||||||
account_type = frappe.db.get_value("Account", second_account, "account_type")
|
account_type = frappe.db.get_value("Account", second_account, "account_type")
|
||||||
if account_type in ["Receivable", "Payable"]:
|
if account_type in ["Receivable", "Payable"]:
|
||||||
if not (party_type and party):
|
if not (party_type and party):
|
||||||
frappe.throw(
|
frappe.throw(_("Party Type and Party is required for Receivable / Payable account {0}").format( second_account))
|
||||||
_("Party Type and Party is required for Receivable / Payable account {0}").format(
|
|
||||||
second_account
|
|
||||||
)
|
|
||||||
)
|
|
||||||
accounts = []
|
accounts = []
|
||||||
# Multi Currency?
|
# Multi Currency?
|
||||||
accounts.append(
|
accounts.append({
|
||||||
{
|
|
||||||
"account": second_account,
|
"account": second_account,
|
||||||
"credit_in_account_currency": bank_transaction.deposit if bank_transaction.deposit > 0 else 0,
|
"credit_in_account_currency": bank_transaction.deposit
|
||||||
"debit_in_account_currency": bank_transaction.withdrawal
|
if bank_transaction.deposit > 0
|
||||||
if bank_transaction.withdrawal > 0
|
else 0,
|
||||||
else 0,
|
"debit_in_account_currency":bank_transaction.withdrawal
|
||||||
"party_type": party_type,
|
if bank_transaction.withdrawal > 0
|
||||||
"party": party,
|
else 0,
|
||||||
}
|
"party_type":party_type,
|
||||||
)
|
"party":party,
|
||||||
|
})
|
||||||
|
|
||||||
accounts.append(
|
accounts.append({
|
||||||
{
|
|
||||||
"account": company_account,
|
"account": company_account,
|
||||||
"bank_account": bank_transaction.bank_account,
|
"bank_account": bank_transaction.bank_account,
|
||||||
"credit_in_account_currency": bank_transaction.withdrawal
|
"credit_in_account_currency": bank_transaction.withdrawal
|
||||||
if bank_transaction.withdrawal > 0
|
if bank_transaction.withdrawal > 0
|
||||||
else 0,
|
else 0,
|
||||||
"debit_in_account_currency": bank_transaction.deposit if bank_transaction.deposit > 0 else 0,
|
"debit_in_account_currency":bank_transaction.deposit
|
||||||
}
|
if bank_transaction.deposit > 0
|
||||||
)
|
else 0,
|
||||||
|
})
|
||||||
|
|
||||||
company = frappe.get_value("Account", company_account, "company")
|
company = frappe.get_value("Account", company_account, "company")
|
||||||
|
|
||||||
journal_entry_dict = {
|
journal_entry_dict = {
|
||||||
"voucher_type": entry_type,
|
"voucher_type" : entry_type,
|
||||||
"company": company,
|
"company" : company,
|
||||||
"posting_date": posting_date,
|
"posting_date" : posting_date,
|
||||||
"cheque_date": reference_date,
|
"cheque_date" : reference_date,
|
||||||
"cheque_no": reference_number,
|
"cheque_no" : reference_number,
|
||||||
"mode_of_payment": mode_of_payment,
|
"mode_of_payment" : mode_of_payment
|
||||||
}
|
}
|
||||||
journal_entry = frappe.new_doc("Journal Entry")
|
journal_entry = frappe.new_doc('Journal Entry')
|
||||||
journal_entry.update(journal_entry_dict)
|
journal_entry.update(journal_entry_dict)
|
||||||
journal_entry.set("accounts", accounts)
|
journal_entry.set("accounts", accounts)
|
||||||
|
|
||||||
|
|
||||||
if allow_edit:
|
if allow_edit:
|
||||||
return journal_entry
|
return journal_entry
|
||||||
|
|
||||||
@@ -190,32 +153,21 @@ def create_journal_entry_bts(
|
|||||||
else:
|
else:
|
||||||
paid_amount = bank_transaction.withdrawal
|
paid_amount = bank_transaction.withdrawal
|
||||||
|
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[{"payment_doctype": "Journal Entry", "payment_name": journal_entry.name, "amount": paid_amount}]
|
"payment_doctype":"Journal Entry",
|
||||||
)
|
"payment_name":journal_entry.name,
|
||||||
|
"amount":paid_amount}])
|
||||||
|
|
||||||
return reconcile_vouchers(bank_transaction.name, vouchers)
|
return reconcile_vouchers(bank_transaction.name, vouchers)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_payment_entry_bts(
|
def create_payment_entry_bts( bank_transaction_name, reference_number=None, reference_date=None, party_type=None, party=None, posting_date=None,
|
||||||
bank_transaction_name,
|
mode_of_payment=None, project=None, cost_center=None, allow_edit=None):
|
||||||
reference_number=None,
|
|
||||||
reference_date=None,
|
|
||||||
party_type=None,
|
|
||||||
party=None,
|
|
||||||
posting_date=None,
|
|
||||||
mode_of_payment=None,
|
|
||||||
project=None,
|
|
||||||
cost_center=None,
|
|
||||||
allow_edit=None,
|
|
||||||
):
|
|
||||||
# Create a new payment entry based on the bank transaction
|
# Create a new payment entry based on the bank transaction
|
||||||
bank_transaction = frappe.db.get_values(
|
bank_transaction = frappe.db.get_values(
|
||||||
"Bank Transaction",
|
"Bank Transaction", bank_transaction_name,
|
||||||
bank_transaction_name,
|
fieldname=["name", "unallocated_amount", "deposit", "bank_account"] ,
|
||||||
fieldname=["name", "unallocated_amount", "deposit", "bank_account"],
|
as_dict=True
|
||||||
as_dict=True,
|
|
||||||
)[0]
|
)[0]
|
||||||
paid_amount = bank_transaction.unallocated_amount
|
paid_amount = bank_transaction.unallocated_amount
|
||||||
payment_type = "Receive" if bank_transaction.deposit > 0 else "Pay"
|
payment_type = "Receive" if bank_transaction.deposit > 0 else "Pay"
|
||||||
@@ -223,26 +175,27 @@ def create_payment_entry_bts(
|
|||||||
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account")
|
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account")
|
||||||
company = frappe.get_value("Account", company_account, "company")
|
company = frappe.get_value("Account", company_account, "company")
|
||||||
payment_entry_dict = {
|
payment_entry_dict = {
|
||||||
"company": company,
|
"company" : company,
|
||||||
"payment_type": payment_type,
|
"payment_type" : payment_type,
|
||||||
"reference_no": reference_number,
|
"reference_no" : reference_number,
|
||||||
"reference_date": reference_date,
|
"reference_date" : reference_date,
|
||||||
"party_type": party_type,
|
"party_type" : party_type,
|
||||||
"party": party,
|
"party" : party,
|
||||||
"posting_date": posting_date,
|
"posting_date" : posting_date,
|
||||||
"paid_amount": paid_amount,
|
"paid_amount": paid_amount,
|
||||||
"received_amount": paid_amount,
|
"received_amount": paid_amount
|
||||||
}
|
}
|
||||||
payment_entry = frappe.new_doc("Payment Entry")
|
payment_entry = frappe.new_doc("Payment Entry")
|
||||||
|
|
||||||
|
|
||||||
payment_entry.update(payment_entry_dict)
|
payment_entry.update(payment_entry_dict)
|
||||||
|
|
||||||
if mode_of_payment:
|
if mode_of_payment:
|
||||||
payment_entry.mode_of_payment = mode_of_payment
|
payment_entry.mode_of_payment = mode_of_payment
|
||||||
if project:
|
if project:
|
||||||
payment_entry.project = project
|
payment_entry.project = project
|
||||||
if cost_center:
|
if cost_center:
|
||||||
payment_entry.cost_center = cost_center
|
payment_entry.cost_center = cost_center
|
||||||
if payment_type == "Receive":
|
if payment_type == "Receive":
|
||||||
payment_entry.paid_to = company_account
|
payment_entry.paid_to = company_account
|
||||||
else:
|
else:
|
||||||
@@ -256,111 +209,78 @@ def create_payment_entry_bts(
|
|||||||
payment_entry.insert()
|
payment_entry.insert()
|
||||||
|
|
||||||
payment_entry.submit()
|
payment_entry.submit()
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[{"payment_doctype": "Payment Entry", "payment_name": payment_entry.name, "amount": paid_amount}]
|
"payment_doctype":"Payment Entry",
|
||||||
)
|
"payment_name":payment_entry.name,
|
||||||
|
"amount":paid_amount}])
|
||||||
return reconcile_vouchers(bank_transaction.name, vouchers)
|
return reconcile_vouchers(bank_transaction.name, vouchers)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def reconcile_vouchers(bank_transaction_name, vouchers):
|
def reconcile_vouchers(bank_transaction_name, vouchers):
|
||||||
# updated clear date of all the vouchers based on the bank transaction
|
# updated clear date of all the vouchers based on the bank transaction
|
||||||
vouchers = json.loads(vouchers)
|
vouchers = json.loads(vouchers)
|
||||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||||
company_account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
|
||||||
|
|
||||||
if transaction.unallocated_amount == 0:
|
if transaction.unallocated_amount == 0:
|
||||||
frappe.throw(_("This bank transaction is already fully reconciled"))
|
frappe.throw(_("This bank transaction is already fully reconciled"))
|
||||||
total_amount = 0
|
total_amount = 0
|
||||||
for voucher in vouchers:
|
for voucher in vouchers:
|
||||||
voucher["payment_entry"] = frappe.get_doc(voucher["payment_doctype"], voucher["payment_name"])
|
voucher['payment_entry'] = frappe.get_doc(voucher['payment_doctype'], voucher['payment_name'])
|
||||||
total_amount += get_paid_amount(
|
total_amount += get_paid_amount(frappe._dict({
|
||||||
frappe._dict(
|
'payment_document': voucher['payment_doctype'],
|
||||||
{
|
'payment_entry': voucher['payment_name'],
|
||||||
"payment_document": voucher["payment_doctype"],
|
}), transaction.currency)
|
||||||
"payment_entry": voucher["payment_name"],
|
|
||||||
}
|
|
||||||
),
|
|
||||||
transaction.currency,
|
|
||||||
company_account,
|
|
||||||
)
|
|
||||||
|
|
||||||
if total_amount > transaction.unallocated_amount:
|
if total_amount > transaction.unallocated_amount:
|
||||||
frappe.throw(
|
frappe.throw(_("The Sum Total of Amounts of All Selected Vouchers Should be Less than the Unallocated Amount of the Bank Transaction"))
|
||||||
_(
|
|
||||||
"The sum total of amounts of all selected vouchers should be less than the unallocated amount of the bank transaction"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
|
||||||
|
|
||||||
for voucher in vouchers:
|
for voucher in vouchers:
|
||||||
gl_entry = frappe.db.get_value(
|
gl_entry = frappe.db.get_value("GL Entry", dict(account=account, voucher_type=voucher['payment_doctype'], voucher_no=voucher['payment_name']), ['credit', 'debit'], as_dict=1)
|
||||||
"GL Entry",
|
gl_amount, transaction_amount = (gl_entry.credit, transaction.deposit) if gl_entry.credit > 0 else (gl_entry.debit, transaction.withdrawal)
|
||||||
dict(
|
|
||||||
account=account, voucher_type=voucher["payment_doctype"], voucher_no=voucher["payment_name"]
|
|
||||||
),
|
|
||||||
["credit_in_account_currency as credit", "debit_in_account_currency as debit"],
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
gl_amount, transaction_amount = (
|
|
||||||
(gl_entry.credit, transaction.deposit)
|
|
||||||
if gl_entry.credit > 0
|
|
||||||
else (gl_entry.debit, transaction.withdrawal)
|
|
||||||
)
|
|
||||||
allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
|
allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
|
||||||
|
|
||||||
transaction.append(
|
transaction.append("payment_entries", {
|
||||||
"payment_entries",
|
"payment_document": voucher['payment_entry'].doctype,
|
||||||
{
|
"payment_entry": voucher['payment_entry'].name,
|
||||||
"payment_document": voucher["payment_entry"].doctype,
|
"allocated_amount": allocated_amount
|
||||||
"payment_entry": voucher["payment_entry"].name,
|
})
|
||||||
"allocated_amount": allocated_amount,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
transaction.save()
|
transaction.save()
|
||||||
transaction.update_allocations()
|
transaction.update_allocations()
|
||||||
return frappe.get_doc("Bank Transaction", bank_transaction_name)
|
return frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_linked_payments(bank_transaction_name, document_types=None):
|
def get_linked_payments(bank_transaction_name, document_types = None):
|
||||||
# get all matching payments for a bank transaction
|
# get all matching payments for a bank transaction
|
||||||
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
|
||||||
bank_account = frappe.db.get_values(
|
bank_account = frappe.db.get_values(
|
||||||
"Bank Account", transaction.bank_account, ["account", "company"], as_dict=True
|
"Bank Account",
|
||||||
)[0]
|
transaction.bank_account,
|
||||||
|
["account", "company"],
|
||||||
|
as_dict=True)[0]
|
||||||
(account, company) = (bank_account.account, bank_account.company)
|
(account, company) = (bank_account.account, bank_account.company)
|
||||||
matching = check_matching(account, company, transaction, document_types)
|
matching = check_matching(account, company, transaction, document_types)
|
||||||
return matching
|
return matching
|
||||||
|
|
||||||
|
|
||||||
def check_matching(bank_account, company, transaction, document_types):
|
def check_matching(bank_account, company, transaction, document_types):
|
||||||
# combine all types of vouchers
|
# combine all types of vocuhers
|
||||||
subquery = get_queries(bank_account, company, transaction, document_types)
|
subquery = get_queries(bank_account, company, transaction, document_types)
|
||||||
filters = {
|
filters = {
|
||||||
"amount": transaction.unallocated_amount,
|
"amount": transaction.unallocated_amount,
|
||||||
"payment_type": "Receive" if transaction.deposit > 0 else "Pay",
|
"payment_type" : "Receive" if transaction.deposit > 0 else "Pay",
|
||||||
"reference_no": transaction.reference_number,
|
"reference_no": transaction.reference_number,
|
||||||
"party_type": transaction.party_type,
|
"party_type": transaction.party_type,
|
||||||
"party": transaction.party,
|
"party": transaction.party,
|
||||||
"bank_account": bank_account,
|
"bank_account": bank_account
|
||||||
}
|
}
|
||||||
|
|
||||||
matching_vouchers = []
|
matching_vouchers = []
|
||||||
|
|
||||||
matching_vouchers.extend(get_loan_vouchers(bank_account, transaction, document_types, filters))
|
|
||||||
|
|
||||||
for query in subquery:
|
for query in subquery:
|
||||||
matching_vouchers.extend(
|
matching_vouchers.extend(
|
||||||
frappe.db.sql(
|
frappe.db.sql(query, filters,)
|
||||||
query,
|
|
||||||
filters,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return sorted(matching_vouchers, key=lambda x: x[0], reverse=True) if matching_vouchers else []
|
return sorted(matching_vouchers, key = lambda x: x[0], reverse=True) if matching_vouchers else []
|
||||||
|
|
||||||
|
|
||||||
def get_queries(bank_account, company, transaction, document_types):
|
def get_queries(bank_account, company, transaction, document_types):
|
||||||
# get queries to get matching vouchers
|
# get queries to get matching vouchers
|
||||||
@@ -377,7 +297,7 @@ def get_queries(bank_account, company, transaction, document_types):
|
|||||||
queries.extend([je_amount_matching])
|
queries.extend([je_amount_matching])
|
||||||
|
|
||||||
if transaction.deposit > 0 and "sales_invoice" in document_types:
|
if transaction.deposit > 0 and "sales_invoice" in document_types:
|
||||||
si_amount_matching = get_si_matching_query(amount_condition)
|
si_amount_matching = get_si_matching_query(amount_condition)
|
||||||
queries.extend([si_amount_matching])
|
queries.extend([si_amount_matching])
|
||||||
|
|
||||||
if transaction.withdrawal > 0:
|
if transaction.withdrawal > 0:
|
||||||
@@ -391,104 +311,13 @@ def get_queries(bank_account, company, transaction, document_types):
|
|||||||
|
|
||||||
return queries
|
return queries
|
||||||
|
|
||||||
|
|
||||||
def get_loan_vouchers(bank_account, transaction, document_types, filters):
|
|
||||||
vouchers = []
|
|
||||||
amount_condition = True if "exact_match" in document_types else False
|
|
||||||
|
|
||||||
if transaction.withdrawal > 0 and "loan_disbursement" in document_types:
|
|
||||||
vouchers.extend(get_ld_matching_query(bank_account, amount_condition, filters))
|
|
||||||
|
|
||||||
if transaction.deposit > 0 and "loan_repayment" in document_types:
|
|
||||||
vouchers.extend(get_lr_matching_query(bank_account, amount_condition, filters))
|
|
||||||
|
|
||||||
return vouchers
|
|
||||||
|
|
||||||
|
|
||||||
def get_ld_matching_query(bank_account, amount_condition, filters):
|
|
||||||
loan_disbursement = frappe.qb.DocType("Loan Disbursement")
|
|
||||||
matching_reference = loan_disbursement.reference_number == filters.get("reference_number")
|
|
||||||
matching_party = loan_disbursement.applicant_type == filters.get(
|
|
||||||
"party_type"
|
|
||||||
) and loan_disbursement.applicant == filters.get("party")
|
|
||||||
|
|
||||||
rank = frappe.qb.terms.Case().when(matching_reference, 1).else_(0)
|
|
||||||
|
|
||||||
rank1 = frappe.qb.terms.Case().when(matching_party, 1).else_(0)
|
|
||||||
|
|
||||||
query = (
|
|
||||||
frappe.qb.from_(loan_disbursement)
|
|
||||||
.select(
|
|
||||||
rank + rank1 + 1,
|
|
||||||
ConstantColumn("Loan Disbursement").as_("doctype"),
|
|
||||||
loan_disbursement.name,
|
|
||||||
loan_disbursement.disbursed_amount,
|
|
||||||
loan_disbursement.reference_number,
|
|
||||||
loan_disbursement.reference_date,
|
|
||||||
loan_disbursement.applicant_type,
|
|
||||||
loan_disbursement.disbursement_date,
|
|
||||||
)
|
|
||||||
.where(loan_disbursement.docstatus == 1)
|
|
||||||
.where(loan_disbursement.clearance_date.isnull())
|
|
||||||
.where(loan_disbursement.disbursement_account == bank_account)
|
|
||||||
)
|
|
||||||
|
|
||||||
if amount_condition:
|
|
||||||
query.where(loan_disbursement.disbursed_amount == filters.get("amount"))
|
|
||||||
else:
|
|
||||||
query.where(loan_disbursement.disbursed_amount <= filters.get("amount"))
|
|
||||||
|
|
||||||
vouchers = query.run(as_list=True)
|
|
||||||
|
|
||||||
return vouchers
|
|
||||||
|
|
||||||
|
|
||||||
def get_lr_matching_query(bank_account, amount_condition, filters):
|
|
||||||
loan_repayment = frappe.qb.DocType("Loan Repayment")
|
|
||||||
matching_reference = loan_repayment.reference_number == filters.get("reference_number")
|
|
||||||
matching_party = loan_repayment.applicant_type == filters.get(
|
|
||||||
"party_type"
|
|
||||||
) and loan_repayment.applicant == filters.get("party")
|
|
||||||
|
|
||||||
rank = frappe.qb.terms.Case().when(matching_reference, 1).else_(0)
|
|
||||||
|
|
||||||
rank1 = frappe.qb.terms.Case().when(matching_party, 1).else_(0)
|
|
||||||
|
|
||||||
query = (
|
|
||||||
frappe.qb.from_(loan_repayment)
|
|
||||||
.select(
|
|
||||||
rank + rank1 + 1,
|
|
||||||
ConstantColumn("Loan Repayment").as_("doctype"),
|
|
||||||
loan_repayment.name,
|
|
||||||
loan_repayment.amount_paid,
|
|
||||||
loan_repayment.reference_number,
|
|
||||||
loan_repayment.reference_date,
|
|
||||||
loan_repayment.applicant_type,
|
|
||||||
loan_repayment.posting_date,
|
|
||||||
)
|
|
||||||
.where(loan_repayment.docstatus == 1)
|
|
||||||
.where(loan_repayment.repay_from_salary == 0)
|
|
||||||
.where(loan_repayment.clearance_date.isnull())
|
|
||||||
.where(loan_repayment.payment_account == bank_account)
|
|
||||||
)
|
|
||||||
|
|
||||||
if amount_condition:
|
|
||||||
query.where(loan_repayment.amount_paid == filters.get("amount"))
|
|
||||||
else:
|
|
||||||
query.where(loan_repayment.amount_paid <= filters.get("amount"))
|
|
||||||
|
|
||||||
vouchers = query.run()
|
|
||||||
|
|
||||||
return vouchers
|
|
||||||
|
|
||||||
|
|
||||||
def get_pe_matching_query(amount_condition, account_from_to, transaction):
|
def get_pe_matching_query(amount_condition, account_from_to, transaction):
|
||||||
# get matching payment entries query
|
# get matching payment entries query
|
||||||
if transaction.deposit > 0:
|
if transaction.deposit > 0:
|
||||||
currency_field = "paid_to_account_currency as currency"
|
currency_field = "paid_to_account_currency as currency"
|
||||||
else:
|
else:
|
||||||
currency_field = "paid_from_account_currency as currency"
|
currency_field = "paid_from_account_currency as currency"
|
||||||
return f"""
|
return f"""
|
||||||
SELECT
|
SELECT
|
||||||
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||||
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
||||||
@@ -515,12 +344,7 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
|
|||||||
|
|
||||||
def get_je_matching_query(amount_condition, transaction):
|
def get_je_matching_query(amount_condition, transaction):
|
||||||
# get matching journal entry query
|
# get matching journal entry query
|
||||||
|
|
||||||
# We have mapping at the bank level
|
|
||||||
# So one bank could have both types of bank accounts like asset and liability
|
|
||||||
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
|
|
||||||
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
|
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
@@ -577,7 +401,6 @@ def get_si_matching_query(amount_condition):
|
|||||||
AND si.docstatus = 1
|
AND si.docstatus = 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_pi_matching_query(amount_condition):
|
def get_pi_matching_query(amount_condition):
|
||||||
# get matching purchase invoice query
|
# get matching purchase invoice query
|
||||||
return f"""
|
return f"""
|
||||||
@@ -603,16 +426,11 @@ def get_pi_matching_query(amount_condition):
|
|||||||
AND cash_bank_account = %(bank_account)s
|
AND cash_bank_account = %(bank_account)s
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_ec_matching_query(bank_account, company, amount_condition):
|
def get_ec_matching_query(bank_account, company, amount_condition):
|
||||||
# get matching Expense Claim query
|
# get matching Expense Claim query
|
||||||
mode_of_payments = [
|
mode_of_payments = [x["parent"] for x in frappe.db.get_list("Mode of Payment Account",
|
||||||
x["parent"]
|
filters={"default_account": bank_account}, fields=["parent"])]
|
||||||
for x in frappe.db.get_all(
|
mode_of_payments = '(\'' + '\', \''.join(mode_of_payments) + '\' )'
|
||||||
"Mode of Payment Account", filters={"default_account": bank_account}, fields=["parent"]
|
|
||||||
)
|
|
||||||
]
|
|
||||||
mode_of_payments = "('" + "', '".join(mode_of_payments) + "' )"
|
|
||||||
company_currency = get_company_currency(company)
|
company_currency = get_company_currency(company)
|
||||||
return f"""
|
return f"""
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|||||||
@@ -239,8 +239,7 @@ frappe.ui.form.on("Bank Statement Import", {
|
|||||||
"withdrawal",
|
"withdrawal",
|
||||||
"description",
|
"description",
|
||||||
"reference_number",
|
"reference_number",
|
||||||
"bank_account",
|
"bank_account"
|
||||||
"currency"
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2019, Frappe Technologies and contributors
|
# Copyright (c) 2019, Frappe Technologies and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
@@ -17,8 +19,6 @@ from openpyxl.styles import Font
|
|||||||
from openpyxl.utils import get_column_letter
|
from openpyxl.utils import get_column_letter
|
||||||
from six import string_types
|
from six import string_types
|
||||||
|
|
||||||
INVALID_VALUES = ("", None)
|
|
||||||
|
|
||||||
|
|
||||||
class BankStatementImport(DataImport):
|
class BankStatementImport(DataImport):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -51,14 +51,16 @@ class BankStatementImport(DataImport):
|
|||||||
self.import_file, self.google_sheets_url
|
self.import_file, self.google_sheets_url
|
||||||
)
|
)
|
||||||
|
|
||||||
if "Bank Account" not in json.dumps(preview["columns"]):
|
if 'Bank Account' not in json.dumps(preview['columns']):
|
||||||
frappe.throw(_("Please add the Bank Account column"))
|
frappe.throw(_("Please add the Bank Account column"))
|
||||||
|
|
||||||
from frappe.core.page.background_jobs.background_jobs import get_info
|
from frappe.core.page.background_jobs.background_jobs import get_info
|
||||||
from frappe.utils.scheduler import is_scheduler_inactive
|
from frappe.utils.scheduler import is_scheduler_inactive
|
||||||
|
|
||||||
if is_scheduler_inactive() and not frappe.flags.in_test:
|
if is_scheduler_inactive() and not frappe.flags.in_test:
|
||||||
frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive"))
|
frappe.throw(
|
||||||
|
_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive")
|
||||||
|
)
|
||||||
|
|
||||||
enqueued_jobs = [d.get("job_name") for d in get_info()]
|
enqueued_jobs = [d.get("job_name") for d in get_info()]
|
||||||
|
|
||||||
@@ -81,41 +83,22 @@ class BankStatementImport(DataImport):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_preview_from_template(data_import, import_file=None, google_sheets_url=None):
|
def get_preview_from_template(data_import, import_file=None, google_sheets_url=None):
|
||||||
return frappe.get_doc("Bank Statement Import", data_import).get_preview_from_template(
|
return frappe.get_doc("Bank Statement Import", data_import).get_preview_from_template(
|
||||||
import_file, google_sheets_url
|
import_file, google_sheets_url
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def form_start_import(data_import):
|
def form_start_import(data_import):
|
||||||
return frappe.get_doc("Bank Statement Import", data_import).start_import()
|
return frappe.get_doc("Bank Statement Import", data_import).start_import()
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def download_errored_template(data_import_name):
|
def download_errored_template(data_import_name):
|
||||||
data_import = frappe.get_doc("Bank Statement Import", data_import_name)
|
data_import = frappe.get_doc("Bank Statement Import", data_import_name)
|
||||||
data_import.export_errored_rows()
|
data_import.export_errored_rows()
|
||||||
|
|
||||||
|
def start_import(data_import, bank_account, import_file_path, google_sheets_url, bank, template_options):
|
||||||
def parse_data_from_template(raw_data):
|
|
||||||
data = []
|
|
||||||
|
|
||||||
for i, row in enumerate(raw_data):
|
|
||||||
if all(v in INVALID_VALUES for v in row):
|
|
||||||
# empty row
|
|
||||||
continue
|
|
||||||
|
|
||||||
data.append(row)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def start_import(
|
|
||||||
data_import, bank_account, import_file_path, google_sheets_url, bank, template_options
|
|
||||||
):
|
|
||||||
"""This method runs in background job"""
|
"""This method runs in background job"""
|
||||||
|
|
||||||
update_mapping_db(bank, template_options)
|
update_mapping_db(bank, template_options)
|
||||||
@@ -123,9 +106,8 @@ def start_import(
|
|||||||
data_import = frappe.get_doc("Bank Statement Import", data_import)
|
data_import = frappe.get_doc("Bank Statement Import", data_import)
|
||||||
file = import_file_path if import_file_path else google_sheets_url
|
file = import_file_path if import_file_path else google_sheets_url
|
||||||
|
|
||||||
import_file = ImportFile("Bank Transaction", file=file, import_type="Insert New Records")
|
import_file = ImportFile("Bank Transaction", file = file, import_type="Insert New Records")
|
||||||
|
data = import_file.raw_data
|
||||||
data = parse_data_from_template(import_file.raw_data)
|
|
||||||
|
|
||||||
if import_file_path:
|
if import_file_path:
|
||||||
add_bank_account(data, bank_account)
|
add_bank_account(data, bank_account)
|
||||||
@@ -143,18 +125,16 @@ def start_import(
|
|||||||
|
|
||||||
frappe.publish_realtime("data_import_refresh", {"data_import": data_import.name})
|
frappe.publish_realtime("data_import_refresh", {"data_import": data_import.name})
|
||||||
|
|
||||||
|
|
||||||
def update_mapping_db(bank, template_options):
|
def update_mapping_db(bank, template_options):
|
||||||
bank = frappe.get_doc("Bank", bank)
|
bank = frappe.get_doc("Bank", bank)
|
||||||
for d in bank.bank_transaction_mapping:
|
for d in bank.bank_transaction_mapping:
|
||||||
d.delete()
|
d.delete()
|
||||||
|
|
||||||
for d in json.loads(template_options)["column_to_field_map"].items():
|
for d in json.loads(template_options)["column_to_field_map"].items():
|
||||||
bank.append("bank_transaction_mapping", {"bank_transaction_field": d[1], "file_field": d[0]})
|
bank.append("bank_transaction_mapping", {"bank_transaction_field": d[1] ,"file_field": d[0]} )
|
||||||
|
|
||||||
bank.save()
|
bank.save()
|
||||||
|
|
||||||
|
|
||||||
def add_bank_account(data, bank_account):
|
def add_bank_account(data, bank_account):
|
||||||
bank_account_loc = None
|
bank_account_loc = None
|
||||||
if "Bank Account" not in data[0]:
|
if "Bank Account" not in data[0]:
|
||||||
@@ -170,7 +150,6 @@ def add_bank_account(data, bank_account):
|
|||||||
else:
|
else:
|
||||||
row.append(bank_account)
|
row.append(bank_account)
|
||||||
|
|
||||||
|
|
||||||
def write_files(import_file, data):
|
def write_files(import_file, data):
|
||||||
full_file_path = import_file.file_doc.get_full_path()
|
full_file_path = import_file.file_doc.get_full_path()
|
||||||
parts = import_file.file_doc.get_extension()
|
parts = import_file.file_doc.get_extension()
|
||||||
@@ -178,12 +157,11 @@ def write_files(import_file, data):
|
|||||||
extension = extension.lstrip(".")
|
extension = extension.lstrip(".")
|
||||||
|
|
||||||
if extension == "csv":
|
if extension == "csv":
|
||||||
with open(full_file_path, "w", newline="") as file:
|
with open(full_file_path, 'w', newline='') as file:
|
||||||
writer = csv.writer(file)
|
writer = csv.writer(file)
|
||||||
writer.writerows(data)
|
writer.writerows(data)
|
||||||
elif extension == "xlsx" or "xls":
|
elif extension == "xlsx" or "xls":
|
||||||
write_xlsx(data, "trans", file_path=full_file_path)
|
write_xlsx(data, "trans", file_path = full_file_path)
|
||||||
|
|
||||||
|
|
||||||
def write_xlsx(data, sheet_name, wb=None, column_widths=None, file_path=None):
|
def write_xlsx(data, sheet_name, wb=None, column_widths=None, file_path=None):
|
||||||
# from xlsx utils with changes
|
# from xlsx utils with changes
|
||||||
@@ -198,21 +176,19 @@ def write_xlsx(data, sheet_name, wb=None, column_widths=None, file_path=None):
|
|||||||
ws.column_dimensions[get_column_letter(i + 1)].width = column_width
|
ws.column_dimensions[get_column_letter(i + 1)].width = column_width
|
||||||
|
|
||||||
row1 = ws.row_dimensions[1]
|
row1 = ws.row_dimensions[1]
|
||||||
row1.font = Font(name="Calibri", bold=True)
|
row1.font = Font(name='Calibri', bold=True)
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
clean_row = []
|
clean_row = []
|
||||||
for item in row:
|
for item in row:
|
||||||
if isinstance(item, string_types) and (
|
if isinstance(item, string_types) and (sheet_name not in ['Data Import Template', 'Data Export']):
|
||||||
sheet_name not in ["Data Import Template", "Data Export"]
|
|
||||||
):
|
|
||||||
value = handle_html(item)
|
value = handle_html(item)
|
||||||
else:
|
else:
|
||||||
value = item
|
value = item
|
||||||
|
|
||||||
if isinstance(item, string_types) and next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
|
if isinstance(item, string_types) and next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
|
||||||
# Remove illegal characters from the string
|
# Remove illegal characters from the string
|
||||||
value = re.sub(ILLEGAL_CHARACTERS_RE, "", value)
|
value = re.sub(ILLEGAL_CHARACTERS_RE, '', value)
|
||||||
|
|
||||||
clean_row.append(value)
|
clean_row.append(value)
|
||||||
|
|
||||||
@@ -221,20 +197,19 @@ def write_xlsx(data, sheet_name, wb=None, column_widths=None, file_path=None):
|
|||||||
wb.save(file_path)
|
wb.save(file_path)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def upload_bank_statement(**args):
|
def upload_bank_statement(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
bsi = frappe.new_doc("Bank Statement Import")
|
bsi = frappe.new_doc("Bank Statement Import")
|
||||||
|
|
||||||
if args.company:
|
if args.company:
|
||||||
bsi.update(
|
bsi.update({
|
||||||
{
|
"company": args.company,
|
||||||
"company": args.company,
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if args.bank_account:
|
if args.bank_account:
|
||||||
bsi.update({"bank_account": args.bank_account})
|
bsi.update({
|
||||||
|
"bank_account": args.bank_account
|
||||||
|
})
|
||||||
|
|
||||||
return bsi
|
return bsi
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020, Frappe Technologies and Contributors
|
# Copyright (c) 2020, Frappe Technologies and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
@@ -28,26 +30,17 @@ class BankTransaction(StatusUpdater):
|
|||||||
|
|
||||||
def update_allocations(self):
|
def update_allocations(self):
|
||||||
if self.payment_entries:
|
if self.payment_entries:
|
||||||
allocated_amount = reduce(
|
allocated_amount = reduce(lambda x, y: flt(x) + flt(y), [x.allocated_amount for x in self.payment_entries])
|
||||||
lambda x, y: flt(x) + flt(y), [x.allocated_amount for x in self.payment_entries]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
allocated_amount = 0
|
allocated_amount = 0
|
||||||
|
|
||||||
if allocated_amount:
|
if allocated_amount:
|
||||||
frappe.db.set_value(self.doctype, self.name, "allocated_amount", flt(allocated_amount))
|
frappe.db.set_value(self.doctype, self.name, "allocated_amount", flt(allocated_amount))
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.withdrawal) - flt(self.deposit)) - flt(allocated_amount))
|
||||||
self.doctype,
|
|
||||||
self.name,
|
|
||||||
"unallocated_amount",
|
|
||||||
abs(flt(self.withdrawal) - flt(self.deposit)) - flt(allocated_amount),
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0)
|
frappe.db.set_value(self.doctype, self.name, "allocated_amount", 0)
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(self.doctype, self.name, "unallocated_amount", abs(flt(self.withdrawal) - flt(self.deposit)))
|
||||||
self.doctype, self.name, "unallocated_amount", abs(flt(self.withdrawal) - flt(self.deposit))
|
|
||||||
)
|
|
||||||
|
|
||||||
amount = self.deposit or self.withdrawal
|
amount = self.deposit or self.withdrawal
|
||||||
if amount == self.allocated_amount:
|
if amount == self.allocated_amount:
|
||||||
@@ -57,14 +50,7 @@ class BankTransaction(StatusUpdater):
|
|||||||
|
|
||||||
def clear_linked_payment_entries(self, for_cancel=False):
|
def clear_linked_payment_entries(self, for_cancel=False):
|
||||||
for payment_entry in self.payment_entries:
|
for payment_entry in self.payment_entries:
|
||||||
if payment_entry.payment_document in [
|
if payment_entry.payment_document in ["Payment Entry", "Journal Entry", "Purchase Invoice", "Expense Claim"]:
|
||||||
"Payment Entry",
|
|
||||||
"Journal Entry",
|
|
||||||
"Purchase Invoice",
|
|
||||||
"Expense Claim",
|
|
||||||
"Loan Repayment",
|
|
||||||
"Loan Disbursement",
|
|
||||||
]:
|
|
||||||
self.clear_simple_entry(payment_entry, for_cancel=for_cancel)
|
self.clear_simple_entry(payment_entry, for_cancel=for_cancel)
|
||||||
|
|
||||||
elif payment_entry.payment_document == "Sales Invoice":
|
elif payment_entry.payment_document == "Sales Invoice":
|
||||||
@@ -72,41 +58,38 @@ class BankTransaction(StatusUpdater):
|
|||||||
|
|
||||||
def clear_simple_entry(self, payment_entry, for_cancel=False):
|
def clear_simple_entry(self, payment_entry, for_cancel=False):
|
||||||
if payment_entry.payment_document == "Payment Entry":
|
if payment_entry.payment_document == "Payment Entry":
|
||||||
if (
|
if frappe.db.get_value("Payment Entry", payment_entry.payment_entry, "payment_type") == "Internal Transfer":
|
||||||
frappe.db.get_value("Payment Entry", payment_entry.payment_entry, "payment_type")
|
|
||||||
== "Internal Transfer"
|
|
||||||
):
|
|
||||||
if len(get_reconciled_bank_transactions(payment_entry)) < 2:
|
if len(get_reconciled_bank_transactions(payment_entry)) < 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
clearance_date = self.date if not for_cancel else None
|
clearance_date = self.date if not for_cancel else None
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
payment_entry.payment_document, payment_entry.payment_entry, "clearance_date", clearance_date
|
payment_entry.payment_document, payment_entry.payment_entry,
|
||||||
)
|
"clearance_date", clearance_date)
|
||||||
|
|
||||||
def clear_sales_invoice(self, payment_entry, for_cancel=False):
|
def clear_sales_invoice(self, payment_entry, for_cancel=False):
|
||||||
clearance_date = self.date if not for_cancel else None
|
clearance_date = self.date if not for_cancel else None
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Sales Invoice Payment",
|
"Sales Invoice Payment",
|
||||||
dict(parenttype=payment_entry.payment_document, parent=payment_entry.payment_entry),
|
dict(
|
||||||
"clearance_date",
|
parenttype=payment_entry.payment_document,
|
||||||
clearance_date,
|
parent=payment_entry.payment_entry
|
||||||
)
|
),
|
||||||
|
"clearance_date", clearance_date)
|
||||||
|
|
||||||
def get_reconciled_bank_transactions(payment_entry):
|
def get_reconciled_bank_transactions(payment_entry):
|
||||||
reconciled_bank_transactions = frappe.get_all(
|
reconciled_bank_transactions = frappe.get_all(
|
||||||
"Bank Transaction Payments",
|
'Bank Transaction Payments',
|
||||||
filters={"payment_entry": payment_entry.payment_entry},
|
filters = {
|
||||||
fields=["parent"],
|
'payment_entry': payment_entry.payment_entry
|
||||||
|
},
|
||||||
|
fields = ['parent']
|
||||||
)
|
)
|
||||||
|
|
||||||
return reconciled_bank_transactions
|
return reconciled_bank_transactions
|
||||||
|
|
||||||
|
|
||||||
def get_total_allocated_amount(payment_entry):
|
def get_total_allocated_amount(payment_entry):
|
||||||
return frappe.db.sql(
|
return frappe.db.sql("""
|
||||||
"""
|
|
||||||
SELECT
|
SELECT
|
||||||
SUM(btp.allocated_amount) as allocated_amount,
|
SUM(btp.allocated_amount) as allocated_amount,
|
||||||
bt.name
|
bt.name
|
||||||
@@ -119,73 +102,36 @@ def get_total_allocated_amount(payment_entry):
|
|||||||
AND
|
AND
|
||||||
btp.payment_entry = %s
|
btp.payment_entry = %s
|
||||||
AND
|
AND
|
||||||
bt.docstatus = 1""",
|
bt.docstatus = 1""", (payment_entry.payment_document, payment_entry.payment_entry), as_dict=True)
|
||||||
(payment_entry.payment_document, payment_entry.payment_entry),
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
def get_paid_amount(payment_entry, currency):
|
||||||
def get_paid_amount(payment_entry, currency, bank_account):
|
|
||||||
if payment_entry.payment_document in ["Payment Entry", "Sales Invoice", "Purchase Invoice"]:
|
if payment_entry.payment_document in ["Payment Entry", "Sales Invoice", "Purchase Invoice"]:
|
||||||
|
|
||||||
paid_amount_field = "paid_amount"
|
paid_amount_field = "paid_amount"
|
||||||
if payment_entry.payment_document == "Payment Entry":
|
if payment_entry.payment_document == 'Payment Entry':
|
||||||
doc = frappe.get_doc("Payment Entry", payment_entry.payment_entry)
|
doc = frappe.get_doc("Payment Entry", payment_entry.payment_entry)
|
||||||
|
paid_amount_field = ("base_paid_amount"
|
||||||
|
if doc.paid_to_account_currency == currency else "paid_amount")
|
||||||
|
|
||||||
if doc.payment_type == "Receive":
|
return frappe.db.get_value(payment_entry.payment_document,
|
||||||
paid_amount_field = (
|
payment_entry.payment_entry, paid_amount_field)
|
||||||
"received_amount" if doc.paid_to_account_currency == currency else "base_received_amount"
|
|
||||||
)
|
|
||||||
elif doc.payment_type == "Pay":
|
|
||||||
paid_amount_field = (
|
|
||||||
"paid_amount" if doc.paid_from_account_currency == currency else "base_paid_amount"
|
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.db.get_value(
|
|
||||||
payment_entry.payment_document, payment_entry.payment_entry, paid_amount_field
|
|
||||||
)
|
|
||||||
|
|
||||||
elif payment_entry.payment_document == "Journal Entry":
|
elif payment_entry.payment_document == "Journal Entry":
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_credit")
|
||||||
"Journal Entry Account",
|
|
||||||
{"parent": payment_entry.payment_entry, "account": bank_account},
|
|
||||||
"sum(credit_in_account_currency)",
|
|
||||||
)
|
|
||||||
|
|
||||||
elif payment_entry.payment_document == "Expense Claim":
|
elif payment_entry.payment_document == "Expense Claim":
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_amount_reimbursed")
|
||||||
payment_entry.payment_document, payment_entry.payment_entry, "total_amount_reimbursed"
|
|
||||||
)
|
|
||||||
|
|
||||||
elif payment_entry.payment_document == "Loan Disbursement":
|
|
||||||
return frappe.db.get_value(
|
|
||||||
payment_entry.payment_document, payment_entry.payment_entry, "disbursed_amount"
|
|
||||||
)
|
|
||||||
|
|
||||||
elif payment_entry.payment_document == "Loan Repayment":
|
|
||||||
return frappe.db.get_value(
|
|
||||||
payment_entry.payment_document, payment_entry.payment_entry, "amount_paid"
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.throw(
|
frappe.throw("Please reconcile {0}: {1} manually".format(payment_entry.payment_document, payment_entry.payment_entry))
|
||||||
"Please reconcile {0}: {1} manually".format(
|
|
||||||
payment_entry.payment_document, payment_entry.payment_entry
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def unclear_reference_payment(doctype, docname):
|
def unclear_reference_payment(doctype, docname):
|
||||||
if frappe.db.exists(doctype, docname):
|
if frappe.db.exists(doctype, docname):
|
||||||
doc = frappe.get_doc(doctype, docname)
|
doc = frappe.get_doc(doctype, docname)
|
||||||
if doctype == "Sales Invoice":
|
if doctype == "Sales Invoice":
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Sales Invoice Payment", dict(parenttype=doc.payment_document,
|
||||||
"Sales Invoice Payment",
|
parent=doc.payment_entry), "clearance_date", None)
|
||||||
dict(parenttype=doc.payment_document, parent=doc.payment_entry),
|
|
||||||
"clearance_date",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
frappe.db.set_value(doc.payment_document, doc.payment_entry, "clearance_date", None)
|
frappe.db.set_value(doc.payment_document, doc.payment_entry, "clearance_date", None)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -19,14 +21,12 @@ def upload_bank_statement():
|
|||||||
fcontent = frappe.local.uploaded_file
|
fcontent = frappe.local.uploaded_file
|
||||||
fname = frappe.local.uploaded_filename
|
fname = frappe.local.uploaded_filename
|
||||||
|
|
||||||
if frappe.safe_encode(fname).lower().endswith("csv".encode("utf-8")):
|
if frappe.safe_encode(fname).lower().endswith("csv".encode('utf-8')):
|
||||||
from frappe.utils.csvutils import read_csv_content
|
from frappe.utils.csvutils import read_csv_content
|
||||||
|
|
||||||
rows = read_csv_content(fcontent, False)
|
rows = read_csv_content(fcontent, False)
|
||||||
|
|
||||||
elif frappe.safe_encode(fname).lower().endswith("xlsx".encode("utf-8")):
|
elif frappe.safe_encode(fname).lower().endswith("xlsx".encode('utf-8')):
|
||||||
from frappe.utils.xlsxutils import read_xlsx_file_from_attached_file
|
from frappe.utils.xlsxutils import read_xlsx_file_from_attached_file
|
||||||
|
|
||||||
rows = read_xlsx_file_from_attached_file(fcontent=fcontent)
|
rows = read_xlsx_file_from_attached_file(fcontent=fcontent)
|
||||||
|
|
||||||
columns = rows[0]
|
columns = rows[0]
|
||||||
@@ -46,10 +46,12 @@ def create_bank_entries(columns, data, bank_account):
|
|||||||
continue
|
continue
|
||||||
fields = {}
|
fields = {}
|
||||||
for key, value in iteritems(header_map):
|
for key, value in iteritems(header_map):
|
||||||
fields.update({key: d[int(value) - 1]})
|
fields.update({key: d[int(value)-1]})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bank_transaction = frappe.get_doc({"doctype": "Bank Transaction"})
|
bank_transaction = frappe.get_doc({
|
||||||
|
"doctype": "Bank Transaction"
|
||||||
|
})
|
||||||
bank_transaction.update(fields)
|
bank_transaction.update(fields)
|
||||||
bank_transaction.date = getdate(parse_date(bank_transaction.date))
|
bank_transaction.date = getdate(parse_date(bank_transaction.date))
|
||||||
bank_transaction.bank_account = bank_account
|
bank_transaction.bank_account = bank_account
|
||||||
@@ -62,7 +64,6 @@ def create_bank_entries(columns, data, bank_account):
|
|||||||
|
|
||||||
return {"success": success, "errors": errors}
|
return {"success": success, "errors": errors}
|
||||||
|
|
||||||
|
|
||||||
def get_header_mapping(columns, bank_account):
|
def get_header_mapping(columns, bank_account):
|
||||||
mapping = get_bank_mapping(bank_account)
|
mapping = get_bank_mapping(bank_account)
|
||||||
|
|
||||||
@@ -73,11 +74,10 @@ def get_header_mapping(columns, bank_account):
|
|||||||
|
|
||||||
return header_map
|
return header_map
|
||||||
|
|
||||||
|
|
||||||
def get_bank_mapping(bank_account):
|
def get_bank_mapping(bank_account):
|
||||||
bank_name = frappe.db.get_value("Bank Account", bank_account, "bank")
|
bank_name = frappe.db.get_value("Bank Account", bank_account, "bank")
|
||||||
bank = frappe.get_doc("Bank", bank_name)
|
bank = frappe.get_doc("Bank", bank_name)
|
||||||
|
|
||||||
mapping = {row.file_field: row.bank_transaction_field for row in bank.bank_transaction_mapping}
|
mapping = {row.file_field:row.bank_transaction_field for row in bank.bank_transaction_mapping}
|
||||||
|
|
||||||
return mapping
|
return mapping
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
@@ -17,7 +19,6 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
|
|||||||
|
|
||||||
test_dependencies = ["Item", "Cost Center"]
|
test_dependencies = ["Item", "Cost Center"]
|
||||||
|
|
||||||
|
|
||||||
class TestBankTransaction(unittest.TestCase):
|
class TestBankTransaction(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -42,34 +43,21 @@ class TestBankTransaction(unittest.TestCase):
|
|||||||
|
|
||||||
# This test checks if ERPNext is able to provide a linked payment for a bank transaction based on the amount of the bank transaction.
|
# This test checks if ERPNext is able to provide a linked payment for a bank transaction based on the amount of the bank transaction.
|
||||||
def test_linked_payments(self):
|
def test_linked_payments(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="Re 95282925234 FE/000002917 AT171513000281183046 Conrad Electronic"))
|
||||||
"Bank Transaction",
|
linked_payments = get_linked_payments(bank_transaction.name, ['payment_entry', 'exact_match'])
|
||||||
dict(description="Re 95282925234 FE/000002917 AT171513000281183046 Conrad Electronic"),
|
|
||||||
)
|
|
||||||
linked_payments = get_linked_payments(bank_transaction.name, ["payment_entry", "exact_match"])
|
|
||||||
self.assertTrue(linked_payments[0][6] == "Conrad Electronic")
|
self.assertTrue(linked_payments[0][6] == "Conrad Electronic")
|
||||||
|
|
||||||
# This test validates a simple reconciliation leading to the clearance of the bank transaction and the payment
|
# This test validates a simple reconciliation leading to the clearance of the bank transaction and the payment
|
||||||
def test_reconcile(self):
|
def test_reconcile(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="1512567 BG/000003025 OPSKATTUZWXXX AT776000000098709849 Herr G"))
|
||||||
"Bank Transaction",
|
|
||||||
dict(description="1512567 BG/000003025 OPSKATTUZWXXX AT776000000098709849 Herr G"),
|
|
||||||
)
|
|
||||||
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1700))
|
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1700))
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[
|
"payment_doctype":"Payment Entry",
|
||||||
{
|
"payment_name":payment.name,
|
||||||
"payment_doctype": "Payment Entry",
|
"amount":bank_transaction.unallocated_amount}])
|
||||||
"payment_name": payment.name,
|
|
||||||
"amount": bank_transaction.unallocated_amount,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
reconcile_vouchers(bank_transaction.name, vouchers)
|
reconcile_vouchers(bank_transaction.name, vouchers)
|
||||||
|
|
||||||
unallocated_amount = frappe.db.get_value(
|
unallocated_amount = frappe.db.get_value("Bank Transaction", bank_transaction.name, "unallocated_amount")
|
||||||
"Bank Transaction", bank_transaction.name, "unallocated_amount"
|
|
||||||
)
|
|
||||||
self.assertTrue(unallocated_amount == 0)
|
self.assertTrue(unallocated_amount == 0)
|
||||||
|
|
||||||
clearance_date = frappe.db.get_value("Payment Entry", payment.name, "clearance_date")
|
clearance_date = frappe.db.get_value("Payment Entry", payment.name, "clearance_date")
|
||||||
@@ -83,177 +71,122 @@ class TestBankTransaction(unittest.TestCase):
|
|||||||
|
|
||||||
# Check if ERPNext can correctly filter a linked payments based on the debit/credit amount
|
# Check if ERPNext can correctly filter a linked payments based on the debit/credit amount
|
||||||
def test_debit_credit_output(self):
|
def test_debit_credit_output(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07"))
|
||||||
"Bank Transaction",
|
linked_payments = get_linked_payments(bank_transaction.name, ['payment_entry', 'exact_match'])
|
||||||
dict(description="Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07"),
|
|
||||||
)
|
|
||||||
linked_payments = get_linked_payments(bank_transaction.name, ["payment_entry", "exact_match"])
|
|
||||||
self.assertTrue(linked_payments[0][3])
|
self.assertTrue(linked_payments[0][3])
|
||||||
|
|
||||||
# Check error if already reconciled
|
# Check error if already reconciled
|
||||||
def test_already_reconciled(self):
|
def test_already_reconciled(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G"))
|
||||||
"Bank Transaction",
|
|
||||||
dict(description="1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G"),
|
|
||||||
)
|
|
||||||
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1200))
|
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1200))
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[
|
"payment_doctype":"Payment Entry",
|
||||||
{
|
"payment_name":payment.name,
|
||||||
"payment_doctype": "Payment Entry",
|
"amount":bank_transaction.unallocated_amount}])
|
||||||
"payment_name": payment.name,
|
|
||||||
"amount": bank_transaction.unallocated_amount,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
reconcile_vouchers(bank_transaction.name, vouchers)
|
reconcile_vouchers(bank_transaction.name, vouchers)
|
||||||
|
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G"))
|
||||||
"Bank Transaction",
|
|
||||||
dict(description="1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G"),
|
|
||||||
)
|
|
||||||
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1200))
|
payment = frappe.get_doc("Payment Entry", dict(party="Mr G", paid_amount=1200))
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[
|
"payment_doctype":"Payment Entry",
|
||||||
{
|
"payment_name":payment.name,
|
||||||
"payment_doctype": "Payment Entry",
|
"amount":bank_transaction.unallocated_amount}])
|
||||||
"payment_name": payment.name,
|
self.assertRaises(frappe.ValidationError, reconcile_vouchers, bank_transaction_name=bank_transaction.name, vouchers=vouchers)
|
||||||
"amount": bank_transaction.unallocated_amount,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
self.assertRaises(
|
|
||||||
frappe.ValidationError,
|
|
||||||
reconcile_vouchers,
|
|
||||||
bank_transaction_name=bank_transaction.name,
|
|
||||||
vouchers=vouchers,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Raise an error if debitor transaction vs debitor payment
|
# Raise an error if debitor transaction vs debitor payment
|
||||||
def test_clear_sales_invoice(self):
|
def test_clear_sales_invoice(self):
|
||||||
bank_transaction = frappe.get_doc(
|
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="I2015000011 VD/000002514 ATWWXXX AT4701345000003510057 Bio"))
|
||||||
"Bank Transaction",
|
|
||||||
dict(description="I2015000011 VD/000002514 ATWWXXX AT4701345000003510057 Bio"),
|
|
||||||
)
|
|
||||||
payment = frappe.get_doc("Sales Invoice", dict(customer="Fayva", status=["=", "Paid"]))
|
payment = frappe.get_doc("Sales Invoice", dict(customer="Fayva", status=["=", "Paid"]))
|
||||||
vouchers = json.dumps(
|
vouchers = json.dumps([{
|
||||||
[
|
"payment_doctype":"Sales Invoice",
|
||||||
{
|
"payment_name":payment.name,
|
||||||
"payment_doctype": "Sales Invoice",
|
"amount":bank_transaction.unallocated_amount}])
|
||||||
"payment_name": payment.name,
|
|
||||||
"amount": bank_transaction.unallocated_amount,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
reconcile_vouchers(bank_transaction.name, vouchers=vouchers)
|
reconcile_vouchers(bank_transaction.name, vouchers=vouchers)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(frappe.db.get_value("Bank Transaction", bank_transaction.name, "unallocated_amount"), 0)
|
||||||
frappe.db.get_value("Bank Transaction", bank_transaction.name, "unallocated_amount"), 0
|
self.assertTrue(frappe.db.get_value("Sales Invoice Payment", dict(parent=payment.name), "clearance_date") is not None)
|
||||||
)
|
|
||||||
self.assertTrue(
|
|
||||||
frappe.db.get_value("Sales Invoice Payment", dict(parent=payment.name), "clearance_date")
|
|
||||||
is not None
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"):
|
def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"):
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Bank",
|
||||||
"doctype": "Bank",
|
"bank_name":bank_name,
|
||||||
"bank_name": bank_name,
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Account",
|
||||||
"doctype": "Bank Account",
|
"account_name":"Checking Account",
|
||||||
"account_name": "Checking Account",
|
"bank": bank_name,
|
||||||
"bank": bank_name,
|
"account": account_name
|
||||||
"account": account_name,
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add_transactions():
|
def add_transactions():
|
||||||
create_bank_account()
|
create_bank_account()
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Transaction",
|
||||||
"doctype": "Bank Transaction",
|
"description":"1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G",
|
||||||
"description": "1512567 BG/000002918 OPSKATTUZWXXX AT776000000098709837 Herr G",
|
"date": "2018-10-23",
|
||||||
"date": "2018-10-23",
|
"deposit": 1200,
|
||||||
"deposit": 1200,
|
"currency": "INR",
|
||||||
"currency": "INR",
|
"bank_account": "Checking Account - Citi Bank"
|
||||||
"bank_account": "Checking Account - Citi Bank",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Transaction",
|
||||||
"doctype": "Bank Transaction",
|
"description":"1512567 BG/000003025 OPSKATTUZWXXX AT776000000098709849 Herr G",
|
||||||
"description": "1512567 BG/000003025 OPSKATTUZWXXX AT776000000098709849 Herr G",
|
"date": "2018-10-23",
|
||||||
"date": "2018-10-23",
|
"deposit": 1700,
|
||||||
"deposit": 1700,
|
"currency": "INR",
|
||||||
"currency": "INR",
|
"bank_account": "Checking Account - Citi Bank"
|
||||||
"bank_account": "Checking Account - Citi Bank",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Transaction",
|
||||||
"doctype": "Bank Transaction",
|
"description":"Re 95282925234 FE/000002917 AT171513000281183046 Conrad Electronic",
|
||||||
"description": "Re 95282925234 FE/000002917 AT171513000281183046 Conrad Electronic",
|
"date": "2018-10-26",
|
||||||
"date": "2018-10-26",
|
"withdrawal": 690,
|
||||||
"withdrawal": 690,
|
"currency": "INR",
|
||||||
"currency": "INR",
|
"bank_account": "Checking Account - Citi Bank"
|
||||||
"bank_account": "Checking Account - Citi Bank",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Transaction",
|
||||||
"doctype": "Bank Transaction",
|
"description":"Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07",
|
||||||
"description": "Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07",
|
"date": "2018-10-27",
|
||||||
"date": "2018-10-27",
|
"deposit": 3900,
|
||||||
"deposit": 3900,
|
"currency": "INR",
|
||||||
"currency": "INR",
|
"bank_account": "Checking Account - Citi Bank"
|
||||||
"bank_account": "Checking Account - Citi Bank",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc({
|
||||||
{
|
"doctype": "Bank Transaction",
|
||||||
"doctype": "Bank Transaction",
|
"description":"I2015000011 VD/000002514 ATWWXXX AT4701345000003510057 Bio",
|
||||||
"description": "I2015000011 VD/000002514 ATWWXXX AT4701345000003510057 Bio",
|
"date": "2018-10-27",
|
||||||
"date": "2018-10-27",
|
"withdrawal": 109080,
|
||||||
"withdrawal": 109080,
|
"currency": "INR",
|
||||||
"currency": "INR",
|
"bank_account": "Checking Account - Citi Bank"
|
||||||
"bank_account": "Checking Account - Citi Bank",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
|
|
||||||
def add_vouchers():
|
def add_vouchers():
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Supplier",
|
||||||
"doctype": "Supplier",
|
"supplier_group":"All Supplier Groups",
|
||||||
"supplier_group": "All Supplier Groups",
|
"supplier_type": "Company",
|
||||||
"supplier_type": "Company",
|
"supplier_name": "Conrad Electronic"
|
||||||
"supplier_name": "Conrad Electronic",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
@@ -267,14 +200,12 @@ def add_vouchers():
|
|||||||
pe.submit()
|
pe.submit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Supplier",
|
||||||
"doctype": "Supplier",
|
"supplier_group":"All Supplier Groups",
|
||||||
"supplier_group": "All Supplier Groups",
|
"supplier_type": "Company",
|
||||||
"supplier_type": "Company",
|
"supplier_name": "Mr G"
|
||||||
"supplier_name": "Mr G",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -293,30 +224,26 @@ def add_vouchers():
|
|||||||
pe.submit()
|
pe.submit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Supplier",
|
||||||
"doctype": "Supplier",
|
"supplier_group":"All Supplier Groups",
|
||||||
"supplier_group": "All Supplier Groups",
|
"supplier_type": "Company",
|
||||||
"supplier_type": "Company",
|
"supplier_name": "Poore Simon's"
|
||||||
"supplier_name": "Poore Simon's",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Customer",
|
||||||
"doctype": "Customer",
|
"customer_group":"All Customer Groups",
|
||||||
"customer_group": "All Customer Groups",
|
"customer_type": "Company",
|
||||||
"customer_type": "Company",
|
"customer_name": "Poore Simon's"
|
||||||
"customer_name": "Poore Simon's",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pi = make_purchase_invoice(supplier="Poore Simon's", qty=1, rate=3900, is_paid=1, do_not_save=1)
|
pi = make_purchase_invoice(supplier="Poore Simon's", qty=1, rate=3900, is_paid=1, do_not_save =1)
|
||||||
pi.cash_bank_account = "_Test Bank - _TC"
|
pi.cash_bank_account = "_Test Bank - _TC"
|
||||||
pi.insert()
|
pi.insert()
|
||||||
pi.submit()
|
pi.submit()
|
||||||
@@ -336,31 +263,33 @@ def add_vouchers():
|
|||||||
pe.submit()
|
pe.submit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
"doctype": "Customer",
|
||||||
"doctype": "Customer",
|
"customer_group":"All Customer Groups",
|
||||||
"customer_group": "All Customer Groups",
|
"customer_type": "Company",
|
||||||
"customer_type": "Company",
|
"customer_name": "Fayva"
|
||||||
"customer_name": "Fayva",
|
}).insert()
|
||||||
}
|
|
||||||
).insert()
|
|
||||||
except frappe.DuplicateEntryError:
|
except frappe.DuplicateEntryError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
mode_of_payment = frappe.get_doc({"doctype": "Mode of Payment", "name": "Cash"})
|
mode_of_payment = frappe.get_doc({
|
||||||
|
"doctype": "Mode of Payment",
|
||||||
|
"name": "Cash"
|
||||||
|
})
|
||||||
|
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value('Mode of Payment Account', {'company': "_Test Company", 'parent': "Cash"}):
|
||||||
"Mode of Payment Account", {"company": "_Test Company", "parent": "Cash"}
|
mode_of_payment.append("accounts", {
|
||||||
):
|
"company": "_Test Company",
|
||||||
mode_of_payment.append(
|
"default_account": "_Test Bank - _TC"
|
||||||
"accounts", {"company": "_Test Company", "default_account": "_Test Bank - _TC"}
|
})
|
||||||
)
|
|
||||||
mode_of_payment.save()
|
mode_of_payment.save()
|
||||||
|
|
||||||
si = create_sales_invoice(customer="Fayva", qty=1, rate=109080, do_not_save=1)
|
si = create_sales_invoice(customer="Fayva", qty=1, rate=109080, do_not_save=1)
|
||||||
si.is_pos = 1
|
si.is_pos = 1
|
||||||
si.append(
|
si.append("payments", {
|
||||||
"payments", {"mode_of_payment": "Cash", "account": "_Test Bank - _TC", "amount": 109080}
|
"mode_of_payment": "Cash",
|
||||||
)
|
"account": "_Test Bank - _TC",
|
||||||
|
"amount": 109080
|
||||||
|
})
|
||||||
si.insert()
|
si.insert()
|
||||||
si.submit()
|
si.submit()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -14,19 +16,13 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
|||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
|
|
||||||
class BudgetError(frappe.ValidationError):
|
class BudgetError(frappe.ValidationError): pass
|
||||||
pass
|
class DuplicateBudgetError(frappe.ValidationError): pass
|
||||||
|
|
||||||
|
|
||||||
class DuplicateBudgetError(frappe.ValidationError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Budget(Document):
|
class Budget(Document):
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
self.name = make_autoname(
|
self.name = make_autoname(self.get(frappe.scrub(self.budget_against))
|
||||||
self.get(frappe.scrub(self.budget_against)) + "/" + self.fiscal_year + "/.###"
|
+ "/" + self.fiscal_year + "/.###")
|
||||||
)
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.get(frappe.scrub(self.budget_against)):
|
if not self.get(frappe.scrub(self.budget_against)):
|
||||||
@@ -41,44 +37,34 @@ class Budget(Document):
|
|||||||
budget_against = self.get(budget_against_field)
|
budget_against = self.get(budget_against_field)
|
||||||
|
|
||||||
accounts = [d.account for d in self.accounts] or []
|
accounts = [d.account for d in self.accounts] or []
|
||||||
existing_budget = frappe.db.sql(
|
existing_budget = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
b.name, ba.account from `tabBudget` b, `tabBudget Account` ba
|
b.name, ba.account from `tabBudget` b, `tabBudget Account` ba
|
||||||
where
|
where
|
||||||
ba.parent = b.name and b.docstatus < 2 and b.company = %s and %s=%s and
|
ba.parent = b.name and b.docstatus < 2 and b.company = %s and %s=%s and
|
||||||
b.fiscal_year=%s and b.name != %s and ba.account in (%s) """
|
b.fiscal_year=%s and b.name != %s and ba.account in (%s) """
|
||||||
% ("%s", budget_against_field, "%s", "%s", "%s", ",".join(["%s"] * len(accounts))),
|
% ('%s', budget_against_field, '%s', '%s', '%s', ','.join(['%s'] * len(accounts))),
|
||||||
(self.company, budget_against, self.fiscal_year, self.name) + tuple(accounts),
|
(self.company, budget_against, self.fiscal_year, self.name) + tuple(accounts), as_dict=1)
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
for d in existing_budget:
|
for d in existing_budget:
|
||||||
frappe.throw(
|
frappe.throw(_("Another Budget record '{0}' already exists against {1} '{2}' and account '{3}' for fiscal year {4}")
|
||||||
_(
|
.format(d.name, self.budget_against, budget_against, d.account, self.fiscal_year), DuplicateBudgetError)
|
||||||
"Another Budget record '{0}' already exists against {1} '{2}' and account '{3}' for fiscal year {4}"
|
|
||||||
).format(d.name, self.budget_against, budget_against, d.account, self.fiscal_year),
|
|
||||||
DuplicateBudgetError,
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_accounts(self):
|
def validate_accounts(self):
|
||||||
account_list = []
|
account_list = []
|
||||||
for d in self.get("accounts"):
|
for d in self.get('accounts'):
|
||||||
if d.account:
|
if d.account:
|
||||||
account_details = frappe.db.get_value(
|
account_details = frappe.db.get_value("Account", d.account,
|
||||||
"Account", d.account, ["is_group", "company", "report_type"], as_dict=1
|
["is_group", "company", "report_type"], as_dict=1)
|
||||||
)
|
|
||||||
|
|
||||||
if account_details.is_group:
|
if account_details.is_group:
|
||||||
frappe.throw(_("Budget cannot be assigned against Group Account {0}").format(d.account))
|
frappe.throw(_("Budget cannot be assigned against Group Account {0}").format(d.account))
|
||||||
elif account_details.company != self.company:
|
elif account_details.company != self.company:
|
||||||
frappe.throw(_("Account {0} does not belongs to company {1}").format(d.account, self.company))
|
frappe.throw(_("Account {0} does not belongs to company {1}")
|
||||||
|
.format(d.account, self.company))
|
||||||
elif account_details.report_type != "Profit and Loss":
|
elif account_details.report_type != "Profit and Loss":
|
||||||
frappe.throw(
|
frappe.throw(_("Budget cannot be assigned against {0}, as it's not an Income or Expense account")
|
||||||
_("Budget cannot be assigned against {0}, as it's not an Income or Expense account").format(
|
.format(d.account))
|
||||||
d.account
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if d.account in account_list:
|
if d.account in account_list:
|
||||||
frappe.throw(_("Account {0} has been entered multiple times").format(d.account))
|
frappe.throw(_("Account {0} has been entered multiple times").format(d.account))
|
||||||
@@ -86,66 +72,51 @@ class Budget(Document):
|
|||||||
account_list.append(d.account)
|
account_list.append(d.account)
|
||||||
|
|
||||||
def set_null_value(self):
|
def set_null_value(self):
|
||||||
if self.budget_against == "Cost Center":
|
if self.budget_against == 'Cost Center':
|
||||||
self.project = None
|
self.project = None
|
||||||
else:
|
else:
|
||||||
self.cost_center = None
|
self.cost_center = None
|
||||||
|
|
||||||
def validate_applicable_for(self):
|
def validate_applicable_for(self):
|
||||||
if self.applicable_on_material_request and not (
|
if (self.applicable_on_material_request
|
||||||
self.applicable_on_purchase_order and self.applicable_on_booking_actual_expenses
|
and not (self.applicable_on_purchase_order and self.applicable_on_booking_actual_expenses)):
|
||||||
):
|
frappe.throw(_("Please enable Applicable on Purchase Order and Applicable on Booking Actual Expenses"))
|
||||||
frappe.throw(
|
|
||||||
_("Please enable Applicable on Purchase Order and Applicable on Booking Actual Expenses")
|
|
||||||
)
|
|
||||||
|
|
||||||
elif self.applicable_on_purchase_order and not (self.applicable_on_booking_actual_expenses):
|
elif (self.applicable_on_purchase_order
|
||||||
|
and not (self.applicable_on_booking_actual_expenses)):
|
||||||
frappe.throw(_("Please enable Applicable on Booking Actual Expenses"))
|
frappe.throw(_("Please enable Applicable on Booking Actual Expenses"))
|
||||||
|
|
||||||
elif not (
|
elif not(self.applicable_on_material_request
|
||||||
self.applicable_on_material_request
|
or self.applicable_on_purchase_order or self.applicable_on_booking_actual_expenses):
|
||||||
or self.applicable_on_purchase_order
|
|
||||||
or self.applicable_on_booking_actual_expenses
|
|
||||||
):
|
|
||||||
self.applicable_on_booking_actual_expenses = 1
|
self.applicable_on_booking_actual_expenses = 1
|
||||||
|
|
||||||
|
|
||||||
def validate_expense_against_budget(args):
|
def validate_expense_against_budget(args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|
||||||
if args.get("company") and not args.fiscal_year:
|
if args.get('company') and not args.fiscal_year:
|
||||||
args.fiscal_year = get_fiscal_year(args.get("posting_date"), company=args.get("company"))[0]
|
args.fiscal_year = get_fiscal_year(args.get('posting_date'), company=args.get('company'))[0]
|
||||||
frappe.flags.exception_approver_role = frappe.get_cached_value(
|
frappe.flags.exception_approver_role = frappe.get_cached_value('Company',
|
||||||
"Company", args.get("company"), "exception_budget_approver_role"
|
args.get('company'), 'exception_budget_approver_role')
|
||||||
)
|
|
||||||
|
|
||||||
if not args.account:
|
if not args.account:
|
||||||
args.account = args.get("expense_account")
|
args.account = args.get("expense_account")
|
||||||
|
|
||||||
if not (args.get("account") and args.get("cost_center")) and args.item_code:
|
if not (args.get('account') and args.get('cost_center')) and args.item_code:
|
||||||
args.cost_center, args.account = get_item_details(args)
|
args.cost_center, args.account = get_item_details(args)
|
||||||
|
|
||||||
if not args.account:
|
if not args.account:
|
||||||
return
|
return
|
||||||
|
|
||||||
for budget_against in ["project", "cost_center"] + get_accounting_dimensions():
|
for budget_against in ['project', 'cost_center'] + get_accounting_dimensions():
|
||||||
if (
|
if (args.get(budget_against) and args.account
|
||||||
args.get(budget_against)
|
and frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"})):
|
||||||
and args.account
|
|
||||||
and frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"})
|
|
||||||
):
|
|
||||||
|
|
||||||
doctype = frappe.unscrub(budget_against)
|
doctype = frappe.unscrub(budget_against)
|
||||||
|
|
||||||
if frappe.get_cached_value("DocType", doctype, "is_tree"):
|
if frappe.get_cached_value('DocType', doctype, 'is_tree'):
|
||||||
lft, rgt = frappe.db.get_value(doctype, args.get(budget_against), ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value(doctype, args.get(budget_against), ["lft", "rgt"])
|
||||||
condition = """and exists(select name from `tab%s`
|
condition = """and exists(select name from `tab%s`
|
||||||
where lft<=%s and rgt>=%s and name=b.%s)""" % (
|
where lft<=%s and rgt>=%s and name=b.%s)""" % (doctype, lft, rgt, budget_against) #nosec
|
||||||
doctype,
|
|
||||||
lft,
|
|
||||||
rgt,
|
|
||||||
budget_against,
|
|
||||||
) # nosec
|
|
||||||
args.is_tree = True
|
args.is_tree = True
|
||||||
else:
|
else:
|
||||||
condition = "and b.%s=%s" % (budget_against, frappe.db.escape(args.get(budget_against)))
|
condition = "and b.%s=%s" % (budget_against, frappe.db.escape(args.get(budget_against)))
|
||||||
@@ -154,8 +125,7 @@ def validate_expense_against_budget(args):
|
|||||||
args.budget_against_field = budget_against
|
args.budget_against_field = budget_against
|
||||||
args.budget_against_doctype = doctype
|
args.budget_against_doctype = doctype
|
||||||
|
|
||||||
budget_records = frappe.db.sql(
|
budget_records = frappe.db.sql("""
|
||||||
"""
|
|
||||||
select
|
select
|
||||||
b.{budget_against_field} as budget_against, ba.budget_amount, b.monthly_distribution,
|
b.{budget_against_field} as budget_against, ba.budget_amount, b.monthly_distribution,
|
||||||
ifnull(b.applicable_on_material_request, 0) as for_material_request,
|
ifnull(b.applicable_on_material_request, 0) as for_material_request,
|
||||||
@@ -170,17 +140,11 @@ def validate_expense_against_budget(args):
|
|||||||
b.name=ba.parent and b.fiscal_year=%s
|
b.name=ba.parent and b.fiscal_year=%s
|
||||||
and ba.account=%s and b.docstatus=1
|
and ba.account=%s and b.docstatus=1
|
||||||
{condition}
|
{condition}
|
||||||
""".format(
|
""".format(condition=condition, budget_against_field=budget_against), (args.fiscal_year, args.account), as_dict=True) #nosec
|
||||||
condition=condition, budget_against_field=budget_against
|
|
||||||
),
|
|
||||||
(args.fiscal_year, args.account),
|
|
||||||
as_dict=True,
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
if budget_records:
|
if budget_records:
|
||||||
validate_budget_records(args, budget_records)
|
validate_budget_records(args, budget_records)
|
||||||
|
|
||||||
|
|
||||||
def validate_budget_records(args, budget_records):
|
def validate_budget_records(args, budget_records):
|
||||||
for budget in budget_records:
|
for budget in budget_records:
|
||||||
if flt(budget.budget_amount):
|
if flt(budget.budget_amount):
|
||||||
@@ -188,118 +152,88 @@ def validate_budget_records(args, budget_records):
|
|||||||
yearly_action, monthly_action = get_actions(args, budget)
|
yearly_action, monthly_action = get_actions(args, budget)
|
||||||
|
|
||||||
if monthly_action in ["Stop", "Warn"]:
|
if monthly_action in ["Stop", "Warn"]:
|
||||||
budget_amount = get_accumulated_monthly_budget(
|
budget_amount = get_accumulated_monthly_budget(budget.monthly_distribution,
|
||||||
budget.monthly_distribution, args.posting_date, args.fiscal_year, budget.budget_amount
|
args.posting_date, args.fiscal_year, budget.budget_amount)
|
||||||
)
|
|
||||||
|
|
||||||
args["month_end_date"] = get_last_day(args.posting_date)
|
args["month_end_date"] = get_last_day(args.posting_date)
|
||||||
|
|
||||||
compare_expense_with_budget(
|
compare_expense_with_budget(args, budget_amount,
|
||||||
args, budget_amount, _("Accumulated Monthly"), monthly_action, budget.budget_against, amount
|
_("Accumulated Monthly"), monthly_action, budget.budget_against, amount)
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
yearly_action in ("Stop", "Warn")
|
|
||||||
and monthly_action != "Stop"
|
|
||||||
and yearly_action != monthly_action
|
|
||||||
):
|
|
||||||
compare_expense_with_budget(
|
|
||||||
args, flt(budget.budget_amount), _("Annual"), yearly_action, budget.budget_against, amount
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if yearly_action in ("Stop", "Warn") and monthly_action != "Stop" \
|
||||||
|
and yearly_action != monthly_action:
|
||||||
|
compare_expense_with_budget(args, flt(budget.budget_amount),
|
||||||
|
_("Annual"), yearly_action, budget.budget_against, amount)
|
||||||
|
|
||||||
def compare_expense_with_budget(args, budget_amount, action_for, action, budget_against, amount=0):
|
def compare_expense_with_budget(args, budget_amount, action_for, action, budget_against, amount=0):
|
||||||
actual_expense = amount or get_actual_expense(args)
|
actual_expense = amount or get_actual_expense(args)
|
||||||
if actual_expense > budget_amount:
|
if actual_expense > budget_amount:
|
||||||
diff = actual_expense - budget_amount
|
diff = actual_expense - budget_amount
|
||||||
currency = frappe.get_cached_value("Company", args.company, "default_currency")
|
currency = frappe.get_cached_value('Company', args.company, 'default_currency')
|
||||||
|
|
||||||
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It will exceed by {5}").format(
|
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It will exceed by {5}").format(
|
||||||
_(action_for),
|
_(action_for), frappe.bold(args.account), args.budget_against_field,
|
||||||
frappe.bold(args.account),
|
frappe.bold(budget_against),
|
||||||
args.budget_against_field,
|
frappe.bold(fmt_money(budget_amount, currency=currency)),
|
||||||
frappe.bold(budget_against),
|
frappe.bold(fmt_money(diff, currency=currency)))
|
||||||
frappe.bold(fmt_money(budget_amount, currency=currency)),
|
|
||||||
frappe.bold(fmt_money(diff, currency=currency)),
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if (frappe.flags.exception_approver_role
|
||||||
frappe.flags.exception_approver_role
|
and frappe.flags.exception_approver_role in frappe.get_roles(frappe.session.user)):
|
||||||
and frappe.flags.exception_approver_role in frappe.get_roles(frappe.session.user)
|
|
||||||
):
|
|
||||||
action = "Warn"
|
action = "Warn"
|
||||||
|
|
||||||
if action == "Stop":
|
if action=="Stop":
|
||||||
frappe.throw(msg, BudgetError)
|
frappe.throw(msg, BudgetError)
|
||||||
else:
|
else:
|
||||||
frappe.msgprint(msg, indicator="orange")
|
frappe.msgprint(msg, indicator='orange')
|
||||||
|
|
||||||
|
|
||||||
def get_actions(args, budget):
|
def get_actions(args, budget):
|
||||||
yearly_action = budget.action_if_annual_budget_exceeded
|
yearly_action = budget.action_if_annual_budget_exceeded
|
||||||
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded
|
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded
|
||||||
|
|
||||||
if args.get("doctype") == "Material Request" and budget.for_material_request:
|
if args.get('doctype') == 'Material Request' and budget.for_material_request:
|
||||||
yearly_action = budget.action_if_annual_budget_exceeded_on_mr
|
yearly_action = budget.action_if_annual_budget_exceeded_on_mr
|
||||||
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded_on_mr
|
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded_on_mr
|
||||||
|
|
||||||
elif args.get("doctype") == "Purchase Order" and budget.for_purchase_order:
|
elif args.get('doctype') == 'Purchase Order' and budget.for_purchase_order:
|
||||||
yearly_action = budget.action_if_annual_budget_exceeded_on_po
|
yearly_action = budget.action_if_annual_budget_exceeded_on_po
|
||||||
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded_on_po
|
monthly_action = budget.action_if_accumulated_monthly_budget_exceeded_on_po
|
||||||
|
|
||||||
return yearly_action, monthly_action
|
return yearly_action, monthly_action
|
||||||
|
|
||||||
|
|
||||||
def get_amount(args, budget):
|
def get_amount(args, budget):
|
||||||
amount = 0
|
amount = 0
|
||||||
|
|
||||||
if args.get("doctype") == "Material Request" and budget.for_material_request:
|
if args.get('doctype') == 'Material Request' and budget.for_material_request:
|
||||||
amount = (
|
amount = (get_requested_amount(args, budget)
|
||||||
get_requested_amount(args, budget) + get_ordered_amount(args, budget) + get_actual_expense(args)
|
+ get_ordered_amount(args, budget) + get_actual_expense(args))
|
||||||
)
|
|
||||||
|
|
||||||
elif args.get("doctype") == "Purchase Order" and budget.for_purchase_order:
|
elif args.get('doctype') == 'Purchase Order' and budget.for_purchase_order:
|
||||||
amount = get_ordered_amount(args, budget) + get_actual_expense(args)
|
amount = get_ordered_amount(args, budget) + get_actual_expense(args)
|
||||||
|
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
|
|
||||||
def get_requested_amount(args, budget):
|
def get_requested_amount(args, budget):
|
||||||
item_code = args.get("item_code")
|
item_code = args.get('item_code')
|
||||||
condition = get_other_condition(args, budget, "Material Request")
|
condition = get_other_condition(args, budget, 'Material Request')
|
||||||
|
|
||||||
data = frappe.db.sql(
|
data = frappe.db.sql(""" select ifnull((sum(child.stock_qty - child.ordered_qty) * rate), 0) as amount
|
||||||
""" select ifnull((sum(child.stock_qty - child.ordered_qty) * rate), 0) as amount
|
|
||||||
from `tabMaterial Request Item` child, `tabMaterial Request` parent where parent.name = child.parent and
|
from `tabMaterial Request Item` child, `tabMaterial Request` parent where parent.name = child.parent and
|
||||||
child.item_code = %s and parent.docstatus = 1 and child.stock_qty > child.ordered_qty and {0} and
|
child.item_code = %s and parent.docstatus = 1 and child.stock_qty > child.ordered_qty and {0} and
|
||||||
parent.material_request_type = 'Purchase' and parent.status != 'Stopped'""".format(
|
parent.material_request_type = 'Purchase' and parent.status != 'Stopped'""".format(condition), item_code, as_list=1)
|
||||||
condition
|
|
||||||
),
|
|
||||||
item_code,
|
|
||||||
as_list=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
return data[0][0] if data else 0
|
return data[0][0] if data else 0
|
||||||
|
|
||||||
|
|
||||||
def get_ordered_amount(args, budget):
|
def get_ordered_amount(args, budget):
|
||||||
item_code = args.get("item_code")
|
item_code = args.get('item_code')
|
||||||
condition = get_other_condition(args, budget, "Purchase Order")
|
condition = get_other_condition(args, budget, 'Purchase Order')
|
||||||
|
|
||||||
data = frappe.db.sql(
|
data = frappe.db.sql(""" select ifnull(sum(child.amount - child.billed_amt), 0) as amount
|
||||||
""" select ifnull(sum(child.amount - child.billed_amt), 0) as amount
|
|
||||||
from `tabPurchase Order Item` child, `tabPurchase Order` parent where
|
from `tabPurchase Order Item` child, `tabPurchase Order` parent where
|
||||||
parent.name = child.parent and child.item_code = %s and parent.docstatus = 1 and child.amount > child.billed_amt
|
parent.name = child.parent and child.item_code = %s and parent.docstatus = 1 and child.amount > child.billed_amt
|
||||||
and parent.status != 'Closed' and {0}""".format(
|
and parent.status != 'Closed' and {0}""".format(condition), item_code, as_list=1)
|
||||||
condition
|
|
||||||
),
|
|
||||||
item_code,
|
|
||||||
as_list=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
return data[0][0] if data else 0
|
return data[0][0] if data else 0
|
||||||
|
|
||||||
|
|
||||||
def get_other_condition(args, budget, for_doc):
|
def get_other_condition(args, budget, for_doc):
|
||||||
condition = "expense_account = '%s'" % (args.expense_account)
|
condition = "expense_account = '%s'" % (args.expense_account)
|
||||||
budget_against_field = args.get("budget_against_field")
|
budget_against_field = args.get("budget_against_field")
|
||||||
@@ -307,51 +241,41 @@ def get_other_condition(args, budget, for_doc):
|
|||||||
if budget_against_field and args.get(budget_against_field):
|
if budget_against_field and args.get(budget_against_field):
|
||||||
condition += " and child.%s = '%s'" % (budget_against_field, args.get(budget_against_field))
|
condition += " and child.%s = '%s'" % (budget_against_field, args.get(budget_against_field))
|
||||||
|
|
||||||
if args.get("fiscal_year"):
|
if args.get('fiscal_year'):
|
||||||
date_field = "schedule_date" if for_doc == "Material Request" else "transaction_date"
|
date_field = 'schedule_date' if for_doc == 'Material Request' else 'transaction_date'
|
||||||
start_date, end_date = frappe.db.get_value(
|
start_date, end_date = frappe.db.get_value('Fiscal Year', args.get('fiscal_year'),
|
||||||
"Fiscal Year", args.get("fiscal_year"), ["year_start_date", "year_end_date"]
|
['year_start_date', 'year_end_date'])
|
||||||
)
|
|
||||||
|
|
||||||
condition += """ and parent.%s
|
condition += """ and parent.%s
|
||||||
between '%s' and '%s' """ % (
|
between '%s' and '%s' """ %(date_field, start_date, end_date)
|
||||||
date_field,
|
|
||||||
start_date,
|
|
||||||
end_date,
|
|
||||||
)
|
|
||||||
|
|
||||||
return condition
|
return condition
|
||||||
|
|
||||||
|
|
||||||
def get_actual_expense(args):
|
def get_actual_expense(args):
|
||||||
if not args.budget_against_doctype:
|
if not args.budget_against_doctype:
|
||||||
args.budget_against_doctype = frappe.unscrub(args.budget_against_field)
|
args.budget_against_doctype = frappe.unscrub(args.budget_against_field)
|
||||||
|
|
||||||
budget_against_field = args.get("budget_against_field")
|
budget_against_field = args.get('budget_against_field')
|
||||||
condition1 = " and gle.posting_date <= %(month_end_date)s" if args.get("month_end_date") else ""
|
condition1 = " and gle.posting_date <= %(month_end_date)s" \
|
||||||
|
if args.get("month_end_date") else ""
|
||||||
|
|
||||||
if args.is_tree:
|
if args.is_tree:
|
||||||
lft_rgt = frappe.db.get_value(
|
lft_rgt = frappe.db.get_value(args.budget_against_doctype,
|
||||||
args.budget_against_doctype, args.get(budget_against_field), ["lft", "rgt"], as_dict=1
|
args.get(budget_against_field), ["lft", "rgt"], as_dict=1)
|
||||||
)
|
|
||||||
|
|
||||||
args.update(lft_rgt)
|
args.update(lft_rgt)
|
||||||
|
|
||||||
condition2 = """and exists(select name from `tab{doctype}`
|
condition2 = """and exists(select name from `tab{doctype}`
|
||||||
where lft>=%(lft)s and rgt<=%(rgt)s
|
where lft>=%(lft)s and rgt<=%(rgt)s
|
||||||
and name=gle.{budget_against_field})""".format(
|
and name=gle.{budget_against_field})""".format(doctype=args.budget_against_doctype, #nosec
|
||||||
doctype=args.budget_against_doctype, budget_against_field=budget_against_field # nosec
|
budget_against_field=budget_against_field)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
condition2 = """and exists(select name from `tab{doctype}`
|
condition2 = """and exists(select name from `tab{doctype}`
|
||||||
where name=gle.{budget_against} and
|
where name=gle.{budget_against} and
|
||||||
gle.{budget_against} = %({budget_against})s)""".format(
|
gle.{budget_against} = %({budget_against})s)""".format(doctype=args.budget_against_doctype,
|
||||||
doctype=args.budget_against_doctype, budget_against=budget_against_field
|
budget_against = budget_against_field)
|
||||||
)
|
|
||||||
|
|
||||||
amount = flt(
|
amount = flt(frappe.db.sql("""
|
||||||
frappe.db.sql(
|
|
||||||
"""
|
|
||||||
select sum(gle.debit) - sum(gle.credit)
|
select sum(gle.debit) - sum(gle.credit)
|
||||||
from `tabGL Entry` gle
|
from `tabGL Entry` gle
|
||||||
where gle.account=%(account)s
|
where gle.account=%(account)s
|
||||||
@@ -360,59 +284,46 @@ def get_actual_expense(args):
|
|||||||
and gle.company=%(company)s
|
and gle.company=%(company)s
|
||||||
and gle.docstatus=1
|
and gle.docstatus=1
|
||||||
{condition2}
|
{condition2}
|
||||||
""".format(
|
""".format(condition1=condition1, condition2=condition2), (args))[0][0]) #nosec
|
||||||
condition1=condition1, condition2=condition2
|
|
||||||
),
|
|
||||||
(args),
|
|
||||||
)[0][0]
|
|
||||||
) # nosec
|
|
||||||
|
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
|
|
||||||
def get_accumulated_monthly_budget(monthly_distribution, posting_date, fiscal_year, annual_budget):
|
def get_accumulated_monthly_budget(monthly_distribution, posting_date, fiscal_year, annual_budget):
|
||||||
distribution = {}
|
distribution = {}
|
||||||
if monthly_distribution:
|
if monthly_distribution:
|
||||||
for d in frappe.db.sql(
|
for d in frappe.db.sql("""select mdp.month, mdp.percentage_allocation
|
||||||
"""select mdp.month, mdp.percentage_allocation
|
|
||||||
from `tabMonthly Distribution Percentage` mdp, `tabMonthly Distribution` md
|
from `tabMonthly Distribution Percentage` mdp, `tabMonthly Distribution` md
|
||||||
where mdp.parent=md.name and md.fiscal_year=%s""",
|
where mdp.parent=md.name and md.fiscal_year=%s""", fiscal_year, as_dict=1):
|
||||||
fiscal_year,
|
distribution.setdefault(d.month, d.percentage_allocation)
|
||||||
as_dict=1,
|
|
||||||
):
|
|
||||||
distribution.setdefault(d.month, d.percentage_allocation)
|
|
||||||
|
|
||||||
dt = frappe.db.get_value("Fiscal Year", fiscal_year, "year_start_date")
|
dt = frappe.db.get_value("Fiscal Year", fiscal_year, "year_start_date")
|
||||||
accumulated_percentage = 0.0
|
accumulated_percentage = 0.0
|
||||||
|
|
||||||
while dt <= getdate(posting_date):
|
while(dt <= getdate(posting_date)):
|
||||||
if monthly_distribution:
|
if monthly_distribution:
|
||||||
accumulated_percentage += distribution.get(getdate(dt).strftime("%B"), 0)
|
accumulated_percentage += distribution.get(getdate(dt).strftime("%B"), 0)
|
||||||
else:
|
else:
|
||||||
accumulated_percentage += 100.0 / 12
|
accumulated_percentage += 100.0/12
|
||||||
|
|
||||||
dt = add_months(dt, 1)
|
dt = add_months(dt, 1)
|
||||||
|
|
||||||
return annual_budget * accumulated_percentage / 100
|
return annual_budget * accumulated_percentage / 100
|
||||||
|
|
||||||
|
|
||||||
def get_item_details(args):
|
def get_item_details(args):
|
||||||
cost_center, expense_account = None, None
|
cost_center, expense_account = None, None
|
||||||
|
|
||||||
if not args.get("company"):
|
if not args.get('company'):
|
||||||
return cost_center, expense_account
|
return cost_center, expense_account
|
||||||
|
|
||||||
if args.item_code:
|
if args.item_code:
|
||||||
item_defaults = frappe.db.get_value(
|
item_defaults = frappe.db.get_value('Item Default',
|
||||||
"Item Default",
|
{'parent': args.item_code, 'company': args.get('company')},
|
||||||
{"parent": args.item_code, "company": args.get("company")},
|
['buying_cost_center', 'expense_account'])
|
||||||
["buying_cost_center", "expense_account"],
|
|
||||||
)
|
|
||||||
if item_defaults:
|
if item_defaults:
|
||||||
cost_center, expense_account = item_defaults
|
cost_center, expense_account = item_defaults
|
||||||
|
|
||||||
if not (cost_center and expense_account):
|
if not (cost_center and expense_account):
|
||||||
for doctype in ["Item Group", "Company"]:
|
for doctype in ['Item Group', 'Company']:
|
||||||
data = get_expense_cost_center(doctype, args)
|
data = get_expense_cost_center(doctype, args)
|
||||||
|
|
||||||
if not cost_center and data:
|
if not cost_center and data:
|
||||||
@@ -426,15 +337,11 @@ def get_item_details(args):
|
|||||||
|
|
||||||
return cost_center, expense_account
|
return cost_center, expense_account
|
||||||
|
|
||||||
|
|
||||||
def get_expense_cost_center(doctype, args):
|
def get_expense_cost_center(doctype, args):
|
||||||
if doctype == "Item Group":
|
if doctype == 'Item Group':
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value('Item Default',
|
||||||
"Item Default",
|
{'parent': args.get(frappe.scrub(doctype)), 'company': args.get('company')},
|
||||||
{"parent": args.get(frappe.scrub(doctype)), "company": args.get("company")},
|
['buying_cost_center', 'expense_account'])
|
||||||
["buying_cost_center", "expense_account"],
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(doctype, args.get(frappe.scrub(doctype)),\
|
||||||
doctype, args.get(frappe.scrub(doctype)), ["cost_center", "default_expense_account"]
|
['cost_center', 'default_expense_account'])
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -11,8 +13,7 @@ from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journ
|
|||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||||
|
|
||||||
test_dependencies = ["Monthly Distribution"]
|
test_dependencies = ['Monthly Distribution']
|
||||||
|
|
||||||
|
|
||||||
class TestBudget(unittest.TestCase):
|
class TestBudget(unittest.TestCase):
|
||||||
def test_monthly_budget_crossed_ignore(self):
|
def test_monthly_budget_crossed_ignore(self):
|
||||||
@@ -20,18 +21,11 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center")
|
budget = make_budget(budget_against="Cost Center")
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True)
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
submit=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||||
frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv.name})
|
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
||||||
)
|
|
||||||
|
|
||||||
budget.cancel()
|
budget.cancel()
|
||||||
jv.cancel()
|
jv.cancel()
|
||||||
@@ -41,17 +35,10 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center")
|
budget = make_budget(budget_against="Cost Center")
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -63,65 +50,49 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center")
|
budget = make_budget(budget_against="Cost Center")
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
frappe.db.set_value("Company", budget.company, "exception_budget_approver_role", "Accounts User")
|
frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', 'Accounts User')
|
||||||
|
|
||||||
jv.submit()
|
jv.submit()
|
||||||
self.assertEqual(frappe.db.get_value("Journal Entry", jv.name, "docstatus"), 1)
|
self.assertEqual(frappe.db.get_value('Journal Entry', jv.name, 'docstatus'), 1)
|
||||||
jv.cancel()
|
jv.cancel()
|
||||||
|
|
||||||
frappe.db.set_value("Company", budget.company, "exception_budget_approver_role", "")
|
frappe.db.set_value('Company', budget.company, 'exception_budget_approver_role', '')
|
||||||
|
|
||||||
budget.load_from_db()
|
budget.load_from_db()
|
||||||
budget.cancel()
|
budget.cancel()
|
||||||
|
|
||||||
def test_monthly_budget_crossed_for_mr(self):
|
def test_monthly_budget_crossed_for_mr(self):
|
||||||
budget = make_budget(
|
budget = make_budget(applicable_on_material_request=1,
|
||||||
applicable_on_material_request=1,
|
applicable_on_purchase_order=1, action_if_accumulated_monthly_budget_exceeded_on_mr="Stop",
|
||||||
applicable_on_purchase_order=1,
|
budget_against="Cost Center")
|
||||||
action_if_accumulated_monthly_budget_exceeded_on_mr="Stop",
|
|
||||||
budget_against="Cost Center",
|
|
||||||
)
|
|
||||||
|
|
||||||
fiscal_year = get_fiscal_year(nowdate())[0]
|
fiscal_year = get_fiscal_year(nowdate())[0]
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
frappe.db.set_value("Budget", budget.name, "fiscal_year", fiscal_year)
|
frappe.db.set_value("Budget", budget.name, "fiscal_year", fiscal_year)
|
||||||
|
|
||||||
mr = frappe.get_doc(
|
mr = frappe.get_doc({
|
||||||
{
|
"doctype": "Material Request",
|
||||||
"doctype": "Material Request",
|
"material_request_type": "Purchase",
|
||||||
"material_request_type": "Purchase",
|
"transaction_date": nowdate(),
|
||||||
"transaction_date": nowdate(),
|
"company": budget.company,
|
||||||
"company": budget.company,
|
"items": [{
|
||||||
"items": [
|
'item_code': '_Test Item',
|
||||||
{
|
'qty': 1,
|
||||||
"item_code": "_Test Item",
|
'uom': "_Test UOM",
|
||||||
"qty": 1,
|
'warehouse': '_Test Warehouse - _TC',
|
||||||
"uom": "_Test UOM",
|
'schedule_date': nowdate(),
|
||||||
"warehouse": "_Test Warehouse - _TC",
|
'rate': 100000,
|
||||||
"schedule_date": nowdate(),
|
'expense_account': '_Test Account Cost for Goods Sold - _TC',
|
||||||
"rate": 100000,
|
'cost_center': '_Test Cost Center - _TC'
|
||||||
"expense_account": "_Test Account Cost for Goods Sold - _TC",
|
}]
|
||||||
"cost_center": "_Test Cost Center - _TC",
|
})
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
mr.set_missing_values()
|
mr.set_missing_values()
|
||||||
|
|
||||||
@@ -131,16 +102,11 @@ class TestBudget(unittest.TestCase):
|
|||||||
budget.cancel()
|
budget.cancel()
|
||||||
|
|
||||||
def test_monthly_budget_crossed_for_po(self):
|
def test_monthly_budget_crossed_for_po(self):
|
||||||
budget = make_budget(
|
budget = make_budget(applicable_on_purchase_order=1,
|
||||||
applicable_on_purchase_order=1,
|
action_if_accumulated_monthly_budget_exceeded_on_po="Stop", budget_against="Cost Center")
|
||||||
action_if_accumulated_monthly_budget_exceeded_on_po="Stop",
|
|
||||||
budget_against="Cost Center",
|
|
||||||
)
|
|
||||||
|
|
||||||
fiscal_year = get_fiscal_year(nowdate())[0]
|
fiscal_year = get_fiscal_year(nowdate())[0]
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
frappe.db.set_value("Budget", budget.name, "fiscal_year", fiscal_year)
|
frappe.db.set_value("Budget", budget.name, "fiscal_year", fiscal_year)
|
||||||
|
|
||||||
po = create_purchase_order(transaction_date=nowdate(), do_not_submit=True)
|
po = create_purchase_order(transaction_date=nowdate(), do_not_submit=True)
|
||||||
@@ -158,20 +124,12 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
budget = make_budget(budget_against="Project")
|
budget = make_budget(budget_against="Project")
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project=project, posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
project=project,
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -183,13 +141,8 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center")
|
budget = make_budget(budget_against="Cost Center")
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 250000, "_Test Cost Center - _TC", posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
250000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -202,14 +155,9 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 250000, "_Test Cost Center - _TC",
|
||||||
"_Test Bank - _TC",
|
project=project, posting_date=nowdate())
|
||||||
250000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
project=project,
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -223,23 +171,14 @@ class TestBudget(unittest.TestCase):
|
|||||||
if month > 9:
|
if month > 9:
|
||||||
month = 9
|
month = 9
|
||||||
|
|
||||||
for i in range(month + 1):
|
for i in range(month+1):
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True)
|
||||||
"_Test Bank - _TC",
|
|
||||||
20000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
submit=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||||
frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv.name})
|
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.cancel)
|
self.assertRaises(BudgetError, jv.cancel)
|
||||||
|
|
||||||
@@ -256,23 +195,14 @@ class TestBudget(unittest.TestCase):
|
|||||||
|
|
||||||
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||||
for i in range(month + 1):
|
for i in range(month + 1):
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True,
|
||||||
"_Test Bank - _TC",
|
project=project)
|
||||||
20000,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
submit=True,
|
|
||||||
project=project,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(frappe.db.get_value("GL Entry",
|
||||||
frappe.db.get_value("GL Entry", {"voucher_type": "Journal Entry", "voucher_no": jv.name})
|
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.cancel)
|
self.assertRaises(BudgetError, jv.cancel)
|
||||||
|
|
||||||
@@ -284,17 +214,10 @@ class TestBudget(unittest.TestCase):
|
|||||||
set_total_expense_zero(nowdate(), "cost_center", "_Test Cost Center 2 - _TC")
|
set_total_expense_zero(nowdate(), "cost_center", "_Test Cost Center 2 - _TC")
|
||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center", cost_center="_Test Company - _TC")
|
budget = make_budget(budget_against="Cost Center", cost_center="_Test Company - _TC")
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, "_Test Cost Center 2 - _TC", posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
"_Test Cost Center 2 - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -305,28 +228,19 @@ class TestBudget(unittest.TestCase):
|
|||||||
cost_center = "_Test Cost Center 3 - _TC"
|
cost_center = "_Test Cost Center 3 - _TC"
|
||||||
|
|
||||||
if not frappe.db.exists("Cost Center", cost_center):
|
if not frappe.db.exists("Cost Center", cost_center):
|
||||||
frappe.get_doc(
|
frappe.get_doc({
|
||||||
{
|
'doctype': 'Cost Center',
|
||||||
"doctype": "Cost Center",
|
'cost_center_name': '_Test Cost Center 3',
|
||||||
"cost_center_name": "_Test Cost Center 3",
|
'parent_cost_center': "_Test Company - _TC",
|
||||||
"parent_cost_center": "_Test Company - _TC",
|
'company': '_Test Company',
|
||||||
"company": "_Test Company",
|
'is_group': 0
|
||||||
"is_group": 0,
|
}).insert(ignore_permissions=True)
|
||||||
}
|
|
||||||
).insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
budget = make_budget(budget_against="Cost Center", cost_center=cost_center)
|
budget = make_budget(budget_against="Cost Center", cost_center=cost_center)
|
||||||
frappe.db.set_value(
|
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
|
||||||
"Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop"
|
|
||||||
)
|
|
||||||
|
|
||||||
jv = make_journal_entry(
|
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", 40000, cost_center, posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
40000,
|
|
||||||
cost_center,
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertRaises(BudgetError, jv.submit)
|
self.assertRaises(BudgetError, jv.submit)
|
||||||
|
|
||||||
@@ -343,16 +257,14 @@ def set_total_expense_zero(posting_date, budget_against_field=None, budget_again
|
|||||||
|
|
||||||
fiscal_year = get_fiscal_year(nowdate())[0]
|
fiscal_year = get_fiscal_year(nowdate())[0]
|
||||||
|
|
||||||
args = frappe._dict(
|
args = frappe._dict({
|
||||||
{
|
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
"account": "_Test Account Cost for Goods Sold - _TC",
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
"cost_center": "_Test Cost Center - _TC",
|
"monthly_end_date": posting_date,
|
||||||
"monthly_end_date": posting_date,
|
"company": "_Test Company",
|
||||||
"company": "_Test Company",
|
"fiscal_year": fiscal_year,
|
||||||
"fiscal_year": fiscal_year,
|
"budget_against_field": budget_against_field,
|
||||||
"budget_against_field": budget_against_field,
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not args.get(budget_against_field):
|
if not args.get(budget_against_field):
|
||||||
args[budget_against_field] = budget_against
|
args[budget_against_field] = budget_against
|
||||||
@@ -361,42 +273,26 @@ def set_total_expense_zero(posting_date, budget_against_field=None, budget_again
|
|||||||
|
|
||||||
if existing_expense:
|
if existing_expense:
|
||||||
if budget_against_field == "cost_center":
|
if budget_against_field == "cost_center":
|
||||||
make_journal_entry(
|
make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True)
|
||||||
"_Test Bank - _TC",
|
|
||||||
-existing_expense,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
posting_date=nowdate(),
|
|
||||||
submit=True,
|
|
||||||
)
|
|
||||||
elif budget_against_field == "project":
|
elif budget_against_field == "project":
|
||||||
make_journal_entry(
|
make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
||||||
"_Test Account Cost for Goods Sold - _TC",
|
"_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project=budget_against, posting_date=nowdate())
|
||||||
"_Test Bank - _TC",
|
|
||||||
-existing_expense,
|
|
||||||
"_Test Cost Center - _TC",
|
|
||||||
submit=True,
|
|
||||||
project=budget_against,
|
|
||||||
posting_date=nowdate(),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def make_budget(**args):
|
def make_budget(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|
||||||
budget_against = args.budget_against
|
budget_against=args.budget_against
|
||||||
cost_center = args.cost_center
|
cost_center=args.cost_center
|
||||||
|
|
||||||
fiscal_year = get_fiscal_year(nowdate())[0]
|
fiscal_year = get_fiscal_year(nowdate())[0]
|
||||||
|
|
||||||
if budget_against == "Project":
|
if budget_against == "Project":
|
||||||
project_name = "{0}%".format("_Test Project/" + fiscal_year)
|
project_name = "{0}%".format("_Test Project/" + fiscal_year)
|
||||||
budget_list = frappe.get_all("Budget", fields=["name"], filters={"name": ("like", project_name)})
|
budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", project_name)})
|
||||||
else:
|
else:
|
||||||
cost_center_name = "{0}%".format(cost_center or "_Test Cost Center - _TC/" + fiscal_year)
|
cost_center_name = "{0}%".format(cost_center or "_Test Cost Center - _TC/" + fiscal_year)
|
||||||
budget_list = frappe.get_all(
|
budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", cost_center_name)})
|
||||||
"Budget", fields=["name"], filters={"name": ("like", cost_center_name)}
|
|
||||||
)
|
|
||||||
for d in budget_list:
|
for d in budget_list:
|
||||||
frappe.db.sql("delete from `tabBudget` where name = %(name)s", d)
|
frappe.db.sql("delete from `tabBudget` where name = %(name)s", d)
|
||||||
frappe.db.sql("delete from `tabBudget Account` where parent = %(name)s", d)
|
frappe.db.sql("delete from `tabBudget Account` where parent = %(name)s", d)
|
||||||
@@ -406,7 +302,7 @@ def make_budget(**args):
|
|||||||
if budget_against == "Project":
|
if budget_against == "Project":
|
||||||
budget.project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
budget.project = frappe.get_value("Project", {"project_name": "_Test Project"})
|
||||||
else:
|
else:
|
||||||
budget.cost_center = cost_center or "_Test Cost Center - _TC"
|
budget.cost_center =cost_center or "_Test Cost Center - _TC"
|
||||||
|
|
||||||
monthly_distribution = frappe.get_doc("Monthly Distribution", "_Test Distribution")
|
monthly_distribution = frappe.get_doc("Monthly Distribution", "_Test Distribution")
|
||||||
monthly_distribution.fiscal_year = fiscal_year
|
monthly_distribution.fiscal_year = fiscal_year
|
||||||
@@ -418,27 +314,20 @@ def make_budget(**args):
|
|||||||
budget.action_if_annual_budget_exceeded = "Stop"
|
budget.action_if_annual_budget_exceeded = "Stop"
|
||||||
budget.action_if_accumulated_monthly_budget_exceeded = "Ignore"
|
budget.action_if_accumulated_monthly_budget_exceeded = "Ignore"
|
||||||
budget.budget_against = budget_against
|
budget.budget_against = budget_against
|
||||||
budget.append(
|
budget.append("accounts", {
|
||||||
"accounts", {"account": "_Test Account Cost for Goods Sold - _TC", "budget_amount": 200000}
|
"account": "_Test Account Cost for Goods Sold - _TC",
|
||||||
)
|
"budget_amount": 200000
|
||||||
|
})
|
||||||
|
|
||||||
if args.applicable_on_material_request:
|
if args.applicable_on_material_request:
|
||||||
budget.applicable_on_material_request = 1
|
budget.applicable_on_material_request = 1
|
||||||
budget.action_if_annual_budget_exceeded_on_mr = (
|
budget.action_if_annual_budget_exceeded_on_mr = args.action_if_annual_budget_exceeded_on_mr or 'Warn'
|
||||||
args.action_if_annual_budget_exceeded_on_mr or "Warn"
|
budget.action_if_accumulated_monthly_budget_exceeded_on_mr = args.action_if_accumulated_monthly_budget_exceeded_on_mr or 'Warn'
|
||||||
)
|
|
||||||
budget.action_if_accumulated_monthly_budget_exceeded_on_mr = (
|
|
||||||
args.action_if_accumulated_monthly_budget_exceeded_on_mr or "Warn"
|
|
||||||
)
|
|
||||||
|
|
||||||
if args.applicable_on_purchase_order:
|
if args.applicable_on_purchase_order:
|
||||||
budget.applicable_on_purchase_order = 1
|
budget.applicable_on_purchase_order = 1
|
||||||
budget.action_if_annual_budget_exceeded_on_po = (
|
budget.action_if_annual_budget_exceeded_on_po = args.action_if_annual_budget_exceeded_on_po or 'Warn'
|
||||||
args.action_if_annual_budget_exceeded_on_po or "Warn"
|
budget.action_if_accumulated_monthly_budget_exceeded_on_po = args.action_if_accumulated_monthly_budget_exceeded_on_po or 'Warn'
|
||||||
)
|
|
||||||
budget.action_if_accumulated_monthly_budget_exceeded_on_po = (
|
|
||||||
args.action_if_accumulated_monthly_budget_exceeded_on_po or "Warn"
|
|
||||||
)
|
|
||||||
|
|
||||||
budget.insert()
|
budget.insert()
|
||||||
budget.submit()
|
budget.submit()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@@ -11,42 +12,28 @@ from frappe.utils import flt
|
|||||||
class CForm(Document):
|
class CForm(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
"""Validate invoice that c-form is applicable
|
"""Validate invoice that c-form is applicable
|
||||||
and no other c-form is received for that"""
|
and no other c-form is received for that"""
|
||||||
|
|
||||||
for d in self.get("invoices"):
|
for d in self.get('invoices'):
|
||||||
if d.invoice_no:
|
if d.invoice_no:
|
||||||
inv = frappe.db.sql(
|
inv = frappe.db.sql("""select c_form_applicable, c_form_no from
|
||||||
"""select c_form_applicable, c_form_no from
|
`tabSales Invoice` where name = %s and docstatus = 1""", d.invoice_no)
|
||||||
`tabSales Invoice` where name = %s and docstatus = 1""",
|
|
||||||
d.invoice_no,
|
|
||||||
)
|
|
||||||
|
|
||||||
if inv and inv[0][0] != "Yes":
|
if inv and inv[0][0] != 'Yes':
|
||||||
frappe.throw(_("C-form is not applicable for Invoice: {0}").format(d.invoice_no))
|
frappe.throw(_("C-form is not applicable for Invoice: {0}").format(d.invoice_no))
|
||||||
|
|
||||||
elif inv and inv[0][1] and inv[0][1] != self.name:
|
elif inv and inv[0][1] and inv[0][1] != self.name:
|
||||||
frappe.throw(
|
frappe.throw(_("""Invoice {0} is tagged in another C-form: {1}.
|
||||||
_(
|
|
||||||
"""Invoice {0} is tagged in another C-form: {1}.
|
|
||||||
If you want to change C-form no for this invoice,
|
If you want to change C-form no for this invoice,
|
||||||
please remove invoice no from the previous c-form and then try again""".format(
|
please remove invoice no from the previous c-form and then try again"""\
|
||||||
d.invoice_no, inv[0][1]
|
.format(d.invoice_no, inv[0][1])))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif not inv:
|
elif not inv:
|
||||||
frappe.throw(
|
frappe.throw(_("Row {0}: Invoice {1} is invalid, it might be cancelled / does not exist. \
|
||||||
_(
|
Please enter a valid Invoice".format(d.idx, d.invoice_no)))
|
||||||
"Row {0}: Invoice {1} is invalid, it might be cancelled / does not exist. \
|
|
||||||
Please enter a valid Invoice".format(
|
|
||||||
d.idx, d.invoice_no
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
"""Update C-Form No on invoices"""
|
""" Update C-Form No on invoices"""
|
||||||
self.set_total_invoiced_amount()
|
self.set_total_invoiced_amount()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
@@ -57,40 +44,30 @@ class CForm(Document):
|
|||||||
frappe.db.sql("""update `tabSales Invoice` set c_form_no=null where c_form_no=%s""", self.name)
|
frappe.db.sql("""update `tabSales Invoice` set c_form_no=null where c_form_no=%s""", self.name)
|
||||||
|
|
||||||
def set_cform_in_sales_invoices(self):
|
def set_cform_in_sales_invoices(self):
|
||||||
inv = [d.invoice_no for d in self.get("invoices")]
|
inv = [d.invoice_no for d in self.get('invoices')]
|
||||||
if inv:
|
if inv:
|
||||||
frappe.db.sql(
|
frappe.db.sql("""update `tabSales Invoice` set c_form_no=%s, modified=%s where name in (%s)""" %
|
||||||
"""update `tabSales Invoice` set c_form_no=%s, modified=%s where name in (%s)"""
|
('%s', '%s', ', '.join(['%s'] * len(inv))), tuple([self.name, self.modified] + inv))
|
||||||
% ("%s", "%s", ", ".join(["%s"] * len(inv))),
|
|
||||||
tuple([self.name, self.modified] + inv),
|
|
||||||
)
|
|
||||||
|
|
||||||
frappe.db.sql(
|
frappe.db.sql("""update `tabSales Invoice` set c_form_no = null, modified = %s
|
||||||
"""update `tabSales Invoice` set c_form_no = null, modified = %s
|
where name not in (%s) and ifnull(c_form_no, '') = %s""" %
|
||||||
where name not in (%s) and ifnull(c_form_no, '') = %s"""
|
('%s', ', '.join(['%s']*len(inv)), '%s'), tuple([self.modified] + inv + [self.name]))
|
||||||
% ("%s", ", ".join(["%s"] * len(inv)), "%s"),
|
|
||||||
tuple([self.modified] + inv + [self.name]),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Please enter atleast 1 invoice in the table"))
|
frappe.throw(_("Please enter atleast 1 invoice in the table"))
|
||||||
|
|
||||||
def set_total_invoiced_amount(self):
|
def set_total_invoiced_amount(self):
|
||||||
total = sum(flt(d.grand_total) for d in self.get("invoices"))
|
total = sum(flt(d.grand_total) for d in self.get('invoices'))
|
||||||
frappe.db.set(self, "total_invoiced_amount", total)
|
frappe.db.set(self, 'total_invoiced_amount', total)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_invoice_details(self, invoice_no):
|
def get_invoice_details(self, invoice_no):
|
||||||
"""Pull details from invoices for referrence"""
|
""" Pull details from invoices for referrence """
|
||||||
if invoice_no:
|
if invoice_no:
|
||||||
inv = frappe.db.get_value(
|
inv = frappe.db.get_value("Sales Invoice", invoice_no,
|
||||||
"Sales Invoice",
|
["posting_date", "territory", "base_net_total", "base_grand_total"], as_dict=True)
|
||||||
invoice_no,
|
|
||||||
["posting_date", "territory", "base_net_total", "base_grand_total"],
|
|
||||||
as_dict=True,
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"invoice_date": inv.posting_date,
|
'invoice_date' : inv.posting_date,
|
||||||
"territory": inv.territory,
|
'territory' : inv.territory,
|
||||||
"net_total": inv.base_net_total,
|
'net_total' : inv.base_net_total,
|
||||||
"grand_total": inv.base_grand_total,
|
'grand_total' : inv.base_grand_total
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# test_records = frappe.get_test_records('C-Form')
|
# test_records = frappe.get_test_records('C-Form')
|
||||||
|
|
||||||
|
|
||||||
class TestCForm(unittest.TestCase):
|
class TestCForm(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
DEFAULT_MAPPERS = [
|
DEFAULT_MAPPERS = [
|
||||||
{
|
{
|
||||||
"doctype": "Cash Flow Mapper",
|
'doctype': 'Cash Flow Mapper',
|
||||||
"section_footer": "Net cash generated by operating activities",
|
'section_footer': 'Net cash generated by operating activities',
|
||||||
"section_header": "Cash flows from operating activities",
|
'section_header': 'Cash flows from operating activities',
|
||||||
"section_leader": "Adjustments for",
|
'section_leader': 'Adjustments for',
|
||||||
"section_name": "Operating Activities",
|
'section_name': 'Operating Activities',
|
||||||
"position": 0,
|
'position': 0,
|
||||||
"section_subtotal": "Cash generated from operations",
|
'section_subtotal': 'Cash generated from operations',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Cash Flow Mapper",
|
'doctype': 'Cash Flow Mapper',
|
||||||
"position": 1,
|
'position': 1,
|
||||||
"section_footer": "Net cash used in investing activities",
|
'section_footer': 'Net cash used in investing activities',
|
||||||
"section_header": "Cash flows from investing activities",
|
'section_header': 'Cash flows from investing activities',
|
||||||
"section_name": "Investing Activities",
|
'section_name': 'Investing Activities'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Cash Flow Mapper",
|
'doctype': 'Cash Flow Mapper',
|
||||||
"position": 2,
|
'position': 2,
|
||||||
"section_footer": "Net cash used in financing activites",
|
'section_footer': 'Net cash used in financing activites',
|
||||||
"section_header": "Cash flows from financing activities",
|
'section_header': 'Cash flows from financing activities',
|
||||||
"section_name": "Financing Activities",
|
'section_name': 'Financing Activities',
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
@@ -11,11 +13,9 @@ class CashFlowMapping(Document):
|
|||||||
self.validate_checked_options()
|
self.validate_checked_options()
|
||||||
|
|
||||||
def validate_checked_options(self):
|
def validate_checked_options(self):
|
||||||
checked_fields = [
|
checked_fields = [d for d in self.meta.fields if d.fieldtype == 'Check' and self.get(d.fieldname) == 1]
|
||||||
d for d in self.meta.fields if d.fieldtype == "Check" and self.get(d.fieldname) == 1
|
|
||||||
]
|
|
||||||
if len(checked_fields) > 1:
|
if len(checked_fields) > 1:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
frappe._("You can only select a maximum of one option from the list of check boxes."),
|
frappe._('You can only select a maximum of one option from the list of check boxes.'),
|
||||||
title="Error",
|
title='Error'
|
||||||
)
|
)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user