fd345f8e90
* [WIP]Hub * [listing] Show items, users and item_groups * Show filters * [start] cart, api for rfq and opp * rfq working * [wip] keys * wip quotes * [hub] register/unregister * [hub] rename password to access_token, remove passed company field * [hub] publishing cases, api call wrapper * [hub] add and remove fields working * [hub] fix flags, update on client save working * [hub] new hub page, client item CUD at hub working * listing, standard rate, local site hack * item listing, item page, search, back to home * [hub] implement hub company * [hub] company filter * [hub] basic rfq-ing, item page cleanup * categories wip * [hub] use get_doc_before_save() * [hub] send opportunity message to hub, api to make locally * [hub] enqueueing in hub api request wrapper * cleanup * [hub] refactor shopping cart's product.py to reuse * sync dynamic item fields daily * Scheduler heartbeat check * [wip] hub categories * [hub] wip enqueued callbacks * [hub] outgoing messages, fixing callback loop * [hub] bug: callback save after primary save * [hub] pricing, stock, currency * [hub] replace send_hub_request with make_and_enqueue * add hub.less, refactor code * Remove template html files, add styling for hub item cards * fix paging * add breadcrumb * Add sidebar * [hub] add company page, change country * [hub] order_by filters * [hub] make hub category a tree * [hub] enqueue batched item enqueueing * [hub] requested products page * [minor] * update hub url * [fix] url * [fix] more reform * fix recursion * [hub] data migration plans as jsons * Hub register, create data connector, sync with run * [add] user registration by session user * Removed hub_message * Remove sync code from hub_settings * Remove hub methods from item.py * Update Hub Sync plan * Hub unregister * Update Hub connector on reregister * Dont delete Hub Connector on unregister * Enable hub on success response * Add new hub whitelisted methods * [hub] list working * Hub register from hub page * [hub] Add hub logo in desk icon, link to page * [hub] hide page head on empty state * [hub] make rfq * [hub] push opportunity doc, poll for opportunity docs * add fields to item mapping * update hub mappings * Make RFQ * [hub] item, home routing * Make rfq and send opportunity refactor * [hub][fix] remote lead data * images passed as base64 * set default company on register * Revert "images passed as base64" This reverts commit 0b033a5fb7072b2d39a1b87a47dc41e7af707bb4. * Add sync to hub page * Prompt for publish items to hub * add post process to hub document to lead * Rename Hub document to Hub message, create opportunity in post process
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
|
from frappe.utils import cint, fmt_money, flt
|
|
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
|
|
|
|
def get_qty_in_stock(item_code, item_warehouse_field):
|
|
in_stock, stock_qty = 0, ''
|
|
template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
|
|
|
|
warehouse = frappe.db.get_value("Item", item_code, item_warehouse_field)
|
|
if not warehouse and template_item_code and template_item_code != item_code:
|
|
warehouse = frappe.db.get_value("Item", template_item_code, item_warehouse_field)
|
|
|
|
if warehouse:
|
|
stock_qty = frappe.db.sql("""select actual_qty from tabBin where
|
|
item_code=%s and warehouse=%s""", (item_code, warehouse))
|
|
if stock_qty:
|
|
in_stock = stock_qty[0][0] > 0 and 1 or 0
|
|
|
|
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty})
|
|
|
|
def get_price(item_code, price_list, customer_group, company, qty=1):
|
|
template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
|
|
|
|
if price_list:
|
|
price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"],
|
|
filters={"price_list": price_list, "item_code": item_code})
|
|
|
|
if template_item_code and not price:
|
|
price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"],
|
|
filters={"price_list": price_list, "item_code": template_item_code})
|
|
|
|
if price:
|
|
pricing_rule = get_pricing_rule_for_item(frappe._dict({
|
|
"item_code": item_code,
|
|
"qty": qty,
|
|
"transaction_type": "selling",
|
|
"price_list": price_list,
|
|
"customer_group": customer_group,
|
|
"company": company,
|
|
"conversion_rate": 1,
|
|
"for_shopping_cart": True
|
|
}))
|
|
|
|
if pricing_rule:
|
|
if pricing_rule.pricing_rule_for == "Discount Percentage":
|
|
price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0)))
|
|
|
|
if pricing_rule.pricing_rule_for == "Price":
|
|
price[0].price_list_rate = pricing_rule.price_list_rate
|
|
|
|
price_obj = price[0]
|
|
if price_obj:
|
|
price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"])
|
|
|
|
price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \
|
|
and (frappe.db.get_value("Currency", price_obj.currency, "symbol") or price_obj.currency) \
|
|
or ""
|
|
|
|
if not price_obj["price_list_rate"]:
|
|
price_obj["price_list_rate"] = 0
|
|
|
|
if not price_obj["currency"]:
|
|
price_obj["currency"] = ""
|
|
|
|
if not price_obj["formatted_price"]:
|
|
price_obj["formatted_price"] = ""
|
|
|
|
return price_obj
|