I’m encountering an AttributeError when submitting a ProposedStockEntry document in a custom mapro app on ERPNext. The error occurs in the repost_item_valuation.py file, specifically in the reset_recreate_stock_ledgers method, because the RepostItemValuation doctype does not have a recreate_stock_ledgers field.
Error Details
Error Message:
AttributeError: 'RepostItemValuation' object has no attribute 'recreate_stock_ledgers'
Traceback (partial, from previous context):
File "apps/erpnext/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py", line 111, in validate self.reset_recreate_stock_ledgers() File "apps/erpnext/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py", line 111, in reset_recreate_stock_ledgers if self.recreate_stock_ledgers and self.based_on != "Transaction": ^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'RepostItemValuation' object has no attribute 'recreate_stock_ledgers'
Context: The error is triggered when a StockEntry is created and submitted from the before_submit method of ProposedStockEntry (in the mapro app), which calls repost_future_sle_and_gle in stock_controller.py, leading to the creation of a RepostItemValuation document.
Attempted Fix
To resolve the issue, I manually added a custom field to the RepostItemValuation doctype:
Field Name: custom_recreate_stock_ledger
Label: Recreate Stock Ledgers
Type: Check
Added Via: Customize Form in Frappe UI
I modified repost_item_valuation.py to use custom_recreate_stock_ledger instead of recreate_stock_ledgers:
def reset_recreate_stock_ledgers(self): if self.custom_recreate_stock_ledger and self.based_on != "Transaction": self.custom_recreate_stock_ledger = 0
I also updated related methods (recreate_stock_ledger_entries and repost) and create_repost_item_valuation_entry in stock_controller.py:
`# repost_item_valuation.py
def recreate_stock_ledger_entries(self):
if self.based_on == “Transaction” and self.custom_recreate_stock_ledger:
doc = frappe.get_doc(self.voucher_type, self.voucher_no)
doc.db_set(“docstatus”, 2)
doc.update_stock_ledger(allow_negative_stock=True)
doc.db_set(“docstatus”, 1)
doc.update_stock_ledger(allow_negative_stock=True)
stock_controller.py
def create_repost_item_valuation_entry(args):
repost_entry = frappe.new_doc(“Repost Item Valuation”)
repost_entry.voucher_type = args.get(“voucher_type”)
repost_entry.voucher_no = args.get(“voucher_no”)
repost_entry.posting_date = args.get(“posting_date”)
repost_entry.posting_time = args.get(“posting_time”)
repost_entry.company = args.get(“company”)
repost_entry.based_on = args.get(“based_on”, “Transaction”)
repost_entry.allow_negative_stock = args.get(“allow_negative_stock”, 1)
repost_entry.via_landed_cost_voucher = args.get(“via_landed_cost_voucher”, 0)
repost_entry.custom_recreate_stock_ledger = args.get(“custom_recreate_stock_ledger”, 1)
repost_entry.save()`
However, the error persists, indicating that recreate_stock_ledgers is still being referenced somewhere or the custom field is not being recognized.
Steps to Reproduce
- Create a ProposedStockEntry document in the mapro app.
- Set stock_entry_type to Material Transfer for Manufacture.
- Add items with valid warehouses, quantities, and batch numbers.
- Submit the ProposedStockEntry.
- A StockEntry is created and submitted, triggering RepostItemValuation creation, which raises the error.
Customizations
- Added custom_recreate_stock_ledger to RepostItemValuation via Customize Form.
- Modified repost_item_valuation.py and stock_controller.py to use custom_recreate_stock_ledger.
- The mapro app’s ProposedStockEntry creates a StockEntry and triggers reposting via repost_future_sle_and_gle.
- Updated ProposedStockEntry’s before_submit to set custom_recreate_stock_ledger:
args = { "voucher_type": stock_entry.doctype, "voucher_no": stock_entry.name, "posting_date": stock_entry.posting_date, "posting_time": stock_entry.posting_time, "company": stock_entry.company, "allow_negative_stock": 1, "via_landed_cost_voucher": 0, "custom_recreate_stock_ledger": 1, } create_repost_item_valuation_entry(args)
Database Check
Confirmed custom_recreate_stock_ledger exists in tabRepost Item Valuation (TINYINT(1)).
No recreate_stock_ledgers field exists in the database.
Questions
- Is recreate_stock_ledgers a standard field in RepostItemValuation for my ERPNext version, or was it removed/renamed?
- Why does the error persist after replacing recreate_stock_ledgers with custom_recreate_stock_ledger?
- Could the mapro app be outdated or overriding RepostItemValuation logic? How can I verify compatibility?
- Are there migrations or patches I might have missed for RepostItemValuation?
- Should I rename custom_recreate_stock_ledger to recreate_stock_ledgers to match the code, or is there a better approach?
Additional Information
I suspect mapro may be incompatible with my ERPNext version, as it seems to expect recreate_stock_ledgers.
I’ve run bench migrate and cleared the cache (bench clear-cache), but the issue remains.
Logs show the error occurs during RepostItemValuation validation.
Request
Please help identify:
Why recreate_stock_ledgers is still referenced despite my changes.
Whether custom_recreate_stock_ledger is the correct fix or if I should restore recreate_stock_ledgers.
How to ensure mapro compatibility with ERPNext.
Any missing migrations or configurations.