refactor!: drop ecommerce in favor of webshop (#33265)
* refactor!: remove ecommerce item group field check
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove `e_commerce` directory
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove `get_context` from `item_group`
https://frappeframework.com/docs/v14/user/en/guides/portal-development/context
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove related `./templates`
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(navbar): remove wishlist (ecommerce)
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(js): remove js from scripts
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove `www/all-products`
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove pages and js
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove js/customer_reviews
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(portal utils): remove shopping cart debtor account
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove e_commerce events from hooks
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(web): remove e_commerce js from bundle
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(setup): remove shopping cart setup
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove pages
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor(item): remove website item button
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(payment request): remove `on_payment_authorized`
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: @staticmethod `get_gateway_details`
to avoid monkey patching, in custom apps
https://discuss.erpnext.com/t/how-to-override-method-in-frappe/28786/36
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(pages): remove product page
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(homepage): do not setup website items
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor(workspace): remove link to ecommerce settings
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(www): remove shop-by-category
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(homepage): remove featured product
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor: remove products in homepage
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor(homepage): remove explore button
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor: remove products fields from homepage
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* Revert "refactor!: @staticmethod `get_gateway_details`"
This reverts commit 561bcd96680a930bb92627869502d9346b10611b.
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: remove payment gateway e_commerce import
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* chore: pre-commit
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!: pass `party` into `get_price`
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor: move `get_item_codes_by_attributes` to `utilities/product`
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* refactor!(quotation): input customer group
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
* chore: pre-commit
* refactor: remove custom `navbar_items.html`
* refactor!(item): remove `published_in_website`
* refactor: move `validate_duplicate_website_item` before rename
* test: remove `test_shopping_cart_without_website_item`
* chore: add doctype drop patch
* refactor: removed website item related code
* refactor: removed shopping_cart code
* refactor: removed e-commerce related patches
* refactor: removed website related fields from item group
* fix: patch create_asset_depreciation_schedules_from_assets, KeyError: '0K BU64 AUY'
---------
Signed-off-by: Sabu Siyad <hello@ssiyad.com>
Co-authored-by: Rohit Waghchaure <rohitw1991@gmail.com>
diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py
index e967f70..7897c15 100644
--- a/erpnext/utilities/product.py
+++ b/erpnext/utilities/product.py
@@ -2,93 +2,12 @@
# License: GNU General Public License v3. See license.txt
import frappe
-from frappe.utils import cint, flt, fmt_money, getdate, nowdate
+from frappe.utils import cint, flt, fmt_money
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
-from erpnext.stock.doctype.batch.batch import get_batch_qty
-from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
-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"]
- )
-
- 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
- )
-
- if warehouse and frappe.get_cached_value("Warehouse", warehouse, "is_group") == 1:
- warehouses = get_child_warehouses(warehouse)
- else:
- warehouses = [warehouse] if warehouse else []
-
- total_stock = 0.0
- if warehouses:
- for warehouse in warehouses:
- 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),
- )
-
- if stock_qty:
- total_stock += adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
-
- in_stock = total_stock > 0 and 1 or 0
-
- return frappe._dict(
- {"in_stock": in_stock, "stock_qty": total_stock, "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"])
- expired_batches = get_expired_batches(batches)
- stock_qty = [list(item) for item in stock_qty]
-
- for batch in expired_batches:
- if warehouse:
- stock_qty[0][0] = max(0, stock_qty[0][0] - get_batch_qty(batch, warehouse))
- else:
- stock_qty[0][0] = max(0, stock_qty[0][0] - qty_from_all_warehouses(get_batch_qty(batch)))
-
- if not stock_qty[0][0]:
- break
-
- return stock_qty[0][0] if stock_qty else 0
-
-
-def get_expired_batches(batches):
- """
- :param batches: A list of dict in the form [{'expiry_date': datetime.date(20XX, 1, 1), 'name': 'batch_id'}, ...]
- """
- return [b.name for b in batches if b.expiry_date and b.expiry_date <= getdate(nowdate())]
-
-
-def qty_from_all_warehouses(batch_info):
- """
- :param batch_info: A list of dict in the form [{u'warehouse': u'Stores - I', u'qty': 0.8}, ...]
- """
- qty = 0
- for batch in batch_info:
- qty = qty + batch.qty
-
- return qty
-
-
-def get_price(item_code, price_list, customer_group, company, qty=1):
- from erpnext.e_commerce.shopping_cart.cart import get_party
-
+def get_price(item_code, price_list, customer_group, company, qty=1, party=None):
template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
if price_list:
@@ -106,7 +25,6 @@
)
if price:
- party = get_party()
pricing_rule_dict = frappe._dict(
{
"item_code": item_code,
@@ -187,16 +105,62 @@
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
+def get_item_codes_by_attributes(attribute_filters, template_item_code=None):
+ items = []
+
+ for attribute, values in attribute_filters.items():
+ attribute_values = values
+
+ if not isinstance(attribute_values, list):
+ attribute_values = [attribute_values]
+
+ if not attribute_values:
+ continue
+
+ wheres = []
+ query_values = []
+ for attribute_value in attribute_values:
+ wheres.append("( attribute = %s and attribute_value = %s )")
+ query_values += [attribute, attribute_value]
+
+ attribute_query = " or ".join(wheres)
+
+ if template_item_code:
+ variant_of_query = "AND t2.variant_of = %s"
+ query_values.append(template_item_code)
+ else:
+ variant_of_query = ""
+
+ query = """
+ SELECT
+ t1.parent
+ FROM
+ `tabItem Variant Attribute` t1
+ WHERE
+ 1 = 1
+ AND (
+ {attribute_query}
+ )
+ AND EXISTS (
+ SELECT
+ 1
+ FROM
+ `tabItem` t2
+ WHERE
+ t2.name = t1.parent
+ {variant_of_query}
+ )
+ GROUP BY
+ t1.parent
+ ORDER BY
+ NULL
+ """.format(
+ attribute_query=attribute_query, variant_of_query=variant_of_query
)
- 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
+
+ item_codes = set([r[0] for r in frappe.db.sql(query, query_values)])
+ items.append(item_codes)
+
+ res = list(set.intersection(*items))
+
+ return res