fix: auto delete draft serial and batch bundle (#38637) (cherry picked from commit 89326bd657217b82e14675ebb464b87214332eec) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
4150ed9b3b
commit
b0675f6490
@ -292,6 +292,7 @@ class AccountsController(TransactionBase):
|
|||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self._remove_references_in_repost_doctypes()
|
self._remove_references_in_repost_doctypes()
|
||||||
self._remove_references_in_unreconcile()
|
self._remove_references_in_unreconcile()
|
||||||
|
self.remove_serial_and_batch_bundle()
|
||||||
|
|
||||||
# delete sl and gl entries on deletion of transaction
|
# delete sl and gl entries on deletion of transaction
|
||||||
if frappe.db.get_single_value("Accounts Settings", "delete_linked_ledger_entries"):
|
if frappe.db.get_single_value("Accounts Settings", "delete_linked_ledger_entries"):
|
||||||
@ -307,6 +308,15 @@ class AccountsController(TransactionBase):
|
|||||||
(self.doctype, self.name),
|
(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):
|
def validate_deferred_income_expense_account(self):
|
||||||
field_map = {
|
field_map = {
|
||||||
"Sales Invoice": "deferred_revenue_account",
|
"Sales Invoice": "deferred_revenue_account",
|
||||||
|
@ -368,6 +368,58 @@ class TestSerialandBatchBundle(FrappeTestCase):
|
|||||||
# Batch does not belong to serial no
|
# Batch does not belong to serial no
|
||||||
self.assertRaises(frappe.exceptions.ValidationError, doc.save)
|
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):
|
def get_batch_from_bundle(bundle):
|
||||||
from erpnext.stock.serial_batch_bundle import get_batch_nos
|
from erpnext.stock.serial_batch_bundle import get_batch_nos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user