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

MPESA Payment Request - ERP Next POS UnboundLocalError: local variable 'grand_total' referenced before assignment #69

Open
dkareithis opened this issue Mar 2, 2024 · 0 comments

Comments

@dkareithis
Copy link

Information about bug

image
Hello, I am loving the system and currently testing it. However, I get the following error while using mpesa payment gateway on POS. I saw a similar issue that was marked as resolved but there was no mention on how it was resolved.

Module

accounts, selling, integrations

Version

Frappe Framework: v15.15.0 (version-15)
ERPNext: v15.14.6 (version-15)

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

### App Versions

{
	"chat": "0.0.1",
	"erpnext": "15.14.6",
	"frappe": "15.15.0",
	"helpdesk": "0.10.0",
	"hrms": "15.12.0",
	"payments": "0.0.1",
	"webshop": "0.0.1"
}

Route

point-of-sale

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, 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 1682, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/handler.py", line 326, in run_doc_method
    response = doc.run_method(method)
  File "apps/frappe/frappe/model/document.py", line 955, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1315, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1297, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 952, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/accounts/doctype/pos_invoice/pos_invoice.py", line 656, in create_payment_request
    pay_req = self.get_new_payment_request(pay)
  File "apps/erpnext/erpnext/accounts/doctype/pos_invoice/pos_invoice.py", line 683, in get_new_payment_request
    return make_payment_request(**args)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/erpnext/erpnext/accounts/doctype/payment_request/payment_request.py", line 438, in make_payment_request
    grand_total = get_amount(ref_doc, gateway_account.get("payment_account"))
  File "apps/erpnext/erpnext/accounts/doctype/payment_request/payment_request.py", line 548, in get_amount
    if grand_total > 0:
UnboundLocalError: local variable 'grand_total' referenced before assignment

Request Data

