Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing liability account scenario in set_liability_account #43321

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

ljain112
Copy link
Contributor

Issue: If "book_advance_payments_in_separate_party_account" is enabled and Default Advance Account is not set. Server Error is raised in Payment Entry.

App Versions

{
	"erpnext": "16.0.0-dev",
	"frappe": "16.0.0-dev",
	"hrms": "16.0.0-dev",
	"india_compliance": "16.0.0-dev"
}

Route

Form/Payment Entry/new-payment-entry-ypcdignjlu

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 115, in application
    response = frappe.api.handle(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
           ^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 1822, in call
    return fn(*args, **newargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/typing_validations.py", line 32, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/desk/form/save.py", line 39, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 340, in save
    return self._save(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 362, in _save
    return self.insert()
           ^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 293, in insert
    self.run_before_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1127, in run_before_save_methods
    self.run_method("validate")
  File "apps/frappe/frappe/model/document.py", line 979, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 1362, in composer
    return composed(self, method, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 1340, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/model/document.py", line 976, in fn
    return method_object(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/erpnext/erpnext/accounts/doctype/payment_entry/payment_entry.py", line 161, in validate
    self.set_liability_account()
  File "apps/erpnext/erpnext/accounts/doctype/payment_entry/payment_entry.py", line 236, in set_liability_account
    liability_account = get_party_account(
                        ^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

Request Data

{
	"type": "POST",
	"args": {
		"doc": "{\"owner\":\"Administrator\",\"docstatus\":0,\"idx\":0,\"naming_series\":\"ACC-PAY-24-25-.####\",\"payment_type\":\"Receive\",\"payment_order_status\":\"Initiated\",\"posting_date\":\"2024-09-21\",\"company\":\"Marvels\",\"party_type\":\"Customer\",\"party\":\"dummy customer\",\"party_name\":\"dummy customer\",\"book_advance_payments_in_separate_party_account\":0,\"reconcile_on_advance_payment_date\":0,\"party_balance\":-3000000,\"paid_from\":\"Debtors - FP\",\"paid_from_account_currency\":\"INR\",\"paid_from_account_balance\":0,\"paid_to\":\"Bank - FP\",\"paid_to_account_currency\":\"INR\",\"paid_to_account_balance\":0,\"paid_amount\":0,\"paid_amount_after_tax\":0,\"source_exchange_rate\":1,\"base_paid_amount\":0,\"base_paid_amount_after_tax\":0,\"received_amount\":0,\"received_amount_after_tax\":0,\"target_exchange_rate\":1,\"base_received_amount\":0,\"base_received_amount_after_tax\":0,\"total_allocated_amount\":0,\"base_total_allocated_amount\":0,\"unallocated_amount\":0,\"difference_amount\":0,\"apply_tax_withholding_amount\":0,\"base_total_taxes_and_charges\":0,\"total_taxes_and_charges\":0,\"reference_date\":\"2024-09-21\",\"status\":\"Draft\",\"custom_remarks\":0,\"is_opening\":\"No\",\"letter_head\":\"Plus LH dup\",\"doctype\":\"Payment Entry\",\"references\":[{\"docstatus\":0,\"idx\":1,\"reference_doctype\":\"Sales Order\",\"reference_name\":\"SAL-ORD-24-25-00031\",\"total_amount\":8260,\"outstanding_amount\":0,\"allocated_amount\":0,\"exchange_rate\":0,\"exchange_gain_loss\":0,\"parentfield\":\"references\",\"parenttype\":\"Payment Entry\",\"doctype\":\"Payment Entry Reference\",\"__islocal\":1,\"parent\":\"new-payment-entry-ypcdignjlu\",\"name\":\"new-payment-entry-reference-pauelchmfi\"}],\"taxes\":[],\"deductions\":[],\"__islocal\":1,\"__unsaved\":1,\"name\":\"new-payment-entry-ypcdignjlu\",\"__last_sync_on\":\"2024-09-21T08:59:52.047Z\"}",
		"action": "Save"
	},
	"btn": {
		"jQuery3700037425789812866371": {
			"events": {
				"click": [
					{
						"type": "click",
						"origType": "click",
						"guid": 3113,
						"namespace": ""
					}
				]
			}
		}
	},
	"freeze": true,
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.desk.form.save.savedocs",
	"request_id": null
}

Response Data

{
	"exception": "IndexError: list index out of range",
	"exc_type": "IndexError",
	"_exc_source": "erpnext (app)"
}

Before:
image

After:
image

Closes: #42521
Frappe Support Issue: https://support.frappe.io/app/hd-ticket/18979

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Sep 21, 2024
@ruthra-kumar ruthra-kumar removed the request for review from deepeshgarg007 September 23, 2024 04:42
@ruthra-kumar ruthra-kumar self-assigned this Sep 23, 2024
@ruthra-kumar ruthra-kumar merged commit 4be6878 into frappe:develop Sep 23, 2024
14 checks passed
ruthra-kumar added a commit that referenced this pull request Sep 23, 2024
…-43321

fix: handle missing liability account scenario in `set_liability_account` (backport #43321)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport version-15-hotfix needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error while creating Payment entry
2 participants