tests: Variant without web item price fetch and add to cart

- Also, optionally get image from template web item for cart if variant has no image
This commit is contained in:
marination
2022-01-21 14:33:30 +05:30
parent 47c8ad0b94
commit 4f7ec25bbe
4 changed files with 91 additions and 27 deletions

View File

@@ -41,7 +41,7 @@ def get_cart_quotation(doc=None):
if not doc.customer_address and addresses:
update_cart_address("billing", addresses[0].name)
print("doc>>", doc, type(doc))
return {
"doc": decorate_quotation_doc(doc),
"shipping_addresses": get_shipping_addresses(party),
@@ -283,12 +283,16 @@ def decorate_quotation_doc(doc):
variant_data = frappe.db.get_values(
"Item",
filters={"item_code": item_code},
fieldname=["variant_of", "item_name"],
fieldname=["variant_of", "item_name", "image"],
as_dict=True
)[0]
item_code = variant_data.variant_of
d.website_item_name = variant_data.item_name
fields = fields[1:]
d.website_item_name = variant_data.item_name
if variant_data.image: # get image from variant or template web item
d.thumbnail = variant_data.image
fields = fields[2:]
d.update(frappe.db.get_value(
"Website Item",

View File

@@ -9,8 +9,8 @@ from frappe.utils import add_months, nowdate
from erpnext.accounts.doctype.tax_rule.tax_rule import ConflictingTaxRule
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
from erpnext.e_commerce.shopping_cart.cart import _get_cart_quotation, get_party, update_cart
from erpnext.tests.utils import create_test_contact_and_address
from erpnext.e_commerce.shopping_cart.cart import _get_cart_quotation, get_cart_quotation, get_party, update_cart
from erpnext.tests.utils import create_test_contact_and_address, change_settings
# test_dependencies = ['Payment Terms Template']
@@ -35,6 +35,7 @@ class TestShoppingCart(unittest.TestCase):
make_website_item(frappe.get_cached_doc("Item", "_Test Item 2"))
def tearDown(self):
frappe.db.rollback()
frappe.set_user("Administrator")
self.disable_shopping_cart()
@@ -129,6 +130,41 @@ class TestShoppingCart(unittest.TestCase):
self.remove_test_quotation(quotation)
@change_settings("E Commerce Settings",{
"company": "_Test Company",
"enabled": 1,
"default_customer_group": "_Test Customer Group",
"price_list": "_Test Price List India",
"show_price": 1
}
)
def test_add_item_variant_without_web_item_to_cart(self):
"Test adding Variants having no Website Items in cart via Template Web Item."
from erpnext.controllers.item_variant import create_variant
from erpnext.e_commerce.doctype.website_item.website_item import make_website_item
from erpnext.stock.doctype.item.test_item import make_item
template_item = make_item("Test-Tshirt-Temp", {
"has_variant": 1,
"variant_based_on": "Item Attribute",
"attributes": [
{"attribute": "Test Size"},
{"attribute": "Test Colour"}
]
})
variant = create_variant("Test-Tshirt-Temp", {
"Test Size": "Small", "Test Colour": "Red"
})
variant.save()
make_website_item(template_item) # publish template not variant
update_cart("Test-Tshirt-Temp-S-R", 1)
cart = get_cart_quotation() # test if cart page gets data without errors
doc = cart.get("doc")
self.assertEqual(doc.get("items")[0].item_name, "Test-Tshirt-Temp-S-R")
def create_tax_rule(self):
tax_rule = frappe.get_test_records("Tax Rule")[0]
try: