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: negative current qty causing recursion issue #37752

Conversation

rohitwaghchaure
Copy link
Collaborator

If the Current Quantity is in negative in the backdated Stock Reconciliation for the Batch Item then system throws the recursion issue while submitting the entry

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 87, in make_sl_entries

    repost_current_voucher(args, allow_negative_stock, via_landed_cost_voucher)

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 103, in repost_current_voucher

    update_entries_after(

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 396, in init

    self.build()

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 444, in build

    self.process_sle_against_current_timestamp()

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 467, in process_sle_against_current_timestamp

    self.process_sle(sle)

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 576, in process_sle

    self.reset_actual_qty_for_stock_reco(sle)

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 648, in reset_actual_qty_for_stock_reco

    doc.recalculate_current_qty(sle.voucher_detail_no, sle.creation, sle.actual_qty >= 0)

  File "apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 659, in recalculate_current_qty

    self.make_sl_entries(sl_entries, allow_negative_stock=self.has_negative_stock_allowed())

  File "apps/erpnext/erpnext/controllers/stock_controller.py", line 513, in make_sl_entries

    make_sl_entries(sl_entries, allow_negative_stock, via_landed_cost_voucher)

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 75, in make_sl_entries

    sle_doc = make_entry(sle, allow_negative_stock, via_landed_cost_voucher)

  File "apps/erpnext/erpnext/stock/stock_ledger.py", line 202, in make_entry

    sle.submit()

  File "apps/frappe/frappe/model/document.py", line 1008, in submit

    return self._submit()

  File "apps/frappe/frappe/model/document.py", line 987, in _submit

    return self.save()

  File "apps/frappe/frappe/model/document.py", line 307, in save

    return self._save(*args, **kwargs)

  File "apps/frappe/frappe/model/document.py", line 329, in _save

    return self.insert()

  File "apps/frappe/frappe/model/document.py", line 261, in insert

    self.run_before_save_methods()

  File "apps/frappe/frappe/model/document.py", line 1056, in run_before_save_methods

    self.run_method("validate")

  File "apps/frappe/frappe/model/document.py", line 917, in run_method

    out = Document.hook(fn)(self, args, *kwargs)

  File "apps/frappe/frappe/model/document.py", line 1279, in composer

    return composed(self, method, args, *kwargs)

  File "apps/frappe/frappe/model/document.py", line 1261, in runner

    add_to_return_value(self, fn(self, args, *kwargs))

  File "apps/frappe/frappe/model/document.py", line 914, in fn

    return method_object(*args, **kwargs)

  File "apps/erpnext/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py", line 45, in validate

    self.validate_item()

  File "apps/erpnext/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py", line 173, in validate_item

    elif not frappe.db.get_value("Batch", {"item": self.item_code, "name": self.batch_no}):

  File "apps/frappe/frappe/database/database.py", line 509, in get_value

    result = self.get_values(

  File "apps/frappe/frappe/database/database.py", line 606, in get_values

    out = self._get_values_from_table(

  File "apps/frappe/frappe/database/database.py", line 822, in getvalues_from_table

    query = frappe.qb.get_query(

  File "apps/frappe/frappe/query_builder/utils.py", line 61, in get_query

    return Engine().get_query(*args, **kwargs)

  File "apps/frappe/frappe/database/query.py", line 73, in get_query

    self.apply_fields(fields)

  File "apps/frappe/frappe/database/query.py", line 101, in apply_fields

    self.fields = self.parse_fields(fields)

  File "apps/frappe/frappe/database/query.py", line 305, in parse_fields

    fields = self.sanitize_fields(fields)

  File "apps/frappe/frappe/database/query.py", line 282, in sanitize_fields

    return [_sanitize_field(field) for field in fields]

  File "apps/frappe/frappe/database/query.py", line 282, in <listcomp>

    return [_sanitize_field(field) for field in fields]

  File "apps/frappe/frappe/database/query.py", line 276, in sanitizefield

    stripped_field = sqlparse.format(field, strip_comments=True, keyword_case="lower")

  File "env/lib/python3.10/site-packages/sqlparse/__init__.py", line 59, in format

    return ''.join(stack.run(sql, encoding))

  File "env/lib/python3.10/site-packages/sqlparse/engine/filter_stack.py", line 36, in run

    stmt = grouping.group(stmt)

  File "env/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 428, in group

    func(stmt)

  File "env/lib/python3.10/site-packages/sqlparse/utils.py", line 74, in wrapped_f

    f(tlist)

  File "env/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 299, in group_comments

    tidx, token = tlist.token_next_by(t=T.Comment)

  File "env/lib/python3.10/site-packages/sqlparse/sql.py", line 266, in token_next_by

    return self._token_matching(lambda tk: imt(tk, i, m, t), idx, end)

  File "env/lib/python3.10/site-packages/sqlparse/sql.py", line 245, in tokenmatching

    if func(token):

  File "env/lib/python3.10/site-packages/sqlparse/sql.py", line 266, in <lambda>

    return self._token_matching(lambda tk: imt(tk, i, m, t), idx, end)

  File "env/lib/python3.10/site-packages/sqlparse/utils.py", line 99, in imt

    elif types and any(token.ttype in ttype for ttype in types):

  File "env/lib/python3.10/site-packages/sqlparse/utils.py", line 99, in <genexpr>

    elif types and any(token.ttype in ttype for ttype in types):

  File "env/lib/python3.10/site-packages/sqlparse/tokens.py", line 19, in contains

    return item is not None and (self is item or item[:len(self)] == self)

RecursionError: maximum recursion depth exceeded in comparison

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Oct 30, 2023
@rohitwaghchaure rohitwaghchaure merged commit f1407bc into frappe:version-14-hotfix Oct 30, 2023
10 checks passed
@rohitwaghchaure
Copy link
Collaborator Author

@Mergifyio backport version-14

@mergify
Copy link
Contributor

mergify bot commented Oct 30, 2023

backport version-14

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 30, 2023
rohitwaghchaure added a commit that referenced this pull request Oct 30, 2023
…37753)

fix: negative current qty causing recursion issue (#37752)

(cherry picked from commit f1407bc)

Co-authored-by: rohitwaghchaure <[email protected]>
frappe-pr-bot pushed a commit that referenced this pull request Oct 30, 2023
## [14.45.4](v14.45.3...v14.45.4) (2023-10-30)

### Bug Fixes

* negative current qty causing recursion issue (backport [#37752](#37752)) ([#37753](#37753)) ([20ca948](20ca948))
frappe-pr-bot pushed a commit that referenced this pull request Oct 31, 2023
# [14.46.0](v14.45.4...v14.46.0) (2023-10-31)

### Bug Fixes

* add regional support to extend purchase gl entries ([d02ebd6](d02ebd6))
* avoid name clash in delivery stop (backport [#37306](#37306)) ([#37701](#37701)) ([556095d](556095d))
* Cash flow mapping fix ([#37522](#37522)) ([8e31379](8e31379))
* close employee loan on write off ([#37638](#37638)) ([922ace4](922ace4))
* **defaults:** apply discount and provisonal defaults from item group and brand if available (backport [#37466](#37466)) ([#37703](#37703)) ([a0893dd](a0893dd))
* **delivery:** rename dt fetch stop action (backport [#37605](#37605)) ([#37606](#37606)) ([8660faa](8660faa))
* GL Entries for receiving non CWIP assets using Purchase Receipt ([#37660](#37660)) ([80774e2](80774e2))
* incorrect cost center in the purchase invoice (backport [#37591](#37591)) ([#37609](#37609)) ([50daf70](50daf70))
* incorrect material request quantity in production plan ([#37785](#37785)) ([25718d9](25718d9))
* incorrect process loss validation for multiple finished items (backport [#37576](#37576)) ([#37656](#37656)) ([638c271](638c271))
* indexing on Delivery Note Item (backport [#37766](#37766)) ([#37777](#37777)) ([9b66a06](9b66a06))
* make changes that enable gantt view for job cards (backport [#37661](#37661)) ([#37756](#37756)) ([712ddb7](712ddb7))
* **minor:** filter bank accounts in bank statement import ([#37525](#37525)) ([1cb9f4c](1cb9f4c))
* **minor:** filter tax template based on company in subscription ([#37562](#37562)) ([c05e0a4](c05e0a4))
* **minor:** set tax values for item variants (backport [#37674](#37674)) ([#37738](#37738)) ([fabcfc1](fabcfc1))
* negative current qty causing recursion issue ([#37752](#37752)) ([f1407bc](f1407bc))
* overallocation on Payment with PO/SO ([d71b885](d71b885))
* purchase receipt with stock and asset items ([375be8c](375be8c))
* remove from or target warehouse for non internal transfer entries (backport [#37612](#37612)) ([#37628](#37628)) ([78b7c26](78b7c26))
* set correct `purchase_sle` in `get_last_sle()` ([#37708](#37708)) ([86cf156](86cf156))
* set empty value for tax template in item details ([#37496](#37496)) ([ec208b8](ec208b8))
* typeerror on tds payable monthly report ([fea27d5](fea27d5))
* update existing doc if possible ([89f07dc](89f07dc))
* wrong german translation ([#37658](#37658)) ([fa5780c](fa5780c))

### Features

* allow return of components for SCO that don't have SCR created (backport [#37686](#37686)) ([#37692](#37692)) ([e96d5b3](e96d5b3))
* **delivery:** link to delivery notes list view from delivery trip (backport [#37604](#37604)) ([#37695](#37695)) ([c58fefb](c58fefb))

### Reverts

* Revert "fix: set empty value for tax template in item details (#37496)" ([ca13816](ca13816)), closes [#37496](#37496) [#37496](#37496)
@frappe-pr-bot
Copy link
Collaborator

🎉 This PR is included in version 14.46.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-tests This PR needs automated unit-tests. released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants