ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Debit and Credit not equal for Sales Invoice #. Difference is


#1

Hello,

We have an issue with backdated opening stock entry, by using ‘Material Receipt’. When try to submit it is returning following error message.

“Debit and Credit not equal for Sales Invoice #INV-DMM-000021. Difference is -0.5.”

Have checked the invoice INV-DMM-000021, but did not find any difference.

I have searched a lot, unluckily couldn’t find any solution.

Please help me to find out the reason/solution for this issue.

Thank you.


#2

Some suggestions -

Are you self hosted? What version erpnext?

Can you include the error traceback?

To include snapshots to illustrate would add to your case.

Search for your issue on github and add it there if none found.

To troubleshoot and find the root cause of the problem, one needs to be able to reproduce it in a ‘clean’ environment, so if you provide that, that would help resolve your case.


#3

Thank you Mr.Clarke for your quick response, please bellow the information requested.

  1. Are you self hosted?
    Ans: Yes

  2. What version erpnext?
    ERPNext: v10.0.9 (master)
    Frappe Framework: v10.0.10 (master)

  3. Can you include the error traceback?

    Traceback (most recent call last):
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
    doc.submit()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 831, in submit
    self._submit()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 820, in _submit
    self.save()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 256, in save
    return self._save(*args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 307, in _save
    self.run_post_save_methods()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 890, in run_post_save_methods
    self.run_method(“on_submit”)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 755, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 1024, in composer
    return composed(self, method, *args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 1007, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 749, in
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 72, in on_submit
    self.make_gl_entries()
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 35, in make_gl_entries
    warehouse_account)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 354, in update_gl_entries_after
    voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 600, in make_gl_entries
    update_outstanding=update_outstanding, merge_entries=False)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 19, in make_gl_entries
    save_entries(gl_map, adv_adj, update_outstanding, from_repost)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 85, in save_entries
    round_off_debit_credit(gl_map)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 133, in round_off_debit_credit
    .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 323, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
    _raise_exception()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
    raise raise_exception(encode(msg))
    ValidationError: Debit and Credit not equal for Sales Invoice #INV-DMM-000021. Difference is -0.5.

    desk.min.js?ver=1516044457.0:1649 Traceback (most recent call last):
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/app.py”, line 62, in application
    response = frappe.handler.handle()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
    data = execute_cmd(cmd)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py”, line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 939, in call
    return fn(*args, **newargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 19, in savedocs
    doc.submit()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 831, in submit
    self._submit()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 820, in _submit
    self.save()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 256, in save
    return self._save(*args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 307, in _save
    self.run_post_save_methods()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 890, in run_post_save_methods
    self.run_method(“on_submit”)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 755, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 1024, in composer
    return composed(self, method, *args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 1007, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py”, line 749, in
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 72, in on_submit
    self.make_gl_entries()
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 35, in make_gl_entries
    warehouse_account)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 354, in update_gl_entries_after
    voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 600, in make_gl_entries
    update_outstanding=update_outstanding, merge_entries=False)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 19, in make_gl_entries
    save_entries(gl_map, adv_adj, update_outstanding, from_repost)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 85, in save_entries
    round_off_debit_credit(gl_map)
    File “/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py”, line 133, in round_off_debit_credit
    .format(gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff))
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 323, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
    _raise_exception()
    File “/home/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
    raise raise_exception(encode(msg))
    ValidationError: Debit and Credit not equal for Sales Invoice #INV-DMM-000021. Difference is -0.5.

  4. To include snapshots to illustrate would add to your case.
    Stock Entry:-


    Invoice:-

GL:-1:

I did searching in the portal, but could not find any solution, Now am stuck with submitting stock entry, somehow i need to update the system, hope you can bring me a solution?
Is there any way to disable this validation that generating error?


#4

“somehow i need to update the system, hope you can bring me a solution?”

Well yes a ‘bench update’ may resolve your problem, but best to do that in a test and not a production environment.

Otherwise someone may recognize or offer you advice say what accounting measures to remedy this?

edit: Here are similar reports, nabin advises this:

“All these errors are related to data, really difficult to replicate. If you can replicate the error in demo.erpnext.com, please create the invoice and share the invoice number.”


#5

This is to respond to an ask for help that referred to this thread…

As nabin says such problems relate to data. So each case is different in that sense -

To find and fix the root cause means analysing and tracing where and how your data values fit together, flow and are derived. To export reports to a spreadsheet to sift through the data in a pivot table often the best way to do that.

To isolate the problem into a simple base case that can be replicated might point to ways to improve the software to avoid such problem cases?


#6

I will jump into the fray with a similar error. We are currently analyzing the data to observe what is causing this.

