def get_product_info_for_website(item_code): """get product price / stock info for website""" if not is_cart_enabled(): return {} cart_quotation = _get_cart_quotation() cart_settings = get_shopping_cart_settings() price = get_price( item_code, cart_quotation.selling_price_list, cart_settings.default_customer_group, cart_settings.company ) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1, "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0 } if product_info["price"]: if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: product_info["qty"] = item[0].qty return product_info
def get_product_info_for_website(item_code): """get product price / stock info for website""" cart_quotation = _get_cart_quotation() cart_settings = get_shopping_cart_settings() price = get_price( item_code, cart_quotation.selling_price_list, cart_settings.default_customer_group, cart_settings.company ) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1, "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website(), "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom") } if product_info["price"]: if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: product_info["qty"] = item[0].qty return { "product_info": product_info, "cart_settings": cart_settings }
def place_order(): quotation = _get_cart_quotation() quotation.company = frappe.db.get_value("Shopping Cart Settings", None, "company") if not quotation.get("customer_address"): throw(_("{0} is required").format(_(quotation.meta.get_label("customer_address")))) quotation.flags.ignore_permissions = True quotation.submit() if quotation.lead: # company used to create customer accounts frappe.defaults.set_user_default("company", quotation.company) 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)) sales_order.flags.ignore_permissions = True sales_order.insert() sales_order.submit() if hasattr(frappe.local, "cookie_manager"): frappe.local.cookie_manager.delete_cookie("cart_count") return sales_order.name
def place_order(): quotation = _get_cart_quotation() quotation.company = frappe.db.get_value("Shopping Cart Settings", None, "company") if not quotation.get("customer_address"): throw(_("{0} is required").format(_(quotation.meta.get_label("customer_address")))) quotation.flags.ignore_permissions = True quotation.submit() if quotation.lead: # company used to create customer accounts frappe.defaults.set_user_default("company", quotation.company) 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 = frappe.db.get_value("Item", item.item_code, "website_warehouse") or None 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() sales_order.submit() if hasattr(frappe.local, "cookie_manager"): frappe.local.cookie_manager.delete_cookie("cart_count") return sales_order.name
def adjust_qty_for_expired_items(data): adjusted_data = [] for item in data: if item.get('has_batch_no') and item.get('website_warehouse'): stock_qty_dict = get_qty_in_stock( item.get('name'), 'website_warehouse', item.get('website_warehouse')) qty = stock_qty_dict.stock_qty[0][0] if stock_qty_dict.stock_qty else 0 item['in_stock'] = 1 if qty else 0 adjusted_data.append(item) return adjusted_data
def get_product_info_for_website(item_code, skip_quotation_creation=False): """get product price / stock info for website""" cart_settings = get_shopping_cart_settings() if not cart_settings.enabled: return frappe._dict() cart_quotation = frappe._dict() if not skip_quotation_creation: cart_quotation = _get_cart_quotation() selling_price_list = cart_quotation.get( "selling_price_list") if cart_quotation else _set_price_list( cart_settings, None) price = get_price( item_code, #cart_quotation.selling_price_list, selling_price_list, cart_settings.default_customer_group, cart_settings.company) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock if stock_status.is_stock_item else get_non_stock_item_status(item_code, "website_warehouse"), "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "show_stock_qty": show_quantity_in_website(), "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom") } if product_info["price"]: if frappe.session.user != "Guest": # item = cart_quotation.get({"item_code": item_code}) item = cart_quotation.get({"item_code": item_code }) if cart_quotation else None if item: product_info["qty"] = item[0].qty return frappe._dict({ "product_info": product_info, "cart_settings": cart_settings })
def get_product_info_for_website1(item_code): # custom implementation print(item_code,'--------------------------------------') print(""" = overriden get_product_info_for_website = """) # original cart_settings = get_shopping_cart_settings() if not cart_settings.enabled: return frappe._dict() cart_quotation = _get_cart_quotation() price = get_price( item_code, cart_quotation.selling_price_list, cart_settings.default_customer_group, cart_settings.company ) stock_status = get_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "stock_qty": stock_status.stock_qty, "in_stock": stock_status.in_stock if stock_status.is_stock_item else 1, "qty": 0, "uom": "ll", "show_stock_qty": show_quantity_in_website(), "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom"), "white_list":"ashish" } if product_info["price"]: if frappe.session.user != "Guest": item = cart_quotation.get({"item_code": item_code}) if item: product_info["qty"] = 99999999999 return frappe._dict({ "product_info": product_info, "cart_settings": cart_settings })
def place_order(): quotation = _get_cart_quotation() cart_settings = frappe.db.get_value( "Shopping Cart Settings", None, ["company", "allow_items_not_in_stock"], as_dict=1) quotation.company = cart_settings.company quotation.flags.ignore_permissions = True quotation.submit() if quotation.quotation_to == 'Lead' and quotation.party_name: # company used to create customer accounts frappe.defaults.set_user_default("company", quotation.company) if not (quotation.shipping_address_name or quotation.customer_address): frappe.throw(_("Set Shipping Address or Billing Address")) from erpnext.selling.doctype.quotation.quotation import _make_sales_order sales_order = frappe.get_doc( _make_sales_order(quotation.name, ignore_permissions=True)) sales_order.payment_schedule = [] if not cint(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 not cint(item_stock.in_stock): throw(_("{1} 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)) sales_order.flags.ignore_permissions = True sales_order.insert() sales_order.submit() if hasattr(frappe.local, "cookie_manager"): frappe.local.cookie_manager.delete_cookie("cart_count") return sales_order.name
def check_stock_status(): stock_notification_list = frappe.get_all('Stock Notification', filters={ 'stock_status': 'Out of Stock', 'email_notify': 0 }, fields=['name', 'item_name']) for stock_notification in stock_notification_list: cur_notification = frappe.get_doc('Stock Notification', stock_notification['name']) stock_status = get_qty_in_stock(stock_notification['item_name'], "website_warehouse") if stock_status[0]['in_stock_item'] == 1: cur_notification.update({ 'stock_status': 'In Stock', 'email_notify': 1 }) cur_notification.save(ignore_permissions=True) return ("Operation Completed")
def place_order(delivery_date=None): """ Place an order for items in the shopping cart. Args: delivery_date (date, optional): The delivery date requested by the sales user/customer. Defaults to None. Returns: string: the name of the quotation or the sales order """ #get the quotation in the cart and the cart settings quotation = _get_cart_quotation() cart_settings = frappe.db.get_value( "Shopping Cart Settings", None, [ "company", "allow_items_not_in_stock", 'sales_team_order_without_payment' ], as_dict=1) quotation.company = cart_settings.company quotation.flags.ignore_permissions = True if quotation.quotation_to == 'Lead' and quotation.party_name: # company used to create customer accounts frappe.defaults.set_user_default("company", quotation.company) if not (quotation.shipping_address_name or quotation.customer_address): frappe.throw(_("Set Shipping Address or Billing Address")) # Checking if items in quotation are in stock, if not throw an error if not cint(cart_settings.allow_items_not_in_stock): for item in quotation.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 not cint(item_stock.in_stock): throw(_("{1} Not in Stock").format(item.item_code)) if item.qty > item_stock.stock_qty[0][0]: throw( _("Only {0} in Stock for item {1}: {2}").format( item_stock.stock_qty[0][0], item.item_code, item.item_name)) #if checkout without payment has been enabled, submit the quotation, and convert to sales order if cart_settings.sales_team_order_without_payment: #add the requested delivery date to the quotation and submit the document quotation.requested_delivery_date = getdate(delivery_date) for item in quotation.items: item.requested_delivery_date = getdate(delivery_date) quotation.save(ignore_permissions=True) quotation.submit() frappe.db.commit() #convert the quotation to a sales order from erpnext.selling.doctype.quotation.quotation import _make_sales_order sales_order = frappe.get_doc( _make_sales_order(quotation.name, ignore_permissions=True)) sales_order.payment_schedule = [] sales_order.transaction_date = nowdate() #expected delivery date to the sales order is mapped from the quotation sales_order.flags.ignore_mandatory = True sales_order.flags.ignore_links = True sales_order.insert(ignore_permissions=True) sales_order.submit() return sales_order.name return quotation.name