Merge pull request #42809 from Vishnu7025/fix_so

fix: warehouse not mapping correctly during Delivery Note creation.
This commit is contained in:
ruthra kumar
2024-09-16 11:01:12 +05:30
committed by GitHub
3 changed files with 87 additions and 2 deletions

View File

@@ -32,8 +32,14 @@ class AccountsTestMixin:
else:
self.supplier = supplier_name
def create_item(self, item_name="_Test Item", is_stock=0, warehouse=None, company=None):
item = create_item(item_name, is_stock_item=is_stock, warehouse=warehouse, company=company)
def create_item(self, item_name="_Test Item", is_stock=0, warehouse=None, company=None, valuation_rate=0):
item = create_item(
item_name,
is_stock_item=is_stock,
warehouse=warehouse,
company=company,
valuation_rate=valuation_rate,
)
self.item = item.name
def create_company(self, company_name="_Test Company", abbr="_TC"):
@@ -104,6 +110,14 @@ class AccountsTestMixin:
new_acc.save()
setattr(self, acc.attribute_name, new_acc.name)
self.identify_default_warehouses()
def identify_default_warehouses(self):
for w in frappe.db.get_all(
"Warehouse", filters={"company": self.company}, fields=["name", "warehouse_name"]
):
setattr(self, "warehouse_" + w.warehouse_name.lower().strip().replace(" ", "_"), w.name)
def create_usd_receivable_account(self):
account_name = "Debtors USD"
if not frappe.db.get_value(

View File

@@ -1047,6 +1047,7 @@ def make_delivery_note(source_name, target_doc=None, kwargs=None):
)
dn_item.qty = flt(sre.reserved_qty) * flt(dn_item.get("conversion_factor", 1))
dn_item.warehouse = sre.warehouse
if sre.reservation_based_on == "Serial and Batch" and (sre.has_serial_no or sre.has_batch_no):
dn_item.serial_and_batch_bundle = get_ssb_bundle_for_voucher(sre)

View File

@@ -53,6 +53,7 @@ class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
self.create_customer("_Test Customer Credit")
def tearDown(self):
frappe.db.rollback()
frappe.set_user("Administrator")
def test_sales_order_with_negative_rate(self):
@@ -2197,6 +2198,75 @@ class TestSalesOrder(AccountsTestMixin, FrappeTestCase):
self.assertRaises(frappe.ValidationError, so1.update_status, "Draft")
@change_settings("Stock Settings", {"enable_stock_reservation": True})
def test_warehouse_mapping_based_on_stock_reservation(self):
self.create_company(company_name="Glass Ceiling", abbr="GC")
self.create_item("Lamy Safari 2", True, self.warehouse_stores, self.company, 2000)
self.create_customer()
self.clear_old_entries()
so = frappe.new_doc("Sales Order")
so.company = self.company
so.customer = self.customer
so.transaction_date = today()
so.append(
"items",
{
"item_code": self.item,
"qty": 10,
"rate": 2000,
"warehouse": self.warehouse_stores,
"delivery_date": today(),
},
)
so.submit()
# Create stock
se = frappe.get_doc(
{
"doctype": "Stock Entry",
"company": self.company,
"stock_entry_type": "Material Receipt",
"posting_date": today(),
"items": [
{"item_code": self.item, "t_warehouse": self.warehouse_stores, "qty": 5},
{"item_code": self.item, "t_warehouse": self.warehouse_finished_goods, "qty": 5},
],
}
)
se.submit()
# Reserve stock on 2 different warehouses
itm = so.items[0]
so.create_stock_reservation_entries(
[
{
"sales_order_item": itm.name,
"item_code": itm.item_code,
"warehouse": self.warehouse_stores,
"qty_to_reserve": 2,
}
]
)
so.create_stock_reservation_entries(
[
{
"sales_order_item": itm.name,
"item_code": itm.item_code,
"warehouse": self.warehouse_finished_goods,
"qty_to_reserve": 3,
}
]
)
# Delivery note should auto-select warehouse based on reservation
dn = make_delivery_note(so.name, kwargs={"for_reserved_stock": True})
self.assertEqual(2, len(dn.items))
self.assertEqual(dn.items[0].qty, 2)
self.assertEqual(dn.items[0].warehouse, self.warehouse_stores)
self.assertEqual(dn.items[1].qty, 3)
self.assertEqual(dn.items[1].warehouse, self.warehouse_finished_goods)
def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")