Prerequisites:

  1. Self hosted ERPNext instance
  2. Version:
    ERPNext: v10.1.80 (master)
    Frappe Framework: v10.1.70(master)

Please note that the problem occurs on a purchase invoice , yet the message refers to a sales invoice

Steps to repeat:

  1. Create a purchase invoice with update stock checked
  2. Save it
  3. Submit it.
  4. Upon submittal, it takes about 20 seconds or longer to return the error message
    Message:

Debit and Credit not equal for Sales Invoice #B-881455. Difference is 2.347143.


5. The traceback from the console shows:

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 833, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 822, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 310, in _save
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in run_post_save_methods
    self.run_method("on_submit")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 757, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1026, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1009, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 751, 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 302, in on_submit
    self.make_gl_entries()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 341, in make_gl_entries
    update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 354, in update_gl_entries_after
    voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 602, in make_gl_entries
    update_outstanding=update_outstanding, merge_entries=False)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 19, 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 85, in save_entries
    round_off_debit_credit(gl_map)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 133, 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 323, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 282, in _raise_exception
    raise raise_exception(encode(msg))
ValidationError: Debit and Credit not equal for Sales Invoice #B-881455. Difference is 2.347143.

06:59:13.722 desk.min.js?ver=1551130323.0:1660 Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, 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 833, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 822, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 310, in _save
    self.run_post_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in run_post_save_methods
    self.run_method("on_submit")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 757, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1026, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1009, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 751, 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 302, in on_submit
    self.make_gl_entries()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py", line 341, in make_gl_entries
    update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 354, in update_gl_entries_after
    voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 602, in make_gl_entries
    update_outstanding=update_outstanding, merge_entries=False)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 19, 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 85, in save_entries
    round_off_debit_credit(gl_map)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/general_ledger.py", line 133, 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 323, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 282, in _raise_exception
    raise raise_exception(encode(msg))
ValidationError: Debit and Credit not equal for Sales Invoice #B-881455. Difference is 2.347143.

Attempted Resolution steps

  1. Disable Rounded Off in Global Settings. No change.
    2.Updated to Version 11. Same problem

Workaround

If the Purchase Invoice is created without “Update Stock” checked, then it will Submit properly.
However, you will not be able to submit a purchase receipt or even a stock entry to increase inventory for this amount.

Assumptions

It seems that if sales invoices have been created with “Update Stock” checked, with dates AFTER the desired purchase invoice / purchase receipt posting date, and with the same item code as the one being purchased / received, then the error occurs. Thus, it is suggested that no sales invoices, delivery notes or material issues with posting dates posterior to the inventory receipt, purchase receipt or purchase invoice are entered BEFORE creating these entries.


#7

So both your case and the OP’s call update_gl_entries_after

You need to trace and and resolve what the code is doing in your particular data case? You may need to use your imagination to speculate and theorize here!?

Some example questions - update_gl_entries_after calls get_future_stock_vouchers that finds some Stock Ledger Entry?

That may shed light on your Sales Invoice in question?


#8

Thanks for shedding light on this issue John.

After some more brain time and inspecting the code, we are closer to determining where the problem lies. Still not there yet, but so far what we understand (using our imagination) is this:

First a Sales Invoice is created and submitted for January 15, 2019. This Sales Invoice also updates stock for item “DIESEL-01”. A Purchase Invoice, which updates stock, is then created, but its posting date is January 2, 2019. It can be saved but not submitted. Thus I imagine the problem really has to do with the validated Sales Invoice.

Thanks to you these are now the functions we are looking at, to see if there can be a workaround or adjustment, and if it is a plausible modification to the software.

I will continue posting our progress until this issue is properly resolved.

At this point we are operating with ERPNext V11 in that instance, I had hoped it would help to upgrade, to no avail. It is nice to have the newest version though :sweat_smile:

EDIT
We explored the option of cancelling a total of 9 Sales Invoices which had stock movements. It was crucial to do from the last posting date to the first posting date, in that order. Otherwise the same error would pop up when cancelling.
Now with the Sales Invoices cancelled, we are trying to create the Purchase invoices.
Initially we had difficulty because of timeouts. I then opted to create a simple purchase receipt and despite taking a bit longer, it finally validated it. So, the solution in my opinion:

  1. Make sure you chronologically add inventory first
  2. Then, you may create movements against inventory.
    (This is not supposed to matter if negative inventory is allowed, however this bug remains to be studied in detail)
  3. If sales invoices or delivery notes have already been validated or created, cancel all of them up until after the purchase receipt or inventory receipt or purchase invoice with stock movement. Then add the items to stock with a material receipt (stock entry), or purchase receipt or purchase invoice.