style: format code with black
This commit is contained in:
@@ -9,32 +9,41 @@ from erpnext.stock.doctype.batch.batch import get_batch_qty
|
||||
|
||||
|
||||
def get_web_item_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
|
||||
in_stock, stock_qty = 0, ''
|
||||
template_item_code, is_stock_item = frappe.db.get_value("Item", item_code, ["variant_of", "is_stock_item"])
|
||||
in_stock, stock_qty = 0, ""
|
||||
template_item_code, is_stock_item = frappe.db.get_value(
|
||||
"Item", item_code, ["variant_of", "is_stock_item"]
|
||||
)
|
||||
|
||||
if not warehouse:
|
||||
warehouse = frappe.db.get_value("Website Item", {"item_code": item_code}, item_warehouse_field)
|
||||
|
||||
if not warehouse and template_item_code and template_item_code != item_code:
|
||||
warehouse = frappe.db.get_value("Website Item", {"item_code": template_item_code}, item_warehouse_field)
|
||||
warehouse = frappe.db.get_value(
|
||||
"Website Item", {"item_code": template_item_code}, item_warehouse_field
|
||||
)
|
||||
|
||||
if warehouse:
|
||||
stock_qty = frappe.db.sql("""
|
||||
stock_qty = frappe.db.sql(
|
||||
"""
|
||||
select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
|
||||
from tabBin S
|
||||
inner join `tabItem` I on S.item_code = I.Item_code
|
||||
left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
|
||||
where S.item_code=%s and S.warehouse=%s""", (item_code, warehouse))
|
||||
where S.item_code=%s and S.warehouse=%s""",
|
||||
(item_code, warehouse),
|
||||
)
|
||||
|
||||
if stock_qty:
|
||||
stock_qty = adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
|
||||
in_stock = stock_qty[0][0] > 0 and 1 or 0
|
||||
|
||||
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item})
|
||||
return frappe._dict(
|
||||
{"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item}
|
||||
)
|
||||
|
||||
|
||||
def adjust_qty_for_expired_items(item_code, stock_qty, warehouse):
|
||||
batches = frappe.get_all('Batch', filters=[{'item': item_code}], fields=['expiry_date', 'name'])
|
||||
batches = frappe.get_all("Batch", filters=[{"item": item_code}], fields=["expiry_date", "name"])
|
||||
expired_batches = get_expired_batches(batches)
|
||||
stock_qty = [list(item) for item in stock_qty]
|
||||
|
||||
@@ -67,33 +76,42 @@ def qty_from_all_warehouses(batch_info):
|
||||
|
||||
return qty
|
||||
|
||||
|
||||
def get_price(item_code, price_list, customer_group, company, qty=1):
|
||||
from erpnext.e_commerce.shopping_cart.cart import get_party
|
||||
|
||||
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})
|
||||
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})
|
||||
price = frappe.get_all(
|
||||
"Item Price",
|
||||
fields=["price_list_rate", "currency"],
|
||||
filters={"price_list": price_list, "item_code": template_item_code},
|
||||
)
|
||||
|
||||
if price:
|
||||
party = get_party()
|
||||
pricing_rule_dict = frappe._dict({
|
||||
"item_code": item_code,
|
||||
"qty": qty,
|
||||
"stock_qty": qty,
|
||||
"transaction_type": "selling",
|
||||
"price_list": price_list,
|
||||
"customer_group": customer_group,
|
||||
"company": company,
|
||||
"conversion_rate": 1,
|
||||
"for_shopping_cart": True,
|
||||
"currency": frappe.db.get_value("Price List", price_list, "currency")
|
||||
})
|
||||
pricing_rule_dict = frappe._dict(
|
||||
{
|
||||
"item_code": item_code,
|
||||
"qty": qty,
|
||||
"stock_qty": qty,
|
||||
"transaction_type": "selling",
|
||||
"price_list": price_list,
|
||||
"customer_group": customer_group,
|
||||
"company": company,
|
||||
"conversion_rate": 1,
|
||||
"for_shopping_cart": True,
|
||||
"currency": frappe.db.get_value("Price List", price_list, "currency"),
|
||||
}
|
||||
)
|
||||
|
||||
if party and party.doctype == "Customer":
|
||||
pricing_rule_dict.update({"customer": party.name})
|
||||
@@ -108,7 +126,9 @@ def get_price(item_code, price_list, customer_group, company, qty=1):
|
||||
if pricing_rule.pricing_rule_for == "Discount Percentage":
|
||||
price_obj.discount_percent = pricing_rule.discount_percentage
|
||||
price_obj.formatted_discount_percent = str(flt(pricing_rule.discount_percentage, 0)) + "%"
|
||||
price_obj.price_list_rate = flt(price_obj.price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0)))
|
||||
price_obj.price_list_rate = flt(
|
||||
price_obj.price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))
|
||||
)
|
||||
|
||||
if pricing_rule.pricing_rule_for == "Rate":
|
||||
rate_discount = flt(mrp) - flt(pricing_rule.price_list_rate)
|
||||
@@ -117,21 +137,33 @@ def get_price(item_code, price_list, customer_group, company, qty=1):
|
||||
price_obj.price_list_rate = pricing_rule.price_list_rate or 0
|
||||
|
||||
if price_obj:
|
||||
price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"])
|
||||
price_obj["formatted_price"] = fmt_money(
|
||||
price_obj["price_list_rate"], currency=price_obj["currency"]
|
||||
)
|
||||
if mrp != price_obj["price_list_rate"]:
|
||||
price_obj["formatted_mrp"] = fmt_money(mrp, 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", cache=True) or 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", cache=True)
|
||||
or price_obj.currency
|
||||
)
|
||||
or ""
|
||||
)
|
||||
|
||||
uom_conversion_factor = frappe.db.sql("""select C.conversion_factor
|
||||
uom_conversion_factor = frappe.db.sql(
|
||||
"""select C.conversion_factor
|
||||
from `tabUOM Conversion Detail` C
|
||||
inner join `tabItem` I on C.parent = I.name and C.uom = I.sales_uom
|
||||
where I.name = %s""", item_code)
|
||||
where I.name = %s""",
|
||||
item_code,
|
||||
)
|
||||
|
||||
uom_conversion_factor = uom_conversion_factor[0][0] if uom_conversion_factor else 1
|
||||
price_obj["formatted_price_sales_uom"] = fmt_money(price_obj["price_list_rate"] * uom_conversion_factor, currency=price_obj["currency"])
|
||||
price_obj["formatted_price_sales_uom"] = fmt_money(
|
||||
price_obj["price_list_rate"] * uom_conversion_factor, currency=price_obj["currency"]
|
||||
)
|
||||
|
||||
if not price_obj["price_list_rate"]:
|
||||
price_obj["price_list_rate"] = 0
|
||||
@@ -144,11 +176,17 @@ def get_price(item_code, price_list, customer_group, company, qty=1):
|
||||
|
||||
return price_obj
|
||||
|
||||
|
||||
def get_non_stock_item_status(item_code, item_warehouse_field):
|
||||
# if item is a product bundle, check if its bundle items are in stock
|
||||
if frappe.db.exists("Product Bundle", item_code):
|
||||
items = frappe.get_doc("Product Bundle", item_code).get_all_children()
|
||||
bundle_warehouse = frappe.db.get_value("Website Item", {"item_code": item_code}, item_warehouse_field)
|
||||
return all(get_web_item_qty_in_stock(d.item_code, item_warehouse_field, bundle_warehouse).in_stock for d in items)
|
||||
bundle_warehouse = frappe.db.get_value(
|
||||
"Website Item", {"item_code": item_code}, item_warehouse_field
|
||||
)
|
||||
return all(
|
||||
get_web_item_qty_in_stock(d.item_code, item_warehouse_field, bundle_warehouse).in_stock
|
||||
for d in items
|
||||
)
|
||||
else:
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user