frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
20.14k stars 7.05k forks source link

Debit and Credit not equal for Purchase Invoice, Additional Charges #26328

Closed jon-nfc closed 1 year ago

jon-nfc commented 3 years ago

Description of the issue

When I create a purchase invoice (in USD company currency is AUD), and add 'additional charges' in this case shipping. I can save the invoice however I'm unable to submit the invoice as a message pops up saying Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77. 7.77 is the value in AUD for the additional charges. however this issue has also occured creating the invoice in the company currency. if no additional charges are added the invoice will submit.

I'm unable to submit any of these invoices that have additional charges included in them. currently this prevents us from progressing on a large number of invoices.

I have looked through all options in the PI interface in an attempt to check if I have caused the error, however it appears everything is correct.

Context information (for bug reports)

Output of bench version

# docker exec -ti frappe-python bench version
bench_manager 0.0.1
erpnext 13.6.0
frappe 13.6.0
wiki 0.0.1
#

Steps to reproduce the issue

  1. Create a purchase invoice under a supplier and fill out
  2. add additional charges under taxes and charges and save invoice
  3. attempt to submit invoice, above error pops up

Observed result

message pop-up Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77. and the invoice is not submitted.

Expected result

  1. Receive an error message that is clear to the end user on the actual cause of the issue and not a message that requires a developer to diagnose the issue at hand.
  2. be able to submit an invoice with additional charges included.

Stacktrace / full error message

