Skip to content

Commit

Permalink
fix: auto delete draft serial and batch bundle (backport #38637) (#38654
Browse files Browse the repository at this point in the history
)

fix: auto delete draft serial and batch bundle (#38637)

(cherry picked from commit 89326bd)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 10, 2023
1 parent 4150ed9 commit b0675f6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def _remove_references_in_repost_doctypes(self):
def on_trash(self):
self._remove_references_in_repost_doctypes()
self._remove_references_in_unreconcile()
self.remove_serial_and_batch_bundle()

# delete sl and gl entries on deletion of transaction
if frappe.db.get_single_value("Accounts Settings", "delete_linked_ledger_entries"):
Expand All @@ -307,6 +308,15 @@ def on_trash(self):
(self.doctype, self.name),
)

def remove_serial_and_batch_bundle(self):
bundles = frappe.get_all(
"Serial and Batch Bundle",
filters={"voucher_type": self.doctype, "voucher_no": self.name, "docstatus": ("!=", 1)},
)

for bundle in bundles:
frappe.delete_doc("Serial and Batch Bundle", bundle.name)

def validate_deferred_income_expense_account(self):
field_map = {
"Sales Invoice": "deferred_revenue_account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,58 @@ def test_batch_not_belong_to_serial_no(self):
# Batch does not belong to serial no
self.assertRaises(frappe.exceptions.ValidationError, doc.save)

def test_auto_delete_draft_serial_and_batch_bundle(self):
serial_and_batch_code = "New Serial No Auto Delete 1"
make_item(
serial_and_batch_code,
{
"has_serial_no": 1,
"serial_no_series": "TEST-SER-VALL-.#####",
"is_stock_item": 1,
},
)

ste = make_stock_entry(
item_code=serial_and_batch_code,
target="_Test Warehouse - _TC",
qty=1,
rate=500,
do_not_submit=True,
)

serial_no = "SN-TEST-AUTO-DEL"
if not frappe.db.exists("Serial No", serial_no):
frappe.get_doc(
{
"doctype": "Serial No",
"serial_no": serial_no,
"item_code": serial_and_batch_code,
"company": "_Test Company",
}
).insert(ignore_permissions=True)

bundle_doc = make_serial_batch_bundle(
{
"item_code": serial_and_batch_code,
"warehouse": "_Test Warehouse - _TC",
"voucher_type": "Stock Entry",
"posting_date": ste.posting_date,
"posting_time": ste.posting_time,
"qty": 1,
"serial_nos": [serial_no],
"type_of_transaction": "Inward",
"do_not_submit": True,
}
)

bundle_doc.reload()
ste.items[0].serial_and_batch_bundle = bundle_doc.name
ste.save()
ste.reload()

ste.delete()
self.assertFalse(frappe.db.exists("Serial and Batch Bundle", bundle_doc.name))


def get_batch_from_bundle(bundle):
from erpnext.stock.serial_batch_bundle import get_batch_nos
Expand Down

0 comments on commit b0675f6

Please sign in to comment.