Merge pull request #17185 from netchampfaris/allow-items-not-in-stock

feat: Allow items not in stock to be added in cart
This commit is contained in:
Nabin Hait
2019-04-15 10:07:49 +05:30
committed by GitHub
3 changed files with 72 additions and 13 deletions

View File

@@ -51,7 +51,9 @@ def get_cart_quotation(doc=None):
@frappe.whitelist()
def place_order():
quotation = _get_cart_quotation()
quotation.company = frappe.db.get_value("Shopping Cart Settings", None, "company")
cart_settings = frappe.db.get_value("Shopping Cart Settings", None,
["company", "allow_items_not_in_stock"], as_dict=1)
quotation.company = cart_settings.company
if not quotation.get("customer_address"):
throw(_("{0} is required").format(_(quotation.meta.get_label("customer_address"))))
@@ -64,14 +66,16 @@ def place_order():
from erpnext.selling.doctype.quotation.quotation import _make_sales_order
sales_order = frappe.get_doc(_make_sales_order(quotation.name, ignore_permissions=True))
for item in sales_order.get("items"):
item.reserved_warehouse, is_stock_item = frappe.db.get_value("Item",
item.item_code, ["website_warehouse", "is_stock_item"])
if is_stock_item:
item_stock = get_qty_in_stock(item.item_code, "website_warehouse")
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 not cart_settings.allow_items_not_in_stock:
for item in sales_order.get("items"):
item.reserved_warehouse, is_stock_item = frappe.db.get_value("Item",
item.item_code, ["website_warehouse", "is_stock_item"])
if is_stock_item:
item_stock = get_qty_in_stock(item.item_code, "website_warehouse")
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))
sales_order.flags.ignore_permissions = True
sales_order.insert()

View File

@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
@@ -19,6 +20,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "enabled",
"fieldtype": "Check",
"hidden": 0,
@@ -51,6 +53,7 @@
"collapsible": 0,
"columns": 0,
"description": "",
"fetch_if_empty": 0,
"fieldname": "display_settings",
"fieldtype": "Section Break",
"hidden": 0,
@@ -84,6 +87,7 @@
"collapsible": 0,
"columns": 0,
"description": "",
"fetch_if_empty": 0,
"fieldname": "show_attachments",
"fieldtype": "Check",
"hidden": 0,
@@ -118,6 +122,7 @@
"columns": 0,
"depends_on": "eval:doc.enabled==0",
"description": "",
"fetch_if_empty": 0,
"fieldname": "show_price",
"fieldtype": "Check",
"hidden": 0,
@@ -150,6 +155,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break_5",
"fieldtype": "Column Break",
"hidden": 0,
@@ -181,6 +187,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "show_stock_availability",
"fieldtype": "Check",
"hidden": 0,
@@ -214,6 +221,7 @@
"collapsible": 0,
"columns": 0,
"depends_on": "show_stock_availability",
"fetch_if_empty": 0,
"fieldname": "show_quantity_in_website",
"fieldtype": "Check",
"hidden": 0,
@@ -246,6 +254,40 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "allow_items_not_in_stock",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Allow items not in stock to be added to cart",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "section_break_2",
"fieldtype": "Section Break",
"hidden": 0,
@@ -276,6 +318,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "company",
"fieldtype": "Link",
"hidden": 0,
@@ -309,6 +352,7 @@
"collapsible": 0,
"columns": 0,
"description": "Prices will not be shown if Price List is not set",
"fetch_if_empty": 0,
"fieldname": "price_list",
"fieldtype": "Link",
"hidden": 0,
@@ -342,6 +386,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break_4",
"fieldtype": "Column Break",
"hidden": 0,
@@ -373,6 +418,7 @@
"collapsible": 0,
"columns": 0,
"description": "",
"fetch_if_empty": 0,
"fieldname": "default_customer_group",
"fieldtype": "Link",
"hidden": 0,
@@ -405,6 +451,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "quotation_series",
"fieldtype": "Select",
"hidden": 0,
@@ -437,6 +484,7 @@
"collapsible": 1,
"collapsible_depends_on": "eval:doc.enable_checkout",
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "section_break_8",
"fieldtype": "Section Break",
"hidden": 0,
@@ -469,6 +517,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "enable_checkout",
"fieldtype": "Check",
"hidden": 0,
@@ -503,6 +552,7 @@
"columns": 0,
"default": "Orders",
"description": "After payment completion redirect user to selected page.",
"fetch_if_empty": 0,
"fieldname": "payment_success_url",
"fieldtype": "Select",
"hidden": 0,
@@ -536,6 +586,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "column_break_11",
"fieldtype": "Column Break",
"hidden": 0,
@@ -567,6 +618,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fetch_if_empty": 0,
"fieldname": "payment_gateway_account",
"fieldtype": "Link",
"hidden": 0,
@@ -605,8 +657,8 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2018-05-31 03:11:58.911732",
"modified_by": "sushant@digithinkit.com",
"modified": "2019-04-09 18:29:43.270862",
"modified_by": "Administrator",
"module": "Shopping Cart",
"name": "Shopping Cart Settings",
"owner": "Administrator",
@@ -637,5 +689,6 @@
"show_name_in_global_search": 0,
"sort_order": "ASC",
"track_changes": 0,
"track_seen": 0
}
"track_seen": 0,
"track_views": 0
}

View File

@@ -14,7 +14,9 @@ frappe.ready(function() {
callback: function(r) {
if(r.message) {
if(r.message.cart_settings.enabled) {
$(".item-cart, .item-price, .item-stock").toggleClass("hide", (!!!r.message.product_info.price || !!!r.message.product_info.in_stock));
let hide_add_to_cart = !r.message.product_info.price
|| (!r.message.product_info.in_stock && !r.message.cart_settings.allow_items_not_in_stock);
$(".item-cart, .item-price, .item-stock").toggleClass('hide', hide_add_to_cart);
}
if(r.message.cart_settings.show_price) {
$(".item-price").toggleClass("hide", false);