fix: transactions where update stock is 0 should not create SLEs (backport #54035) (#54076)

* fix: transactions where update stock is 0 should not create SLEs (#54035)

(cherry picked from commit 66780543bd)

# Conflicts:
#	erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py

* chore: resolve conflicts

* chore: resolve conflicts

---------

Co-authored-by: Nishka Gosalia <58264710+nishkagosalia@users.noreply.github.com>
Co-authored-by: Mihir Kandoi <kandoimihir@gmail.com>
This commit is contained in:
mergify[bot]
2026-04-07 06:31:51 +00:00
committed by GitHub
parent ee812687e6
commit bcf59e7171
2 changed files with 10 additions and 5 deletions

View File

@@ -74,6 +74,7 @@ class RepostItemValuation(Document):
def validate(self):
self.set_company()
self.validate_update_stock()
self.validate_period_closing_voucher()
self.set_status(write=False)
self.reset_field_values()
@@ -81,6 +82,15 @@ class RepostItemValuation(Document):
self.reset_recreate_stock_ledgers()
self.validate_recreate_stock_ledgers()
def validate_update_stock(self):
if self.voucher_type in ["Sales Invoice", "Purchase Invoice"]:
update_stock = frappe.get_value(self.voucher_type, self.voucher_no, "update_stock")
if not update_stock:
msg = _(
"Since {0} has 'Update Stock' disabled, you cannot create repost item valuation against it"
).format(get_link_to_form(self.voucher_type, self.voucher_no))
frappe.throw(msg)
def validate_recreate_stock_ledgers(self):
if not self.recreate_stock_ledgers:
return

View File

@@ -137,19 +137,14 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin):
item_code="_Test Item",
warehouse="_Test Warehouse - _TC",
based_on="Item and Warehouse",
voucher_type="Sales Invoice",
voucher_no="SI-1",
posting_date="2021-01-02",
posting_time="00:01:00",
)
# new repost without any duplicates
riv1 = frappe.get_doc(riv_args)
riv1.flags.dont_run_in_test = True
riv1.submit()
_assert_status(riv1, "Queued")
self.assertEqual(riv1.voucher_type, "Sales Invoice") # traceability
self.assertEqual(riv1.voucher_no, "SI-1")
# newer than existing duplicate - riv1
riv2 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-03"}))