mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 20:29:09 +00:00
fix: allow to select parent warehouse in the website item (#37047)
(cherry picked from commit e6199dc802)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -312,7 +312,7 @@ class TestWebsiteItem(unittest.TestCase):
|
||||
# check if stock details are fetched and item not in stock with warehouse set
|
||||
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
|
||||
self.assertFalse(bool(data.product_info["in_stock"]))
|
||||
self.assertEqual(data.product_info["stock_qty"][0][0], 0)
|
||||
self.assertEqual(data.product_info["stock_qty"], 0)
|
||||
|
||||
# disable show stock availability
|
||||
setup_e_commerce_settings({"show_stock_availability": 0})
|
||||
@@ -355,7 +355,7 @@ class TestWebsiteItem(unittest.TestCase):
|
||||
# check if stock details are fetched and item is in stock with warehouse set
|
||||
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
|
||||
self.assertTrue(bool(data.product_info["in_stock"]))
|
||||
self.assertEqual(data.product_info["stock_qty"][0][0], 2)
|
||||
self.assertEqual(data.product_info["stock_qty"], 2)
|
||||
|
||||
# unset warehouse
|
||||
frappe.db.set_value("Website Item", {"item_code": item_code}, "website_warehouse", "")
|
||||
@@ -364,7 +364,7 @@ class TestWebsiteItem(unittest.TestCase):
|
||||
# (even though it has stock in some warehouse)
|
||||
data = get_product_info_for_website(item_code, skip_quotation_creation=True)
|
||||
self.assertFalse(bool(data.product_info["in_stock"]))
|
||||
self.assertFalse(bool(data.product_info["stock_qty"]))
|
||||
self.assertFalse(data.product_info["stock_qty"])
|
||||
|
||||
# disable show stock availability
|
||||
setup_e_commerce_settings({"show_stock_availability": 0})
|
||||
|
||||
@@ -5,12 +5,6 @@ frappe.ui.form.on('Website Item', {
|
||||
onload: (frm) => {
|
||||
// should never check Private
|
||||
frm.fields_dict["website_image"].df.is_private = 0;
|
||||
|
||||
frm.set_query("website_warehouse", () => {
|
||||
return {
|
||||
filters: {"is_group": 0}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: (frm) => {
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"description": "Show Stock availability based on this warehouse.",
|
||||
"description": "Show Stock availability based on this warehouse. If the parent warehouse is selected, then the system will display the consolidated available quantity of all child warehouses.",
|
||||
"fieldname": "website_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
@@ -348,7 +348,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"make_attachments_public": 1,
|
||||
"modified": "2022-09-30 04:01:52.090732",
|
||||
"modified": "2023-09-12 14:19:22.822689",
|
||||
"modified_by": "Administrator",
|
||||
"module": "E-commerce",
|
||||
"name": "Website Item",
|
||||
|
||||
@@ -259,6 +259,10 @@ class ProductQuery:
|
||||
)
|
||||
|
||||
def get_stock_availability(self, item):
|
||||
from erpnext.templates.pages.wishlist import (
|
||||
get_stock_availability as get_stock_availability_from_template,
|
||||
)
|
||||
|
||||
"""Modify item object and add stock details."""
|
||||
item.in_stock = False
|
||||
warehouse = item.get("website_warehouse")
|
||||
@@ -274,11 +278,7 @@ class ProductQuery:
|
||||
else:
|
||||
item.in_stock = True
|
||||
elif warehouse:
|
||||
# stock item and has warehouse
|
||||
actual_qty = frappe.db.get_value(
|
||||
"Bin", {"item_code": item.item_code, "warehouse": item.get("website_warehouse")}, "actual_qty"
|
||||
)
|
||||
item.in_stock = bool(flt(actual_qty))
|
||||
item.in_stock = get_stock_availability_from_template(item.item_code, warehouse)
|
||||
|
||||
def get_cart_items(self):
|
||||
customer = get_customer(silent=True)
|
||||
|
||||
@@ -111,8 +111,8 @@ def place_order():
|
||||
item_stock = get_web_item_qty_in_stock(item.item_code, "website_warehouse")
|
||||
if not cint(item_stock.in_stock):
|
||||
throw(_("{0} Not in Stock").format(item.item_code))
|
||||
if item.qty > item_stock.stock_qty[0][0]:
|
||||
throw(_("Only {0} in Stock for item {1}").format(item_stock.stock_qty[0][0], item.item_code))
|
||||
if item.qty > item_stock.stock_qty:
|
||||
throw(_("Only {0} in Stock for item {1}").format(item_stock.stock_qty, item.item_code))
|
||||
|
||||
sales_order.flags.ignore_permissions = True
|
||||
sales_order.insert()
|
||||
@@ -150,6 +150,10 @@ def update_cart(item_code, qty, additional_notes=None, with_items=False):
|
||||
empty_card = True
|
||||
|
||||
else:
|
||||
warehouse = frappe.get_cached_value(
|
||||
"Website Item", {"item_code": item_code}, "website_warehouse"
|
||||
)
|
||||
|
||||
quotation_items = quotation.get("items", {"item_code": item_code})
|
||||
if not quotation_items:
|
||||
quotation.append(
|
||||
@@ -159,11 +163,13 @@ def update_cart(item_code, qty, additional_notes=None, with_items=False):
|
||||
"item_code": item_code,
|
||||
"qty": qty,
|
||||
"additional_notes": additional_notes,
|
||||
"warehouse": warehouse,
|
||||
},
|
||||
)
|
||||
else:
|
||||
quotation_items[0].qty = qty
|
||||
quotation_items[0].additional_notes = additional_notes
|
||||
quotation_items[0].warehouse = warehouse
|
||||
|
||||
apply_cart_settings(quotation=quotation)
|
||||
|
||||
@@ -322,6 +328,10 @@ def decorate_quotation_doc(doc):
|
||||
fields = fields[2:]
|
||||
|
||||
d.update(frappe.db.get_value("Website Item", {"item_code": item_code}, fields, as_dict=True))
|
||||
website_warehouse = frappe.get_cached_value(
|
||||
"Website Item", {"item_code": item_code}, "website_warehouse"
|
||||
)
|
||||
d.warehouse = website_warehouse
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
@@ -104,6 +104,8 @@ def get_attributes_and_values(item_code):
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_next_attribute_and_values(item_code, selected_attributes):
|
||||
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
|
||||
|
||||
"""Find the count of Items that match the selected attributes.
|
||||
Also, find the attribute values that are not applicable for further searching.
|
||||
If less than equal to 10 items are found, return item_codes of those items.
|
||||
@@ -168,7 +170,7 @@ def get_next_attribute_and_values(item_code, selected_attributes):
|
||||
product_info = None
|
||||
|
||||
product_id = ""
|
||||
website_warehouse = ""
|
||||
warehouse = ""
|
||||
if exact_match or filtered_items:
|
||||
if exact_match and len(exact_match) == 1:
|
||||
product_id = exact_match[0]
|
||||
@@ -176,16 +178,19 @@ def get_next_attribute_and_values(item_code, selected_attributes):
|
||||
product_id = list(filtered_items)[0]
|
||||
|
||||
if product_id:
|
||||
website_warehouse = frappe.get_cached_value(
|
||||
warehouse = frappe.get_cached_value(
|
||||
"Website Item", {"item_code": product_id}, "website_warehouse"
|
||||
)
|
||||
|
||||
available_qty = 0.0
|
||||
if website_warehouse:
|
||||
available_qty = flt(
|
||||
frappe.db.get_value(
|
||||
"Bin", {"item_code": product_id, "warehouse": website_warehouse}, "actual_qty"
|
||||
)
|
||||
if warehouse and frappe.get_cached_value("Warehouse", warehouse, "is_group") == 1:
|
||||
warehouses = get_child_warehouses(warehouse)
|
||||
else:
|
||||
warehouses = [warehouse] if warehouse else []
|
||||
|
||||
for warehouse in warehouses:
|
||||
available_qty += flt(
|
||||
frappe.db.get_value("Bin", {"item_code": product_id, "warehouse": warehouse}, "actual_qty")
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user