def get_mapped_product(item_doc): wc_product_category_id = frappe.db.get_value("Item Group", item_doc.item_group, "woocommerce_id_za") woo_settings = frappe.get_doc("Woocommerce Settings") shopping_cart_settings = frappe.get_doc("Shopping Cart Settings") item_price = get_price(item_doc.item_code, woo_settings.price_list, shopping_cart_settings.default_customer_group, woo_settings.company) if woo_settings.promo_price_list: promo = get_price(item_doc.item_code, woo_settings.promo_price_list, shopping_cart_settings.default_customer_group, woo_settings.company) print("settings : %s %s" % (woo_settings.warehouse or '', item_price)) warehouse = woo_settings.warehouse qty = get_latest_stock_qty(item_doc.item_code, warehouse) or 0 product = { "featured": item_doc.is_featured, "type": "simple", "weight": str(item_doc.weight_per_unit or "0"), "sku": item_doc.ugs, "manage_stock": item_doc.is_stock_item, "stock_quantity": qty, "regular_price": item_price and cstr(item_price["price_list_rate"]) or "", "sale_price": promo and cstr(promo["price_list_rate"]) or "", "description": item_doc.description, "short_description": item_doc.description, "name": item_doc.item_name, "categories": [{ "id": wc_product_category_id }], #"images":{} #"images": [ # { # "src": "{}/{}".format(frappe.utils.get_url(), item_doc.image) if (item_doc.image and ' ' not in item_doc.image) else "" # "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" # } #] } if item_doc.image and item_doc.send_product_image_again: product['images'] = [{ "src": "{}/{}".format(frappe.utils.get_url(), item_doc.image) if (item_doc.image and ' ' not in item_doc.image) else "" # "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }] frappe.db.set_value("Item", item_doc.item_code, "send_product_image_again", 0) if item_doc.woocommerce_id: product["id"] = item_doc.woocommerce_id return product
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 get_recommended_items(self, settings): items = frappe.db.sql(f""" select ri.website_item_thumbnail, ri.website_item_name, ri.route, ri.item_code from `tabRecommended Items` ri, `tabWebsite Item` wi where ri.item_code = wi.item_code and ri.parent = '{self.name}' and wi.published = 1 order by ri.idx """, as_dict=1) if settings.show_price: is_guest = frappe.session.user == "Guest" # Show Price if logged in. # If not logged in and price is hidden for guest, skip price fetch. if is_guest and settings.hide_price_for_guest: return items selling_price_list = _set_price_list(settings, None) for item in items: item.price_info = get_price(item.item_code, selling_price_list, settings.default_customer_group, settings.company) return items
def get_spare_price(item_code, price_list, customer_group="All Customer Groups", company=None): price = get_price(item_code, price_list, customer_group, company) if not price: price = frappe._dict({'price_list_rate': 0.0}) return price
def get_spare_price(item_code, price_list, customer_group="All Customer Groups", company="ROOP DYES & INTERMEDIATES"): price = get_price(item_code, price_list, customer_group, company) if not price: price = frappe._dict({'price_list_rate': 0.0}) return price
def get_item_rate(item,customer): price_list = frappe.db.get_value("Customer", customer, "default_price_list") customer_group = frappe.db.get_value("Customer", customer, "customer_group") company = frappe.db.get_single_value('Global Defaults', 'default_company') rate = get_price(item,price_list,customer_group,company) if rate: return rate["price_list_rate"]
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_plan_rate(plan, quantity=1, customer=None, start_date=None, end_date=None, prorate_factor=1): plan = frappe.get_doc("Subscription Plan", plan) if plan.price_determination == "Fixed Rate": return plan.cost * prorate_factor elif plan.price_determination == "Based On Price List": if customer: customer_group = frappe.db.get_value("Customer", customer, "customer_group") else: customer_group = None price = get_price(item_code=plan.item, price_list=plan.price_list, customer_group=customer_group, company=None, qty=quantity) if not price: return 0 else: return price.price_list_rate * prorate_factor elif plan.price_determination == 'Monthly Rate': start_date = getdate(start_date) end_date = getdate(end_date) no_of_months = (end_date.year - start_date.year) * 12 + ( end_date.month - start_date.month) + 1 cost = plan.cost * no_of_months # Adjust cost if start or end date is not month start or end prorate = frappe.db.get_single_value('Subscription Settings', 'prorate') if prorate: prorate_factor = flt( date_diff(start_date, get_first_day(start_date)) / date_diff(get_last_day(start_date), get_first_day(start_date)), 1) prorate_factor += flt( date_diff(get_last_day(end_date), end_date) / date_diff(get_last_day(end_date), get_first_day(end_date)), 1) cost -= (plan.cost * prorate_factor) return cost
def get_item_variant_price_dict(item_code, cart_settings): if cart_settings.enabled and cart_settings.show_price: is_guest = frappe.session.user == "Guest" # Show Price if logged in. # If not logged in, check if price is hidden for guest. if not is_guest or not cart_settings.hide_price_for_guest: price_list = _set_price_list(cart_settings, None) price = get_price(item_code, price_list, cart_settings.default_customer_group, cart_settings.company) return {"price": price} return None
def get_slot_price(item_code, qty, price_list=None): from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings from erpnext.utilities.product import get_price settings = get_shopping_cart_settings() if not price_list: price_list = settings.price_list price = get_price(item_code, price_list, settings.default_customer_group, settings.company, qty) return fmt_money(float(price.price_list_rate) * float(qty), currency=price.currency)
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 fn(item_code): price_obj = (get_price( item_code, price_list, customer_group=frappe.get_cached_value("Selling Settings", None, "customer_group"), company=frappe.defaults.get_global_default("company"), ) or {}) price_list_rate = item_prices.get(item_code, {}).get("price_list_rate") item_price = price_obj.get("price_list_rate") or price_list_rate return { "price_list_rate": item_price, "slashed_rate": price_list_rate if price_list_rate != item_price else None, }
def get_plan_rate(plan, quantity=1, customer=None): plan = frappe.get_doc("Subscription Plan", plan) if plan.price_determination == "Fixed rate": return plan.cost elif plan.price_determination == "Based on price list": if customer: customer_group = frappe.db.get_value("Customer", customer, "customer_group") else: customer_group = None price = get_price(item_code=plan.item, price_list=plan.price_list, customer_group=customer_group, company=None, qty=quantity) if not price: return 0 else: return price.price_list_rate
def get_item_price(item_code, uom): cart_settings = get_shopping_cart_settings() if not cart_settings.enabled: return frappe._dict() cart_quotation = _get_cart_quotation() price = get_price(item_code=item_code, price_list=cart_quotation.selling_price_list, customer_group=cart_settings.default_customer_group, company=cart_settings.company, uom=uom) return { "item_name": frappe.db.get_value("Item", item_code, "item_name"), "price": price }
def set_stock_price_details(items, settings, selling_price_list): for item in items: if settings.show_stock_availability: item.available = get_stock_availability(item.item_code, item.get("warehouse")) price_details = get_price(item.item_code, selling_price_list, settings.default_customer_group, settings.company) if price_details: item.formatted_price = price_details.get('formatted_price') item.formatted_mrp = price_details.get('formatted_mrp') if item.formatted_mrp: item.discount = price_details.get('formatted_discount_percent') or \ price_details.get('formatted_discount_rate') return items
def get_plan_rate(plan, quantity=1, customer=None): plan = frappe.get_doc("Subscription Plan", plan) if plan.price_determination == "Fixed rate": return plan.cost elif plan.price_determination == "Based on price list": if customer: customer_group = frappe.db.get_value("Customer", customer, "customer_group") else: customer_group = None price = get_price(item_code=plan.item, price_list=plan.price_list, customer_group=customer_group, company=None, qty=quantity) if not price: return 0 else: return price.price_list_rate
def get_mapped_product(item_doc): wc_product_category_id = frappe.db.get_value("Item Group", item_doc.item_group, "woocommerce_id_za") shopping_cart_settings = frappe.get_doc("Shopping Cart Settings") item_price = get_price(item_doc.item_code, shopping_cart_settings.price_list, shopping_cart_settings.default_customer_group, shopping_cart_settings.company) product = { "name": item_doc.item_name, "type": "simple", "regular_price": item_price and cstr(item_price["price_list_rate"]) or "", "description": item_doc.description, "short_description": item_doc.description, "categories": [{ "id": wc_product_category_id }], "images": [{ "src": "{}/{}".format(frappe.utils.get_url(), item_doc.image) if (item_doc.image and ' ' not in item_doc.image) else "" # "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }] } if item_doc.woocommerce_id: product["id"] = item_doc.woocommerce_id return product
def get_item_price(item_code, price_list, customer_group, company, qty=1): price = get_price(item_code, price_list, customer_group, company, qty) return price
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 settings even if cart is disabled return frappe._dict({ "product_info": {}, "cart_settings": cart_settings }) 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 = {} if cart_settings.show_price: is_guest = frappe.session.user == "Guest" # Show Price if logged in. # If not logged in, check if price is hidden for guest. if not is_guest or not cart_settings.hide_price_for_guest: price = get_price(item_code, selling_price_list, cart_settings.default_customer_group, cart_settings.company) stock_status = None if cart_settings.show_stock_availability: on_backorder = frappe.get_cached_value("Website Item", {"item_code": item_code}, "on_backorder") if on_backorder: stock_status = frappe._dict({"on_backorder": True}) else: stock_status = get_web_item_qty_in_stock(item_code, "website_warehouse") product_info = { "price": price, "qty": 0, "uom": frappe.db.get_value("Item", item_code, "stock_uom"), "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom"), } if stock_status: if stock_status.on_backorder: product_info["on_backorder"] = True else: product_info["stock_qty"] = stock_status.stock_qty product_info["in_stock"] = ( stock_status.in_stock if stock_status.is_stock_item else get_non_stock_item_status(item_code, "website_warehouse")) product_info["show_stock_qty"] = show_quantity_in_website() if product_info["price"]: if frappe.session.user != "Guest": 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 })