{
	"type": "POST",
	"args": {
		"docs": "{\"name\":\"ACC-PSINV-2024-00004\",\"owner\":\"Administrator\",\"creation\":\"2024-03-01 11:12:34.711636\",\"modified\":\"2024-03-01 11:12:53.315487\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":0,\"title\":\"John Doe\",\"naming_series\":\"ACC-PSINV-.YYYY.-\",\"customer\":\"John Doe\",\"customer_name\":\"John Doe\",\"pos_profile\":\"Test POS\",\"is_pos\":1,\"is_return\":0,\"update_billed_amount_in_sales_order\":0,\"update_billed_amount_in_delivery_note\":1,\"company\":\"Test (Demo)\",\"posting_date\":\"2024-03-01\",\"posting_time\":\"11:12:53.553423\",\"set_posting_time\":0,\"due_date\":\"2024-03-01\",\"contact_person\":\"John Doe-John Doe\",\"contact_display\":\"John Doe\",\"contact_mobile\":\"727312513\",\"contact_email\":\"\",\"currency\":\"KES\",\"conversion_rate\":1,\"selling_price_list\":\"Hourly Charges\",\"price_list_currency\":\"KES\",\"plc_conversion_rate\":1,\"ignore_pricing_rule\":1,\"set_warehouse\":\"Bungoma - TsTBD\",\"update_stock\":1,\"total_billing_amount\":0,\"total_qty\":1,\"base_total\":50,\"base_net_total\":12.5,\"total\":50,\"net_total\":12.5,\"total_net_weight\":0,\"taxes_and_charges\":\"\",\"tax_category\":\"\",\"base_total_taxes_and_charges\":0,\"total_taxes_and_charges\":0,\"loyalty_points\":0,\"loyalty_amount\":0,\"redeem_loyalty_points\":0,\"apply_discount_on\":\"Grand Total\",\"base_discount_amount\":37.5,\"additional_discount_percentage\":75,\"discount_amount\":37.5,\"base_grand_total\":12.5,\"base_rounding_adjustment\":-0.5,\"base_rounded_total\":12,\"base_in_words\":\"KES Twelve only.\",\"grand_total\":12.5,\"rounding_adjustment\":-0.5,\"rounded_total\":12,\"in_words\":\"KES Twelve only.\",\"total_advance\":0,\"outstanding_amount\":0,\"allocate_advances_automatically\":0,\"base_paid_amount\":12,\"paid_amount\":12,\"base_change_amount\":0,\"change_amount\":0,\"account_for_change_amount\":\"Bungoma Main Stage - KwBD\",\"write_off_amount\":0,\"base_write_off_amount\":0,\"write_off_outstanding_amount_automatically\":0,\"write_off_account\":\"Administrative Expenses - KwBD\",\"write_off_cost_center\":\"Main - KwBD\",\"letter_head\":\"Test\",\"group_same_items\":0,\"language\":\"en\",\"is_discounted\":0,\"status\":\"Draft\",\"debit_to\":\"Debtors - KwBD\",\"party_account_currency\":\"KES\",\"is_opening\":\"No\",\"amount_eligible_for_commission\":12.5,\"commission_rate\":0,\"total_commission\":0,\"doctype\":\"POS Invoice\",\"sales_team\":[],\"items\":[{\"name\":\"a7738cdfd4\",\"owner\":\"Administrator\",\"creation\":\"2024-03-01 11:12:34.711636\",\"modified\":\"2024-03-01 11:12:53.315487\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":1,\"has_item_scanned\":0,\"item_code\":\"Luggage Deposit Large\",\"item_name\":\"Luggage Deposit Large\",\"description\":\"Luggage Deposit Large\",\"item_group\":\"Services\",\"image\":\"\",\"qty\":1,\"stock_uom\":\"Nos\",\"uom\":\"Nos\",\"conversion_factor\":1,\"stock_qty\":1,\"price_list_rate\":50,\"base_price_list_rate\":50,\"margin_type\":\"\",\"margin_rate_or_amount\":0,\"rate_with_margin\":0,\"discount_percentage\":0,\"discount_amount\":0,\"base_rate_with_margin\":0,\"rate\":50,\"amount\":50,\"base_rate\":50,\"base_amount\":50,\"pricing_rules\":\"\",\"is_free_item\":0,\"grant_commission\":1,\"net_rate\":12.5,\"net_amount\":12.5,\"base_net_rate\":12.5,\"base_net_amount\":12.5,\"delivered_by_supplier\":0,\"income_account\":\"Bungoma Main Stage - KwBD\",\"is_fixed_asset\":0,\"expense_account\":\"Cost of Goods Sold - KwBD\",\"enable_deferred_revenue\":0,\"weight_per_unit\":0,\"total_weight\":0,\"warehouse\":\"KwB Bungoma Main Stage - KwBD\",\"use_serial_batch_fields\":0,\"allow_zero_valuation_rate\":0,\"item_tax_rate\":\"{}\",\"actual_batch_qty\":0,\"actual_qty\":0,\"batch_no\":\"\",\"delivered_qty\":0,\"cost_center\":\"Main - KwBD\",\"page_break\":0,\"parent\":\"ACC-PSINV-2024-00004\",\"parentfield\":\"items\",\"parenttype\":\"POS Invoice\",\"doctype\":\"POS Invoice Item\",\"__unsaved\":1}],\"payment_schedule\":[],\"timesheets\":[],\"taxes\":[],\"payments\":[{\"name\":\"20a167ae1c\",\"owner\":\"Administrator\",\"creation\":\"2024-03-01 11:12:34.711636\",\"modified\":\"2024-03-01 11:12:53.315487\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":1,\"default\":0,\"mode_of_payment\":\"Bank Draft\",\"amount\":0,\"account\":\"Bank Account - KwBD\",\"type\":\"Bank\",\"base_amount\":0,\"parent\":\"ACC-PSINV-2024-00004\",\"parentfield\":\"payments\",\"parenttype\":\"POS Invoice\",\"doctype\":\"Sales Invoice Payment\",\"__unsaved\":1},{\"name\":\"8e5cec9605\",\"owner\":\"Administrator\",\"creation\":\"2024-03-01 11:12:34.711636\",\"modified\":\"2024-03-01 11:12:53.315487\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":2,\"default\":0,\"mode_of_payment\":\"Cash\",\"amount\":0,\"account\":\"Cash - KwBD\",\"type\":\"Cash\",\"base_amount\":0,\"parent\":\"ACC-PSINV-2024-00004\",\"parentfield\":\"payments\",\"parenttype\":\"POS Invoice\",\"doctype\":\"Sales Invoice Payment\",\"__unsaved\":1},{\"name\":\"a3484f4840\",\"owner\":\"Administrator\",\"creation\":\"2024-03-01 11:12:34.711636\",\"modified\":\"2024-03-01 11:12:53.315487\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":3,\"default\":1,\"mode_of_payment\":\"Mpesa-Test Mpesa Live\",\"amount\":12,\"account\":\"Bank Account - KwBD\",\"type\":\"Phone\",\"base_amount\":12,\"parent\":\"ACC-PSINV-2024-00004\",\"parentfield\":\"payments\",\"parenttype\":\"POS Invoice\",\"doctype\":\"Sales Invoice Payment\",\"__unsaved\":1}],\"packed_items\":[],\"pricing_rules\":[],\"advances\":[],\"__onload\":{\"make_payment_via_journal_entry\":0}}",
		"method": "create_payment_request"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/run_doc_method",
	"request_id": null
}

Response Data

{
	"exception": "UnboundLocalError: local variable 'grand_total' referenced before assignment",
	"exc_type": "UnboundLocalError",
	"_exc_source": "erpnext (app)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant