fix: serial and batch bundle company mandatory error (backport #38994) (backport #38999) (#39003)

fix: serial and batch bundle company mandatory error (backport #38994) (#38999)

fix: serial and batch bundle company mandatory error (#38994)

(cherry picked from commit 10074e9980c8f2a1473827c61c888d970da4b73a)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
(cherry picked from commit d2580be4fd0a08aeddbdbf9b87d99b71a45d7820)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2023-12-28 18:59:20 +05:30 committed by GitHub
parent c4794c95df
commit 027a75bcb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 5 deletions

View File

@ -1145,15 +1145,16 @@ def add_serial_batch_ledgers(entries, child_row, doc, warehouse) -> object:
if isinstance(entries, str):
entries = parse_json(entries)
if doc and isinstance(doc, str):
parent_doc = parse_json(doc)
parent_doc = doc
if parent_doc and isinstance(parent_doc, str):
parent_doc = parse_json(parent_doc)
if frappe.db.exists("Serial and Batch Bundle", child_row.serial_and_batch_bundle):
doc = update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse)
sb_doc = update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse)
else:
doc = create_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse)
sb_doc = create_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse)
return doc
return sb_doc
def create_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse=None) -> object:
@ -1177,6 +1178,7 @@ def create_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse=Non
"type_of_transaction": type_of_transaction,
"posting_date": parent_doc.get("posting_date"),
"posting_time": parent_doc.get("posting_time"),
"company": parent_doc.get("company"),
}
)

View File

@ -8,6 +8,9 @@ from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, add_to_date, flt, nowdate, nowtime, today
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import (
add_serial_batch_ledgers,
)
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
@ -420,6 +423,43 @@ class TestSerialandBatchBundle(FrappeTestCase):
ste.delete()
self.assertFalse(frappe.db.exists("Serial and Batch Bundle", bundle_doc.name))
def test_serial_and_batch_bundle_company(self):
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
item = make_item(
properties={
"has_serial_no": 1,
"serial_no_series": "TT-SER-VAL-.#####",
}
)
pr = make_purchase_receipt(
item_code=item,
warehouse="_Test Warehouse - _TC",
qty=3,
rate=500,
do_not_submit=True,
)
entries = []
for serial_no in ["TT-SER-VAL-00001", "TT-SER-VAL-00002", "TT-SER-VAL-00003"]:
entries.append(frappe._dict({"serial_no": serial_no, "qty": 1}))
if not frappe.db.exists("Serial No", serial_no):
frappe.get_doc(
{
"doctype": "Serial No",
"serial_no": serial_no,
"item_code": item,
}
).insert(ignore_permissions=True)
item_row = pr.items[0]
item_row.type_of_transaction = "Inward"
item_row.is_rejected = 0
sn_doc = add_serial_batch_ledgers(entries, item_row, pr, "_Test Warehouse - _TC")
self.assertEqual(sn_doc.company, "_Test Company")
def get_batch_from_bundle(bundle):
from erpnext.stock.serial_batch_bundle import get_batch_nos