Sabu Siyad f900a78995
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>
2023-10-17 17:05:44 +05:30

167 lines
4.6 KiB
Python

# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from frappe.utils import cint, flt, fmt_money
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
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:
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_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"),
"doctype": "Quotation",
}
)
if party and party.doctype == "Customer":
pricing_rule_dict.update({"customer": party.name})
pricing_rule = get_pricing_rule_for_item(pricing_rule_dict)
price_obj = price[0]
if pricing_rule:
# price without any rules applied
mrp = price_obj.price_list_rate or 0
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))
)
if pricing_rule.pricing_rule_for == "Rate":
rate_discount = flt(mrp) - flt(pricing_rule.price_list_rate)
if rate_discount > 0:
price_obj.formatted_discount_rate = fmt_money(rate_discount, currency=price_obj["currency"])
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"]
)
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
)
or ""
)
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,
)
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"]
)
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"], price_obj["formatted_mrp"] = "", ""
return price_obj
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
)
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