stack trace below is one single action, clicking on the 'Submit' button for the PI.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods
    self.run_method("on_submit")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit
    self.make_gl_entries()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries
    make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries
    save_entries(gl_map, adv_adj, update_outstanding, from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries
    round_off_debit_credit(gl_map)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 176, in round_off_debit_credit
    .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1172, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods
    self.run_method("on_submit")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit
    self.make_gl_entries()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries
    make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries
    save_entries(gl_map, adv_adj, update_outstanding, from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries
    round_off_debit_credit(gl_map)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 176, in round_off_debit_credit
    .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1172, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods
    self.run_method("on_submit")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit
    self.make_gl_entries()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries
    make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries
    save_entries(gl_map, adv_adj, update_outstanding, from_repost)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries
    round_off_debit_credit(gl_map)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 176, in round_off_debit_credit
    .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77.

Additional information

My setup consists of using docker images see below for details on debian 10. I use the frappe images as the base images and build images that include all of the required apps in them.

OS version / distribution, ERPNext install method, etc.

# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:    10
Codename:   buster
# docker images
REPOSITORY                      TAG              IMAGE ID       CREATED        SIZE
frappe/frappe-nginx             v13.6.0          692ce4f9122b   3 days ago     337MB
frappe/frappe-worker            v13.6.0          0a7910575899   3 days ago     1.24GB
frappe/frappe-socketio          v13.6.0          c18b9bfeb59f   3 days ago     189MB
jon-nfc commented 3 years ago

After further investigation, it appears that the GL entries are incomplete. with nothing within the purchase invoice interface that I noticed where I could change it to correct the GL entries.

Code changes made command ouput from: `docker exec -ti frappe-python sh -c "cd ../apps/erpnext && git diff"` ``` diff diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 25d2cf1..393c347 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -158,11 +158,14 @@ def round_off_debit_credit(gl_map): precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), currency=frappe.get_cached_value('Company', gl_map[0].company, "default_currency")) + debug_msg = [] debit_credit_diff = 0.0 for entry in gl_map: entry.debit = flt(entry.debit, precision) entry.credit = flt(entry.credit, precision) debit_credit_diff += entry.debit - entry.credit + + debug_msg.append(("voucher: {0} account: {1}, debit: {2}, credit: {3}").format(entry.voucher_no, entry.account, entry.debit, entry.credit) + "\n") debit_credit_diff = flt(debit_credit_diff, precision) @@ -173,7 +176,7 @@ def round_off_debit_credit(gl_map): if abs(debit_credit_diff) > allowance: frappe.throw(_("Debit and Credit not equal for {0} #{1}. Difference is {2}.") - .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff)) + .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff) + "\n Debug-GL Entries: " + ("").join(f"\n {msg}" for msg in debug_msg)) elif abs(debit_credit_diff) >= (1.0 / (10**precision)): make_round_off_gle(gl_map, debit_credit_diff, precision) ```
Output from changes made above: ``` shell Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs doc.submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit self._submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit self.save() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save return self._save(*args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save self.run_post_save_methods() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods self.run_method("on_submit") File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method out = Document.hook(fn)(self, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer return composed(self, method, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner add_to_return_value(self, fn(self, *args, **kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit self.make_gl_entries() File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries save_entries(gl_map, adv_adj, update_outstanding, from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries round_off_debit_credit(gl_map) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 179, in round_off_debit_credit .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff) + "\n Debug-GL Entries: " + ("").join(f"\n {msg}" for msg in debug_msg)) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint _raise_exception() File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception raise raise_exception(msg) frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77. Debug-GL Entries: voucher: ACC-PINV-2021-00093 account: 2-1110-01 - Creditors - JL-I, debit: 0.0, credit: 23.9 voucher: ACC-PINV-2021-00093 account: 1-7121-99 - Other Electronic Equipments - JL-I, debit: 23.9, credit: 0.0 voucher: ACC-PINV-2021-00093 account: 6-0510 - Postage, Freight and Courier - JL-I, debit: 7.77, credit: 0.0 Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application response = frappe.api.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle return frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle data = execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd return frappe.call(method, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1172, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs doc.submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit self._submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit self.save() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save return self._save(*args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save self.run_post_save_methods() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods self.run_method("on_submit") File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method out = Document.hook(fn)(self, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer return composed(self, method, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner add_to_return_value(self, fn(self, *args, **kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit self.make_gl_entries() File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries save_entries(gl_map, adv_adj, update_outstanding, from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries round_off_debit_credit(gl_map) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 179, in round_off_debit_credit .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff) + "\n Debug-GL Entries: " + ("").join(f"\n {msg}" for msg in debug_msg)) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint _raise_exception() File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception raise raise_exception(msg) frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77. Debug-GL Entries: voucher: ACC-PINV-2021-00093 account: 2-1110-01 - Creditors - JL-I, debit: 0.0, credit: 23.9 voucher: ACC-PINV-2021-00093 account: 1-7121-99 - Other Electronic Equipments - JL-I, debit: 23.9, credit: 0.0 voucher: ACC-PINV-2021-00093 account: 6-0510 - Postage, Freight and Courier - JL-I, debit: 7.77, credit: 0.0 Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application response = frappe.api.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle return frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle data = execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd return frappe.call(method, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1172, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs doc.submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 929, in submit self._submit() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 918, in _submit self.save() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 285, in save return self._save(*args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 337, in _save self.run_post_save_methods() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 997, in run_post_save_methods self.run_method("on_submit") File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_method out = Document.hook(fn)(self, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1148, in composer return composed(self, method, *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1131, in runner add_to_return_value(self, fn(self, *args, **kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 853, in fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 408, in on_submit self.make_gl_entries() File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 424, in make_gl_entries make_gl_entries(gl_entries, update_outstanding=update_outstanding, merge_entries=False, from_repost=from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 20, in make_gl_entries save_entries(gl_map, adv_adj, update_outstanding, from_repost) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 125, in save_entries round_off_debit_credit(gl_map) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 179, in round_off_debit_credit .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff) + "\n Debug-GL Entries: " + ("").join(f"\n {msg}" for msg in debug_msg)) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 432, in throw msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 411, in msgprint _raise_exception() File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 365, in _raise_exception raise raise_exception(msg) frappe.exceptions.ValidationError: Debit and Credit not equal for Purchase Invoice #ACC-PINV-2021-00093. Difference is 7.77. Debug-GL Entries: voucher: ACC-PINV-2021-00093 account: 2-1110-01 - Creditors - JL-I, debit: 0.0, credit: 23.9 voucher: ACC-PINV-2021-00093 account: 1-7121-99 - Other Electronic Equipments - JL-I, debit: 23.9, credit: 0.0 voucher: ACC-PINV-2021-00093 account: 6-0510 - Postage, Freight and Courier - JL-I, debit: 7.77, credit: 0.0 ```

Account 2-1110-01 is a liability, 1-7121-99 is an asset account with 6-0510 being an expense account.

Is there a configuration setting somewhere that I have missed? It appears as though the additional charge does not get charged against a supplier, for example a postage company.

jon-nfc commented 3 years ago

Since no comment was left after label "can't-reproduce" please see screen grab of the unhelpful error. FYI, the debug changes from my previous comment are still implemented and visible.

PI0093-Debit-Credit-not_equal

jon-nfc commented 3 years ago

@yadavyk

Bump. For review. This issue is still outstanding and preventing use of additional charges.

I have simulated the invoice creation on the demo erpnext site, (without full access to the backend) it appears that my issue is that the additional charges are not being added to the ledger entries, preventing submission of the invoice. Further to the issue, any failed validation of configuration does not denote an error to the user which is left only with the above catch all exception(debit credit not equal). There are only two reasons for this to occur, improper validation or no validation. Either way this needs to be fixed. A simple message to the user with the actual cause of the issue would suffice as the end user could then rectify the misconfiguration/error.

ankush commented 3 years ago

however this issue has also occured creating the invoice in the company currency.

I have simulated the invoice creation on the demo erpnext site.

If this was on ERPNext.com / Frappe cloud then share the site and document details and I'll take a look. This seems like a rather peculiar issue and we can't reproduce this. FYI "Additional Charges" are used by hundreds of our users every day, so it's not such a basic issue TBH!

jon-nfc commented 3 years ago

@ankush The invoice creation on the demo erpnext site worked as it should, however has been deleted. (Assuming data was reset). It demonstrated that the additional charges were being added as part of the invoice creation. (Confirmed by viewing the general ledger)

I can recreate the invoice on the demo erpnext site if required, please advise.

I'm unable to share or provide access to my erpnext site as it has live data on it.

Understand that others have got it working so may not be an important issue to work on, however I clearly have done something different that any validation has failed to notify the cause of the issue. As such additional charges are in a non-usable state.

I have full access to the server erpnext is hosted on and am happy to assist with any information you or any of the devs require.

matthewdwatkins commented 3 years ago

I am also having this problem. I was able to figure out that if I enable Capital Works In Progress Accounting for the Asset Category in question, then it calls get_asset_gl_entry in purchase_invoice.py and everything works correctly. I think this is probably related to the problem. I would take a stab at it except I don't understand what's supposed to be happening or why it's implemented the way it is.

I don't understand why line 469-470 in purchase_invoice.py checks for CWIP to be enabled in order to call get_asset_gl_entry. It seems like we want to create those entries for all assets whenever they're on the invoice and then handle CWIP checking as part of get_asset_gl_entry, since nothing above the "else" statement at line 781 touches CWIP.

There's also some confusing control flow going on in get_asset_gl_entry that makes it difficult to understand what's actually supposed to be going on. I would be happy to help solve this problem if someone could offer some guidance.

jon-nfc commented 2 years ago

@matthewdwatkins

Thank you for looking into and replying!!

I made the necessary adjustments as you suggested, however the problem still persists. This does raise a question though, why does cwip accounting need to be enabled for a fixed asset? I too attempted to code dive to find the issue, but it's a rats nest.

I'm still perplexed as to why no dev has actually looked at this issue, being a significant issue that renders this software unusable. A full stack trace was provided!

Agreed, the code is all over the place with no software design document to be found which makes it harder to fault find or even document what should happen. Not even the user docs are helpful in this regard.

My two cents is as follows. This software requires some serious adjustments to how the project is managed. There is a common theme with frappe/erpnext, being look at the code and figure it out. This makes frappe/erpnext a dev driven project that in the end increases project liabilities (bugs, breaking things, security issues, regression etc) which will ultimately lead to unstable software that no one not even the devs can figure out. An example is provided in the issues that are being raised in both frappe/erpnext and the clear lack of documentation in relation to developing and what has been developed.

deepeshgarg007 commented 1 year ago

@jon-nfc I'll try and fix this, will share updates shortly