Compare commits

...

6 Commits

Author SHA1 Message Date
ruthra kumar
ae010cb948 refactor(test): set valuation rate for stocked item
(cherry picked from commit e5b699821f)
2024-10-18 10:46:00 +05:30
ruthra kumar
30c82a0e39 refactor(test): set company on item
(cherry picked from commit 71412a7b7e)
2024-10-18 10:46:00 +05:30
ruthra kumar
c738c1a280 refactor(test): DN should auto-select warehouses based on reservation
(cherry picked from commit 58a879bb39)
2024-10-18 10:46:00 +05:30
ruthra kumar
46ac52eac0 refactor(test): create and reserve stock against 2 diff warehouses
(cherry picked from commit c345c75dca)
2024-10-18 10:46:00 +05:30
ruthra kumar
91540b03a3 test: utilize test mixin and barebones test case
(cherry picked from commit dab6709549)
2024-10-18 10:45:58 +05:30
vishnu
24c84822ac fix: warehouse not mapping correctly during Delivery Note creation.
(cherry picked from commit 3b9f8aa378)
2024-10-18 10:45:36 +05:30
3 changed files with 79 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"):

View File

@@ -1040,6 +1040,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

@@ -55,6 +55,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):
@@ -2119,6 +2120,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")