Skip to content

Commit

Permalink
fix: serial and batch bundle company mandatory error (backport #38994) (
Browse files Browse the repository at this point in the history
#38999)

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

(cherry picked from commit 10074e9)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 28, 2023
1 parent e0755f9 commit d2580be
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"),
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
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


Expand Down Expand Up @@ -420,6 +423,43 @@ def test_auto_delete_draft_serial_and_batch_bundle(self):
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
Expand Down

0 comments on commit d2580be

Please sign in to comment.